data-structure-typed 2.5.2 → 2.6.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.
Files changed (162) hide show
  1. package/.husky/pre-commit +3 -0
  2. package/CHANGELOG.md +3 -1
  3. package/MIGRATION.md +217 -0
  4. package/README.md +80 -8
  5. package/README_CN.md +569 -143
  6. package/SPECIFICATION.md +44 -14
  7. package/SPECIFICATION.zh-CN.md +44 -14
  8. package/dist/cjs/binary-tree.cjs +5841 -1678
  9. package/dist/cjs/graph.cjs +422 -14
  10. package/dist/cjs/hash.cjs +95 -7
  11. package/dist/cjs/heap.cjs +174 -16
  12. package/dist/cjs/index.cjs +7751 -2449
  13. package/dist/cjs/linked-list.cjs +443 -2
  14. package/dist/cjs/matrix.cjs +56 -0
  15. package/dist/cjs/priority-queue.cjs +172 -14
  16. package/dist/cjs/queue.cjs +435 -0
  17. package/dist/cjs/stack.cjs +103 -4
  18. package/dist/cjs/trie.cjs +106 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +5933 -1772
  20. package/dist/cjs-legacy/graph.cjs +422 -14
  21. package/dist/cjs-legacy/hash.cjs +95 -7
  22. package/dist/cjs-legacy/heap.cjs +174 -16
  23. package/dist/cjs-legacy/index.cjs +8154 -2854
  24. package/dist/cjs-legacy/linked-list.cjs +443 -2
  25. package/dist/cjs-legacy/matrix.cjs +56 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +172 -14
  27. package/dist/cjs-legacy/queue.cjs +435 -0
  28. package/dist/cjs-legacy/stack.cjs +103 -4
  29. package/dist/cjs-legacy/trie.cjs +106 -0
  30. package/dist/esm/binary-tree.mjs +5841 -1678
  31. package/dist/esm/graph.mjs +422 -14
  32. package/dist/esm/hash.mjs +95 -7
  33. package/dist/esm/heap.mjs +174 -16
  34. package/dist/esm/index.mjs +7751 -2449
  35. package/dist/esm/linked-list.mjs +443 -2
  36. package/dist/esm/matrix.mjs +56 -0
  37. package/dist/esm/priority-queue.mjs +172 -14
  38. package/dist/esm/queue.mjs +435 -0
  39. package/dist/esm/stack.mjs +103 -4
  40. package/dist/esm/trie.mjs +106 -0
  41. package/dist/esm-legacy/binary-tree.mjs +5933 -1772
  42. package/dist/esm-legacy/graph.mjs +422 -14
  43. package/dist/esm-legacy/hash.mjs +95 -7
  44. package/dist/esm-legacy/heap.mjs +174 -16
  45. package/dist/esm-legacy/index.mjs +8154 -2854
  46. package/dist/esm-legacy/linked-list.mjs +443 -2
  47. package/dist/esm-legacy/matrix.mjs +56 -0
  48. package/dist/esm-legacy/priority-queue.mjs +172 -14
  49. package/dist/esm-legacy/queue.mjs +435 -0
  50. package/dist/esm-legacy/stack.mjs +103 -4
  51. package/dist/esm-legacy/trie.mjs +106 -0
  52. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  53. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  54. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  55. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  56. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  57. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  58. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  59. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  60. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  61. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  62. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  63. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  64. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  65. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  66. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  67. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  68. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  69. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  70. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  71. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  72. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  73. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  74. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  75. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  76. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  77. package/dist/umd/data-structure-typed.js +7784 -2484
  78. package/dist/umd/data-structure-typed.min.js +4 -4
  79. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
  80. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
  81. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
  82. package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
  83. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
  84. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
  85. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +143 -155
  86. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  87. package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
  88. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
  89. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
  90. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
  91. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
  92. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  93. package/docs-site-docusaurus/docs/api/classes/HashMap.md +38 -38
  94. package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
  95. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
  96. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +23 -23
  97. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
  98. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
  99. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +46 -42
  100. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
  101. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
  102. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
  103. package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
  104. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
  105. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
  106. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
  107. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
  108. package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
  109. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
  110. package/docs-site-docusaurus/docs/api/classes/Queue.md +111 -59
  111. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
  112. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
  113. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
  114. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
  115. package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
  116. package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
  117. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
  118. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
  119. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
  120. package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
  121. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  122. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
  123. package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
  124. package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
  125. package/docs-site-docusaurus/docs/guide/faq.md +53 -0
  126. package/docs-site-docusaurus/docs/guide/guides.md +8 -9
  127. package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
  128. package/docs-site-docusaurus/docs/guide/overview.md +131 -17
  129. package/docs-site-docusaurus/src/pages/index.tsx +4 -0
  130. package/docs-site-docusaurus/typedoc.json +1 -0
  131. package/jest.integration.config.js +1 -2
  132. package/package.json +10 -7
  133. package/src/data-structures/base/iterable-element-base.ts +32 -0
  134. package/src/data-structures/base/linear-base.ts +11 -0
  135. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  136. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  137. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  138. package/src/data-structures/binary-tree/bst.ts +173 -7
  139. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  140. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  141. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  142. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  143. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  144. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  145. package/src/data-structures/graph/directed-graph.ts +71 -1
  146. package/src/data-structures/graph/undirected-graph.ts +64 -1
  147. package/src/data-structures/hash/hash-map.ts +100 -12
  148. package/src/data-structures/heap/heap.ts +149 -19
  149. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  150. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  151. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  152. package/src/data-structures/matrix/matrix.ts +56 -0
  153. package/src/data-structures/queue/deque.ts +187 -0
  154. package/src/data-structures/queue/queue.ts +109 -0
  155. package/src/data-structures/stack/stack.ts +75 -5
  156. package/src/data-structures/trie/trie.ts +84 -0
  157. package/src/interfaces/binary-tree.ts +1 -9
  158. package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
  159. package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
  160. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
  161. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
  162. package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
