data-structure-typed 2.5.2 → 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.
Files changed (156) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/MIGRATION.md +169 -0
  3. package/README.md +60 -6
  4. package/README_CN.md +551 -143
  5. package/SPECIFICATION.md +20 -14
  6. package/SPECIFICATION.zh-CN.md +20 -14
  7. package/dist/cjs/binary-tree.cjs +2417 -132
  8. package/dist/cjs/graph.cjs +248 -14
  9. package/dist/cjs/hash.cjs +62 -7
  10. package/dist/cjs/heap.cjs +103 -16
  11. package/dist/cjs/index.cjs +3046 -124
  12. package/dist/cjs/linked-list.cjs +219 -0
  13. package/dist/cjs/matrix.cjs +32 -0
  14. package/dist/cjs/priority-queue.cjs +101 -14
  15. package/dist/cjs/queue.cjs +215 -0
  16. package/dist/cjs/stack.cjs +44 -4
  17. package/dist/cjs/trie.cjs +44 -0
  18. package/dist/cjs-legacy/binary-tree.cjs +2406 -123
  19. package/dist/cjs-legacy/graph.cjs +248 -14
  20. package/dist/cjs-legacy/hash.cjs +62 -7
  21. package/dist/cjs-legacy/heap.cjs +103 -16
  22. package/dist/cjs-legacy/index.cjs +3105 -185
  23. package/dist/cjs-legacy/linked-list.cjs +219 -0
  24. package/dist/cjs-legacy/matrix.cjs +32 -0
  25. package/dist/cjs-legacy/priority-queue.cjs +101 -14
  26. package/dist/cjs-legacy/queue.cjs +215 -0
  27. package/dist/cjs-legacy/stack.cjs +44 -4
  28. package/dist/cjs-legacy/trie.cjs +44 -0
  29. package/dist/esm/binary-tree.mjs +2417 -132
  30. package/dist/esm/graph.mjs +248 -14
  31. package/dist/esm/hash.mjs +62 -7
  32. package/dist/esm/heap.mjs +103 -16
  33. package/dist/esm/index.mjs +3046 -124
  34. package/dist/esm/linked-list.mjs +219 -0
  35. package/dist/esm/matrix.mjs +32 -0
  36. package/dist/esm/priority-queue.mjs +101 -14
  37. package/dist/esm/queue.mjs +215 -0
  38. package/dist/esm/stack.mjs +44 -4
  39. package/dist/esm/trie.mjs +44 -0
  40. package/dist/esm-legacy/binary-tree.mjs +2406 -123
  41. package/dist/esm-legacy/graph.mjs +248 -14
  42. package/dist/esm-legacy/hash.mjs +62 -7
  43. package/dist/esm-legacy/heap.mjs +103 -16
  44. package/dist/esm-legacy/index.mjs +3105 -185
  45. package/dist/esm-legacy/linked-list.mjs +219 -0
  46. package/dist/esm-legacy/matrix.mjs +32 -0
  47. package/dist/esm-legacy/priority-queue.mjs +101 -14
  48. package/dist/esm-legacy/queue.mjs +215 -0
  49. package/dist/esm-legacy/stack.mjs +44 -4
  50. package/dist/esm-legacy/trie.mjs +44 -0
  51. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
  52. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
  53. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
  54. package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
  55. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
  56. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
  57. package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
  58. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
  59. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
  60. package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
  61. package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
  62. package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
  63. package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
  64. package/dist/types/data-structures/heap/heap.d.ts +98 -12
  65. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
  66. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
  67. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
  68. package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
  69. package/dist/types/data-structures/queue/deque.d.ts +82 -0
  70. package/dist/types/data-structures/queue/queue.d.ts +61 -0
  71. package/dist/types/data-structures/stack/stack.d.ts +42 -2
  72. package/dist/types/data-structures/trie/trie.d.ts +48 -0
  73. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  74. package/dist/umd/data-structure-typed.js +3105 -185
  75. package/dist/umd/data-structure-typed.min.js +4 -4
  76. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
  77. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
  78. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
  79. package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
  80. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
  81. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
  82. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +143 -155
  83. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  84. package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
  85. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
  86. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
  87. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
  88. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
  89. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  90. package/docs-site-docusaurus/docs/api/classes/HashMap.md +38 -38
  91. package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
  92. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
  93. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +23 -23
  94. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
  95. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
  96. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +42 -42
  97. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
  98. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
  99. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
  100. package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
  101. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
  102. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
  103. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
  104. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
  105. package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
  106. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
  107. package/docs-site-docusaurus/docs/api/classes/Queue.md +111 -59
  108. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
  109. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
  110. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
  111. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
  112. package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
  113. package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
  114. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
  115. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
  116. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
  117. package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
  118. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  119. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
  120. package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
  121. package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
  122. package/docs-site-docusaurus/docs/guide/faq.md +53 -0
  123. package/docs-site-docusaurus/docs/guide/guides.md +8 -9
  124. package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
  125. package/docs-site-docusaurus/docs/guide/overview.md +131 -17
  126. package/docs-site-docusaurus/src/pages/index.tsx +4 -0
  127. package/docs-site-docusaurus/typedoc.json +1 -0
  128. package/package.json +7 -6
  129. package/src/data-structures/binary-tree/avl-tree.ts +52 -5
  130. package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
  131. package/src/data-structures/binary-tree/binary-tree.ts +167 -81
  132. package/src/data-structures/binary-tree/bst.ts +101 -7
  133. package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
  134. package/src/data-structures/binary-tree/segment-tree.ts +24 -0
  135. package/src/data-structures/binary-tree/tree-map.ts +540 -3
  136. package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
  137. package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
  138. package/src/data-structures/binary-tree/tree-set.ts +520 -3
  139. package/src/data-structures/graph/directed-graph.ts +41 -1
  140. package/src/data-structures/graph/undirected-graph.ts +37 -1
  141. package/src/data-structures/hash/hash-map.ts +67 -12
  142. package/src/data-structures/heap/heap.ts +107 -19
  143. package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
  144. package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
  145. package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
  146. package/src/data-structures/matrix/matrix.ts +32 -0
  147. package/src/data-structures/queue/deque.ts +85 -0
  148. package/src/data-structures/queue/queue.ts +73 -0
  149. package/src/data-structures/stack/stack.ts +45 -5
  150. package/src/data-structures/trie/trie.ts +48 -0
  151. package/src/interfaces/binary-tree.ts +1 -9
  152. package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
  153. package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
  154. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
  155. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
  156. package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
