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.
Files changed (158) hide show
  1. package/.github/workflows/ci.yml +7 -2
  2. package/.github/workflows/release-package.yml +9 -2
  3. package/.husky/pre-commit +3 -0
  4. package/CHANGELOG.md +1 -1
  5. package/MIGRATION.md +48 -0
  6. package/README.md +20 -2
  7. package/README_CN.md +20 -2
  8. package/SPECIFICATION.md +24 -0
  9. package/SPECIFICATION.zh-CN.md +24 -0
  10. package/dist/cjs/binary-tree.cjs +1897 -19
  11. package/dist/cjs/graph.cjs +174 -0
  12. package/dist/cjs/hash.cjs +33 -0
  13. package/dist/cjs/heap.cjs +71 -0
  14. package/dist/cjs/index.cjs +2383 -3
  15. package/dist/cjs/linked-list.cjs +224 -2
  16. package/dist/cjs/matrix.cjs +24 -0
  17. package/dist/cjs/priority-queue.cjs +71 -0
  18. package/dist/cjs/queue.cjs +221 -1
  19. package/dist/cjs/stack.cjs +59 -0
  20. package/dist/cjs/trie.cjs +62 -0
  21. package/dist/cjs-legacy/binary-tree.cjs +1897 -19
  22. package/dist/cjs-legacy/graph.cjs +174 -0
  23. package/dist/cjs-legacy/hash.cjs +33 -0
  24. package/dist/cjs-legacy/heap.cjs +71 -0
  25. package/dist/cjs-legacy/index.cjs +2383 -3
  26. package/dist/cjs-legacy/linked-list.cjs +224 -2
  27. package/dist/cjs-legacy/matrix.cjs +24 -0
  28. package/dist/cjs-legacy/priority-queue.cjs +71 -0
  29. package/dist/cjs-legacy/queue.cjs +221 -1
  30. package/dist/cjs-legacy/stack.cjs +59 -0
  31. package/dist/cjs-legacy/trie.cjs +62 -0
  32. package/dist/esm/binary-tree.mjs +1897 -19
  33. package/dist/esm/graph.mjs +174 -0
  34. package/dist/esm/hash.mjs +33 -0
  35. package/dist/esm/heap.mjs +71 -0
  36. package/dist/esm/index.mjs +2383 -3
  37. package/dist/esm/linked-list.mjs +224 -2
  38. package/dist/esm/matrix.mjs +24 -0
  39. package/dist/esm/priority-queue.mjs +71 -0
  40. package/dist/esm/queue.mjs +221 -1
  41. package/dist/esm/stack.mjs +59 -0
  42. package/dist/esm/trie.mjs +62 -0
  43. package/dist/esm-legacy/binary-tree.mjs +1897 -19
  44. package/dist/esm-legacy/graph.mjs +174 -0
  45. package/dist/esm-legacy/hash.mjs +33 -0
  46. package/dist/esm-legacy/heap.mjs +71 -0
  47. package/dist/esm-legacy/index.mjs +2383 -3
  48. package/dist/esm-legacy/linked-list.mjs +224 -2
  49. package/dist/esm-legacy/matrix.mjs +24 -0
  50. package/dist/esm-legacy/priority-queue.mjs +71 -0
  51. package/dist/esm-legacy/queue.mjs +221 -1
  52. package/dist/esm-legacy/stack.mjs +59 -0
  53. package/dist/esm-legacy/trie.mjs +62 -0
  54. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  55. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  56. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +36 -0
  57. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  58. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
  59. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
  60. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  61. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  62. package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
  63. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  64. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  65. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
  66. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  67. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  68. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  69. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  70. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
  71. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  72. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  73. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  74. package/dist/types/data-structures/queue/deque.d.ts +90 -1
  75. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  76. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  77. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  78. package/dist/umd/data-structure-typed.js +2383 -3
  79. package/dist/umd/data-structure-typed.min.js +3 -3
  80. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +108 -108
  81. package/docs-site-docusaurus/docs/api/classes/BST.md +101 -101
  82. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -13
  83. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +66 -66
  84. package/docs-site-docusaurus/docs/api/classes/Deque.md +235 -51
  85. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +21 -21
  86. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +231 -67
  87. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
  88. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  89. package/docs-site-docusaurus/docs/api/classes/HashMap.md +14 -14
  90. package/docs-site-docusaurus/docs/api/classes/Heap.md +117 -34
  91. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +83 -13
  92. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +124 -20
  93. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +140 -32
  94. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +30 -26
  95. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +159 -51
  96. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +20 -20
  97. package/docs-site-docusaurus/docs/api/classes/Matrix.md +23 -23
  98. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -34
  99. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +117 -34
  100. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -34
  101. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +117 -34
  102. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +117 -34
  103. package/docs-site-docusaurus/docs/api/classes/Queue.md +142 -34
  104. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +117 -117
  105. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +8 -8
  106. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +158 -50
  107. package/docs-site-docusaurus/docs/api/classes/SkipList.md +21 -21
  108. package/docs-site-docusaurus/docs/api/classes/Stack.md +108 -26
  109. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +33 -33
  110. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +75 -39
  111. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +301 -39
  112. package/docs-site-docusaurus/docs/api/classes/Trie.md +110 -28
  113. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +20 -20
  114. package/jest.integration.config.js +1 -2
  115. package/package.json +51 -50
  116. package/src/common/error.ts +15 -32
  117. package/src/common/index.ts +0 -3
  118. package/src/data-structures/base/iterable-element-base.ts +32 -3
  119. package/src/data-structures/base/linear-base.ts +13 -36
  120. package/src/data-structures/binary-tree/avl-tree.ts +31 -493
  121. package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -530
  122. package/src/data-structures/binary-tree/binary-tree.ts +326 -1236
  123. package/src/data-structures/binary-tree/bst.ts +158 -1010
  124. package/src/data-structures/binary-tree/red-black-tree.ts +451 -1233
  125. package/src/data-structures/binary-tree/segment-tree.ts +73 -333
  126. package/src/data-structures/binary-tree/tree-map.ts +462 -4749
  127. package/src/data-structures/binary-tree/tree-multi-map.ts +310 -4530
  128. package/src/data-structures/binary-tree/tree-multi-set.ts +300 -3652
  129. package/src/data-structures/binary-tree/tree-set.ts +437 -4443
  130. package/src/data-structures/graph/abstract-graph.ts +98 -167
  131. package/src/data-structures/graph/directed-graph.ts +137 -532
  132. package/src/data-structures/graph/map-graph.ts +0 -3
  133. package/src/data-structures/graph/undirected-graph.ts +132 -484
  134. package/src/data-structures/hash/hash-map.ts +154 -549
  135. package/src/data-structures/heap/heap.ts +200 -753
  136. package/src/data-structures/linked-list/doubly-linked-list.ts +153 -809
  137. package/src/data-structures/linked-list/singly-linked-list.ts +122 -749
  138. package/src/data-structures/linked-list/skip-linked-list.ts +211 -864
  139. package/src/data-structures/matrix/matrix.ts +179 -494
  140. package/src/data-structures/matrix/navigator.ts +0 -1
  141. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
  142. package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
  143. package/src/data-structures/priority-queue/priority-queue.ts +1 -2
  144. package/src/data-structures/queue/deque.ts +241 -807
  145. package/src/data-structures/queue/queue.ts +102 -589
  146. package/src/data-structures/stack/stack.ts +76 -475
  147. package/src/data-structures/trie/trie.ts +98 -592
  148. package/src/types/common.ts +0 -10
  149. package/src/types/data-structures/binary-tree/bst.ts +0 -7
  150. package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
  151. package/src/types/data-structures/graph/abstract-graph.ts +0 -2
  152. package/src/types/data-structures/hash/hash-map.ts +0 -3
  153. package/src/types/data-structures/hash/index.ts +0 -1
  154. package/src/types/data-structures/matrix/navigator.ts +0 -2
  155. package/src/types/utils/utils.ts +0 -7
  156. package/src/types/utils/validate-type.ts +0 -7
  157. package/src/utils/number.ts +0 -2
  158. package/src/utils/utils.ts +0 -5
