data-structure-typed 2.2.7 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +9 -0
- package/CHANGELOG.md +1 -1
- package/README.md +14 -3
- package/README_CN.md +119 -275
- package/benchmark/report.html +1 -1
- package/benchmark/report.json +20 -324
- package/dist/cjs/index.cjs +689 -182
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +693 -185
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +689 -182
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +693 -185
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/leetcode/avl-tree-counter.mjs +2957 -0
- package/dist/leetcode/avl-tree-multi-map.mjs +2889 -0
- package/dist/leetcode/avl-tree.mjs +2720 -0
- package/dist/leetcode/binary-tree.mjs +1594 -0
- package/dist/leetcode/bst.mjs +2398 -0
- package/dist/leetcode/deque.mjs +683 -0
- package/dist/leetcode/directed-graph.mjs +1733 -0
- package/dist/leetcode/doubly-linked-list.mjs +709 -0
- package/dist/leetcode/hash-map.mjs +493 -0
- package/dist/leetcode/heap.mjs +542 -0
- package/dist/leetcode/max-heap.mjs +375 -0
- package/dist/leetcode/max-priority-queue.mjs +383 -0
- package/dist/leetcode/min-heap.mjs +363 -0
- package/dist/leetcode/min-priority-queue.mjs +371 -0
- package/dist/leetcode/priority-queue.mjs +363 -0
- package/dist/leetcode/queue.mjs +943 -0
- package/dist/leetcode/red-black-tree.mjs +2765 -0
- package/dist/leetcode/singly-linked-list.mjs +754 -0
- package/dist/leetcode/stack.mjs +217 -0
- package/dist/leetcode/tree-counter.mjs +3039 -0
- package/dist/leetcode/tree-multi-map.mjs +2913 -0
- package/dist/leetcode/trie.mjs +413 -0
- package/dist/leetcode/undirected-graph.mjs +1650 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +25 -27
- package/dist/types/data-structures/binary-tree/bst.d.ts +13 -12
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +151 -21
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/types/interfaces/binary-tree.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +689 -181
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +50 -172
- package/src/data-structures/base/linear-base.ts +2 -12
- package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
- package/src/data-structures/binary-tree/avl-tree.ts +15 -15
- package/src/data-structures/binary-tree/binary-tree.ts +57 -60
- package/src/data-structures/binary-tree/bst.ts +100 -26
- package/src/data-structures/binary-tree/red-black-tree.ts +586 -76
- package/src/data-structures/binary-tree/tree-counter.ts +25 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
- package/src/data-structures/queue/deque.ts +10 -0
- package/src/interfaces/binary-tree.ts +1 -1
- package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +1 -2
- package/test/unit/data-structures/base/iterable-element-base.coverage.test.ts +106 -0
- package/test/unit/data-structures/base/iterable-element-base.more-branches.coverage.test.ts +61 -0
- package/test/unit/data-structures/base/linear-base.array.coverage.test.ts +168 -0
- package/test/unit/data-structures/base/linear-base.concat-else.coverage.test.ts +82 -0
- package/test/unit/data-structures/base/linear-base.coverage.test.ts +72 -0
- package/test/unit/data-structures/base/linear-base.more-branches.coverage.test.ts +417 -0
- package/test/unit/data-structures/binary-tree/avl-tree-counter.more-branches-3.coverage.test.ts +146 -0
- package/test/unit/data-structures/binary-tree/avl-tree-counter.more-branches.coverage.test.ts +93 -0
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +30 -30
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.coverage.test.ts +108 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.more-branches-2.coverage.test.ts +85 -0
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +46 -46
- package/test/unit/data-structures/binary-tree/avl-tree-node.familyPosition-root-left.coverage.test.ts +17 -0
- package/test/unit/data-structures/binary-tree/avl-tree.more-branches-2.coverage.test.ts +99 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +43 -43
- package/test/unit/data-structures/binary-tree/binary-indexed-tree.more-branches.coverage.test.ts +18 -0
- package/test/unit/data-structures/binary-tree/binary-tree.more-branches.coverage.test.ts +56 -0
- package/test/unit/data-structures/binary-tree/binary-tree.remaining-branches.coverage.test.ts +229 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +151 -151
- package/test/unit/data-structures/binary-tree/bst.bound-by-predicate.coverage.test.ts +33 -0
- package/test/unit/data-structures/binary-tree/bst.coverage.test.ts +94 -0
- package/test/unit/data-structures/binary-tree/bst.deletebykey.coverage.test.ts +70 -0
- package/test/unit/data-structures/binary-tree/bst.deletewhere.coverage.test.ts +37 -0
- package/test/unit/data-structures/binary-tree/bst.floor-lower-predicate.coverage.test.ts +29 -0
- package/test/unit/data-structures/binary-tree/bst.floor-setmany.coverage.test.ts +72 -0
- package/test/unit/data-structures/binary-tree/bst.getnode.range-ensure.coverage.test.ts +22 -0
- package/test/unit/data-structures/binary-tree/bst.misc-branches.coverage.test.ts +100 -0
- package/test/unit/data-structures/binary-tree/bst.more-branches-2.coverage.test.ts +133 -0
- package/test/unit/data-structures/binary-tree/bst.more-branches-3.coverage.test.ts +45 -0
- package/test/unit/data-structures/binary-tree/bst.more-branches-4.coverage.test.ts +36 -0
- package/test/unit/data-structures/binary-tree/bst.more-branches-5.coverage.test.ts +40 -0
- package/test/unit/data-structures/binary-tree/bst.more.coverage.test.ts +39 -0
- package/test/unit/data-structures/binary-tree/bst.node-family.coverage.test.ts +29 -0
- package/test/unit/data-structures/binary-tree/bst.range-pruning.coverage.test.ts +43 -0
- package/test/unit/data-structures/binary-tree/bst.search-fastpath.coverage.test.ts +30 -0
- package/test/unit/data-structures/binary-tree/bst.test.ts +124 -154
- package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/red-black-tree.boundary-corruption-repair.coverage.test.ts +66 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.boundary-max-update.coverage.test.ts +18 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.boundary-null.coverage.test.ts +53 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.boundary-stale-cache.coverage.test.ts +25 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.boundary-update.coverage.test.ts +23 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.cache-delete.coverage.test.ts +49 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.cache-edge.coverage.test.ts +37 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.cache-stale-insert.coverage.test.ts +39 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.coverage.test.ts +334 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.delete-fixup.coverage.test.ts +68 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.delete-successor.coverage.test.ts +75 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.factories.coverage.test.ts +26 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-cache-compare-update.coverage.test.ts +74 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-cache-no-update.coverage.test.ts +44 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-cache-nullish.coverage.test.ts +61 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-mapmode-defined.coverage.test.ts +35 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-mapmode-undefined.coverage.test.ts +43 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint-more.coverage.test.ts +99 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.hint.coverage.test.ts +60 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.insert-cache-nullish.coverage.test.ts +29 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.insert-header-parent-nullish.coverage.test.ts +17 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.internal-walk.coverage.test.ts +57 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.minmax-cache.test.ts +65 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.misc-inputs.coverage.test.ts +17 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.more-branches-2.coverage.test.ts +121 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.more-branches-3.coverage.test.ts +55 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.more-branches-4.coverage.test.ts +44 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.predsucc.coverage.test.ts +40 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.remaining-branches.coverage.test.ts +123 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.set-inputs.coverage.test.ts +64 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.setkvnode-parent-cache.coverage.test.ts +79 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.setkvnode-remaining.coverage.test.ts +44 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.setkvnode-uncovered.coverage.test.ts +74 -0
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +141 -141
- package/test/unit/data-structures/binary-tree/red-black-tree.update-branches.coverage.test.ts +30 -0
- package/test/unit/data-structures/binary-tree/segment-tree.more-branches.coverage.test.ts +31 -0
- package/test/unit/data-structures/binary-tree/tree-counter.coverage.test.ts +115 -0
- package/test/unit/data-structures/binary-tree/tree-counter.more-branches.coverage.test.ts +244 -0
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +41 -39
- package/test/unit/data-structures/binary-tree/tree-multi-map.coverage.test.ts +104 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.more-branches-2.coverage.test.ts +59 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +145 -145
- package/test/unit/data-structures/graph/abstract-graph.more-branches-2.coverage.test.ts +40 -0
- package/test/unit/data-structures/graph/abstract-graph.more-branches-3.coverage.test.ts +65 -0
- package/test/unit/data-structures/graph/abstract-graph.more-branches-4.coverage.test.ts +98 -0
- package/test/unit/data-structures/graph/abstract-graph.more-branches-5.coverage.test.ts +51 -0
- package/test/unit/data-structures/graph/abstract-graph.more-branches.coverage.test.ts +62 -0
- package/test/unit/data-structures/graph/directed-graph.more-branches-2.coverage.test.ts +38 -0
- package/test/unit/data-structures/graph/directed-graph.more-branches-3.coverage.test.ts +25 -0
- package/test/unit/data-structures/graph/directed-graph.more-branches.coverage.test.ts +82 -0
- package/test/unit/data-structures/graph/map-graph.more-branches.coverage.test.ts +22 -0
- package/test/unit/data-structures/graph/undirected-graph.more-branches-2.coverage.test.ts +35 -0
- package/test/unit/data-structures/graph/undirected-graph.more-branches.coverage.test.ts +87 -0
- package/test/unit/data-structures/hash/hash-map.more-branches.coverage.test.ts +64 -0
- package/test/unit/data-structures/hash/hash-map.toEntryFn-branch.coverage.test.ts +9 -0
- package/test/unit/data-structures/heap/heap.misc-branches.coverage.test.ts +110 -0
- package/test/unit/data-structures/heap/heap.remaining-branches.coverage.test.ts +22 -0
- package/test/unit/data-structures/heap/max-heap.coverage.test.ts +29 -0
- package/test/unit/data-structures/linked-list/doubly-linked-list.more-branches.coverage.test.ts +72 -0
- package/test/unit/data-structures/linked-list/linked-list.unshiftMany-else.coverage.test.ts +15 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.coverage.test.ts +221 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.more-branches.coverage.test.ts +86 -0
- package/test/unit/data-structures/linked-list/skip-linked-list.more-branches.coverage.test.ts +31 -0
- package/test/unit/data-structures/matrix/matrix.more-branches.coverage.test.ts +81 -0
- package/test/unit/data-structures/matrix/matrix.pivotElement-nullish.coverage.test.ts +28 -0
- package/test/unit/data-structures/priority-queue/max-priority-queue.more-branches.coverage.test.ts +10 -0
- package/test/unit/data-structures/priority-queue/priority-queue.coverage.test.ts +21 -0
- package/test/unit/data-structures/queue/deque.coverage.test.ts +173 -0
- package/test/unit/data-structures/queue/deque.more-branches-2.coverage.test.ts +39 -0
- package/test/unit/data-structures/queue/deque.more-branches-3.coverage.test.ts +9 -0
- package/test/unit/data-structures/queue/deque.more-branches.coverage.test.ts +95 -0
- package/test/unit/data-structures/queue/queue.coverage.test.ts +138 -0
- package/test/unit/data-structures/queue/queue.more-branches-2.coverage.test.ts +27 -0
- package/test/unit/data-structures/stack/stack.coverage.test.ts +112 -0
- package/test/unit/data-structures/tree/tree.more-branches.coverage.test.ts +9 -0
- package/test/unit/data-structures/trie/trie.more-branches-2.coverage.test.ts +51 -0
- package/test/utils/patch.ts +33 -0
- package/tsup.config.js +50 -21
- package/tsup.umd.config.js +29 -0
- package/tsup.node.config.js +0 -83
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var IterableElementBase = class {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "IterableElementBase");
|
|
6
|
+
}
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (options) {
|
|
9
|
+
const { toElementFn } = options;
|
|
10
|
+
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
11
|
+
else if (toElementFn) throw new TypeError("toElementFn must be a function type");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
_toElementFn;
|
|
15
|
+
get toElementFn() {
|
|
16
|
+
return this._toElementFn;
|
|
17
|
+
}
|
|
18
|
+
*[Symbol.iterator](...args) {
|
|
19
|
+
yield* this._getIterator(...args);
|
|
20
|
+
}
|
|
21
|
+
*values() {
|
|
22
|
+
for (const item of this) yield item;
|
|
23
|
+
}
|
|
24
|
+
every(predicate, thisArg) {
|
|
25
|
+
let index = 0;
|
|
26
|
+
for (const item of this) {
|
|
27
|
+
if (thisArg === void 0) {
|
|
28
|
+
if (!predicate(item, index++, this)) return false;
|
|
29
|
+
} else {
|
|
30
|
+
const fn = predicate;
|
|
31
|
+
if (!fn.call(thisArg, item, index++, this)) return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
some(predicate, thisArg) {
|
|
37
|
+
let index = 0;
|
|
38
|
+
for (const item of this) {
|
|
39
|
+
if (thisArg === void 0) {
|
|
40
|
+
if (predicate(item, index++, this)) return true;
|
|
41
|
+
} else {
|
|
42
|
+
const fn = predicate;
|
|
43
|
+
if (fn.call(thisArg, item, index++, this)) return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
forEach(callbackfn, thisArg) {
|
|
49
|
+
let index = 0;
|
|
50
|
+
for (const item of this) {
|
|
51
|
+
if (thisArg === void 0) {
|
|
52
|
+
callbackfn(item, index++, this);
|
|
53
|
+
} else {
|
|
54
|
+
const fn = callbackfn;
|
|
55
|
+
fn.call(thisArg, item, index++, this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
find(predicate, thisArg) {
|
|
60
|
+
let index = 0;
|
|
61
|
+
for (const item of this) {
|
|
62
|
+
if (thisArg === void 0) {
|
|
63
|
+
if (predicate(item, index++, this)) return item;
|
|
64
|
+
} else {
|
|
65
|
+
const fn = predicate;
|
|
66
|
+
if (fn.call(thisArg, item, index++, this)) return item;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
has(element) {
|
|
72
|
+
for (const ele of this) if (ele === element) return true;
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
reduce(callbackfn, initialValue) {
|
|
76
|
+
let index = 0;
|
|
77
|
+
const iter = this[Symbol.iterator]();
|
|
78
|
+
let acc;
|
|
79
|
+
if (arguments.length >= 2) {
|
|
80
|
+
acc = initialValue;
|
|
81
|
+
} else {
|
|
82
|
+
const first = iter.next();
|
|
83
|
+
if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
|
|
84
|
+
acc = first.value;
|
|
85
|
+
index = 1;
|
|
86
|
+
}
|
|
87
|
+
for (const value of iter) {
|
|
88
|
+
acc = callbackfn(acc, value, index++, this);
|
|
89
|
+
}
|
|
90
|
+
return acc;
|
|
91
|
+
}
|
|
92
|
+
toArray() {
|
|
93
|
+
return [...this];
|
|
94
|
+
}
|
|
95
|
+
toVisual() {
|
|
96
|
+
return [...this];
|
|
97
|
+
}
|
|
98
|
+
print() {
|
|
99
|
+
console.log(this.toVisual());
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var Heap = class _Heap extends IterableElementBase {
|
|
103
|
+
static {
|
|
104
|
+
__name(this, "Heap");
|
|
105
|
+
}
|
|
106
|
+
_equals = Object.is;
|
|
107
|
+
constructor(elements = [], options) {
|
|
108
|
+
super(options);
|
|
109
|
+
if (options) {
|
|
110
|
+
const { comparator } = options;
|
|
111
|
+
if (comparator) this._comparator = comparator;
|
|
112
|
+
}
|
|
113
|
+
this.addMany(elements);
|
|
114
|
+
}
|
|
115
|
+
_elements = [];
|
|
116
|
+
get elements() {
|
|
117
|
+
return this._elements;
|
|
118
|
+
}
|
|
119
|
+
get size() {
|
|
120
|
+
return this.elements.length;
|
|
121
|
+
}
|
|
122
|
+
get leaf() {
|
|
123
|
+
return this.elements[this.size - 1] ?? void 0;
|
|
124
|
+
}
|
|
125
|
+
static from(elements, options) {
|
|
126
|
+
return new this(elements, options);
|
|
127
|
+
}
|
|
128
|
+
static heapify(elements, options) {
|
|
129
|
+
return new _Heap(elements, options);
|
|
130
|
+
}
|
|
131
|
+
add(element) {
|
|
132
|
+
this._elements.push(element);
|
|
133
|
+
return this._bubbleUp(this.elements.length - 1);
|
|
134
|
+
}
|
|
135
|
+
addMany(elements) {
|
|
136
|
+
const flags = [];
|
|
137
|
+
for (const el of elements) {
|
|
138
|
+
if (this.toElementFn) {
|
|
139
|
+
const ok = this.add(this.toElementFn(el));
|
|
140
|
+
flags.push(ok);
|
|
141
|
+
} else {
|
|
142
|
+
const ok = this.add(el);
|
|
143
|
+
flags.push(ok);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return flags;
|
|
147
|
+
}
|
|
148
|
+
poll() {
|
|
149
|
+
if (this.elements.length === 0) return;
|
|
150
|
+
const value = this.elements[0];
|
|
151
|
+
const last = this.elements.pop();
|
|
152
|
+
if (this.elements.length) {
|
|
153
|
+
this.elements[0] = last;
|
|
154
|
+
this._sinkDown(0, this.elements.length >> 1);
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
peek() {
|
|
159
|
+
return this.elements[0];
|
|
160
|
+
}
|
|
161
|
+
isEmpty() {
|
|
162
|
+
return this.size === 0;
|
|
163
|
+
}
|
|
164
|
+
clear() {
|
|
165
|
+
this._elements = [];
|
|
166
|
+
}
|
|
167
|
+
refill(elements) {
|
|
168
|
+
this._elements = Array.from(elements);
|
|
169
|
+
return this.fix();
|
|
170
|
+
}
|
|
171
|
+
has(element) {
|
|
172
|
+
for (const el of this.elements) if (this._equals(el, element)) return true;
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
delete(element) {
|
|
176
|
+
let index = -1;
|
|
177
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
178
|
+
if (this._equals(this.elements[i], element)) {
|
|
179
|
+
index = i;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (index < 0) return false;
|
|
184
|
+
if (index === 0) {
|
|
185
|
+
this.poll();
|
|
186
|
+
} else if (index === this.elements.length - 1) {
|
|
187
|
+
this.elements.pop();
|
|
188
|
+
} else {
|
|
189
|
+
this.elements.splice(index, 1, this.elements.pop());
|
|
190
|
+
this._bubbleUp(index);
|
|
191
|
+
this._sinkDown(index, this.elements.length >> 1);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
deleteBy(predicate) {
|
|
196
|
+
let idx = -1;
|
|
197
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
198
|
+
if (predicate(this.elements[i], i, this)) {
|
|
199
|
+
idx = i;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (idx < 0) return false;
|
|
204
|
+
if (idx === 0) {
|
|
205
|
+
this.poll();
|
|
206
|
+
} else if (idx === this.elements.length - 1) {
|
|
207
|
+
this.elements.pop();
|
|
208
|
+
} else {
|
|
209
|
+
this.elements.splice(idx, 1, this.elements.pop());
|
|
210
|
+
this._bubbleUp(idx);
|
|
211
|
+
this._sinkDown(idx, this.elements.length >> 1);
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
setEquality(equals) {
|
|
216
|
+
this._equals = equals;
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
dfs(order = "PRE") {
|
|
220
|
+
const result = [];
|
|
221
|
+
const _dfs = __name((index) => {
|
|
222
|
+
const left = 2 * index + 1, right = left + 1;
|
|
223
|
+
if (index < this.size) {
|
|
224
|
+
if (order === "IN") {
|
|
225
|
+
_dfs(left);
|
|
226
|
+
result.push(this.elements[index]);
|
|
227
|
+
_dfs(right);
|
|
228
|
+
} else if (order === "PRE") {
|
|
229
|
+
result.push(this.elements[index]);
|
|
230
|
+
_dfs(left);
|
|
231
|
+
_dfs(right);
|
|
232
|
+
} else if (order === "POST") {
|
|
233
|
+
_dfs(left);
|
|
234
|
+
_dfs(right);
|
|
235
|
+
result.push(this.elements[index]);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}, "_dfs");
|
|
239
|
+
_dfs(0);
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
fix() {
|
|
243
|
+
const results = [];
|
|
244
|
+
for (let i = Math.floor(this.size / 2) - 1; i >= 0; i--) {
|
|
245
|
+
results.push(this._sinkDown(i, this.elements.length >> 1));
|
|
246
|
+
}
|
|
247
|
+
return results;
|
|
248
|
+
}
|
|
249
|
+
sort() {
|
|
250
|
+
const visited = [];
|
|
251
|
+
const cloned = this._createInstance();
|
|
252
|
+
for (const x of this.elements) cloned.add(x);
|
|
253
|
+
while (!cloned.isEmpty()) {
|
|
254
|
+
const top = cloned.poll();
|
|
255
|
+
if (top !== void 0) visited.push(top);
|
|
256
|
+
}
|
|
257
|
+
return visited;
|
|
258
|
+
}
|
|
259
|
+
clone() {
|
|
260
|
+
const next = this._createInstance();
|
|
261
|
+
for (const x of this.elements) next.add(x);
|
|
262
|
+
return next;
|
|
263
|
+
}
|
|
264
|
+
filter(callback, thisArg) {
|
|
265
|
+
const out = this._createInstance();
|
|
266
|
+
let i = 0;
|
|
267
|
+
for (const x of this) {
|
|
268
|
+
if (thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this)) {
|
|
269
|
+
out.add(x);
|
|
270
|
+
} else {
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
map(callback, options, thisArg) {
|
|
277
|
+
const { comparator, toElementFn, ...rest } = options ?? {};
|
|
278
|
+
if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
|
|
279
|
+
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
280
|
+
let i = 0;
|
|
281
|
+
for (const x of this) {
|
|
282
|
+
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
283
|
+
out.add(v);
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
mapSame(callback, thisArg) {
|
|
288
|
+
const out = this._createInstance();
|
|
289
|
+
let i = 0;
|
|
290
|
+
for (const x of this) {
|
|
291
|
+
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
292
|
+
out.add(v);
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
_DEFAULT_COMPARATOR = __name((a, b) => {
|
|
297
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
298
|
+
throw TypeError("When comparing object types, define a custom comparator in options.");
|
|
299
|
+
}
|
|
300
|
+
if (a > b) return 1;
|
|
301
|
+
if (a < b) return -1;
|
|
302
|
+
return 0;
|
|
303
|
+
}, "_DEFAULT_COMPARATOR");
|
|
304
|
+
_comparator = this._DEFAULT_COMPARATOR;
|
|
305
|
+
get comparator() {
|
|
306
|
+
return this._comparator;
|
|
307
|
+
}
|
|
308
|
+
*_getIterator() {
|
|
309
|
+
for (const element of this.elements) yield element;
|
|
310
|
+
}
|
|
311
|
+
_bubbleUp(index) {
|
|
312
|
+
const element = this.elements[index];
|
|
313
|
+
while (index > 0) {
|
|
314
|
+
const parent = index - 1 >> 1;
|
|
315
|
+
const parentItem = this.elements[parent];
|
|
316
|
+
if (this.comparator(parentItem, element) <= 0) break;
|
|
317
|
+
this.elements[index] = parentItem;
|
|
318
|
+
index = parent;
|
|
319
|
+
}
|
|
320
|
+
this.elements[index] = element;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
_sinkDown(index, halfLength) {
|
|
324
|
+
const element = this.elements[index];
|
|
325
|
+
while (index < halfLength) {
|
|
326
|
+
let left = index << 1 | 1;
|
|
327
|
+
const right = left + 1;
|
|
328
|
+
let minItem = this.elements[left];
|
|
329
|
+
if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
|
|
330
|
+
left = right;
|
|
331
|
+
minItem = this.elements[right];
|
|
332
|
+
}
|
|
333
|
+
if (this.comparator(minItem, element) >= 0) break;
|
|
334
|
+
this.elements[index] = minItem;
|
|
335
|
+
index = left;
|
|
336
|
+
}
|
|
337
|
+
this.elements[index] = element;
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
_createInstance(options) {
|
|
341
|
+
const Ctor = this.constructor;
|
|
342
|
+
const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
343
|
+
return next;
|
|
344
|
+
}
|
|
345
|
+
_createLike(elements = [], options) {
|
|
346
|
+
const Ctor = this.constructor;
|
|
347
|
+
return new Ctor(elements, options);
|
|
348
|
+
}
|
|
349
|
+
_spawnLike(options) {
|
|
350
|
+
return this._createLike([], options);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var MinHeap = class extends Heap {
|
|
354
|
+
static {
|
|
355
|
+
__name(this, "MinHeap");
|
|
356
|
+
}
|
|
357
|
+
constructor(elements = [], options) {
|
|
358
|
+
super(elements, options);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
export {
|
|
362
|
+
MinHeap
|
|
363
|
+
};
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
var IterableElementBase = class {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "IterableElementBase");
|
|
6
|
+
}
|
|
7
|
+
constructor(options) {
|
|
8
|
+
if (options) {
|
|
9
|
+
const { toElementFn } = options;
|
|
10
|
+
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
11
|
+
else if (toElementFn) throw new TypeError("toElementFn must be a function type");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
_toElementFn;
|
|
15
|
+
get toElementFn() {
|
|
16
|
+
return this._toElementFn;
|
|
17
|
+
}
|
|
18
|
+
*[Symbol.iterator](...args) {
|
|
19
|
+
yield* this._getIterator(...args);
|
|
20
|
+
}
|
|
21
|
+
*values() {
|
|
22
|
+
for (const item of this) yield item;
|
|
23
|
+
}
|
|
24
|
+
every(predicate, thisArg) {
|
|
25
|
+
let index = 0;
|
|
26
|
+
for (const item of this) {
|
|
27
|
+
if (thisArg === void 0) {
|
|
28
|
+
if (!predicate(item, index++, this)) return false;
|
|
29
|
+
} else {
|
|
30
|
+
const fn = predicate;
|
|
31
|
+
if (!fn.call(thisArg, item, index++, this)) return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
some(predicate, thisArg) {
|
|
37
|
+
let index = 0;
|
|
38
|
+
for (const item of this) {
|
|
39
|
+
if (thisArg === void 0) {
|
|
40
|
+
if (predicate(item, index++, this)) return true;
|
|
41
|
+
} else {
|
|
42
|
+
const fn = predicate;
|
|
43
|
+
if (fn.call(thisArg, item, index++, this)) return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
forEach(callbackfn, thisArg) {
|
|
49
|
+
let index = 0;
|
|
50
|
+
for (const item of this) {
|
|
51
|
+
if (thisArg === void 0) {
|
|
52
|
+
callbackfn(item, index++, this);
|
|
53
|
+
} else {
|
|
54
|
+
const fn = callbackfn;
|
|
55
|
+
fn.call(thisArg, item, index++, this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
find(predicate, thisArg) {
|
|
60
|
+
let index = 0;
|
|
61
|
+
for (const item of this) {
|
|
62
|
+
if (thisArg === void 0) {
|
|
63
|
+
if (predicate(item, index++, this)) return item;
|
|
64
|
+
} else {
|
|
65
|
+
const fn = predicate;
|
|
66
|
+
if (fn.call(thisArg, item, index++, this)) return item;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
has(element) {
|
|
72
|
+
for (const ele of this) if (ele === element) return true;
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
reduce(callbackfn, initialValue) {
|
|
76
|
+
let index = 0;
|
|
77
|
+
const iter = this[Symbol.iterator]();
|
|
78
|
+
let acc;
|
|
79
|
+
if (arguments.length >= 2) {
|
|
80
|
+
acc = initialValue;
|
|
81
|
+
} else {
|
|
82
|
+
const first = iter.next();
|
|
83
|
+
if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
|
|
84
|
+
acc = first.value;
|
|
85
|
+
index = 1;
|
|
86
|
+
}
|
|
87
|
+
for (const value of iter) {
|
|
88
|
+
acc = callbackfn(acc, value, index++, this);
|
|
89
|
+
}
|
|
90
|
+
return acc;
|
|
91
|
+
}
|
|
92
|
+
toArray() {
|
|
93
|
+
return [...this];
|
|
94
|
+
}
|
|
95
|
+
toVisual() {
|
|
96
|
+
return [...this];
|
|
97
|
+
}
|
|
98
|
+
print() {
|
|
99
|
+
console.log(this.toVisual());
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var Heap = class _Heap extends IterableElementBase {
|
|
103
|
+
static {
|
|
104
|
+
__name(this, "Heap");
|
|
105
|
+
}
|
|
106
|
+
_equals = Object.is;
|
|
107
|
+
constructor(elements = [], options) {
|
|
108
|
+
super(options);
|
|
109
|
+
if (options) {
|
|
110
|
+
const { comparator } = options;
|
|
111
|
+
if (comparator) this._comparator = comparator;
|
|
112
|
+
}
|
|
113
|
+
this.addMany(elements);
|
|
114
|
+
}
|
|
115
|
+
_elements = [];
|
|
116
|
+
get elements() {
|
|
117
|
+
return this._elements;
|
|
118
|
+
}
|
|
119
|
+
get size() {
|
|
120
|
+
return this.elements.length;
|
|
121
|
+
}
|
|
122
|
+
get leaf() {
|
|
123
|
+
return this.elements[this.size - 1] ?? void 0;
|
|
124
|
+
}
|
|
125
|
+
static from(elements, options) {
|
|
126
|
+
return new this(elements, options);
|
|
127
|
+
}
|
|
128
|
+
static heapify(elements, options) {
|
|
129
|
+
return new _Heap(elements, options);
|
|
130
|
+
}
|
|
131
|
+
add(element) {
|
|
132
|
+
this._elements.push(element);
|
|
133
|
+
return this._bubbleUp(this.elements.length - 1);
|
|
134
|
+
}
|
|
135
|
+
addMany(elements) {
|
|
136
|
+
const flags = [];
|
|
137
|
+
for (const el of elements) {
|
|
138
|
+
if (this.toElementFn) {
|
|
139
|
+
const ok = this.add(this.toElementFn(el));
|
|
140
|
+
flags.push(ok);
|
|
141
|
+
} else {
|
|
142
|
+
const ok = this.add(el);
|
|
143
|
+
flags.push(ok);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return flags;
|
|
147
|
+
}
|
|
148
|
+
poll() {
|
|
149
|
+
if (this.elements.length === 0) return;
|
|
150
|
+
const value = this.elements[0];
|
|
151
|
+
const last = this.elements.pop();
|
|
152
|
+
if (this.elements.length) {
|
|
153
|
+
this.elements[0] = last;
|
|
154
|
+
this._sinkDown(0, this.elements.length >> 1);
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
peek() {
|
|
159
|
+
return this.elements[0];
|
|
160
|
+
}
|
|
161
|
+
isEmpty() {
|
|
162
|
+
return this.size === 0;
|
|
163
|
+
}
|
|
164
|
+
clear() {
|
|
165
|
+
this._elements = [];
|
|
166
|
+
}
|
|
167
|
+
refill(elements) {
|
|
168
|
+
this._elements = Array.from(elements);
|
|
169
|
+
return this.fix();
|
|
170
|
+
}
|
|
171
|
+
has(element) {
|
|
172
|
+
for (const el of this.elements) if (this._equals(el, element)) return true;
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
delete(element) {
|
|
176
|
+
let index = -1;
|
|
177
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
178
|
+
if (this._equals(this.elements[i], element)) {
|
|
179
|
+
index = i;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (index < 0) return false;
|
|
184
|
+
if (index === 0) {
|
|
185
|
+
this.poll();
|
|
186
|
+
} else if (index === this.elements.length - 1) {
|
|
187
|
+
this.elements.pop();
|
|
188
|
+
} else {
|
|
189
|
+
this.elements.splice(index, 1, this.elements.pop());
|
|
190
|
+
this._bubbleUp(index);
|
|
191
|
+
this._sinkDown(index, this.elements.length >> 1);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
deleteBy(predicate) {
|
|
196
|
+
let idx = -1;
|
|
197
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
198
|
+
if (predicate(this.elements[i], i, this)) {
|
|
199
|
+
idx = i;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (idx < 0) return false;
|
|
204
|
+
if (idx === 0) {
|
|
205
|
+
this.poll();
|
|
206
|
+
} else if (idx === this.elements.length - 1) {
|
|
207
|
+
this.elements.pop();
|
|
208
|
+
} else {
|
|
209
|
+
this.elements.splice(idx, 1, this.elements.pop());
|
|
210
|
+
this._bubbleUp(idx);
|
|
211
|
+
this._sinkDown(idx, this.elements.length >> 1);
|
|
212
|
+
}
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
setEquality(equals) {
|
|
216
|
+
this._equals = equals;
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
dfs(order = "PRE") {
|
|
220
|
+
const result = [];
|
|
221
|
+
const _dfs = __name((index) => {
|
|
222
|
+
const left = 2 * index + 1, right = left + 1;
|
|
223
|
+
if (index < this.size) {
|
|
224
|
+
if (order === "IN") {
|
|
225
|
+
_dfs(left);
|
|
226
|
+
result.push(this.elements[index]);
|
|
227
|
+
_dfs(right);
|
|
228
|
+
} else if (order === "PRE") {
|
|
229
|
+
result.push(this.elements[index]);
|
|
230
|
+
_dfs(left);
|
|
231
|
+
_dfs(right);
|
|
232
|
+
} else if (order === "POST") {
|
|
233
|
+
_dfs(left);
|
|
234
|
+
_dfs(right);
|
|
235
|
+
result.push(this.elements[index]);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}, "_dfs");
|
|
239
|
+
_dfs(0);
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
fix() {
|
|
243
|
+
const results = [];
|
|
244
|
+
for (let i = Math.floor(this.size / 2) - 1; i >= 0; i--) {
|
|
245
|
+
results.push(this._sinkDown(i, this.elements.length >> 1));
|
|
246
|
+
}
|
|
247
|
+
return results;
|
|
248
|
+
}
|
|
249
|
+
sort() {
|
|
250
|
+
const visited = [];
|
|
251
|
+
const cloned = this._createInstance();
|
|
252
|
+
for (const x of this.elements) cloned.add(x);
|
|
253
|
+
while (!cloned.isEmpty()) {
|
|
254
|
+
const top = cloned.poll();
|
|
255
|
+
if (top !== void 0) visited.push(top);
|
|
256
|
+
}
|
|
257
|
+
return visited;
|
|
258
|
+
}
|
|
259
|
+
clone() {
|
|
260
|
+
const next = this._createInstance();
|
|
261
|
+
for (const x of this.elements) next.add(x);
|
|
262
|
+
return next;
|
|
263
|
+
}
|
|
264
|
+
filter(callback, thisArg) {
|
|
265
|
+
const out = this._createInstance();
|
|
266
|
+
let i = 0;
|
|
267
|
+
for (const x of this) {
|
|
268
|
+
if (thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this)) {
|
|
269
|
+
out.add(x);
|
|
270
|
+
} else {
|
|
271
|
+
i++;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
map(callback, options, thisArg) {
|
|
277
|
+
const { comparator, toElementFn, ...rest } = options ?? {};
|
|
278
|
+
if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
|
|
279
|
+
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
280
|
+
let i = 0;
|
|
281
|
+
for (const x of this) {
|
|
282
|
+
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
283
|
+
out.add(v);
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
mapSame(callback, thisArg) {
|
|
288
|
+
const out = this._createInstance();
|
|
289
|
+
let i = 0;
|
|
290
|
+
for (const x of this) {
|
|
291
|
+
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
292
|
+
out.add(v);
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
_DEFAULT_COMPARATOR = __name((a, b) => {
|
|
297
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
298
|
+
throw TypeError("When comparing object types, define a custom comparator in options.");
|
|
299
|
+
}
|
|
300
|
+
if (a > b) return 1;
|
|
301
|
+
if (a < b) return -1;
|
|
302
|
+
return 0;
|
|
303
|
+
}, "_DEFAULT_COMPARATOR");
|
|
304
|
+
_comparator = this._DEFAULT_COMPARATOR;
|
|
305
|
+
get comparator() {
|
|
306
|
+
return this._comparator;
|
|
307
|
+
}
|
|
308
|
+
*_getIterator() {
|
|
309
|
+
for (const element of this.elements) yield element;
|
|
310
|
+
}
|
|
311
|
+
_bubbleUp(index) {
|
|
312
|
+
const element = this.elements[index];
|
|
313
|
+
while (index > 0) {
|
|
314
|
+
const parent = index - 1 >> 1;
|
|
315
|
+
const parentItem = this.elements[parent];
|
|
316
|
+
if (this.comparator(parentItem, element) <= 0) break;
|
|
317
|
+
this.elements[index] = parentItem;
|
|
318
|
+
index = parent;
|
|
319
|
+
}
|
|
320
|
+
this.elements[index] = element;
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
_sinkDown(index, halfLength) {
|
|
324
|
+
const element = this.elements[index];
|
|
325
|
+
while (index < halfLength) {
|
|
326
|
+
let left = index << 1 | 1;
|
|
327
|
+
const right = left + 1;
|
|
328
|
+
let minItem = this.elements[left];
|
|
329
|
+
if (right < this.elements.length && this.comparator(minItem, this.elements[right]) > 0) {
|
|
330
|
+
left = right;
|
|
331
|
+
minItem = this.elements[right];
|
|
332
|
+
}
|
|
333
|
+
if (this.comparator(minItem, element) >= 0) break;
|
|
334
|
+
this.elements[index] = minItem;
|
|
335
|
+
index = left;
|
|
336
|
+
}
|
|
337
|
+
this.elements[index] = element;
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
_createInstance(options) {
|
|
341
|
+
const Ctor = this.constructor;
|
|
342
|
+
const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
343
|
+
return next;
|
|
344
|
+
}
|
|
345
|
+
_createLike(elements = [], options) {
|
|
346
|
+
const Ctor = this.constructor;
|
|
347
|
+
return new Ctor(elements, options);
|
|
348
|
+
}
|
|
349
|
+
_spawnLike(options) {
|
|
350
|
+
return this._createLike([], options);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var PriorityQueue = class extends Heap {
|
|
354
|
+
static {
|
|
355
|
+
__name(this, "PriorityQueue");
|
|
356
|
+
}
|
|
357
|
+
constructor(elements = [], options) {
|
|
358
|
+
super(elements, options);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var MinPriorityQueue = class extends PriorityQueue {
|
|
362
|
+
static {
|
|
363
|
+
__name(this, "MinPriorityQueue");
|
|
364
|
+
}
|
|
365
|
+
constructor(elements = [], options) {
|
|
366
|
+
super(elements, options);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
export {
|
|
370
|
+
MinPriorityQueue
|
|
371
|
+
};
|