@@ -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
  *
@@ -285,6 +314,13 @@ var Stack = class extends IterableElementBase {
285
314
 
286
315
 
287
316
 
317
+
318
+
319
+
320
+
321
+
322
+
323
+
288
324
 
289
325
 
290
326
 
@@ -345,6 +381,13 @@ var Stack = class extends IterableElementBase {
345
381
 
346
382
 
347
383
 
384
+
385
+
386
+
387
+
388
+
389
+
390
+
348
391
 
349
392
 
350
393
 
@@ -394,6 +437,13 @@ var Stack = class extends IterableElementBase {
394
437
 
395
438
 
396
439
 
440
+
441
+
442
+
443
+
444
+
445
+
446
+
397
447
 
398
448
 
399
449
 
@@ -443,6 +493,13 @@ var Stack = class extends IterableElementBase {
443
493
 
444
494
 
445
495
 
496
+
497
+
498
+
499
+
500
+
501
+
502
+
446
503
 
447
504
 
448
505
 
@@ -501,6 +558,13 @@ var Stack = class extends IterableElementBase {
501
558
 
502
559
 
503
560
 
561
+
562
+
563
+
564
+
565
+
566
+
567
+
504
568
 
505
569
 
506
570
 
@@ -574,6 +638,13 @@ var Stack = class extends IterableElementBase {
574
638
 
575
639
 
576
640
 
641
+
642
+
643
+
644
+
645
+
646
+
647
+
577
648
 
578
649
 
579
650
 
@@ -590,18 +661,18 @@ var Stack = class extends IterableElementBase {
590
661
  */
591
662
  delete(element) {
592
663
  const idx = this._indexOfByEquals(element);
593
- return this.deleteAt(idx);
664
+ return this.deleteAt(idx) !== void 0;
594
665
  }
595
666
  /**
596
667
  * Delete the element at an index.
597
668
  * @remarks Time O(N), Space O(1)
598
669
  * @param index - Zero-based index from the bottom.
599
- * @returns True if removed.
670
+ * @returns The removed element, or undefined if the index is out of range.
600
671
  */
601
672
  deleteAt(index) {
602
- if (index < 0 || index >= this.elements.length) return false;
673
+ if (index < 0 || index >= this.elements.length) return void 0;
603
674
  const spliced = this.elements.splice(index, 1);
604
- return spliced.length === 1;
675
+ return spliced[0];
605
676
  }
606
677
  /**
607
678
  * Delete the first element that satisfies a predicate.
@@ -647,6 +718,13 @@ var Stack = class extends IterableElementBase {
647
718
 
648
719
 
649
720
 
721
+
722
+
723
+
724
+
725
+
726
+
727
+
650
728
 
651
729
 
652
730
 
@@ -693,6 +771,13 @@ var Stack = class extends IterableElementBase {
693
771
 
694
772
 
695
773
 
774
+
775
+
776
+
777
+
778
+
779
+
780
+
696
781
 
697
782
 
698
783
 
@@ -745,6 +830,13 @@ var Stack = class extends IterableElementBase {
745
830
 
746
831
 
747
832
 
833
+
834
+
835
+
836
+
837
+
838
+
839
+
748
840
 
749
841
 
750
842
 
@@ -817,6 +909,13 @@ var Stack = class extends IterableElementBase {
817
909
 
818
910
 
819
911
 
912
+
913
+
914
+
915
+
916
+
917
+
918
+
820
919
 
821
920
 
822
921
 
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
  *
@@ -413,6 +442,13 @@ var Trie = class extends IterableElementBase {
413
442
 
414
443
 
415
444
 
445
+
446
+
447
+
448
+
449
+
450
+
451
+
416
452
 
417
453
 
418
454
 
@@ -485,6 +521,13 @@ var Trie = class extends IterableElementBase {
485
521
 
486
522
 
487
523
 
524
+
525
+
526
+
527
+
528
+
529
+
530
+
488
531
 
489
532
 
490
533
 
@@ -544,6 +587,13 @@ var Trie = class extends IterableElementBase {
544
587
 
545
588
 
546
589
 
590
+
591
+
592
+
593
+
594
+
595
+
596
+
547
597
 
548
598
 
549
599
 
@@ -598,6 +648,13 @@ var Trie = class extends IterableElementBase {
598
648
 
599
649
 
600
650
 
651
+
652
+
653
+
654
+
655
+
656
+
657
+
601
658
 
602
659
 
603
660
 
@@ -644,6 +701,13 @@ var Trie = class extends IterableElementBase {
644
701
 
645
702
 
646
703
 
704
+
705
+
706
+
707
+
708
+
709
+
710
+
647
711
 
648
712
 
649
713
 
@@ -694,6 +758,13 @@ var Trie = class extends IterableElementBase {
694
758
 
695
759
 
696
760
 
761
+
762
+
763
+
764
+
765
+
766
+
767
+
697
768
 
698
769
 
699
770
 
@@ -826,6 +897,13 @@ var Trie = class extends IterableElementBase {
826
897
 
827
898
 
828
899
 
900
+
901
+
902
+
903
+
904
+
905
+
906
+
829
907
 
830
908
 
831
909
 
@@ -902,6 +980,13 @@ var Trie = class extends IterableElementBase {
902
980
 
903
981
 
904
982
 
983
+
984
+
985
+
986
+
987
+
988
+
989
+
905
990
 
906
991
 
907
992
 
@@ -961,6 +1046,13 @@ var Trie = class extends IterableElementBase {
961
1046
 
962
1047
 
963
1048
 
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
964
1056
 
965
1057
 
966
1058
 
@@ -1038,6 +1130,13 @@ var Trie = class extends IterableElementBase {
1038
1130
 
1039
1131
 
1040
1132
 
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1041
1140
 
1042
1141
 
1043
1142
 
@@ -1088,6 +1187,13 @@ var Trie = class extends IterableElementBase {
1088
1187
 
1089
1188
 
1090
1189
 
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1091
1197
 
1092
1198
 
1093
1199