This commit is contained in:
2025-11-11 00:04:55 -06:00
parent a76ad41fde
commit 40538eddfd
6405 changed files with 1289756 additions and 0 deletions

16
node_modules/sweet-collections/dist/heap/Heap.d.ts generated vendored Normal file
View File

@ -0,0 +1,16 @@
export declare class Heap<T> {
private heap;
private readonly comparator;
constructor(comparator: (a: T, b: T) => boolean);
push(...values: T[]): this;
peek(): T;
pop(): T;
replace(value: T): T;
clear(): void;
toArray(): T[];
get size(): number;
private greater;
private swap;
private siftUp;
private siftDown;
}

70
node_modules/sweet-collections/dist/heap/Heap.js generated vendored Normal file
View File

@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Heap = void 0;
const parent = (i) => ((i + 1) >>> 1) - 1;
const left = (i) => (i << 1) + 1;
const right = (i) => (i + 1) << 1;
class Heap {
constructor(comparator) {
this.comparator = comparator;
this.heap = [];
}
push(...values) {
for (const item of values) {
this.heap.push(item);
this.siftUp();
}
return this;
}
peek() {
return this.heap[0];
}
pop() {
const poppedValue = this.peek();
const bottom = this.size - 1;
if (bottom > 0) {
this.swap(0, bottom);
}
this.heap.pop();
this.siftDown();
return poppedValue;
}
replace(value) {
const replacedValue = this.peek();
this.heap[0] = value;
this.siftDown();
return replacedValue;
}
clear() {
this.heap = [];
}
toArray() {
return this.heap;
}
get size() {
return this.heap.length;
}
greater(i, j) {
return this.comparator(this.heap[i], this.heap[j]);
}
swap(i, j) {
[this.heap[i], this.heap[j]] = [this.heap[j], this.heap[i]];
}
siftUp() {
let node = this.size - 1;
while (node > 0 && this.greater(node, parent(node))) {
this.swap(node, parent(node));
node = parent(node);
}
}
siftDown() {
let node = 0;
while ((left(node) < this.size && this.greater(left(node), node)) ||
(right(node) < this.size && this.greater(right(node), node))) {
const maxChild = right(node) < this.size && this.greater(right(node), left(node)) ? right(node) : left(node);
this.swap(node, maxChild);
node = maxChild;
}
}
}
exports.Heap = Heap;

1
node_modules/sweet-collections/dist/heap/index.d.ts generated vendored Normal file
View File

@ -0,0 +1 @@
export * from './Heap';

13
node_modules/sweet-collections/dist/heap/index.js generated vendored Normal file
View File

@ -0,0 +1,13 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./Heap"), exports);