@@ -159,6 +159,35 @@ var IterableElementBase = class {
159
159
  for (const ele of this) if (ele === element) return true;
160
160
  return false;
161
161
  }
162
+ /**
163
+ * Check whether a value exists (Array-compatible alias for `has`).
164
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
165
+ * @param element - Element to search for (uses `===`).
166
+ * @returns `true` if found.
167
+ */
168
+ includes(element) {
169
+ return this.has(element);
170
+ }
171
+ /**
172
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
173
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
174
+ */
175
+ *entries() {
176
+ let index = 0;
177
+ for (const value of this) {
178
+ yield [index++, value];
179
+ }
180
+ }
181
+ /**
182
+ * Return an iterator of numeric indices (Array-compatible).
183
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
184
+ */
185
+ *keys() {
186
+ let index = 0;
187
+ for (const _ of this) {
188
+ yield index++;
189
+ }
190
+ }
162
191
  /**
163
192
  * Reduces all elements to a single accumulated value.
164
193
  *
@@ -293,6 +322,9 @@ var Stack = class extends IterableElementBase {
293
322
 
294
323
 
295
324
 
325
+
326
+
327
+
296
328
 
297
329
 
298
330
 
@@ -357,6 +389,9 @@ var Stack = class extends IterableElementBase {
357
389
 
358
390
 
359
391
 
392
+
393
+
394
+
360
395
 
361
396
 
362
397
 
@@ -410,6 +445,9 @@ var Stack = class extends IterableElementBase {
410
445
 
411
446
 
412
447
 
448
+
449
+
450
+
413
451
 
414
452
 
415
453
 
@@ -463,6 +501,9 @@ var Stack = class extends IterableElementBase {
463
501
 
464
502
 
465
503
 
504
+
505
+
506
+
466
507
 
467
508
 
468
509
 
@@ -525,6 +566,9 @@ var Stack = class extends IterableElementBase {
525
566
 
526
567
 
527
568
 
569
+
570
+
571
+
528
572
 
529
573
 
530
574
 
@@ -602,6 +646,9 @@ var Stack = class extends IterableElementBase {
602
646
 
603
647
 
604
648
 
649
+
650
+
651
+
605
652
 
606
653
 
607
654
 
@@ -679,6 +726,9 @@ var Stack = class extends IterableElementBase {
679
726
 
680
727
 
681
728
 
729
+
730
+
731
+
682
732
 
683
733
 
684
734
 
@@ -729,6 +779,9 @@ var Stack = class extends IterableElementBase {
729
779
 
730
780
 
731
781
 
782
+
783
+
784
+
732
785
 
733
786
 
734
787
 
@@ -785,6 +838,9 @@ var Stack = class extends IterableElementBase {
785
838
 
786
839
 
787
840
 
841
+
842
+
843
+
788
844
 
789
845
 
790
846
 
@@ -861,6 +917,9 @@ var Stack = class extends IterableElementBase {
861
917
 
862
918
 
863
919
 
920
+
921
+
922
+
864
923
 
865
924
 
866
925
 
package/dist/esm/trie.mjs CHANGED
@@ -184,6 +184,35 @@ var IterableElementBase = class {
184
184
  for (const ele of this) if (ele === element) return true;
185
185
  return false;
186
186
  }
187
+ /**
188
+ * Check whether a value exists (Array-compatible alias for `has`).
189
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
190
+ * @param element - Element to search for (uses `===`).
191
+ * @returns `true` if found.
192
+ */
193
+ includes(element) {
194
+ return this.has(element);
195
+ }
196
+ /**
197
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
198
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
199
+ */
200
+ *entries() {
201
+ let index = 0;
202
+ for (const value of this) {
203
+ yield [index++, value];
204
+ }
205
+ }
206
+ /**
207
+ * Return an iterator of numeric indices (Array-compatible).
208
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
209
+ */
210
+ *keys() {
211
+ let index = 0;
212
+ for (const _ of this) {
213
+ yield index++;
214
+ }
215
+ }
187
216
  /**
188
217
  * Reduces all elements to a single accumulated value.
189
218
  *
@@ -421,6 +450,9 @@ var Trie = class extends IterableElementBase {
421
450
 
422
451
 
423
452
 
453
+
454
+
455
+
424
456
 
425
457
 
426
458
 
@@ -497,6 +529,9 @@ var Trie = class extends IterableElementBase {
497
529
 
498
530
 
499
531
 
532
+
533
+
534
+
500
535
 
501
536
 
502
537
 
@@ -560,6 +595,9 @@ var Trie = class extends IterableElementBase {
560
595
 
561
596
 
562
597
 
598
+
599
+
600
+
563
601
 
564
602
 
565
603
 
@@ -618,6 +656,9 @@ var Trie = class extends IterableElementBase {
618
656
 
619
657
 
620
658
 
659
+
660
+
661
+
621
662
 
622
663
 
623
664
 
@@ -668,6 +709,9 @@ var Trie = class extends IterableElementBase {
668
709
 
669
710
 
670
711
 
712
+
713
+
714
+
671
715
 
672
716
 
673
717
 
@@ -722,6 +766,9 @@ var Trie = class extends IterableElementBase {
722
766
 
723
767
 
724
768
 
769
+
770
+
771
+
725
772
 
726
773
 
727
774
 
@@ -858,6 +905,9 @@ var Trie = class extends IterableElementBase {
858
905
 
859
906
 
860
907
 
908
+
909
+
910
+
861
911
 
862
912
 
863
913
 
@@ -938,6 +988,9 @@ var Trie = class extends IterableElementBase {
938
988
 
939
989
 
940
990
 
991
+
992
+
993
+
941
994
 
942
995
 
943
996
 
@@ -1001,6 +1054,9 @@ var Trie = class extends IterableElementBase {
1001
1054
 
1002
1055
 
1003
1056
 
1057
+
1058
+
1059
+
1004
1060
 
1005
1061
 
1006
1062
 
@@ -1082,6 +1138,9 @@ var Trie = class extends IterableElementBase {
1082
1138
 
1083
1139
 
1084
1140
 
1141
+
1142
+
1143
+
1085
1144
 
1086
1145
 
1087
1146
 
@@ -1136,6 +1195,9 @@ var Trie = class extends IterableElementBase {
1136
1195
 
1137
1196
 
1138
1197
 
1198
+
1199
+
1200
+
1139
1201
 
1140
1202
 
1141
1203