@@ -328,6 +328,10 @@ var _Heap = class _Heap extends IterableElementBase {
328
328
 
329
329
 
330
330
 
331
+
332
+
333
+
334
+
331
335
 
332
336
 
333
337
 
@@ -382,7 +386,7 @@ var _Heap = class _Heap extends IterableElementBase {
382
386
  }
383
387
  /**
384
388
  * Insert an element.
385
- * @remarks Time O(1) amortized, Space O(1)
389
+ * @remarks Time O(log N) amortized, Space O(1)
386
390
  * @param element - Element to insert.
387
391
  * @returns True.
388
392
 
@@ -415,6 +419,10 @@ var _Heap = class _Heap extends IterableElementBase {
415
419
 
416
420
 
417
421
 
422
+
423
+
424
+
425
+
418
426
 
419
427
 
420
428
 
@@ -472,6 +480,10 @@ var _Heap = class _Heap extends IterableElementBase {
472
480
 
473
481
 
474
482
 
483
+
484
+
485
+
486
+
475
487
 
476
488
 
477
489
 
@@ -536,6 +548,37 @@ var _Heap = class _Heap extends IterableElementBase {
536
548
 
537
549
 
538
550
 
551
+
552
+
553
+
554
+ * @example
555
+ * // Heap with custom comparator (MaxHeap behavior)
556
+ * interface Task {
557
+ * id: number;
558
+ * priority: number;
559
+ * name: string;
560
+ * }
561
+ *
562
+ * // Custom comparator for max heap behavior (higher priority first)
563
+ * const tasks: Task[] = [
564
+ * { id: 1, priority: 5, name: 'Email' },
565
+ * { id: 2, priority: 3, name: 'Chat' },
566
+ * { id: 3, priority: 8, name: 'Alert' }
567
+ * ];
568
+ *
569
+ * const maxHeap = new Heap(tasks, {
570
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
571
+ * });
572
+ *
573
+ * console.log(maxHeap.size); // 3;
574
+ *
575
+ * // Peek returns highest priority task
576
+ * const topTask = maxHeap.peek();
577
+ * console.log(topTask?.priority); // 8;
578
+ * console.log(topTask?.name); // 'Alert';
579
+ */
580
+ /**
581
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
539
582
  * @example
540
583
  * // Heap with custom comparator (MaxHeap behavior)
541
584
  * interface Task {
@@ -563,6 +606,14 @@ var _Heap = class _Heap extends IterableElementBase {
563
606
  * console.log(topTask?.name); // 'Alert';
564
607
  */
565
608
  poll() {
609
+ return this.pop();
610
+ }
611
+ /**
612
+ * Remove and return the top element (min or max depending on comparator).
613
+ * @remarks Time O(log N) amortized, Space O(1)
614
+ * @returns The removed top element, or undefined if empty.
615
+ */
616
+ pop() {
566
617
  if (this.elements.length === 0) return;
567
618
  const value = this.elements[0];
568
619
  const last = this.elements.pop();
@@ -606,6 +657,10 @@ var _Heap = class _Heap extends IterableElementBase {
606
657
 
607
658
 
608
659
 
660
+
661
+
662
+
663
+
609
664
 
610
665
 
611
666
 
@@ -706,6 +761,10 @@ var _Heap = class _Heap extends IterableElementBase {
706
761
 
707
762
 
708
763
 
764
+
765
+
766
+
767
+
709
768
 
710
769
 
711
770
 
@@ -753,6 +812,10 @@ var _Heap = class _Heap extends IterableElementBase {
753
812
 
754
813
 
755
814
 
815
+
816
+
817
+
818
+
756
819
 
757
820
 
758
821
 
@@ -767,16 +830,6 @@ var _Heap = class _Heap extends IterableElementBase {
767
830
  clear() {
768
831
  this._elements = [];
769
832
  }
770
- /**
771
- * Replace the backing array and rebuild the heap.
772
- * @remarks Time O(N), Space O(N)
773
- * @param elements - Iterable used to refill the heap.
774
- * @returns Array of per-node results from fixing steps.
775
- */
776
- refill(elements) {
777
- this._elements = Array.from(elements);
778
- return this.fix();
779
- }
780
833
  /**
781
834
  * Check if an equal element exists in the heap.
782
835
  * @remarks Time O(N), Space O(1)
@@ -803,6 +856,10 @@ var _Heap = class _Heap extends IterableElementBase {
803
856
 
804
857
 
805
858
 
859
+
860
+
861
+
862
+
806
863
 
807
864
 
808
865
 
@@ -850,6 +907,10 @@ var _Heap = class _Heap extends IterableElementBase {
850
907
 
851
908
 
852
909
 
910
+
911
+
912
+
913
+
853
914
 
854
915
 
855
916
 
@@ -871,7 +932,7 @@ var _Heap = class _Heap extends IterableElementBase {
871
932
  }
872
933
  if (index < 0) return false;
873
934
  if (index === 0) {
874
- this.poll();
935
+ this.pop();
875
936
  } else if (index === this.elements.length - 1) {
876
937
  this.elements.pop();
877
938
  } else {
@@ -881,13 +942,19 @@ var _Heap = class _Heap extends IterableElementBase {
881
942
  }
882
943
  return true;
883
944
  }
945
+ /**
946
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
947
+ */
948
+ deleteBy(predicate) {
949
+ return this.deleteWhere(predicate);
950
+ }
884
951
  /**
885
952
  * Delete the first element that matches a predicate.
886
953
  * @remarks Time O(N), Space O(1)
887
954
  * @param predicate - Function (element, index, heap) → boolean.
888
955
  * @returns True if an element was removed.
889
956
  */
890
- deleteBy(predicate) {
957
+ deleteWhere(predicate) {
891
958
  let idx = -1;
892
959
  for (let i = 0; i < this.elements.length; i++) {
893
960
  if (predicate(this.elements[i], i, this)) {
@@ -897,7 +964,7 @@ var _Heap = class _Heap extends IterableElementBase {
897
964
  }
898
965
  if (idx < 0) return false;
899
966
  if (idx === 0) {
900
- this.poll();
967
+ this.pop();
901
968
  } else if (idx === this.elements.length - 1) {
902
969
  this.elements.pop();
903
970
  } else {
@@ -943,6 +1010,10 @@ var _Heap = class _Heap extends IterableElementBase {
943
1010
 
944
1011
 
945
1012
 
1013
+
1014
+
1015
+
1016
+
946
1017
 
947
1018
 
948
1019
 
@@ -1023,6 +1094,10 @@ var _Heap = class _Heap extends IterableElementBase {
1023
1094
 
1024
1095
 
1025
1096
 
1097
+
1098
+
1099
+
1100
+
1026
1101
 
1027
1102
 
1028
1103
 
@@ -1076,6 +1151,10 @@ var _Heap = class _Heap extends IterableElementBase {
1076
1151
 
1077
1152
 
1078
1153
 
1154
+
1155
+
1156
+
1157
+
1079
1158
 
1080
1159
 
1081
1160
 
@@ -1128,6 +1207,10 @@ var _Heap = class _Heap extends IterableElementBase {
1128
1207
 
1129
1208
 
1130
1209
 
1210
+
1211
+
1212
+
1213
+
1131
1214
 
1132
1215
 
1133
1216
 
@@ -1187,6 +1270,10 @@ var _Heap = class _Heap extends IterableElementBase {
1187
1270
 
1188
1271
 
1189
1272
 
1273
+
1274
+
1275
+
1276
+
1190
1277
 
1191
1278
 
1192
1279