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
|
@@ -326,6 +326,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
326
326
|
|
|
327
327
|
|
|
328
328
|
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
329
333
|
|
|
330
334
|
|
|
331
335
|
|
|
@@ -380,7 +384,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
380
384
|
}
|
|
381
385
|
/**
|
|
382
386
|
* Insert an element.
|
|
383
|
-
* @remarks Time O(
|
|
387
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
384
388
|
* @param element - Element to insert.
|
|
385
389
|
* @returns True.
|
|
386
390
|
|
|
@@ -413,6 +417,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
413
417
|
|
|
414
418
|
|
|
415
419
|
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
416
424
|
|
|
417
425
|
|
|
418
426
|
|
|
@@ -470,6 +478,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
470
478
|
|
|
471
479
|
|
|
472
480
|
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
473
485
|
|
|
474
486
|
|
|
475
487
|
|
|
@@ -534,6 +546,37 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
534
546
|
|
|
535
547
|
|
|
536
548
|
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
* @example
|
|
553
|
+
* // Heap with custom comparator (MaxHeap behavior)
|
|
554
|
+
* interface Task {
|
|
555
|
+
* id: number;
|
|
556
|
+
* priority: number;
|
|
557
|
+
* name: string;
|
|
558
|
+
* }
|
|
559
|
+
*
|
|
560
|
+
* // Custom comparator for max heap behavior (higher priority first)
|
|
561
|
+
* const tasks: Task[] = [
|
|
562
|
+
* { id: 1, priority: 5, name: 'Email' },
|
|
563
|
+
* { id: 2, priority: 3, name: 'Chat' },
|
|
564
|
+
* { id: 3, priority: 8, name: 'Alert' }
|
|
565
|
+
* ];
|
|
566
|
+
*
|
|
567
|
+
* const maxHeap = new Heap(tasks, {
|
|
568
|
+
* comparator: (a: Task, b: Task) => b.priority - a.priority
|
|
569
|
+
* });
|
|
570
|
+
*
|
|
571
|
+
* console.log(maxHeap.size); // 3;
|
|
572
|
+
*
|
|
573
|
+
* // Peek returns highest priority task
|
|
574
|
+
* const topTask = maxHeap.peek();
|
|
575
|
+
* console.log(topTask?.priority); // 8;
|
|
576
|
+
* console.log(topTask?.name); // 'Alert';
|
|
577
|
+
*/
|
|
578
|
+
/**
|
|
579
|
+
* @deprecated Use `pop` instead. Will be removed in a future major version.
|
|
537
580
|
* @example
|
|
538
581
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
539
582
|
* interface Task {
|
|
@@ -561,6 +604,14 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
561
604
|
* console.log(topTask?.name); // 'Alert';
|
|
562
605
|
*/
|
|
563
606
|
poll() {
|
|
607
|
+
return this.pop();
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Remove and return the top element (min or max depending on comparator).
|
|
611
|
+
* @remarks Time O(log N) amortized, Space O(1)
|
|
612
|
+
* @returns The removed top element, or undefined if empty.
|
|
613
|
+
*/
|
|
614
|
+
pop() {
|
|
564
615
|
if (this.elements.length === 0) return;
|
|
565
616
|
const value = this.elements[0];
|
|
566
617
|
const last = this.elements.pop();
|
|
@@ -604,6 +655,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
604
655
|
|
|
605
656
|
|
|
606
657
|
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
607
662
|
|
|
608
663
|
|
|
609
664
|
|
|
@@ -704,6 +759,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
704
759
|
|
|
705
760
|
|
|
706
761
|
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
707
766
|
|
|
708
767
|
|
|
709
768
|
|
|
@@ -751,6 +810,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
751
810
|
|
|
752
811
|
|
|
753
812
|
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
754
817
|
|
|
755
818
|
|
|
756
819
|
|
|
@@ -765,16 +828,6 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
765
828
|
clear() {
|
|
766
829
|
this._elements = [];
|
|
767
830
|
}
|
|
768
|
-
/**
|
|
769
|
-
* Replace the backing array and rebuild the heap.
|
|
770
|
-
* @remarks Time O(N), Space O(N)
|
|
771
|
-
* @param elements - Iterable used to refill the heap.
|
|
772
|
-
* @returns Array of per-node results from fixing steps.
|
|
773
|
-
*/
|
|
774
|
-
refill(elements) {
|
|
775
|
-
this._elements = Array.from(elements);
|
|
776
|
-
return this.fix();
|
|
777
|
-
}
|
|
778
831
|
/**
|
|
779
832
|
* Check if an equal element exists in the heap.
|
|
780
833
|
* @remarks Time O(N), Space O(1)
|
|
@@ -801,6 +854,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
801
854
|
|
|
802
855
|
|
|
803
856
|
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
804
861
|
|
|
805
862
|
|
|
806
863
|
|
|
@@ -848,6 +905,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
848
905
|
|
|
849
906
|
|
|
850
907
|
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
851
912
|
|
|
852
913
|
|
|
853
914
|
|
|
@@ -869,7 +930,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
869
930
|
}
|
|
870
931
|
if (index < 0) return false;
|
|
871
932
|
if (index === 0) {
|
|
872
|
-
this.
|
|
933
|
+
this.pop();
|
|
873
934
|
} else if (index === this.elements.length - 1) {
|
|
874
935
|
this.elements.pop();
|
|
875
936
|
} else {
|
|
@@ -879,13 +940,19 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
879
940
|
}
|
|
880
941
|
return true;
|
|
881
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
|
|
945
|
+
*/
|
|
946
|
+
deleteBy(predicate) {
|
|
947
|
+
return this.deleteWhere(predicate);
|
|
948
|
+
}
|
|
882
949
|
/**
|
|
883
950
|
* Delete the first element that matches a predicate.
|
|
884
951
|
* @remarks Time O(N), Space O(1)
|
|
885
952
|
* @param predicate - Function (element, index, heap) → boolean.
|
|
886
953
|
* @returns True if an element was removed.
|
|
887
954
|
*/
|
|
888
|
-
|
|
955
|
+
deleteWhere(predicate) {
|
|
889
956
|
let idx = -1;
|
|
890
957
|
for (let i = 0; i < this.elements.length; i++) {
|
|
891
958
|
if (predicate(this.elements[i], i, this)) {
|
|
@@ -895,7 +962,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
895
962
|
}
|
|
896
963
|
if (idx < 0) return false;
|
|
897
964
|
if (idx === 0) {
|
|
898
|
-
this.
|
|
965
|
+
this.pop();
|
|
899
966
|
} else if (idx === this.elements.length - 1) {
|
|
900
967
|
this.elements.pop();
|
|
901
968
|
} else {
|
|
@@ -941,6 +1008,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
941
1008
|
|
|
942
1009
|
|
|
943
1010
|
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
944
1015
|
|
|
945
1016
|
|
|
946
1017
|
|
|
@@ -1021,6 +1092,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1021
1092
|
|
|
1022
1093
|
|
|
1023
1094
|
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
|
|
1024
1099
|
|
|
1025
1100
|
|
|
1026
1101
|
|
|
@@ -1074,6 +1149,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1074
1149
|
|
|
1075
1150
|
|
|
1076
1151
|
|
|
1152
|
+
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
|
|
1077
1156
|
|
|
1078
1157
|
|
|
1079
1158
|
|
|
@@ -1126,6 +1205,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1126
1205
|
|
|
1127
1206
|
|
|
1128
1207
|
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1129
1212
|
|
|
1130
1213
|
|
|
1131
1214
|
|
|
@@ -1185,6 +1268,10 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
1185
1268
|
|
|
1186
1269
|
|
|
1187
1270
|
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1188
1275
|
|
|
1189
1276
|
|
|
1190
1277
|
|