awa
This commit is contained in:
44
_internal/editor/esm/vs/base/common/numbers.js
Normal file
44
_internal/editor/esm/vs/base/common/numbers.js
Normal file
@@ -0,0 +1,44 @@
|
||||
export function clamp(value, min, max) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
export class MovingAverage {
|
||||
constructor() {
|
||||
this._n = 1;
|
||||
this._val = 0;
|
||||
}
|
||||
update(value) {
|
||||
this._val = this._val + (value - this._val) / this._n;
|
||||
this._n += 1;
|
||||
return this._val;
|
||||
}
|
||||
get value() {
|
||||
return this._val;
|
||||
}
|
||||
}
|
||||
export class SlidingWindowAverage {
|
||||
constructor(size) {
|
||||
this._n = 0;
|
||||
this._val = 0;
|
||||
this._values = [];
|
||||
this._index = 0;
|
||||
this._sum = 0;
|
||||
this._values = new Array(size);
|
||||
this._values.fill(0, 0, size);
|
||||
}
|
||||
update(value) {
|
||||
const oldValue = this._values[this._index];
|
||||
this._values[this._index] = value;
|
||||
this._index = (this._index + 1) % this._values.length;
|
||||
this._sum -= oldValue;
|
||||
this._sum += value;
|
||||
if (this._n < this._values.length) {
|
||||
this._n += 1;
|
||||
}
|
||||
this._val = this._sum / this._n;
|
||||
return this._val;
|
||||
}
|
||||
get value() {
|
||||
return this._val;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=numbers.js.map
|
||||
Reference in New Issue
Block a user