"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * ExponentialSaveCompactor stores saves in backed-off buckets, so older
 * saves are kept with lesser granularity.
 */
class ExponentialSaveCompactor {
    constructor(options) {
        this.options = options;
    }
    trim(data, now) {
        const toRemove = [];
        const maxCutoff = now - this.options.maxRetentionMs;
        let currentCutoff = now;
        let lastBucket = this.options.baseBucketMs;
        for (let i = data.length - 1; i >= 0; i--) {
            const time = data[i][0].getTime();
            if (time > currentCutoff || time < maxCutoff) {
                toRemove.push(data[i][1]);
                continue;
            }
            while (time <= currentCutoff) {
                currentCutoff -= lastBucket;
                lastBucket = Math.min(lastBucket * this.options.bucketIncreaseMultiplier, this.options.bucketMaxMs);
            }
        }
        return toRemove;
    }
}
exports.ExponentialSaveCompactor = ExponentialSaveCompactor;
