data-structure-typed 2.5.1 → 2.5.3
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/CHANGELOG.md +5 -1
- package/MIGRATION.md +169 -0
- package/README.md +135 -23
- package/README_CN.md +551 -143
- package/SPECIFICATION.md +20 -14
- package/SPECIFICATION.zh-CN.md +20 -14
- package/dist/cjs/binary-tree.cjs +6460 -1591
- package/dist/cjs/graph.cjs +440 -20
- package/dist/cjs/hash.cjs +125 -22
- package/dist/cjs/heap.cjs +196 -47
- package/dist/cjs/index.cjs +8486 -2429
- package/dist/cjs/linked-list.cjs +456 -31
- package/dist/cjs/matrix.cjs +79 -9
- package/dist/cjs/priority-queue.cjs +193 -44
- package/dist/cjs/queue.cjs +391 -2
- package/dist/cjs/stack.cjs +92 -6
- package/dist/cjs/trie.cjs +122 -28
- package/dist/cjs-legacy/binary-tree.cjs +6484 -1612
- package/dist/cjs-legacy/graph.cjs +440 -20
- package/dist/cjs-legacy/hash.cjs +125 -22
- package/dist/cjs-legacy/heap.cjs +196 -47
- package/dist/cjs-legacy/index.cjs +8654 -2594
- package/dist/cjs-legacy/linked-list.cjs +456 -31
- package/dist/cjs-legacy/matrix.cjs +79 -9
- package/dist/cjs-legacy/priority-queue.cjs +193 -44
- package/dist/cjs-legacy/queue.cjs +391 -2
- package/dist/cjs-legacy/stack.cjs +92 -6
- package/dist/cjs-legacy/trie.cjs +122 -28
- package/dist/esm/binary-tree.mjs +6460 -1591
- package/dist/esm/graph.mjs +440 -20
- package/dist/esm/hash.mjs +125 -22
- package/dist/esm/heap.mjs +196 -47
- package/dist/esm/index.mjs +8486 -2430
- package/dist/esm/linked-list.mjs +456 -31
- package/dist/esm/matrix.mjs +79 -9
- package/dist/esm/priority-queue.mjs +193 -44
- package/dist/esm/queue.mjs +391 -2
- package/dist/esm/stack.mjs +92 -6
- package/dist/esm/trie.mjs +122 -28
- package/dist/esm-legacy/binary-tree.mjs +6484 -1612
- package/dist/esm-legacy/graph.mjs +440 -20
- package/dist/esm-legacy/hash.mjs +125 -22
- package/dist/esm-legacy/heap.mjs +196 -47
- package/dist/esm-legacy/index.mjs +8654 -2595
- package/dist/esm-legacy/linked-list.mjs +456 -31
- package/dist/esm-legacy/matrix.mjs +79 -9
- package/dist/esm-legacy/priority-queue.mjs +193 -44
- package/dist/esm-legacy/queue.mjs +391 -2
- package/dist/esm-legacy/stack.mjs +92 -6
- package/dist/esm-legacy/trie.mjs +122 -28
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +98 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +112 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +214 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +294 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +155 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +48 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1370 -323
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1329 -316
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +1116 -295
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1330 -326
- package/dist/types/data-structures/graph/directed-graph.d.ts +80 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +72 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +95 -6
- package/dist/types/data-structures/heap/heap.d.ts +154 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +143 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +144 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +64 -0
- package/dist/types/data-structures/queue/deque.d.ts +142 -0
- package/dist/types/data-structures/queue/queue.d.ts +109 -0
- package/dist/types/data-structures/stack/stack.d.ts +82 -2
- package/dist/types/data-structures/trie/trie.d.ts +96 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/data-structure-typed.js +8623 -2564
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +696 -194
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +71 -71
- package/docs-site-docusaurus/docs/api/classes/BST.md +639 -189
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +148 -160
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +105 -91
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +104 -74
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +51 -51
- package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +33 -33
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +50 -50
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +78 -78
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
- package/docs-site-docusaurus/docs/api/classes/Queue.md +112 -60
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +708 -206
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +79 -79
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +44 -44
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +236 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +162 -46
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +232 -32
- package/docs-site-docusaurus/docs/api/classes/Trie.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +81 -81
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -5
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -3
- package/docs-site-docusaurus/docs/guide/faq.md +233 -0
- package/docs-site-docusaurus/docs/guide/guides.md +43 -58
- package/docs-site-docusaurus/docs/guide/installation.md +2 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +75 -176
- package/docs-site-docusaurus/docs/guide/overview.md +132 -11
- package/docs-site-docusaurus/docs/guide/performance.md +2 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +31 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
- package/docs-site-docusaurus/docusaurus.config.ts +1 -1
- package/docs-site-docusaurus/src/pages/index.tsx +55 -2
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/llms.txt +37 -0
- package/package.json +65 -56
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
|
@@ -4,6 +4,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
|
|
6
6
|
// src/common/error.ts
|
|
7
|
+
function raise(ErrorClass, message) {
|
|
8
|
+
throw new ErrorClass(message);
|
|
9
|
+
}
|
|
10
|
+
__name(raise, "raise");
|
|
7
11
|
var ERR = {
|
|
8
12
|
// Range / index
|
|
9
13
|
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
@@ -25,7 +29,9 @@ var ERR = {
|
|
|
25
29
|
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
26
30
|
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
27
31
|
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
28
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
32
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
33
|
+
// Order statistic
|
|
34
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
29
35
|
};
|
|
30
36
|
|
|
31
37
|
// src/data-structures/matrix/matrix.ts
|
|
@@ -136,6 +142,14 @@ var _Matrix = class _Matrix {
|
|
|
136
142
|
|
|
137
143
|
|
|
138
144
|
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
139
153
|
|
|
140
154
|
|
|
141
155
|
|
|
@@ -200,6 +214,14 @@ var _Matrix = class _Matrix {
|
|
|
200
214
|
|
|
201
215
|
|
|
202
216
|
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
203
225
|
|
|
204
226
|
|
|
205
227
|
|
|
@@ -260,6 +282,14 @@ var _Matrix = class _Matrix {
|
|
|
260
282
|
|
|
261
283
|
|
|
262
284
|
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
263
293
|
|
|
264
294
|
|
|
265
295
|
|
|
@@ -295,7 +325,7 @@ var _Matrix = class _Matrix {
|
|
|
295
325
|
add(matrix) {
|
|
296
326
|
var _a;
|
|
297
327
|
if (!this.isMatchForCalculate(matrix)) {
|
|
298
|
-
|
|
328
|
+
raise(Error, ERR.matrixDimensionMismatch("addition"));
|
|
299
329
|
}
|
|
300
330
|
const resultData = [];
|
|
301
331
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -343,6 +373,14 @@ var _Matrix = class _Matrix {
|
|
|
343
373
|
|
|
344
374
|
|
|
345
375
|
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
346
384
|
|
|
347
385
|
|
|
348
386
|
|
|
@@ -362,7 +400,7 @@ var _Matrix = class _Matrix {
|
|
|
362
400
|
subtract(matrix) {
|
|
363
401
|
var _a;
|
|
364
402
|
if (!this.isMatchForCalculate(matrix)) {
|
|
365
|
-
|
|
403
|
+
raise(Error, ERR.matrixDimensionMismatch("subtraction"));
|
|
366
404
|
}
|
|
367
405
|
const resultData = [];
|
|
368
406
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -409,6 +447,14 @@ var _Matrix = class _Matrix {
|
|
|
409
447
|
|
|
410
448
|
|
|
411
449
|
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
412
458
|
|
|
413
459
|
|
|
414
460
|
|
|
@@ -443,7 +489,7 @@ var _Matrix = class _Matrix {
|
|
|
443
489
|
*/
|
|
444
490
|
multiply(matrix) {
|
|
445
491
|
if (this.cols !== matrix.rows) {
|
|
446
|
-
|
|
492
|
+
raise(Error, ERR.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));
|
|
447
493
|
}
|
|
448
494
|
const resultData = [];
|
|
449
495
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -496,6 +542,14 @@ var _Matrix = class _Matrix {
|
|
|
496
542
|
|
|
497
543
|
|
|
498
544
|
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
499
553
|
|
|
500
554
|
|
|
501
555
|
|
|
@@ -527,7 +581,7 @@ var _Matrix = class _Matrix {
|
|
|
527
581
|
*/
|
|
528
582
|
transpose() {
|
|
529
583
|
if (this.data.some((row) => row.length !== this.cols)) {
|
|
530
|
-
|
|
584
|
+
raise(Error, ERR.matrixNotRectangular());
|
|
531
585
|
}
|
|
532
586
|
const resultData = [];
|
|
533
587
|
for (let j = 0; j < this.cols; j++) {
|
|
@@ -570,6 +624,14 @@ var _Matrix = class _Matrix {
|
|
|
570
624
|
|
|
571
625
|
|
|
572
626
|
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
573
635
|
|
|
574
636
|
|
|
575
637
|
|
|
@@ -594,7 +656,7 @@ var _Matrix = class _Matrix {
|
|
|
594
656
|
inverse() {
|
|
595
657
|
var _a;
|
|
596
658
|
if (this.rows !== this.cols) {
|
|
597
|
-
|
|
659
|
+
raise(Error, ERR.matrixNotSquare());
|
|
598
660
|
}
|
|
599
661
|
const augmentedMatrixData = [];
|
|
600
662
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -616,12 +678,12 @@ var _Matrix = class _Matrix {
|
|
|
616
678
|
pivotRow++;
|
|
617
679
|
}
|
|
618
680
|
if (pivotRow === this.rows) {
|
|
619
|
-
|
|
681
|
+
raise(Error, ERR.matrixSingular());
|
|
620
682
|
}
|
|
621
683
|
augmentedMatrix._swapRows(i, pivotRow);
|
|
622
684
|
const pivotElement = (_a = augmentedMatrix.get(i, i)) != null ? _a : 1;
|
|
623
685
|
if (pivotElement === 0) {
|
|
624
|
-
|
|
686
|
+
raise(Error, ERR.matrixSingular());
|
|
625
687
|
}
|
|
626
688
|
augmentedMatrix._scaleRow(i, 1 / pivotElement);
|
|
627
689
|
for (let j = 0; j < this.rows; j++) {
|
|
@@ -670,6 +732,14 @@ var _Matrix = class _Matrix {
|
|
|
670
732
|
|
|
671
733
|
|
|
672
734
|
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
673
743
|
|
|
674
744
|
|
|
675
745
|
|
|
@@ -688,7 +758,7 @@ var _Matrix = class _Matrix {
|
|
|
688
758
|
*/
|
|
689
759
|
dot(matrix) {
|
|
690
760
|
if (this.cols !== matrix.rows) {
|
|
691
|
-
|
|
761
|
+
raise(Error, ERR.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));
|
|
692
762
|
}
|
|
693
763
|
const resultData = [];
|
|
694
764
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -3,6 +3,37 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
|
|
6
|
+
// src/common/error.ts
|
|
7
|
+
function raise(ErrorClass, message) {
|
|
8
|
+
throw new ErrorClass(message);
|
|
9
|
+
}
|
|
10
|
+
__name(raise, "raise");
|
|
11
|
+
var ERR = {
|
|
12
|
+
// Range / index
|
|
13
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
14
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
15
|
+
// Type / argument
|
|
16
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
17
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
18
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
19
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
20
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
21
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
22
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
23
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
24
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
25
|
+
// State / operation
|
|
26
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
27
|
+
// Matrix
|
|
28
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
29
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
30
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
31
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
32
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
33
|
+
// Order statistic
|
|
34
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
35
|
+
};
|
|
36
|
+
|
|
6
37
|
// src/data-structures/base/iterable-element-base.ts
|
|
7
38
|
var _IterableElementBase = class _IterableElementBase {
|
|
8
39
|
/**
|
|
@@ -25,7 +56,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
25
56
|
if (options) {
|
|
26
57
|
const { toElementFn } = options;
|
|
27
58
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
28
|
-
else if (toElementFn)
|
|
59
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
29
60
|
}
|
|
30
61
|
}
|
|
31
62
|
/**
|
|
@@ -181,7 +212,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
181
212
|
acc = initialValue;
|
|
182
213
|
} else {
|
|
183
214
|
const first = iter.next();
|
|
184
|
-
if (first.done)
|
|
215
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
185
216
|
acc = first.value;
|
|
186
217
|
index = 1;
|
|
187
218
|
}
|
|
@@ -225,31 +256,6 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
225
256
|
__name(_IterableElementBase, "IterableElementBase");
|
|
226
257
|
var IterableElementBase = _IterableElementBase;
|
|
227
258
|
|
|
228
|
-
// src/common/error.ts
|
|
229
|
-
var ERR = {
|
|
230
|
-
// Range / index
|
|
231
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
232
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
233
|
-
// Type / argument
|
|
234
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
235
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
236
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
237
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
238
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
239
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
240
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
241
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
242
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
243
|
-
// State / operation
|
|
244
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
245
|
-
// Matrix
|
|
246
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
247
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
248
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
249
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
250
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
251
|
-
};
|
|
252
|
-
|
|
253
259
|
// src/data-structures/heap/heap.ts
|
|
254
260
|
var _Heap = class _Heap extends IterableElementBase {
|
|
255
261
|
/**
|
|
@@ -265,7 +271,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
265
271
|
__publicField(this, "_elements", []);
|
|
266
272
|
__publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
|
|
267
273
|
if (typeof a === "object" || typeof b === "object") {
|
|
268
|
-
|
|
274
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
269
275
|
}
|
|
270
276
|
if (a > b) return 1;
|
|
271
277
|
if (a < b) return -1;
|
|
@@ -312,6 +318,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
312
318
|
|
|
313
319
|
|
|
314
320
|
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
315
329
|
|
|
316
330
|
|
|
317
331
|
|
|
@@ -370,7 +384,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
370
384
|
}
|
|
371
385
|
/**
|
|
372
386
|
* Insert an element.
|
|
373
|
-
* @remarks Time O(
|
|
387
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
374
388
|
* @param element - Element to insert.
|
|
375
389
|
* @returns True.
|
|
376
390
|
|
|
@@ -395,6 +409,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
395
409
|
|
|
396
410
|
|
|
397
411
|
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
398
420
|
|
|
399
421
|
|
|
400
422
|
|
|
@@ -448,6 +470,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
448
470
|
|
|
449
471
|
|
|
450
472
|
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
451
481
|
|
|
452
482
|
|
|
453
483
|
|
|
@@ -504,6 +534,13 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
504
534
|
|
|
505
535
|
|
|
506
536
|
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
507
544
|
|
|
508
545
|
|
|
509
546
|
|
|
@@ -512,6 +549,34 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
512
549
|
|
|
513
550
|
|
|
514
551
|
|
|
552
|
+
* @example
|
|
553
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
554
|
+
* interface Task {
|
|
555
|
+
* id: number;
|
|
556
|
+
* priority: number;
|
|
557
|
+
* name: string;
|
|
558
|
+
* }
|
|
559
|
+
*
|
|
560
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
561
|
+
* const tasks: Task[] = [
|
|
562
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
563
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
564
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
565
|
+
* ];
|
|
566
|
+
*
|
|
567
|
+
* const maxHeap = new Heap(tasks, {
|
|
568
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
569
|
+
* });
|
|
570
|
+
*
|
|
571
|
+
* console.log(maxHeap.size); // 3;
|
|
572
|
+
*
|
|
573
|
+
* // Peek returns highest priority task
|
|
574
|
+
* const topTask = maxHeap.peek();
|
|
575
|
+
* console.log(topTask?.priority); // 8;
|
|
576
|
+
* console.log(topTask?.name); // 'Alert';
|
|
577
|
+
*/
|
|
578
|
+
/**
|
|
579
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
515
580
|
* @example
|
|
516
581
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
517
582
|
* interface Task {
|
|
@@ -539,6 +604,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
539
604
|
* console.log(topTask?.name); // 'Alert';
|
|
540
605
|
*/
|
|
541
606
|
poll() {
|
|
607
|
+
return this.pop();
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
611
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
612
|
+
* @returns The removed top element, or undefined if empty.
|
|
613
|
+
*/
|
|
614
|
+
pop() {
|
|
542
615
|
if (this.elements.length === 0) return;
|
|
543
616
|
const value = this.elements[0];
|
|
544
617
|
const last = this.elements.pop();
|
|
@@ -574,6 +647,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
574
647
|
|
|
575
648
|
|
|
576
649
|
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
577
658
|
|
|
578
659
|
|
|
579
660
|
|
|
@@ -670,6 +751,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
670
751
|
|
|
671
752
|
|
|
672
753
|
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
673
762
|
|
|
674
763
|
|
|
675
764
|
|
|
@@ -713,6 +802,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
713
802
|
|
|
714
803
|
|
|
715
804
|
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
716
813
|
|
|
717
814
|
|
|
718
815
|
|
|
@@ -731,16 +828,6 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
731
828
|
clear() {
|
|
732
829
|
this._elements = [];
|
|
733
830
|
}
|
|
734
|
-
/**
|
|
735
|
-
* Replace the backing array and rebuild the heap.
|
|
736
|
-
* @remarks Time O(N), Space O(N)
|
|
737
|
-
* @param elements - Iterable used to refill the heap.
|
|
738
|
-
* @returns Array of per-node results from fixing steps.
|
|
739
|
-
*/
|
|
740
|
-
refill(elements) {
|
|
741
|
-
this._elements = Array.from(elements);
|
|
742
|
-
return this.fix();
|
|
743
|
-
}
|
|
744
831
|
/**
|
|
745
832
|
* Check if an equal element exists in the heap.
|
|
746
833
|
* @remarks Time O(N), Space O(1)
|
|
@@ -759,6 +846,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
759
846
|
|
|
760
847
|
|
|
761
848
|
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
762
857
|
|
|
763
858
|
|
|
764
859
|
|
|
@@ -802,6 +897,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
802
897
|
|
|
803
898
|
|
|
804
899
|
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
805
908
|
|
|
806
909
|
|
|
807
910
|
|
|
@@ -827,7 +930,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
827
930
|
}
|
|
828
931
|
if (index < 0) return false;
|
|
829
932
|
if (index === 0) {
|
|
830
|
-
this.
|
|
933
|
+
this.pop();
|
|
831
934
|
} else if (index === this.elements.length - 1) {
|
|
832
935
|
this.elements.pop();
|
|
833
936
|
} else {
|
|
@@ -837,13 +940,19 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
837
940
|
}
|
|
838
941
|
return true;
|
|
839
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
945
|
+
*/
|
|
946
|
+
deleteBy(predicate) {
|
|
947
|
+
return this.deleteWhere(predicate);
|
|
948
|
+
}
|
|
840
949
|
/**
|
|
841
950
|
* Delete the first element that matches a predicate.
|
|
842
951
|
* @remarks Time O(N), Space O(1)
|
|
843
952
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
844
953
|
* @returns True if an element was removed.
|
|
845
954
|
*/
|
|
846
|
-
|
|
955
|
+
deleteWhere(predicate) {
|
|
847
956
|
let idx = -1;
|
|
848
957
|
for (let i = 0; i < this.elements.length; i++) {
|
|
849
958
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -853,7 +962,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
853
962
|
}
|
|
854
963
|
if (idx < 0) return false;
|
|
855
964
|
if (idx === 0) {
|
|
856
|
-
this.
|
|
965
|
+
this.pop();
|
|
857
966
|
} else if (idx === this.elements.length - 1) {
|
|
858
967
|
this.elements.pop();
|
|
859
968
|
} else {
|
|
@@ -891,6 +1000,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
891
1000
|
|
|
892
1001
|
|
|
893
1002
|
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
894
1011
|
|
|
895
1012
|
|
|
896
1013
|
|
|
@@ -967,6 +1084,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
967
1084
|
|
|
968
1085
|
|
|
969
1086
|
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
970
1095
|
|
|
971
1096
|
|
|
972
1097
|
|
|
@@ -1016,6 +1141,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1016
1141
|
|
|
1017
1142
|
|
|
1018
1143
|
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1019
1152
|
|
|
1020
1153
|
|
|
1021
1154
|
|
|
@@ -1064,6 +1197,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1064
1197
|
|
|
1065
1198
|
|
|
1066
1199
|
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1067
1208
|
|
|
1068
1209
|
|
|
1069
1210
|
|
|
@@ -1119,6 +1260,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1119
1260
|
|
|
1120
1261
|
|
|
1121
1262
|
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1122
1271
|
|
|
1123
1272
|
|
|
1124
1273
|
|
|
@@ -1136,7 +1285,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1136
1285
|
*/
|
|
1137
1286
|
map(callback, options, thisArg) {
|
|
1138
1287
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
1139
|
-
if (!comparator)
|
|
1288
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
1140
1289
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
1141
1290
|
let i = 0;
|
|
1142
1291
|
for (const x of this) {
|
|
@@ -1276,7 +1425,7 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
|
|
|
1276
1425
|
super(elements, {
|
|
1277
1426
|
comparator: /* @__PURE__ */ __name((a, b) => {
|
|
1278
1427
|
if (typeof a === "object" || typeof b === "object") {
|
|
1279
|
-
|
|
1428
|
+
raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
|
|
1280
1429
|
}
|
|
1281
1430
|
if (a < b) return 1;
|
|
1282
1431
|
if (a > b) return -1;
|