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
@@ -319,6 +319,10 @@ var Heap = class _Heap extends IterableElementBase {
319
319
 
320
320
 
321
321
 
322
+
323
+
324
+
325
+
322
326
 
323
327
 
324
328
 
@@ -372,7 +376,7 @@ var Heap = class _Heap extends IterableElementBase {
372
376
  }
373
377
  /**
374
378
  * Insert an element.
375
- * @remarks Time O(1) amortized, Space O(1)
379
+ * @remarks Time O(log N) amortized, Space O(1)
376
380
  * @param element - Element to insert.
377
381
  * @returns True.
378
382
 
@@ -405,6 +409,10 @@ var Heap = class _Heap extends IterableElementBase {
405
409
 
406
410
 
407
411
 
412
+
413
+
414
+
415
+
408
416
 
409
417
 
410
418
 
@@ -462,6 +470,10 @@ var Heap = class _Heap extends IterableElementBase {
462
470
 
463
471
 
464
472
 
473
+
474
+
475
+
476
+
465
477
 
466
478
 
467
479
 
@@ -526,6 +538,37 @@ var Heap = class _Heap extends IterableElementBase {
526
538
 
527
539
 
528
540
 
541
+
542
+
543
+
544
+ * @example
545
+ * // Heap with custom comparator (MaxHeap behavior)
546
+ * interface Task {
547
+ * id: number;
548
+ * priority: number;
549
+ * name: string;
550
+ * }
551
+ *
552
+ * // Custom comparator for max heap behavior (higher priority first)
553
+ * const tasks: Task[] = [
554
+ * { id: 1, priority: 5, name: 'Email' },
555
+ * { id: 2, priority: 3, name: 'Chat' },
556
+ * { id: 3, priority: 8, name: 'Alert' }
557
+ * ];
558
+ *
559
+ * const maxHeap = new Heap(tasks, {
560
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
561
+ * });
562
+ *
563
+ * console.log(maxHeap.size); // 3;
564
+ *
565
+ * // Peek returns highest priority task
566
+ * const topTask = maxHeap.peek();
567
+ * console.log(topTask?.priority); // 8;
568
+ * console.log(topTask?.name); // 'Alert';
569
+ */
570
+ /**
571
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
529
572
  * @example
530
573
  * // Heap with custom comparator (MaxHeap behavior)
531
574
  * interface Task {
@@ -553,6 +596,14 @@ var Heap = class _Heap extends IterableElementBase {
553
596
  * console.log(topTask?.name); // 'Alert';
554
597
  */
555
598
  poll() {
599
+ return this.pop();
600
+ }
601
+ /**
602
+ * Remove and return the top element (min or max depending on comparator).
603
+ * @remarks Time O(log N) amortized, Space O(1)
604
+ * @returns The removed top element, or undefined if empty.
605
+ */
606
+ pop() {
556
607
  if (this.elements.length === 0) return;
557
608
  const value = this.elements[0];
558
609
  const last = this.elements.pop();
@@ -596,6 +647,10 @@ var Heap = class _Heap extends IterableElementBase {
596
647
 
597
648
 
598
649
 
650
+
651
+
652
+
653
+
599
654
 
600
655
 
601
656
 
@@ -696,6 +751,10 @@ var Heap = class _Heap extends IterableElementBase {
696
751
 
697
752
 
698
753
 
754
+
755
+
756
+
757
+
699
758
 
700
759
 
701
760
 
@@ -743,6 +802,10 @@ var Heap = class _Heap extends IterableElementBase {
743
802
 
744
803
 
745
804
 
805
+
806
+
807
+
808
+
746
809
 
747
810
 
748
811
 
@@ -757,16 +820,6 @@ var Heap = class _Heap extends IterableElementBase {
757
820
  clear() {
758
821
  this._elements = [];
759
822
  }
760
- /**
761
- * Replace the backing array and rebuild the heap.
762
- * @remarks Time O(N), Space O(N)
763
- * @param elements - Iterable used to refill the heap.
764
- * @returns Array of per-node results from fixing steps.
765
- */
766
- refill(elements) {
767
- this._elements = Array.from(elements);
768
- return this.fix();
769
- }
770
823
  /**
771
824
  * Check if an equal element exists in the heap.
772
825
  * @remarks Time O(N), Space O(1)
@@ -793,6 +846,10 @@ var Heap = class _Heap extends IterableElementBase {
793
846
 
794
847
 
795
848
 
849
+
850
+
851
+
852
+
796
853
 
797
854
 
798
855
 
@@ -840,6 +897,10 @@ var Heap = class _Heap extends IterableElementBase {
840
897
 
841
898
 
842
899
 
900
+
901
+
902
+
903
+
843
904
 
844
905
 
845
906
 
@@ -861,7 +922,7 @@ var Heap = class _Heap extends IterableElementBase {
861
922
  }
862
923
  if (index < 0) return false;
863
924
  if (index === 0) {
864
- this.poll();
925
+ this.pop();
865
926
  } else if (index === this.elements.length - 1) {
866
927
  this.elements.pop();
867
928
  } else {
@@ -871,13 +932,19 @@ var Heap = class _Heap extends IterableElementBase {
871
932
  }
872
933
  return true;
873
934
  }
935
+ /**
936
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
937
+ */
938
+ deleteBy(predicate) {
939
+ return this.deleteWhere(predicate);
940
+ }
874
941
  /**
875
942
  * Delete the first element that matches a predicate.
876
943
  * @remarks Time O(N), Space O(1)
877
944
  * @param predicate - Function (element, index, heap) → boolean.
878
945
  * @returns True if an element was removed.
879
946
  */
880
- deleteBy(predicate) {
947
+ deleteWhere(predicate) {
881
948
  let idx = -1;
882
949
  for (let i = 0; i < this.elements.length; i++) {
883
950
  if (predicate(this.elements[i], i, this)) {
@@ -887,7 +954,7 @@ var Heap = class _Heap extends IterableElementBase {
887
954
  }
888
955
  if (idx < 0) return false;
889
956
  if (idx === 0) {
890
- this.poll();
957
+ this.pop();
891
958
  } else if (idx === this.elements.length - 1) {
892
959
  this.elements.pop();
893
960
  } else {
@@ -933,6 +1000,10 @@ var Heap = class _Heap extends IterableElementBase {
933
1000
 
934
1001
 
935
1002
 
1003
+
1004
+
1005
+
1006
+
936
1007
 
937
1008
 
938
1009
 
@@ -1013,6 +1084,10 @@ var Heap = class _Heap extends IterableElementBase {
1013
1084
 
1014
1085
 
1015
1086
 
1087
+
1088
+
1089
+
1090
+
1016
1091
 
1017
1092
 
1018
1093
 
@@ -1066,6 +1141,10 @@ var Heap = class _Heap extends IterableElementBase {
1066
1141
 
1067
1142
 
1068
1143
 
1144
+
1145
+
1146
+
1147
+
1069
1148
 
1070
1149
 
1071
1150
 
@@ -1118,6 +1197,10 @@ var Heap = class _Heap extends IterableElementBase {
1118
1197
 
1119
1198
 
1120
1199
 
1200
+
1201
+
1202
+
1203
+
1121
1204
 
1122
1205
 
1123
1206
 
@@ -1177,6 +1260,10 @@ var Heap = class _Heap extends IterableElementBase {
1177
1260
 
1178
1261
 
1179
1262
 
1263
+
1264
+
1265
+
1266
+
1180
1267
 
1181
1268
 
1182
1269