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
|
@@ -160,6 +160,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
160
160
|
for (const ele of this) if (ele === element) return true;
|
|
161
161
|
return false;
|
|
162
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
165
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
166
|
+
* @param element - Element to search for (uses `===`).
|
|
167
|
+
* @returns `true` if found.
|
|
168
|
+
*/
|
|
169
|
+
includes(element) {
|
|
170
|
+
return this.has(element);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
174
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
175
|
+
*/
|
|
176
|
+
*entries() {
|
|
177
|
+
let index = 0;
|
|
178
|
+
for (const value of this) {
|
|
179
|
+
yield [index++, value];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
184
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
185
|
+
*/
|
|
186
|
+
*keys() {
|
|
187
|
+
let index = 0;
|
|
188
|
+
for (const _ of this) {
|
|
189
|
+
yield index++;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
163
192
|
/**
|
|
164
193
|
* Reduces all elements to a single accumulated value.
|
|
165
194
|
*
|
|
@@ -293,6 +322,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
293
322
|
|
|
294
323
|
|
|
295
324
|
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
296
328
|
|
|
297
329
|
|
|
298
330
|
|
|
@@ -357,6 +389,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
357
389
|
|
|
358
390
|
|
|
359
391
|
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
360
395
|
|
|
361
396
|
|
|
362
397
|
|
|
@@ -410,6 +445,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
410
445
|
|
|
411
446
|
|
|
412
447
|
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
413
451
|
|
|
414
452
|
|
|
415
453
|
|
|
@@ -463,6 +501,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
463
501
|
|
|
464
502
|
|
|
465
503
|
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
466
507
|
|
|
467
508
|
|
|
468
509
|
|
|
@@ -525,6 +566,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
525
566
|
|
|
526
567
|
|
|
527
568
|
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
528
572
|
|
|
529
573
|
|
|
530
574
|
|
|
@@ -602,6 +646,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
602
646
|
|
|
603
647
|
|
|
604
648
|
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
605
652
|
|
|
606
653
|
|
|
607
654
|
|
|
@@ -679,6 +726,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
679
726
|
|
|
680
727
|
|
|
681
728
|
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
682
732
|
|
|
683
733
|
|
|
684
734
|
|
|
@@ -729,6 +779,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
729
779
|
|
|
730
780
|
|
|
731
781
|
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
732
785
|
|
|
733
786
|
|
|
734
787
|
|
|
@@ -785,6 +838,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
785
838
|
|
|
786
839
|
|
|
787
840
|
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
788
844
|
|
|
789
845
|
|
|
790
846
|
|
|
@@ -861,6 +917,9 @@ var _Stack = class _Stack extends IterableElementBase {
|
|
|
861
917
|
|
|
862
918
|
|
|
863
919
|
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
864
923
|
|
|
865
924
|
|
|
866
925
|
|
package/dist/cjs-legacy/trie.cjs
CHANGED
|
@@ -185,6 +185,35 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
185
185
|
for (const ele of this) if (ele === element) return true;
|
|
186
186
|
return false;
|
|
187
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Check whether a value exists (Array-compatible alias for `has`).
|
|
190
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
|
|
191
|
+
* @param element - Element to search for (uses `===`).
|
|
192
|
+
* @returns `true` if found.
|
|
193
|
+
*/
|
|
194
|
+
includes(element) {
|
|
195
|
+
return this.has(element);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Return an iterator of `[index, value]` pairs (Array-compatible).
|
|
199
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
200
|
+
*/
|
|
201
|
+
*entries() {
|
|
202
|
+
let index = 0;
|
|
203
|
+
for (const value of this) {
|
|
204
|
+
yield [index++, value];
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Return an iterator of numeric indices (Array-compatible).
|
|
209
|
+
* @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
|
|
210
|
+
*/
|
|
211
|
+
*keys() {
|
|
212
|
+
let index = 0;
|
|
213
|
+
for (const _ of this) {
|
|
214
|
+
yield index++;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
188
217
|
/**
|
|
189
218
|
* Reduces all elements to a single accumulated value.
|
|
190
219
|
*
|
|
@@ -420,6 +449,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
420
449
|
|
|
421
450
|
|
|
422
451
|
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
423
455
|
|
|
424
456
|
|
|
425
457
|
|
|
@@ -496,6 +528,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
496
528
|
|
|
497
529
|
|
|
498
530
|
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
499
534
|
|
|
500
535
|
|
|
501
536
|
|
|
@@ -559,6 +594,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
559
594
|
|
|
560
595
|
|
|
561
596
|
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
562
600
|
|
|
563
601
|
|
|
564
602
|
|
|
@@ -617,6 +655,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
617
655
|
|
|
618
656
|
|
|
619
657
|
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
620
661
|
|
|
621
662
|
|
|
622
663
|
|
|
@@ -667,6 +708,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
667
708
|
|
|
668
709
|
|
|
669
710
|
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
670
714
|
|
|
671
715
|
|
|
672
716
|
|
|
@@ -721,6 +765,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
721
765
|
|
|
722
766
|
|
|
723
767
|
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
724
771
|
|
|
725
772
|
|
|
726
773
|
|
|
@@ -857,6 +904,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
857
904
|
|
|
858
905
|
|
|
859
906
|
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
860
910
|
|
|
861
911
|
|
|
862
912
|
|
|
@@ -937,6 +987,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
937
987
|
|
|
938
988
|
|
|
939
989
|
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
940
993
|
|
|
941
994
|
|
|
942
995
|
|
|
@@ -1000,6 +1053,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
1000
1053
|
|
|
1001
1054
|
|
|
1002
1055
|
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1003
1059
|
|
|
1004
1060
|
|
|
1005
1061
|
|
|
@@ -1081,6 +1137,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
1081
1137
|
|
|
1082
1138
|
|
|
1083
1139
|
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1084
1143
|
|
|
1085
1144
|
|
|
1086
1145
|
|
|
@@ -1135,6 +1194,9 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
1135
1194
|
|
|
1136
1195
|
|
|
1137
1196
|
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1138
1200
|
|
|
1139
1201
|
|
|
1140
1202
|
|