@visactor/vmind
Version:
<div align="center"> <a href="https://github.com/VisActor#gh-light-mode-only" target="_blank"> <img alt="VisActor Logo" width="200" src="https://github.com/VisActor/.github/blob/main/profile/logo_500_200_light.svg"/> </a> <a href="https://githu
48 lines (43 loc) • 2.08 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.AdwinRowBucketList = void 0;
class AdwinBucketRow {
constructor(maxBuckets = 5, nextBucketRow = null, previousBucketRow = null) {
this.maxBuckets = maxBuckets, this.bucketCount = 0, this.nextBucketRow = nextBucketRow,
this.previousBucketRow = previousBucketRow, null !== nextBucketRow && (nextBucketRow.previousBucketRow = this),
null !== previousBucketRow && (previousBucketRow.nextBucketRow = this), this.bucketSum = new Array(this.maxBuckets + 1).fill(0),
this.bucketVariance = new Array(this.maxBuckets + 1).fill(0);
}
insertBucket(value, variance) {
this.bucketSum[this.bucketCount] = value, this.bucketVariance[this.bucketCount] = variance,
this.bucketCount += 1;
}
compressBucket(numberDeleted) {
const deleteIndex = this.maxBuckets - numberDeleted + 1;
for (let i = 0; i < deleteIndex; i++) this.bucketSum[i] = this.bucketSum[i + numberDeleted],
this.bucketVariance[i] = this.bucketVariance[i + numberDeleted];
for (let i = deleteIndex; i < this.maxBuckets + 1; i++) this.bucketSum[i] = 0, this.bucketVariance[i] = 0;
this.bucketCount -= numberDeleted;
}
}
class AdwinRowBucketList {
constructor(maxBuckets = 5) {
this.maxBuckets = maxBuckets, this.count = 0, this.head = null, this.tail = null,
this._addToHead();
}
_addToHead() {
this.head = new AdwinBucketRow(this.maxBuckets, this.head), null === this.tail && (this.tail = this.head),
this.count += 1;
}
addToTail() {
this.tail = new AdwinBucketRow(this.maxBuckets, null, this.tail), null === this.head && (this.head = this.tail),
this.count += 1;
}
removeFromTail() {
null !== this.tail && (this.tail = this.tail.previousBucketRow, null === this.tail ? this.head = null : this.tail.nextBucketRow = null,
this.count -= 1);
}
}
exports.AdwinRowBucketList = AdwinRowBucketList;
//# sourceMappingURL=bucket.js.map