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.
- package/CHANGELOG.md +3 -1
- package/MIGRATION.md +169 -0
- package/README.md +60 -6
- package/README_CN.md +551 -143
- package/SPECIFICATION.md +20 -14
- package/SPECIFICATION.zh-CN.md +20 -14
- package/dist/cjs/binary-tree.cjs +2417 -132
- package/dist/cjs/graph.cjs +248 -14
- package/dist/cjs/hash.cjs +62 -7
- package/dist/cjs/heap.cjs +103 -16
- package/dist/cjs/index.cjs +3046 -124
- package/dist/cjs/linked-list.cjs +219 -0
- package/dist/cjs/matrix.cjs +32 -0
- package/dist/cjs/priority-queue.cjs +101 -14
- package/dist/cjs/queue.cjs +215 -0
- package/dist/cjs/stack.cjs +44 -4
- package/dist/cjs/trie.cjs +44 -0
- package/dist/cjs-legacy/binary-tree.cjs +2406 -123
- package/dist/cjs-legacy/graph.cjs +248 -14
- package/dist/cjs-legacy/hash.cjs +62 -7
- package/dist/cjs-legacy/heap.cjs +103 -16
- package/dist/cjs-legacy/index.cjs +3105 -185
- package/dist/cjs-legacy/linked-list.cjs +219 -0
- package/dist/cjs-legacy/matrix.cjs +32 -0
- package/dist/cjs-legacy/priority-queue.cjs +101 -14
- package/dist/cjs-legacy/queue.cjs +215 -0
- package/dist/cjs-legacy/stack.cjs +44 -4
- package/dist/cjs-legacy/trie.cjs +44 -0
- package/dist/esm/binary-tree.mjs +2417 -132
- package/dist/esm/graph.mjs +248 -14
- package/dist/esm/hash.mjs +62 -7
- package/dist/esm/heap.mjs +103 -16
- package/dist/esm/index.mjs +3046 -124
- package/dist/esm/linked-list.mjs +219 -0
- package/dist/esm/matrix.mjs +32 -0
- package/dist/esm/priority-queue.mjs +101 -14
- package/dist/esm/queue.mjs +215 -0
- package/dist/esm/stack.mjs +44 -4
- package/dist/esm/trie.mjs +44 -0
- package/dist/esm-legacy/binary-tree.mjs +2406 -123
- package/dist/esm-legacy/graph.mjs +248 -14
- package/dist/esm-legacy/hash.mjs +62 -7
- package/dist/esm-legacy/heap.mjs +103 -16
- package/dist/esm-legacy/index.mjs +3105 -185
- package/dist/esm-legacy/linked-list.mjs +219 -0
- package/dist/esm-legacy/matrix.mjs +32 -0
- package/dist/esm-legacy/priority-queue.mjs +101 -14
- package/dist/esm-legacy/queue.mjs +215 -0
- package/dist/esm-legacy/stack.mjs +44 -4
- package/dist/esm-legacy/trie.mjs +44 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
- package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
- package/dist/types/data-structures/heap/heap.d.ts +98 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
- package/dist/types/data-structures/queue/deque.d.ts +82 -0
- package/dist/types/data-structures/queue/queue.d.ts +61 -0
- package/dist/types/data-structures/stack/stack.d.ts +42 -2
- package/dist/types/data-structures/trie/trie.d.ts +48 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/data-structure-typed.js +3105 -185
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
- package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +143 -155
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
- package/docs-site-docusaurus/docs/api/classes/Queue.md +111 -59
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
- package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
- package/docs-site-docusaurus/docs/guide/faq.md +53 -0
- package/docs-site-docusaurus/docs/guide/guides.md +8 -9
- package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
- package/docs-site-docusaurus/docs/guide/overview.md +131 -17
- package/docs-site-docusaurus/src/pages/index.tsx +4 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/package.json +7 -6
- package/src/data-structures/binary-tree/avl-tree.ts +52 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
- package/src/data-structures/binary-tree/binary-tree.ts +167 -81
- package/src/data-structures/binary-tree/bst.ts +101 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
- package/src/data-structures/binary-tree/segment-tree.ts +24 -0
- package/src/data-structures/binary-tree/tree-map.ts +540 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
- package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
- package/src/data-structures/binary-tree/tree-set.ts +520 -3
- package/src/data-structures/graph/directed-graph.ts +41 -1
- package/src/data-structures/graph/undirected-graph.ts +37 -1
- package/src/data-structures/hash/hash-map.ts +67 -12
- package/src/data-structures/heap/heap.ts +107 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
- package/src/data-structures/matrix/matrix.ts +32 -0
- package/src/data-structures/queue/deque.ts +85 -0
- package/src/data-structures/queue/queue.ts +73 -0
- package/src/data-structures/stack/stack.ts +45 -5
- package/src/data-structures/trie/trie.ts +48 -0
- package/src/interfaces/binary-tree.ts +1 -9
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
|
@@ -321,6 +321,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
321
321
|
|
|
322
322
|
|
|
323
323
|
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
324
328
|
|
|
325
329
|
|
|
326
330
|
|
|
@@ -374,7 +378,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
374
378
|
}
|
|
375
379
|
/**
|
|
376
380
|
* Insert an element.
|
|
377
|
-
* @remarks Time O(
|
|
381
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
378
382
|
* @param element - Element to insert.
|
|
379
383
|
* @returns True.
|
|
380
384
|
|
|
@@ -407,6 +411,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
407
411
|
|
|
408
412
|
|
|
409
413
|
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
410
418
|
|
|
411
419
|
|
|
412
420
|
|
|
@@ -464,6 +472,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
464
472
|
|
|
465
473
|
|
|
466
474
|
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
467
479
|
|
|
468
480
|
|
|
469
481
|
|
|
@@ -528,6 +540,37 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
528
540
|
|
|
529
541
|
|
|
530
542
|
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
* @example
|
|
547
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
548
|
+
* interface Task {
|
|
549
|
+
* id: number;
|
|
550
|
+
* priority: number;
|
|
551
|
+
* name: string;
|
|
552
|
+
* }
|
|
553
|
+
*
|
|
554
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
555
|
+
* const tasks: Task[] = [
|
|
556
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
557
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
558
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
559
|
+
* ];
|
|
560
|
+
*
|
|
561
|
+
* const maxHeap = new Heap(tasks, {
|
|
562
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
563
|
+
* });
|
|
564
|
+
*
|
|
565
|
+
* console.log(maxHeap.size); // 3;
|
|
566
|
+
*
|
|
567
|
+
* // Peek returns highest priority task
|
|
568
|
+
* const topTask = maxHeap.peek();
|
|
569
|
+
* console.log(topTask?.priority); // 8;
|
|
570
|
+
* console.log(topTask?.name); // 'Alert';
|
|
571
|
+
*/
|
|
572
|
+
/**
|
|
573
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
531
574
|
* @example
|
|
532
575
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
533
576
|
* interface Task {
|
|
@@ -555,6 +598,14 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
555
598
|
* console.log(topTask?.name); // 'Alert';
|
|
556
599
|
*/
|
|
557
600
|
poll() {
|
|
601
|
+
return this.pop();
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
605
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
606
|
+
* @returns The removed top element, or undefined if empty.
|
|
607
|
+
*/
|
|
608
|
+
pop() {
|
|
558
609
|
if (this.elements.length === 0) return;
|
|
559
610
|
const value = this.elements[0];
|
|
560
611
|
const last = this.elements.pop();
|
|
@@ -598,6 +649,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
598
649
|
|
|
599
650
|
|
|
600
651
|
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
601
656
|
|
|
602
657
|
|
|
603
658
|
|
|
@@ -698,6 +753,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
698
753
|
|
|
699
754
|
|
|
700
755
|
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
701
760
|
|
|
702
761
|
|
|
703
762
|
|
|
@@ -745,6 +804,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
745
804
|
|
|
746
805
|
|
|
747
806
|
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
748
811
|
|
|
749
812
|
|
|
750
813
|
|
|
@@ -759,16 +822,6 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
759
822
|
clear() {
|
|
760
823
|
this._elements = [];
|
|
761
824
|
}
|
|
762
|
-
/**
|
|
763
|
-
* Replace the backing array and rebuild the heap.
|
|
764
|
-
* @remarks Time O(N), Space O(N)
|
|
765
|
-
* @param elements - Iterable used to refill the heap.
|
|
766
|
-
* @returns Array of per-node results from fixing steps.
|
|
767
|
-
*/
|
|
768
|
-
refill(elements) {
|
|
769
|
-
this._elements = Array.from(elements);
|
|
770
|
-
return this.fix();
|
|
771
|
-
}
|
|
772
825
|
/**
|
|
773
826
|
* Check if an equal element exists in the heap.
|
|
774
827
|
* @remarks Time O(N), Space O(1)
|
|
@@ -795,6 +848,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
795
848
|
|
|
796
849
|
|
|
797
850
|
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
798
855
|
|
|
799
856
|
|
|
800
857
|
|
|
@@ -842,6 +899,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
842
899
|
|
|
843
900
|
|
|
844
901
|
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
845
906
|
|
|
846
907
|
|
|
847
908
|
|
|
@@ -863,7 +924,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
863
924
|
}
|
|
864
925
|
if (index < 0) return false;
|
|
865
926
|
if (index === 0) {
|
|
866
|
-
this.
|
|
927
|
+
this.pop();
|
|
867
928
|
} else if (index === this.elements.length - 1) {
|
|
868
929
|
this.elements.pop();
|
|
869
930
|
} else {
|
|
@@ -873,13 +934,19 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
873
934
|
}
|
|
874
935
|
return true;
|
|
875
936
|
}
|
|
937
|
+
/**
|
|
938
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
939
|
+
*/
|
|
940
|
+
deleteBy(predicate) {
|
|
941
|
+
return this.deleteWhere(predicate);
|
|
942
|
+
}
|
|
876
943
|
/**
|
|
877
944
|
* Delete the first element that matches a predicate.
|
|
878
945
|
* @remarks Time O(N), Space O(1)
|
|
879
946
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
880
947
|
* @returns True if an element was removed.
|
|
881
948
|
*/
|
|
882
|
-
|
|
949
|
+
deleteWhere(predicate) {
|
|
883
950
|
let idx = -1;
|
|
884
951
|
for (let i = 0; i < this.elements.length; i++) {
|
|
885
952
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -889,7 +956,7 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
889
956
|
}
|
|
890
957
|
if (idx < 0) return false;
|
|
891
958
|
if (idx === 0) {
|
|
892
|
-
this.
|
|
959
|
+
this.pop();
|
|
893
960
|
} else if (idx === this.elements.length - 1) {
|
|
894
961
|
this.elements.pop();
|
|
895
962
|
} else {
|
|
@@ -935,6 +1002,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
935
1002
|
|
|
936
1003
|
|
|
937
1004
|
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
|
|
1008
|
+
|
|
938
1009
|
|
|
939
1010
|
|
|
940
1011
|
|
|
@@ -1015,6 +1086,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1015
1086
|
|
|
1016
1087
|
|
|
1017
1088
|
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1018
1093
|
|
|
1019
1094
|
|
|
1020
1095
|
|
|
@@ -1068,6 +1143,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1068
1143
|
|
|
1069
1144
|
|
|
1070
1145
|
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
1071
1150
|
|
|
1072
1151
|
|
|
1073
1152
|
|
|
@@ -1120,6 +1199,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1120
1199
|
|
|
1121
1200
|
|
|
1122
1201
|
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1123
1206
|
|
|
1124
1207
|
|
|
1125
1208
|
|
|
@@ -1179,6 +1262,10 @@ var Heap = class _Heap extends IterableElementBase {
|
|
|
1179
1262
|
|
|
1180
1263
|
|
|
1181
1264
|
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1182
1269
|
|
|
1183
1270
|
|
|
1184
1271
|
|