data-structure-typed 2.5.3 → 2.6.1
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 +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/.husky/pre-commit +3 -0
- package/CHANGELOG.md +1 -1
- package/MIGRATION.md +48 -0
- package/README.md +20 -2
- package/README_CN.md +20 -2
- package/SPECIFICATION.md +24 -0
- package/SPECIFICATION.zh-CN.md +24 -0
- package/dist/cjs/binary-tree.cjs +1897 -19
- package/dist/cjs/graph.cjs +174 -0
- package/dist/cjs/hash.cjs +33 -0
- package/dist/cjs/heap.cjs +71 -0
- package/dist/cjs/index.cjs +2383 -3
- package/dist/cjs/linked-list.cjs +224 -2
- package/dist/cjs/matrix.cjs +24 -0
- package/dist/cjs/priority-queue.cjs +71 -0
- package/dist/cjs/queue.cjs +221 -1
- package/dist/cjs/stack.cjs +59 -0
- package/dist/cjs/trie.cjs +62 -0
- package/dist/cjs-legacy/binary-tree.cjs +1897 -19
- package/dist/cjs-legacy/graph.cjs +174 -0
- package/dist/cjs-legacy/hash.cjs +33 -0
- package/dist/cjs-legacy/heap.cjs +71 -0
- package/dist/cjs-legacy/index.cjs +2383 -3
- package/dist/cjs-legacy/linked-list.cjs +224 -2
- package/dist/cjs-legacy/matrix.cjs +24 -0
- package/dist/cjs-legacy/priority-queue.cjs +71 -0
- package/dist/cjs-legacy/queue.cjs +221 -1
- package/dist/cjs-legacy/stack.cjs +59 -0
- package/dist/cjs-legacy/trie.cjs +62 -0
- package/dist/esm/binary-tree.mjs +1897 -19
- package/dist/esm/graph.mjs +174 -0
- package/dist/esm/hash.mjs +33 -0
- package/dist/esm/heap.mjs +71 -0
- package/dist/esm/index.mjs +2383 -3
- package/dist/esm/linked-list.mjs +224 -2
- package/dist/esm/matrix.mjs +24 -0
- package/dist/esm/priority-queue.mjs +71 -0
- package/dist/esm/queue.mjs +221 -1
- package/dist/esm/stack.mjs +59 -0
- package/dist/esm/trie.mjs +62 -0
- package/dist/esm-legacy/binary-tree.mjs +1897 -19
- package/dist/esm-legacy/graph.mjs +174 -0
- package/dist/esm-legacy/hash.mjs +33 -0
- package/dist/esm-legacy/heap.mjs +71 -0
- package/dist/esm-legacy/index.mjs +2383 -3
- package/dist/esm-legacy/linked-list.mjs +224 -2
- package/dist/esm-legacy/matrix.mjs +24 -0
- package/dist/esm-legacy/priority-queue.mjs +71 -0
- package/dist/esm-legacy/queue.mjs +221 -1
- package/dist/esm-legacy/stack.mjs +59 -0
- package/dist/esm-legacy/trie.mjs +62 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +90 -1
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- package/dist/umd/data-structure-typed.js +2383 -3
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +108 -108
- package/docs-site-docusaurus/docs/api/classes/BST.md +101 -101
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +66 -66
- package/docs-site-docusaurus/docs/api/classes/Deque.md +235 -51
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +21 -21
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +231 -67
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +14 -14
- package/docs-site-docusaurus/docs/api/classes/Heap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +83 -13
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +124 -20
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +140 -32
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +30 -26
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +159 -51
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +20 -20
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/Queue.md +142 -34
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +117 -117
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +158 -50
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +21 -21
- package/docs-site-docusaurus/docs/api/classes/Stack.md +108 -26
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +33 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +75 -39
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +301 -39
- package/docs-site-docusaurus/docs/api/classes/Trie.md +110 -28
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +20 -20
- package/jest.integration.config.js +1 -2
- package/package.json +51 -50
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +32 -3
- package/src/data-structures/base/linear-base.ts +13 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -493
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -530
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1236
- package/src/data-structures/binary-tree/bst.ts +158 -1010
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1233
- package/src/data-structures/binary-tree/segment-tree.ts +73 -333
- package/src/data-structures/binary-tree/tree-map.ts +462 -4749
- package/src/data-structures/binary-tree/tree-multi-map.ts +310 -4530
- package/src/data-structures/binary-tree/tree-multi-set.ts +300 -3652
- package/src/data-structures/binary-tree/tree-set.ts +437 -4443
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -532
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -484
- package/src/data-structures/hash/hash-map.ts +154 -549
- package/src/data-structures/heap/heap.ts +200 -753
- package/src/data-structures/linked-list/doubly-linked-list.ts +153 -809
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -749
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -864
- package/src/data-structures/matrix/matrix.ts +179 -494
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +241 -807
- package/src/data-structures/queue/queue.ts +102 -589
- package/src/data-structures/stack/stack.ts +76 -475
- package/src/data-structures/trie/trie.ts +98 -592
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
package/dist/cjs/stack.cjs
CHANGED
|
@@ -161,6 +161,35 @@ var IterableElementBase = class {
|
|
|
161
161
|
for (const ele of this) if (ele === element) return true;
|
|
162
162
|
return false;
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
166
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
167
|
+
* @param element - Element to search for (uses `===`).
|
|
168
|
+
* @returns `true` if found.
|
|
169
|
+
*/
|
|
170
|
+
includes(element) {
|
|
171
|
+
return this.has(element);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
175
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
176
|
+
*/
|
|
177
|
+
*entries() {
|
|
178
|
+
let index = 0;
|
|
179
|
+
for (const value of this) {
|
|
180
|
+
yield [index++, value];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
185
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
186
|
+
*/
|
|
187
|
+
*keys() {
|
|
188
|
+
let index = 0;
|
|
189
|
+
for (const _ of this) {
|
|
190
|
+
yield index++;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
164
193
|
/**
|
|
165
194
|
* Reduces all elements to a single accumulated value.
|
|
166
195
|
*
|
|
@@ -295,6 +324,9 @@ var Stack = class extends IterableElementBase {
|
|
|
295
324
|
|
|
296
325
|
|
|
297
326
|
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
298
330
|
|
|
299
331
|
|
|
300
332
|
|
|
@@ -359,6 +391,9 @@ var Stack = class extends IterableElementBase {
|
|
|
359
391
|
|
|
360
392
|
|
|
361
393
|
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
362
397
|
|
|
363
398
|
|
|
364
399
|
|
|
@@ -412,6 +447,9 @@ var Stack = class extends IterableElementBase {
|
|
|
412
447
|
|
|
413
448
|
|
|
414
449
|
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
415
453
|
|
|
416
454
|
|
|
417
455
|
|
|
@@ -465,6 +503,9 @@ var Stack = class extends IterableElementBase {
|
|
|
465
503
|
|
|
466
504
|
|
|
467
505
|
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
468
509
|
|
|
469
510
|
|
|
470
511
|
|
|
@@ -527,6 +568,9 @@ var Stack = class extends IterableElementBase {
|
|
|
527
568
|
|
|
528
569
|
|
|
529
570
|
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
530
574
|
|
|
531
575
|
|
|
532
576
|
|
|
@@ -604,6 +648,9 @@ var Stack = class extends IterableElementBase {
|
|
|
604
648
|
|
|
605
649
|
|
|
606
650
|
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
607
654
|
|
|
608
655
|
|
|
609
656
|
|
|
@@ -681,6 +728,9 @@ var Stack = class extends IterableElementBase {
|
|
|
681
728
|
|
|
682
729
|
|
|
683
730
|
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
684
734
|
|
|
685
735
|
|
|
686
736
|
|
|
@@ -731,6 +781,9 @@ var Stack = class extends IterableElementBase {
|
|
|
731
781
|
|
|
732
782
|
|
|
733
783
|
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
734
787
|
|
|
735
788
|
|
|
736
789
|
|
|
@@ -787,6 +840,9 @@ var Stack = class extends IterableElementBase {
|
|
|
787
840
|
|
|
788
841
|
|
|
789
842
|
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
790
846
|
|
|
791
847
|
|
|
792
848
|
|
|
@@ -863,6 +919,9 @@ var Stack = class extends IterableElementBase {
|
|
|
863
919
|
|
|
864
920
|
|
|
865
921
|
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
866
925
|
|
|
867
926
|
|
|
868
927
|
|
package/dist/cjs/trie.cjs
CHANGED
|
@@ -186,6 +186,35 @@ var IterableElementBase = class {
|
|
|
186
186
|
for (const ele of this) if (ele === element) return true;
|
|
187
187
|
return false;
|
|
188
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
191
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
192
|
+
* @param element - Element to search for (uses `===`).
|
|
193
|
+
* @returns `true` if found.
|
|
194
|
+
*/
|
|
195
|
+
includes(element) {
|
|
196
|
+
return this.has(element);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
200
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
201
|
+
*/
|
|
202
|
+
*entries() {
|
|
203
|
+
let index = 0;
|
|
204
|
+
for (const value of this) {
|
|
205
|
+
yield [index++, value];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
210
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
211
|
+
*/
|
|
212
|
+
*keys() {
|
|
213
|
+
let index = 0;
|
|
214
|
+
for (const _ of this) {
|
|
215
|
+
yield index++;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
189
218
|
/**
|
|
190
219
|
* Reduces all elements to a single accumulated value.
|
|
191
220
|
*
|
|
@@ -423,6 +452,9 @@ var Trie = class extends IterableElementBase {
|
|
|
423
452
|
|
|
424
453
|
|
|
425
454
|
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
426
458
|
|
|
427
459
|
|
|
428
460
|
|
|
@@ -499,6 +531,9 @@ var Trie = class extends IterableElementBase {
|
|
|
499
531
|
|
|
500
532
|
|
|
501
533
|
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
502
537
|
|
|
503
538
|
|
|
504
539
|
|
|
@@ -562,6 +597,9 @@ var Trie = class extends IterableElementBase {
|
|
|
562
597
|
|
|
563
598
|
|
|
564
599
|
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
565
603
|
|
|
566
604
|
|
|
567
605
|
|
|
@@ -620,6 +658,9 @@ var Trie = class extends IterableElementBase {
|
|
|
620
658
|
|
|
621
659
|
|
|
622
660
|
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
623
664
|
|
|
624
665
|
|
|
625
666
|
|
|
@@ -670,6 +711,9 @@ var Trie = class extends IterableElementBase {
|
|
|
670
711
|
|
|
671
712
|
|
|
672
713
|
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
673
717
|
|
|
674
718
|
|
|
675
719
|
|
|
@@ -724,6 +768,9 @@ var Trie = class extends IterableElementBase {
|
|
|
724
768
|
|
|
725
769
|
|
|
726
770
|
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
727
774
|
|
|
728
775
|
|
|
729
776
|
|
|
@@ -860,6 +907,9 @@ var Trie = class extends IterableElementBase {
|
|
|
860
907
|
|
|
861
908
|
|
|
862
909
|
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
863
913
|
|
|
864
914
|
|
|
865
915
|
|
|
@@ -940,6 +990,9 @@ var Trie = class extends IterableElementBase {
|
|
|
940
990
|
|
|
941
991
|
|
|
942
992
|
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
943
996
|
|
|
944
997
|
|
|
945
998
|
|
|
@@ -1003,6 +1056,9 @@ var Trie = class extends IterableElementBase {
|
|
|
1003
1056
|
|
|
1004
1057
|
|
|
1005
1058
|
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1006
1062
|
|
|
1007
1063
|
|
|
1008
1064
|
|
|
@@ -1084,6 +1140,9 @@ var Trie = class extends IterableElementBase {
|
|
|
1084
1140
|
|
|
1085
1141
|
|
|
1086
1142
|
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1087
1146
|
|
|
1088
1147
|
|
|
1089
1148
|
|
|
@@ -1138,6 +1197,9 @@ var Trie = class extends IterableElementBase {
|
|
|
1138
1197
|
|
|
1139
1198
|
|
|
1140
1199
|
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1141
1203
|
|
|
1142
1204
|
|
|
1143
1205
|
|