vulcain-corejs
Version: 
Vulcain micro-service framework
30 lines (28 loc) • 898 B
JavaScript
"use strict";
class PercentileBucket {
    constructor(dataLength = 100) {
        this.dataLength = dataLength;
        this.pos = 0;
        this.length = 0;
        this.bucketValues = [];
    }
    addValue(value) {
        this.bucketValues[this.pos] = value;
        this.pos = (this.pos + 1) % this.dataLength; // roll over
        if (this.length < this.dataLength)
            this.length = this.length + 1;
    }
    get values() {
        if (this.length === 0)
            return null;
        return this.length < this.dataLength ? this.bucketValues.slice(0, this.length) : this.bucketValues;
    }
    reset(windowStart) {
        this.windowStart = windowStart;
        this.pos = this.length = 0;
        this.bucketValues = [];
    }
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PercentileBucket;
//# sourceMappingURL=percentileBucket.js.map