data-structure-typed 2.6.0 → 2.6.2
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/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
- package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- package/package.json +45 -46
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +0 -3
- package/src/data-structures/base/linear-base.ts +2 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -529
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
- package/src/data-structures/binary-tree/bst.ts +158 -1082
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
- package/src/data-structures/binary-tree/segment-tree.ts +73 -351
- package/src/data-structures/binary-tree/tree-map.ts +462 -5124
- package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
- package/src/data-structures/binary-tree/tree-multi-set.ts +299 -3983
- package/src/data-structures/binary-tree/tree-set.ts +338 -4836
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -562
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -511
- package/src/data-structures/hash/hash-map.ts +154 -582
- package/src/data-structures/heap/heap.ts +200 -795
- package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
- package/src/data-structures/matrix/matrix.ts +179 -518
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +214 -882
- package/src/data-structures/queue/queue.ts +102 -625
- package/src/data-structures/stack/stack.ts +76 -505
- package/src/data-structures/trie/trie.ts +98 -628
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: AVLTree\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
9
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:309](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L309)
|
|
10
10
|
|
|
11
11
|
Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
|
|
12
12
|
This tree extends BST and performs rotations on set/delete to maintain balance.
|
|
@@ -182,7 +182,7 @@ The type of the raw data object (if using `toEntryFn`).
|
|
|
182
182
|
new AVLTree<K, V, R>(keysNodesEntriesOrRaws?, options?): AVLTree<K, V, R>;
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
185
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:317](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L317)
|
|
186
186
|
|
|
187
187
|
Creates an instance of AVLTree.
|
|
188
188
|
|
|
@@ -228,7 +228,7 @@ Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
|
228
228
|
get comparator(): Comparator<K>;
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
231
|
+
Defined in: [data-structures/binary-tree/bst.ts:390](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L390)
|
|
232
232
|
|
|
233
233
|
Gets the comparator function used by the tree.
|
|
234
234
|
|
|
@@ -256,7 +256,7 @@ The comparator function.
|
|
|
256
256
|
get isDuplicate(): boolean;
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
259
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:326](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L326)
|
|
260
260
|
|
|
261
261
|
Gets whether the tree allows duplicate keys.
|
|
262
262
|
|
|
@@ -290,7 +290,7 @@ IBinaryTree.isDuplicate
|
|
|
290
290
|
get isMapMode(): boolean;
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
293
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:316](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L316)
|
|
294
294
|
|
|
295
295
|
Gets whether the tree is in Map mode.
|
|
296
296
|
|
|
@@ -358,7 +358,7 @@ IBinaryTree.NIL
|
|
|
358
358
|
get root(): OptNode<BSTNode<K, V>>;
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
361
|
+
Defined in: [data-structures/binary-tree/bst.ts:380](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L380)
|
|
362
362
|
|
|
363
363
|
Gets the root node of the tree.
|
|
364
364
|
|
|
@@ -392,7 +392,7 @@ IBinaryTree.root
|
|
|
392
392
|
get size(): number;
|
|
393
393
|
```
|
|
394
394
|
|
|
395
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
395
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:363](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L363)
|
|
396
396
|
|
|
397
397
|
Gets the number of nodes in the tree.
|
|
398
398
|
|
|
@@ -426,7 +426,7 @@ IBinaryTree.size
|
|
|
426
426
|
get store(): Map<K, BinaryTreeNode<K, V>>;
|
|
427
427
|
```
|
|
428
428
|
|
|
429
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
429
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:339](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L339)
|
|
430
430
|
|
|
431
431
|
Gets the external value store (used in Map mode).
|
|
432
432
|
|
|
@@ -460,7 +460,7 @@ IBinaryTree.store
|
|
|
460
460
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
461
461
|
```
|
|
462
462
|
|
|
463
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
463
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:383](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L383)
|
|
464
464
|
|
|
465
465
|
Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
466
466
|
|
|
@@ -530,7 +530,7 @@ IBinaryTree.[iterator]
|
|
|
530
530
|
add(keyNodeOrEntry): boolean;
|
|
531
531
|
```
|
|
532
532
|
|
|
533
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
533
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:609](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L609)
|
|
534
534
|
|
|
535
535
|
Adds a new node to the tree.
|
|
536
536
|
|
|
@@ -552,8 +552,6 @@ The key, node, or entry to add.
|
|
|
552
552
|
|
|
553
553
|
True if the addition was successful, false otherwise.
|
|
554
554
|
|
|
555
|
-
*
|
|
556
|
-
|
|
557
555
|
#### Remarks
|
|
558
556
|
|
|
559
557
|
Time O(N) — level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
@@ -588,7 +586,7 @@ IBinaryTree.add
|
|
|
588
586
|
addMany(keysNodesEntriesOrRaws): boolean[];
|
|
589
587
|
```
|
|
590
588
|
|
|
591
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
589
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:711](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L711)
|
|
592
590
|
|
|
593
591
|
Adds multiple items to the tree.
|
|
594
592
|
|
|
@@ -612,8 +610,6 @@ An iterable of items to set.
|
|
|
612
610
|
|
|
613
611
|
An array of booleans indicating the success of each individual `set` operation.
|
|
614
612
|
|
|
615
|
-
*
|
|
616
|
-
|
|
617
613
|
#### Remarks
|
|
618
614
|
|
|
619
615
|
Time O(N * M), where N is the number of items to set and M is the size of the tree at insertion (due to O(M) `set` operation). Space O(M) (from `set`) + O(N) (for the `inserted` array).
|
|
@@ -669,12 +665,10 @@ The traversal method.
|
|
|
669
665
|
bfs(): (K | undefined)[];
|
|
670
666
|
```
|
|
671
667
|
|
|
672
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
668
|
+
Defined in: [data-structures/binary-tree/bst.ts:493](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L493)
|
|
673
669
|
|
|
674
670
|
BinaryTree level-order traversal
|
|
675
671
|
|
|
676
|
-
*
|
|
677
|
-
|
|
678
672
|
##### Returns
|
|
679
673
|
|
|
680
674
|
(`K` \| `undefined`)[]
|
|
@@ -707,12 +701,10 @@ bfs<C>(
|
|
|
707
701
|
iterationType?): ReturnType<C>[];
|
|
708
702
|
```
|
|
709
703
|
|
|
710
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
704
|
+
Defined in: [data-structures/binary-tree/bst.ts:494](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L494)
|
|
711
705
|
|
|
712
706
|
BinaryTree level-order traversal
|
|
713
707
|
|
|
714
|
-
*
|
|
715
|
-
|
|
716
708
|
##### Type Parameters
|
|
717
709
|
|
|
718
710
|
###### C
|
|
@@ -769,15 +761,13 @@ IBinaryTree.bfs
|
|
|
769
761
|
ceiling(keyNodeEntryOrPredicate): K | undefined;
|
|
770
762
|
```
|
|
771
763
|
|
|
772
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
764
|
+
Defined in: [data-structures/binary-tree/bst.ts:1253](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1253)
|
|
773
765
|
|
|
774
766
|
Returns the first key with a value >= target.
|
|
775
767
|
Equivalent to Java TreeMap.ceiling.
|
|
776
768
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
777
769
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
778
770
|
|
|
779
|
-
*
|
|
780
|
-
|
|
781
771
|
##### Parameters
|
|
782
772
|
|
|
783
773
|
###### keyNodeEntryOrPredicate
|
|
@@ -816,7 +806,7 @@ ceiling<C>(
|
|
|
816
806
|
iterationType?): ReturnType<C>;
|
|
817
807
|
```
|
|
818
808
|
|
|
819
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
809
|
+
Defined in: [data-structures/binary-tree/bst.ts:1268](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1268)
|
|
820
810
|
|
|
821
811
|
Returns the first node with a key >= target and applies callback.
|
|
822
812
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -863,7 +853,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
863
853
|
clear(): void;
|
|
864
854
|
```
|
|
865
855
|
|
|
866
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
856
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1087](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1087)
|
|
867
857
|
|
|
868
858
|
Clears the tree of all nodes and values.
|
|
869
859
|
|
|
@@ -875,8 +865,6 @@ Clears the tree of all nodes and values.
|
|
|
875
865
|
|
|
876
866
|
Time O(N) if in Map mode (due to `_store.clear()`), O(1) otherwise. Space O(1)
|
|
877
867
|
|
|
878
|
-
*
|
|
879
|
-
|
|
880
868
|
#### Example
|
|
881
869
|
|
|
882
870
|
```ts
|
|
@@ -904,7 +892,7 @@ IBinaryTree.clear
|
|
|
904
892
|
clone(): this;
|
|
905
893
|
```
|
|
906
894
|
|
|
907
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
895
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1939](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1939)
|
|
908
896
|
|
|
909
897
|
Clones the tree.
|
|
910
898
|
|
|
@@ -914,8 +902,6 @@ Clones the tree.
|
|
|
914
902
|
|
|
915
903
|
A new, cloned instance of the tree.
|
|
916
904
|
|
|
917
|
-
*
|
|
918
|
-
|
|
919
905
|
#### Remarks
|
|
920
906
|
|
|
921
907
|
Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `set`, and `set` is O(M)). Space O(N) for the new tree and the BFS queue.
|
|
@@ -948,7 +934,7 @@ IBinaryTree.clone
|
|
|
948
934
|
createNode(key, value?): AVLTreeNode<K, V>;
|
|
949
935
|
```
|
|
950
936
|
|
|
951
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
937
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:336](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L336)
|
|
952
938
|
|
|
953
939
|
(Protected) Creates a new AVL tree node.
|
|
954
940
|
|
|
@@ -994,7 +980,7 @@ IBinaryTree.createNode
|
|
|
994
980
|
createTree(options?): this;
|
|
995
981
|
```
|
|
996
982
|
|
|
997
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
983
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:439](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L439)
|
|
998
984
|
|
|
999
985
|
Creates a new, empty tree of the same type and configuration.
|
|
1000
986
|
|
|
@@ -1034,7 +1020,7 @@ IBinaryTree.createTree
|
|
|
1034
1020
|
delete(keyNodeOrEntry): boolean;
|
|
1035
1021
|
```
|
|
1036
1022
|
|
|
1037
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
1023
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:391](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L391)
|
|
1038
1024
|
|
|
1039
1025
|
Deletes a node from the AVL tree and re-balances the tree.
|
|
1040
1026
|
|
|
@@ -1056,8 +1042,6 @@ The node to delete.
|
|
|
1056
1042
|
|
|
1057
1043
|
An array containing deletion results.
|
|
1058
1044
|
|
|
1059
|
-
*
|
|
1060
|
-
|
|
1061
1045
|
#### Remarks
|
|
1062
1046
|
|
|
1063
1047
|
Time O(log N) (O(H) for BST delete + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
@@ -1094,7 +1078,7 @@ deleteWhere(
|
|
|
1094
1078
|
iterationType?): boolean;
|
|
1095
1079
|
```
|
|
1096
1080
|
|
|
1097
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1081
|
+
Defined in: [data-structures/binary-tree/bst.ts:1838](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1838)
|
|
1098
1082
|
|
|
1099
1083
|
Deletes nodes that match a key, node, entry, predicate, or range.
|
|
1100
1084
|
|
|
@@ -1205,12 +1189,10 @@ The traversal method.
|
|
|
1205
1189
|
dfs(): (K | undefined)[];
|
|
1206
1190
|
```
|
|
1207
1191
|
|
|
1208
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1192
|
+
Defined in: [data-structures/binary-tree/bst.ts:453](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L453)
|
|
1209
1193
|
|
|
1210
1194
|
Depth-first search traversal
|
|
1211
1195
|
|
|
1212
|
-
*
|
|
1213
|
-
|
|
1214
1196
|
##### Returns
|
|
1215
1197
|
|
|
1216
1198
|
(`K` \| `undefined`)[]
|
|
@@ -1245,12 +1227,10 @@ dfs<C>(
|
|
|
1245
1227
|
iterationType?): ReturnType<C>[];
|
|
1246
1228
|
```
|
|
1247
1229
|
|
|
1248
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1230
|
+
Defined in: [data-structures/binary-tree/bst.ts:455](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L455)
|
|
1249
1231
|
|
|
1250
1232
|
Depth-first search traversal
|
|
1251
1233
|
|
|
1252
|
-
*
|
|
1253
|
-
|
|
1254
1234
|
##### Type Parameters
|
|
1255
1235
|
|
|
1256
1236
|
###### C
|
|
@@ -1313,7 +1293,7 @@ IBinaryTree.dfs
|
|
|
1313
1293
|
ensureNode(keyNodeOrEntry, iterationType?): OptNode<BSTNode<K, V>>;
|
|
1314
1294
|
```
|
|
1315
1295
|
|
|
1316
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1296
|
+
Defined in: [data-structures/binary-tree/bst.ts:414](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L414)
|
|
1317
1297
|
|
|
1318
1298
|
Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
1319
1299
|
|
|
@@ -1435,7 +1415,7 @@ IBinaryTree.every
|
|
|
1435
1415
|
filter(predicate, thisArg?): this;
|
|
1436
1416
|
```
|
|
1437
1417
|
|
|
1438
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1418
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1958](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1958)
|
|
1439
1419
|
|
|
1440
1420
|
Creates a new tree containing only the entries that satisfy the predicate.
|
|
1441
1421
|
|
|
@@ -1459,8 +1439,6 @@ A function to test each [key, value] pair.
|
|
|
1459
1439
|
|
|
1460
1440
|
A new, filtered tree.
|
|
1461
1441
|
|
|
1462
|
-
*
|
|
1463
|
-
|
|
1464
1442
|
#### Remarks
|
|
1465
1443
|
|
|
1466
1444
|
Time O(N * M), where N is nodes in this tree, and M is size of the new tree during insertion (O(N) iteration + O(M) `set` for each item). Space O(N) for the new tree.
|
|
@@ -1540,15 +1518,13 @@ IBinaryTree.find
|
|
|
1540
1518
|
floor(keyNodeEntryOrPredicate): K | undefined;
|
|
1541
1519
|
```
|
|
1542
1520
|
|
|
1543
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1521
|
+
Defined in: [data-structures/binary-tree/bst.ts:1394](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1394)
|
|
1544
1522
|
|
|
1545
1523
|
Returns the first key with a value <= target.
|
|
1546
1524
|
Equivalent to Java TreeMap.floor.
|
|
1547
1525
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
1548
1526
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
1549
1527
|
|
|
1550
|
-
*
|
|
1551
|
-
|
|
1552
1528
|
##### Parameters
|
|
1553
1529
|
|
|
1554
1530
|
###### keyNodeEntryOrPredicate
|
|
@@ -1587,7 +1563,7 @@ floor<C>(
|
|
|
1587
1563
|
iterationType?): ReturnType<C>;
|
|
1588
1564
|
```
|
|
1589
1565
|
|
|
1590
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1566
|
+
Defined in: [data-structures/binary-tree/bst.ts:1409](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1409)
|
|
1591
1567
|
|
|
1592
1568
|
Returns the first node with a key <= target and applies callback.
|
|
1593
1569
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -1681,7 +1657,7 @@ get(
|
|
|
1681
1657
|
iterationType?): V | undefined;
|
|
1682
1658
|
```
|
|
1683
1659
|
|
|
1684
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1660
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:995](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L995)
|
|
1685
1661
|
|
|
1686
1662
|
Gets the value associated with a key.
|
|
1687
1663
|
|
|
@@ -1718,8 +1694,6 @@ The traversal method (if not in Map mode).
|
|
|
1718
1694
|
|
|
1719
1695
|
The associated value, or undefined.
|
|
1720
1696
|
|
|
1721
|
-
*
|
|
1722
|
-
|
|
1723
1697
|
#### Remarks
|
|
1724
1698
|
|
|
1725
1699
|
Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O(H) or O(N) otherwise. BST subclasses override non-Map-mode to O(log N).
|
|
@@ -1728,7 +1702,11 @@ Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O
|
|
|
1728
1702
|
|
|
1729
1703
|
```ts
|
|
1730
1704
|
// Retrieve value by key
|
|
1731
|
-
const tree = new BinaryTree<number, string>([
|
|
1705
|
+
const tree = new BinaryTree<number, string>([
|
|
1706
|
+
[1, 'root'],
|
|
1707
|
+
[2, 'left'],
|
|
1708
|
+
[3, 'right']
|
|
1709
|
+
]);
|
|
1732
1710
|
console.log(tree.get(2)); // 'left';
|
|
1733
1711
|
console.log(tree.get(99)); // undefined;
|
|
1734
1712
|
```
|
|
@@ -1753,7 +1731,7 @@ IBinaryTree.get
|
|
|
1753
1731
|
getByRank(k): K | undefined;
|
|
1754
1732
|
```
|
|
1755
1733
|
|
|
1756
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1734
|
+
Defined in: [data-structures/binary-tree/bst.ts:853](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L853)
|
|
1757
1735
|
|
|
1758
1736
|
Returns the element at the k-th position in tree order (0-indexed).
|
|
1759
1737
|
|
|
@@ -1770,7 +1748,6 @@ The 0-based position in tree order (0 = first element).
|
|
|
1770
1748
|
`K` \| `undefined`
|
|
1771
1749
|
|
|
1772
1750
|
The key at position k, or `undefined` if out of bounds.
|
|
1773
|
-
*
|
|
1774
1751
|
|
|
1775
1752
|
##### Remarks
|
|
1776
1753
|
|
|
@@ -1800,7 +1777,7 @@ getByRank<C>(
|
|
|
1800
1777
|
iterationType?): ReturnType<C> | undefined;
|
|
1801
1778
|
```
|
|
1802
1779
|
|
|
1803
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1780
|
+
Defined in: [data-structures/binary-tree/bst.ts:864](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L864)
|
|
1804
1781
|
|
|
1805
1782
|
Returns the element at the k-th position in tree order and applies a callback.
|
|
1806
1783
|
|
|
@@ -1852,7 +1829,7 @@ Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderS
|
|
|
1852
1829
|
getDepth(dist, startNode?): number;
|
|
1853
1830
|
```
|
|
1854
1831
|
|
|
1855
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1832
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1187](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1187)
|
|
1856
1833
|
|
|
1857
1834
|
Gets the depth of a node (distance from `startNode`).
|
|
1858
1835
|
|
|
@@ -1883,8 +1860,6 @@ The node to measure depth from (defaults to root).
|
|
|
1883
1860
|
|
|
1884
1861
|
The depth (0 if `dist` is `startNode`).
|
|
1885
1862
|
|
|
1886
|
-
*
|
|
1887
|
-
|
|
1888
1863
|
#### Remarks
|
|
1889
1864
|
|
|
1890
1865
|
Time O(H), where H is the depth of the `dist` node relative to `startNode`. O(N) worst-case. Space O(1).
|
|
@@ -1916,7 +1891,7 @@ IBinaryTree.getDepth
|
|
|
1916
1891
|
getHeight(startNode?, iterationType?): number;
|
|
1917
1892
|
```
|
|
1918
1893
|
|
|
1919
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1894
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1216](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1216)
|
|
1920
1895
|
|
|
1921
1896
|
Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
1922
1897
|
|
|
@@ -1943,8 +1918,6 @@ The traversal method.
|
|
|
1943
1918
|
|
|
1944
1919
|
The height ( -1 for an empty tree, 0 for a single-node tree).
|
|
1945
1920
|
|
|
1946
|
-
*
|
|
1947
|
-
|
|
1948
1921
|
#### Remarks
|
|
1949
1922
|
|
|
1950
1923
|
Time O(N), as it must visit every node. Space O(H) for recursive stack (O(N) worst-case) or O(N) for iterative stack (storing node + depth).
|
|
@@ -1999,7 +1972,7 @@ The traversal method.
|
|
|
1999
1972
|
getLeftMost(): K | undefined;
|
|
2000
1973
|
```
|
|
2001
1974
|
|
|
2002
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1975
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1343](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1343)
|
|
2003
1976
|
|
|
2004
1977
|
##### Returns
|
|
2005
1978
|
|
|
@@ -2024,7 +1997,7 @@ getLeftMost<C>(
|
|
|
2024
1997
|
iterationType?): ReturnType<C>;
|
|
2025
1998
|
```
|
|
2026
1999
|
|
|
2027
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2000
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1345](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1345)
|
|
2028
2001
|
|
|
2029
2002
|
##### Type Parameters
|
|
2030
2003
|
|
|
@@ -2071,7 +2044,7 @@ IBinaryTree.getLeftMost
|
|
|
2071
2044
|
getMinHeight(startNode?, iterationType?): number;
|
|
2072
2045
|
```
|
|
2073
2046
|
|
|
2074
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2047
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1258](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1258)
|
|
2075
2048
|
|
|
2076
2049
|
Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
2077
2050
|
|
|
@@ -2123,7 +2096,7 @@ getNode(
|
|
|
2123
2096
|
iterationType?): OptNode<BSTNode<K, V>>;
|
|
2124
2097
|
```
|
|
2125
2098
|
|
|
2126
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2099
|
+
Defined in: [data-structures/binary-tree/bst.ts:574](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L574)
|
|
2127
2100
|
|
|
2128
2101
|
Gets the first node matching a predicate.
|
|
2129
2102
|
|
|
@@ -2158,8 +2131,6 @@ The traversal method.
|
|
|
2158
2131
|
|
|
2159
2132
|
The first matching node, or undefined if not found.
|
|
2160
2133
|
|
|
2161
|
-
*
|
|
2162
|
-
|
|
2163
2134
|
#### Remarks
|
|
2164
2135
|
|
|
2165
2136
|
Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N) or O(N).
|
|
@@ -2168,7 +2139,11 @@ Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N
|
|
|
2168
2139
|
|
|
2169
2140
|
```ts
|
|
2170
2141
|
// Get node object by key
|
|
2171
|
-
const bst = new BST<number, string>([
|
|
2142
|
+
const bst = new BST<number, string>([
|
|
2143
|
+
[5, 'root'],
|
|
2144
|
+
[3, 'left'],
|
|
2145
|
+
[7, 'right']
|
|
2146
|
+
]);
|
|
2172
2147
|
const node = bst.getNode(3);
|
|
2173
2148
|
console.log(node?.key); // 3;
|
|
2174
2149
|
console.log(node?.value); // 'left';
|
|
@@ -2196,7 +2171,7 @@ getNodes(
|
|
|
2196
2171
|
iterationType?): BinaryTreeNode<K, V>[];
|
|
2197
2172
|
```
|
|
2198
2173
|
|
|
2199
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2174
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:912](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L912)
|
|
2200
2175
|
|
|
2201
2176
|
Gets all nodes matching a predicate.
|
|
2202
2177
|
|
|
@@ -2240,8 +2215,6 @@ The traversal method.
|
|
|
2240
2215
|
|
|
2241
2216
|
An array of matching nodes.
|
|
2242
2217
|
|
|
2243
|
-
*
|
|
2244
|
-
|
|
2245
2218
|
#### Remarks
|
|
2246
2219
|
|
|
2247
2220
|
Time O(N) (via `search`). Space O(H) or O(N) (via `search`).
|
|
@@ -2291,7 +2264,7 @@ If true, returns the path from root-to-node.
|
|
|
2291
2264
|
getPathToRoot(beginNode): (K | undefined)[];
|
|
2292
2265
|
```
|
|
2293
2266
|
|
|
2294
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2267
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1305](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1305)
|
|
2295
2268
|
|
|
2296
2269
|
##### Parameters
|
|
2297
2270
|
|
|
@@ -2326,7 +2299,7 @@ getPathToRoot<C>(
|
|
|
2326
2299
|
isReverse?): ReturnType<C>[];
|
|
2327
2300
|
```
|
|
2328
2301
|
|
|
2329
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2302
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1309](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1309)
|
|
2330
2303
|
|
|
2331
2304
|
##### Type Parameters
|
|
2332
2305
|
|
|
@@ -2374,7 +2347,7 @@ IBinaryTree.getPathToRoot
|
|
|
2374
2347
|
getPredecessor(node): BinaryTreeNode<K, V>;
|
|
2375
2348
|
```
|
|
2376
2349
|
|
|
2377
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2350
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1443](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1443)
|
|
2378
2351
|
|
|
2379
2352
|
Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
2380
2353
|
|
|
@@ -2410,7 +2383,7 @@ This is primarily a helper for Morris traversal. Time O(H), where H is the heigh
|
|
|
2410
2383
|
getRank(keyNodeEntryOrPredicate): number;
|
|
2411
2384
|
```
|
|
2412
2385
|
|
|
2413
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2386
|
+
Defined in: [data-structures/binary-tree/bst.ts:909](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L909)
|
|
2414
2387
|
|
|
2415
2388
|
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
2416
2389
|
|
|
@@ -2448,7 +2421,7 @@ Tree order is defined by the comparator. When the key is not found, returns the
|
|
|
2448
2421
|
getRank(keyNodeEntryOrPredicate, iterationType): number;
|
|
2449
2422
|
```
|
|
2450
2423
|
|
|
2451
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2424
|
+
Defined in: [data-structures/binary-tree/bst.ts:927](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L927)
|
|
2452
2425
|
|
|
2453
2426
|
Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
2454
2427
|
|
|
@@ -2517,7 +2490,7 @@ The traversal method.
|
|
|
2517
2490
|
getRightMost(): K | undefined;
|
|
2518
2491
|
```
|
|
2519
2492
|
|
|
2520
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2493
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1390](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1390)
|
|
2521
2494
|
|
|
2522
2495
|
##### Returns
|
|
2523
2496
|
|
|
@@ -2542,7 +2515,7 @@ getRightMost<C>(
|
|
|
2542
2515
|
iterationType?): ReturnType<C>;
|
|
2543
2516
|
```
|
|
2544
2517
|
|
|
2545
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2518
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1392](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1392)
|
|
2546
2519
|
|
|
2547
2520
|
##### Type Parameters
|
|
2548
2521
|
|
|
@@ -2589,7 +2562,7 @@ IBinaryTree.getRightMost
|
|
|
2589
2562
|
getSuccessor(x?): BinaryTreeNode<K, V> | null | undefined;
|
|
2590
2563
|
```
|
|
2591
2564
|
|
|
2592
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2565
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1464](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1464)
|
|
2593
2566
|
|
|
2594
2567
|
Gets the in-order successor of a node in a BST.
|
|
2595
2568
|
|
|
@@ -2626,7 +2599,7 @@ has(
|
|
|
2626
2599
|
iterationType?): boolean;
|
|
2627
2600
|
```
|
|
2628
2601
|
|
|
2629
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2602
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1045](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1045)
|
|
2630
2603
|
|
|
2631
2604
|
Checks if a node matching the predicate exists in the tree.
|
|
2632
2605
|
|
|
@@ -2663,8 +2636,6 @@ The traversal method.
|
|
|
2663
2636
|
|
|
2664
2637
|
True if a matching node exists, false otherwise.
|
|
2665
2638
|
|
|
2666
|
-
*
|
|
2667
|
-
|
|
2668
2639
|
#### Remarks
|
|
2669
2640
|
|
|
2670
2641
|
Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
|
|
@@ -2761,15 +2732,13 @@ IBinaryTree.hasValue
|
|
|
2761
2732
|
higher(keyNodeEntryOrPredicate): K | undefined;
|
|
2762
2733
|
```
|
|
2763
2734
|
|
|
2764
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2735
|
+
Defined in: [data-structures/binary-tree/bst.ts:1323](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1323)
|
|
2765
2736
|
|
|
2766
2737
|
Returns the first key with a value > target.
|
|
2767
2738
|
Equivalent to Java TreeMap.higher.
|
|
2768
2739
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
2769
2740
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
2770
2741
|
|
|
2771
|
-
*
|
|
2772
|
-
|
|
2773
2742
|
##### Parameters
|
|
2774
2743
|
|
|
2775
2744
|
###### keyNodeEntryOrPredicate
|
|
@@ -2807,7 +2776,7 @@ higher<C>(
|
|
|
2807
2776
|
iterationType?): ReturnType<C>;
|
|
2808
2777
|
```
|
|
2809
2778
|
|
|
2810
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2779
|
+
Defined in: [data-structures/binary-tree/bst.ts:1338](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1338)
|
|
2811
2780
|
|
|
2812
2781
|
Returns the first node with a key > target and applies callback.
|
|
2813
2782
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -2854,7 +2823,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
2854
2823
|
isAVLBalanced(iterationType?): boolean;
|
|
2855
2824
|
```
|
|
2856
2825
|
|
|
2857
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2826
|
+
Defined in: [data-structures/binary-tree/bst.ts:1722](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1722)
|
|
2858
2827
|
|
|
2859
2828
|
Checks if the tree meets the AVL balance condition (height difference <= 1).
|
|
2860
2829
|
|
|
@@ -2872,8 +2841,6 @@ The traversal method.
|
|
|
2872
2841
|
|
|
2873
2842
|
True if the tree is AVL balanced, false otherwise.
|
|
2874
2843
|
|
|
2875
|
-
*
|
|
2876
|
-
|
|
2877
2844
|
#### Remarks
|
|
2878
2845
|
|
|
2879
2846
|
Time O(N), as it must visit every node to compute height. Space O(log N) for recursion or O(N) for iterative map.
|
|
@@ -2898,7 +2865,7 @@ Time O(N), as it must visit every node to compute height. Space O(log N) for rec
|
|
|
2898
2865
|
isBST(startNode?, iterationType?): boolean;
|
|
2899
2866
|
```
|
|
2900
2867
|
|
|
2901
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2868
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1131](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1131)
|
|
2902
2869
|
|
|
2903
2870
|
Checks if the tree is a valid Binary Search Tree (BST).
|
|
2904
2871
|
|
|
@@ -2925,8 +2892,6 @@ The traversal method.
|
|
|
2925
2892
|
|
|
2926
2893
|
True if it's a valid BST, false otherwise.
|
|
2927
2894
|
|
|
2928
|
-
*
|
|
2929
|
-
|
|
2930
2895
|
#### Remarks
|
|
2931
2896
|
|
|
2932
2897
|
Time O(N), as it must visit every node. Space O(H) for the call stack (recursive) or explicit stack (iterative), where H is the tree height (O(N) worst-case).
|
|
@@ -2958,7 +2923,7 @@ IBinaryTree.isBST
|
|
|
2958
2923
|
isEmpty(): boolean;
|
|
2959
2924
|
```
|
|
2960
2925
|
|
|
2961
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2926
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1101](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1101)
|
|
2962
2927
|
|
|
2963
2928
|
Checks if the tree is empty.
|
|
2964
2929
|
|
|
@@ -2968,8 +2933,6 @@ Checks if the tree is empty.
|
|
|
2968
2933
|
|
|
2969
2934
|
True if the tree has no nodes, false otherwise.
|
|
2970
2935
|
|
|
2971
|
-
*
|
|
2972
|
-
|
|
2973
2936
|
#### Remarks
|
|
2974
2937
|
|
|
2975
2938
|
Time O(1), Space O(1)
|
|
@@ -2999,7 +2962,7 @@ IBinaryTree.isEmpty
|
|
|
2999
2962
|
isEntry(keyNodeOrEntry): keyNodeOrEntry is BTNEntry<K, V>;
|
|
3000
2963
|
```
|
|
3001
2964
|
|
|
3002
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2965
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:576](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L576)
|
|
3003
2966
|
|
|
3004
2967
|
Checks if the given item is a [key, value] entry pair.
|
|
3005
2968
|
|
|
@@ -3037,7 +3000,7 @@ Time O(1), Space O(1)
|
|
|
3037
3000
|
isLeaf(keyNodeOrEntry): boolean;
|
|
3038
3001
|
```
|
|
3039
3002
|
|
|
3040
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3003
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:562](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L562)
|
|
3041
3004
|
|
|
3042
3005
|
Checks if a node is a leaf (has no real children).
|
|
3043
3006
|
|
|
@@ -3075,7 +3038,7 @@ Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is pass
|
|
|
3075
3038
|
isNIL(keyNodeOrEntry): boolean;
|
|
3076
3039
|
```
|
|
3077
3040
|
|
|
3078
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3041
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:531](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L531)
|
|
3079
3042
|
|
|
3080
3043
|
Checks if the given item is the sentinel NIL node.
|
|
3081
3044
|
|
|
@@ -3113,7 +3076,7 @@ Time O(1), Space O(1)
|
|
|
3113
3076
|
isNode(keyNodeOrEntry): keyNodeOrEntry is AVLTreeNode<K, V>;
|
|
3114
3077
|
```
|
|
3115
3078
|
|
|
3116
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
3079
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:347](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L347)
|
|
3117
3080
|
|
|
3118
3081
|
Checks if the given item is an `AVLTreeNode` instance.
|
|
3119
3082
|
|
|
@@ -3151,7 +3114,7 @@ Time O(1), Space O(1)
|
|
|
3151
3114
|
isPerfectlyBalanced(startNode?): boolean;
|
|
3152
3115
|
```
|
|
3153
3116
|
|
|
3154
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3117
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1112](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1112)
|
|
3155
3118
|
|
|
3156
3119
|
Checks if the tree is perfectly balanced.
|
|
3157
3120
|
|
|
@@ -3194,7 +3157,7 @@ IBinaryTree.isPerfectlyBalanced
|
|
|
3194
3157
|
isRange(keyNodeEntryOrPredicate): keyNodeEntryOrPredicate is Range<K>;
|
|
3195
3158
|
```
|
|
3196
3159
|
|
|
3197
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3160
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:542](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L542)
|
|
3198
3161
|
|
|
3199
3162
|
Checks if the given item is a `Range` object.
|
|
3200
3163
|
|
|
@@ -3234,7 +3197,7 @@ Time O(1), Space O(1)
|
|
|
3234
3197
|
isRaw(keyNodeEntryOrRaw): keyNodeEntryOrRaw is R;
|
|
3235
3198
|
```
|
|
3236
3199
|
|
|
3237
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3200
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:491](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L491)
|
|
3238
3201
|
|
|
3239
3202
|
Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
3240
3203
|
|
|
@@ -3273,7 +3236,7 @@ Time O(1), Space O(1)
|
|
|
3273
3236
|
isRealNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
3274
3237
|
```
|
|
3275
3238
|
|
|
3276
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3239
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:504](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L504)
|
|
3277
3240
|
|
|
3278
3241
|
Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
3279
3242
|
|
|
@@ -3311,7 +3274,7 @@ Time O(1), Space O(1)
|
|
|
3311
3274
|
isRealNodeOrNull(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
3312
3275
|
```
|
|
3313
3276
|
|
|
3314
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3277
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:518](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L518)
|
|
3315
3278
|
|
|
3316
3279
|
Checks if the given item is either a "real" node or null.
|
|
3317
3280
|
|
|
@@ -3349,7 +3312,7 @@ Time O(1), Space O(1)
|
|
|
3349
3312
|
isValidKey(key): key is K;
|
|
3350
3313
|
```
|
|
3351
3314
|
|
|
3352
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3315
|
+
Defined in: [data-structures/binary-tree/bst.ts:441](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L441)
|
|
3353
3316
|
|
|
3354
3317
|
Checks if the given key is valid (comparable).
|
|
3355
3318
|
|
|
@@ -3439,12 +3402,10 @@ The traversal method.
|
|
|
3439
3402
|
leaves(): (K | undefined)[];
|
|
3440
3403
|
```
|
|
3441
3404
|
|
|
3442
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3405
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1655](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1655)
|
|
3443
3406
|
|
|
3444
3407
|
Get leaf nodes
|
|
3445
3408
|
|
|
3446
|
-
*
|
|
3447
|
-
|
|
3448
3409
|
##### Returns
|
|
3449
3410
|
|
|
3450
3411
|
(`K` \| `undefined`)[]
|
|
@@ -3477,12 +3438,10 @@ leaves<C>(
|
|
|
3477
3438
|
iterationType?): ReturnType<C>[];
|
|
3478
3439
|
```
|
|
3479
3440
|
|
|
3480
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3441
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1657](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1657)
|
|
3481
3442
|
|
|
3482
3443
|
Get leaf nodes
|
|
3483
3444
|
|
|
3484
|
-
*
|
|
3485
|
-
|
|
3486
3445
|
##### Type Parameters
|
|
3487
3446
|
|
|
3488
3447
|
###### C
|
|
@@ -3565,7 +3524,7 @@ The traversal method.
|
|
|
3565
3524
|
lesserOrGreaterTraverse(): (K | undefined)[];
|
|
3566
3525
|
```
|
|
3567
3526
|
|
|
3568
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3527
|
+
Defined in: [data-structures/binary-tree/bst.ts:1614](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1614)
|
|
3569
3528
|
|
|
3570
3529
|
##### Returns
|
|
3571
3530
|
|
|
@@ -3585,7 +3544,7 @@ lesserOrGreaterTraverse<C>(
|
|
|
3585
3544
|
iterationType?): ReturnType<C>[];
|
|
3586
3545
|
```
|
|
3587
3546
|
|
|
3588
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3547
|
+
Defined in: [data-structures/binary-tree/bst.ts:1616](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1616)
|
|
3589
3548
|
|
|
3590
3549
|
##### Type Parameters
|
|
3591
3550
|
|
|
@@ -3654,12 +3613,10 @@ The traversal method.
|
|
|
3654
3613
|
listLevels(): (K | undefined)[][];
|
|
3655
3614
|
```
|
|
3656
3615
|
|
|
3657
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3616
|
+
Defined in: [data-structures/binary-tree/bst.ts:529](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L529)
|
|
3658
3617
|
|
|
3659
3618
|
Level-order grouping
|
|
3660
3619
|
|
|
3661
|
-
*
|
|
3662
|
-
|
|
3663
3620
|
##### Returns
|
|
3664
3621
|
|
|
3665
3622
|
(`K` \| `undefined`)[][]
|
|
@@ -3695,12 +3652,10 @@ listLevels<C>(
|
|
|
3695
3652
|
iterationType?): ReturnType<C>[][];
|
|
3696
3653
|
```
|
|
3697
3654
|
|
|
3698
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3655
|
+
Defined in: [data-structures/binary-tree/bst.ts:531](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L531)
|
|
3699
3656
|
|
|
3700
3657
|
Level-order grouping
|
|
3701
3658
|
|
|
3702
|
-
*
|
|
3703
|
-
|
|
3704
3659
|
##### Type Parameters
|
|
3705
3660
|
|
|
3706
3661
|
###### C
|
|
@@ -3760,15 +3715,13 @@ IBinaryTree.listLevels
|
|
|
3760
3715
|
lower(keyNodeEntryOrPredicate): K | undefined;
|
|
3761
3716
|
```
|
|
3762
3717
|
|
|
3763
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3718
|
+
Defined in: [data-structures/binary-tree/bst.ts:1509](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1509)
|
|
3764
3719
|
|
|
3765
3720
|
Returns the first key with a value < target.
|
|
3766
3721
|
Equivalent to Java TreeMap.lower.
|
|
3767
3722
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
3768
3723
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
3769
3724
|
|
|
3770
|
-
*
|
|
3771
|
-
|
|
3772
3725
|
##### Parameters
|
|
3773
3726
|
|
|
3774
3727
|
###### keyNodeEntryOrPredicate
|
|
@@ -3806,7 +3759,7 @@ lower<C>(
|
|
|
3806
3759
|
iterationType?): ReturnType<C>;
|
|
3807
3760
|
```
|
|
3808
3761
|
|
|
3809
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3762
|
+
Defined in: [data-structures/binary-tree/bst.ts:1524](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1524)
|
|
3810
3763
|
|
|
3811
3764
|
Returns the first node with a key < target and applies callback.
|
|
3812
3765
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -3856,7 +3809,7 @@ map<MK, MV, MR>(
|
|
|
3856
3809
|
thisArg?): AVLTree<MK, MV, MR>;
|
|
3857
3810
|
```
|
|
3858
3811
|
|
|
3859
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
3812
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:466](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L466)
|
|
3860
3813
|
|
|
3861
3814
|
Creates a new AVLTree by mapping each [key, value] pair.
|
|
3862
3815
|
|
|
@@ -3906,8 +3859,6 @@ Options for the new AVLTree.
|
|
|
3906
3859
|
|
|
3907
3860
|
A new, mapped AVLTree.
|
|
3908
3861
|
|
|
3909
|
-
*
|
|
3910
|
-
|
|
3911
3862
|
#### Remarks
|
|
3912
3863
|
|
|
3913
3864
|
Time O(N log N) (O(N) iteration + O(log M) `set` for each item into the new tree). Space O(N) for the new tree.
|
|
@@ -3916,7 +3867,11 @@ Time O(N log N) (O(N) iteration + O(log M) `set` for each item into the new tree
|
|
|
3916
3867
|
|
|
3917
3868
|
```ts
|
|
3918
3869
|
// Transform to new tree
|
|
3919
|
-
const avl = new AVLTree<number, number>([
|
|
3870
|
+
const avl = new AVLTree<number, number>([
|
|
3871
|
+
[1, 10],
|
|
3872
|
+
[2, 20],
|
|
3873
|
+
[3, 30]
|
|
3874
|
+
]);
|
|
3920
3875
|
const doubled = avl.map((value, key) => [key, (value ?? 0) * 2] as [number, number]);
|
|
3921
3876
|
console.log([...doubled.values()]); // [20, 40, 60];
|
|
3922
3877
|
```
|
|
@@ -3939,7 +3894,7 @@ IBinaryTree.map
|
|
|
3939
3894
|
merge(anotherTree): void;
|
|
3940
3895
|
```
|
|
3941
3896
|
|
|
3942
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3897
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:777](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L777)
|
|
3943
3898
|
|
|
3944
3899
|
Merges another tree into this one by seting all its nodes.
|
|
3945
3900
|
|
|
@@ -3951,8 +3906,6 @@ Merges another tree into this one by seting all its nodes.
|
|
|
3951
3906
|
|
|
3952
3907
|
The tree to merge.
|
|
3953
3908
|
|
|
3954
|
-
*
|
|
3955
|
-
|
|
3956
3909
|
#### Returns
|
|
3957
3910
|
|
|
3958
3911
|
`void`
|
|
@@ -4013,12 +3966,10 @@ The node to start from.
|
|
|
4013
3966
|
morris(): (K | undefined)[];
|
|
4014
3967
|
```
|
|
4015
3968
|
|
|
4016
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3969
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1809](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1809)
|
|
4017
3970
|
|
|
4018
3971
|
Morris traversal (O(1) space)
|
|
4019
3972
|
|
|
4020
|
-
*
|
|
4021
|
-
|
|
4022
3973
|
##### Returns
|
|
4023
3974
|
|
|
4024
3975
|
(`K` \| `undefined`)[]
|
|
@@ -4051,12 +4002,10 @@ morris<C>(
|
|
|
4051
4002
|
startNode?): ReturnType<C>[];
|
|
4052
4003
|
```
|
|
4053
4004
|
|
|
4054
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4005
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1811](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1811)
|
|
4055
4006
|
|
|
4056
4007
|
Morris traversal (O(1) space)
|
|
4057
4008
|
|
|
4058
|
-
*
|
|
4059
|
-
|
|
4060
4009
|
##### Type Parameters
|
|
4061
4010
|
|
|
4062
4011
|
###### C
|
|
@@ -4111,7 +4060,7 @@ IBinaryTree.morris
|
|
|
4111
4060
|
perfectlyBalance(iterationType?): boolean;
|
|
4112
4061
|
```
|
|
4113
4062
|
|
|
4114
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4063
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:420](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L420)
|
|
4115
4064
|
|
|
4116
4065
|
Rebuilds the tree to be perfectly balanced.
|
|
4117
4066
|
|
|
@@ -4129,8 +4078,6 @@ The traversal method for the initial node export.
|
|
|
4129
4078
|
|
|
4130
4079
|
True if successful, false if the tree was empty.
|
|
4131
4080
|
|
|
4132
|
-
*
|
|
4133
|
-
|
|
4134
4081
|
#### Remarks
|
|
4135
4082
|
|
|
4136
4083
|
AVL trees are already height-balanced, but this makes them *perfectly* balanced (minimal height and all leaves at N or N-1).
|
|
@@ -4160,7 +4107,7 @@ Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and r
|
|
|
4160
4107
|
print(options?, startNode?): void;
|
|
4161
4108
|
```
|
|
4162
4109
|
|
|
4163
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4110
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2041](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2041)
|
|
4164
4111
|
|
|
4165
4112
|
Prints a visual representation of the tree to the console.
|
|
4166
4113
|
|
|
@@ -4181,8 +4128,6 @@ Options to control the output.
|
|
|
4181
4128
|
|
|
4182
4129
|
The node to start printing from.
|
|
4183
4130
|
|
|
4184
|
-
*
|
|
4185
|
-
|
|
4186
4131
|
#### Returns
|
|
4187
4132
|
|
|
4188
4133
|
`void`
|
|
@@ -4213,7 +4158,7 @@ Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
|
4213
4158
|
rangeByRank(start, end): (K | undefined)[];
|
|
4214
4159
|
```
|
|
4215
4160
|
|
|
4216
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4161
|
+
Defined in: [data-structures/binary-tree/bst.ts:989](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L989)
|
|
4217
4162
|
|
|
4218
4163
|
Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
4219
4164
|
|
|
@@ -4255,7 +4200,7 @@ rangeByRank<C>(
|
|
|
4255
4200
|
iterationType?): ReturnType<C>[];
|
|
4256
4201
|
```
|
|
4257
4202
|
|
|
4258
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4203
|
+
Defined in: [data-structures/binary-tree/bst.ts:1001](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1001)
|
|
4259
4204
|
|
|
4260
4205
|
Returns elements by position range in tree order with callback and optional iteration type.
|
|
4261
4206
|
|
|
@@ -4341,12 +4286,10 @@ The traversal method.
|
|
|
4341
4286
|
rangeSearch(range): (K | undefined)[];
|
|
4342
4287
|
```
|
|
4343
4288
|
|
|
4344
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4289
|
+
Defined in: [data-structures/binary-tree/bst.ts:807](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L807)
|
|
4345
4290
|
|
|
4346
4291
|
Find all keys in a range
|
|
4347
4292
|
|
|
4348
|
-
*
|
|
4349
|
-
|
|
4350
4293
|
##### Parameters
|
|
4351
4294
|
|
|
4352
4295
|
###### range
|
|
@@ -4379,12 +4322,10 @@ rangeSearch<C>(
|
|
|
4379
4322
|
iterationType?): ReturnType<C>[];
|
|
4380
4323
|
```
|
|
4381
4324
|
|
|
4382
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4325
|
+
Defined in: [data-structures/binary-tree/bst.ts:809](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L809)
|
|
4383
4326
|
|
|
4384
4327
|
Find all keys in a range
|
|
4385
4328
|
|
|
4386
|
-
*
|
|
4387
|
-
|
|
4388
4329
|
##### Type Parameters
|
|
4389
4330
|
|
|
4390
4331
|
###### C
|
|
@@ -4522,12 +4463,10 @@ Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
|
4522
4463
|
search(keyNodeEntryOrPredicate, onlyOne?): (K | undefined)[];
|
|
4523
4464
|
```
|
|
4524
4465
|
|
|
4525
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4466
|
+
Defined in: [data-structures/binary-tree/bst.ts:646](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L646)
|
|
4526
4467
|
|
|
4527
4468
|
Search nodes by predicate
|
|
4528
4469
|
|
|
4529
|
-
*
|
|
4530
|
-
|
|
4531
4470
|
##### Parameters
|
|
4532
4471
|
|
|
4533
4472
|
###### keyNodeEntryOrPredicate
|
|
@@ -4552,7 +4491,12 @@ Search nodes by predicate
|
|
|
4552
4491
|
|
|
4553
4492
|
```ts
|
|
4554
4493
|
// Search nodes by predicate
|
|
4555
|
-
const bst = new BST<number, string>([
|
|
4494
|
+
const bst = new BST<number, string>([
|
|
4495
|
+
[1, 'a'],
|
|
4496
|
+
[2, 'b'],
|
|
4497
|
+
[3, 'c'],
|
|
4498
|
+
[4, 'd']
|
|
4499
|
+
]);
|
|
4556
4500
|
const found = bst.search(node => node.key > 2, true);
|
|
4557
4501
|
console.log(found.length); // >= 1;
|
|
4558
4502
|
```
|
|
@@ -4578,12 +4522,10 @@ search<C>(
|
|
|
4578
4522
|
iterationType?): ReturnType<C>[];
|
|
4579
4523
|
```
|
|
4580
4524
|
|
|
4581
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4525
|
+
Defined in: [data-structures/binary-tree/bst.ts:658](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L658)
|
|
4582
4526
|
|
|
4583
4527
|
Search nodes by predicate
|
|
4584
4528
|
|
|
4585
|
-
*
|
|
4586
|
-
|
|
4587
4529
|
##### Type Parameters
|
|
4588
4530
|
|
|
4589
4531
|
###### C
|
|
@@ -4629,7 +4571,12 @@ Search nodes by predicate
|
|
|
4629
4571
|
|
|
4630
4572
|
```ts
|
|
4631
4573
|
// Search nodes by predicate
|
|
4632
|
-
const bst = new BST<number, string>([
|
|
4574
|
+
const bst = new BST<number, string>([
|
|
4575
|
+
[1, 'a'],
|
|
4576
|
+
[2, 'b'],
|
|
4577
|
+
[3, 'c'],
|
|
4578
|
+
[4, 'd']
|
|
4579
|
+
]);
|
|
4633
4580
|
const found = bst.search(node => node.key > 2, true);
|
|
4634
4581
|
console.log(found.length); // >= 1;
|
|
4635
4582
|
```
|
|
@@ -4652,7 +4599,7 @@ IBinaryTree.search
|
|
|
4652
4599
|
set(keyNodeOrEntry, value?): boolean;
|
|
4653
4600
|
```
|
|
4654
4601
|
|
|
4655
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4602
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:367](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L367)
|
|
4656
4603
|
|
|
4657
4604
|
Sets a new node to the AVL tree and balances the tree path.
|
|
4658
4605
|
|
|
@@ -4680,8 +4627,6 @@ The value, if providing just a key.
|
|
|
4680
4627
|
|
|
4681
4628
|
True if the addition was successful, false otherwise.
|
|
4682
4629
|
|
|
4683
|
-
*
|
|
4684
|
-
|
|
4685
4630
|
#### Remarks
|
|
4686
4631
|
|
|
4687
4632
|
Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
@@ -4718,7 +4663,7 @@ setMany(
|
|
|
4718
4663
|
iterationType?): boolean[];
|
|
4719
4664
|
```
|
|
4720
4665
|
|
|
4721
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4666
|
+
Defined in: [data-structures/binary-tree/bst.ts:1149](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1149)
|
|
4722
4667
|
|
|
4723
4668
|
Adds multiple items to the tree.
|
|
4724
4669
|
|
|
@@ -4754,8 +4699,6 @@ The traversal method for balanced set (recursive or iterative).
|
|
|
4754
4699
|
|
|
4755
4700
|
An array of booleans indicating the success of each individual `set` operation.
|
|
4756
4701
|
|
|
4757
|
-
*
|
|
4758
|
-
|
|
4759
4702
|
#### Remarks
|
|
4760
4703
|
|
|
4761
4704
|
If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
@@ -4767,7 +4710,11 @@ Space O(N) for sorting and recursion/iteration stack.
|
|
|
4767
4710
|
```ts
|
|
4768
4711
|
// Set multiple key-value pairs
|
|
4769
4712
|
const bst = new BST<number, string>();
|
|
4770
|
-
bst.setMany([
|
|
4713
|
+
bst.setMany([
|
|
4714
|
+
[1, 'a'],
|
|
4715
|
+
[2, 'b'],
|
|
4716
|
+
[3, 'c']
|
|
4717
|
+
]);
|
|
4771
4718
|
console.log(bst.size); // 3;
|
|
4772
4719
|
console.log(bst.get(2)); // 'b';
|
|
4773
4720
|
```
|
|
@@ -4856,7 +4803,7 @@ Time O(n), Space O(n)
|
|
|
4856
4803
|
toVisual(startNode?, options?): string;
|
|
4857
4804
|
```
|
|
4858
4805
|
|
|
4859
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4806
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2004](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2004)
|
|
4860
4807
|
|
|
4861
4808
|
Generates a string representation of the tree for visualization.
|
|
4862
4809
|
|
|
@@ -4934,7 +4881,7 @@ IBinaryTree.values
|
|
|
4934
4881
|
protected readonly _comparator: Comparator<K>;
|
|
4935
4882
|
```
|
|
4936
4883
|
|
|
4937
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4884
|
+
Defined in: [data-structures/binary-tree/bst.ts:340](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L340)
|
|
4938
4885
|
|
|
4939
4886
|
The comparator function used to determine the order of keys in the tree.
|
|
4940
4887
|
|
|
@@ -4954,7 +4901,7 @@ Time O(1) Space O(1)
|
|
|
4954
4901
|
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
4955
4902
|
```
|
|
4956
4903
|
|
|
4957
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4904
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2298](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2298)
|
|
4958
4905
|
|
|
4959
4906
|
(Protected) Default callback function, returns the node's key.
|
|
4960
4907
|
|
|
@@ -4982,7 +4929,7 @@ The node's key or undefined.
|
|
|
4982
4929
|
protected _balanceFactor(node): number;
|
|
4983
4930
|
```
|
|
4984
4931
|
|
|
4985
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4932
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:558](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L558)
|
|
4986
4933
|
|
|
4987
4934
|
(Protected) Calculates the balance factor (height(right) - height(left)).
|
|
4988
4935
|
|
|
@@ -5012,7 +4959,7 @@ Time O(1) (assumes heights are stored).
|
|
|
5012
4959
|
protected _balanceLL(A): void;
|
|
5013
4960
|
```
|
|
5014
4961
|
|
|
5015
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4962
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:582](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L582)
|
|
5016
4963
|
|
|
5017
4964
|
(Protected) Performs a Left-Left (LL) rotation (a single right rotation).
|
|
5018
4965
|
|
|
@@ -5040,7 +4987,7 @@ Time O(1), Space O(1)
|
|
|
5040
4987
|
protected _balanceLR(A): void;
|
|
5041
4988
|
```
|
|
5042
4989
|
|
|
5043
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4990
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:617](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L617)
|
|
5044
4991
|
|
|
5045
4992
|
(Protected) Performs a Left-Right (LR) double rotation.
|
|
5046
4993
|
|
|
@@ -5068,7 +5015,7 @@ Time O(1), Space O(1)
|
|
|
5068
5015
|
protected _balancePath(node): void;
|
|
5069
5016
|
```
|
|
5070
5017
|
|
|
5071
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5018
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:756](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L756)
|
|
5072
5019
|
|
|
5073
5020
|
(Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
|
|
5074
5021
|
|
|
@@ -5100,7 +5047,7 @@ Time O(log N) (O(H)), as it traverses the path to root. Space O(H) for the path
|
|
|
5100
5047
|
protected _balanceRL(A): void;
|
|
5101
5048
|
```
|
|
5102
5049
|
|
|
5103
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5050
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:707](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L707)
|
|
5104
5051
|
|
|
5105
5052
|
(Protected) Performs a Right-Left (RL) double rotation.
|
|
5106
5053
|
|
|
@@ -5128,7 +5075,7 @@ Time O(1), Space O(1)
|
|
|
5128
5075
|
protected _balanceRR(A): void;
|
|
5129
5076
|
```
|
|
5130
5077
|
|
|
5131
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5078
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:668](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L668)
|
|
5132
5079
|
|
|
5133
5080
|
(Protected) Performs a Right-Right (RR) rotation (a single left rotation).
|
|
5134
5081
|
|
|
@@ -5159,7 +5106,7 @@ protected _bound(
|
|
|
5159
5106
|
iterationType): BSTNode<K, V> | undefined;
|
|
5160
5107
|
```
|
|
5161
5108
|
|
|
5162
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5109
|
+
Defined in: [data-structures/binary-tree/bst.ts:2139](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2139)
|
|
5163
5110
|
|
|
5164
5111
|
(Protected) Core bound search implementation supporting all parameter types.
|
|
5165
5112
|
Unified logic for both lowerBound and upperBound.
|
|
@@ -5211,7 +5158,7 @@ protected _boundByKey(
|
|
|
5211
5158
|
iterationType): BSTNode<K, V> | undefined;
|
|
5212
5159
|
```
|
|
5213
5160
|
|
|
5214
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5161
|
+
Defined in: [data-structures/binary-tree/bst.ts:2196](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2196)
|
|
5215
5162
|
|
|
5216
5163
|
(Protected) Binary search for bound by key with pruning optimization.
|
|
5217
5164
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5256,7 +5203,7 @@ The first node matching the bound condition, or undefined if none exists.
|
|
|
5256
5203
|
protected _boundByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5257
5204
|
```
|
|
5258
5205
|
|
|
5259
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5206
|
+
Defined in: [data-structures/binary-tree/bst.ts:2251](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2251)
|
|
5260
5207
|
|
|
5261
5208
|
(Protected) In-order traversal search by predicate.
|
|
5262
5209
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5296,7 +5243,7 @@ The first node satisfying predicate, or undefined if none found.
|
|
|
5296
5243
|
protected _clearNodes(): void;
|
|
5297
5244
|
```
|
|
5298
5245
|
|
|
5299
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5246
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2701](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2701)
|
|
5300
5247
|
|
|
5301
5248
|
(Protected) Clears all nodes from the tree.
|
|
5302
5249
|
|
|
@@ -5320,7 +5267,7 @@ Time O(1)
|
|
|
5320
5267
|
protected _clearValues(): void;
|
|
5321
5268
|
```
|
|
5322
5269
|
|
|
5323
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5270
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2710](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2710)
|
|
5324
5271
|
|
|
5325
5272
|
(Protected) Clears all values from the external store.
|
|
5326
5273
|
|
|
@@ -5344,7 +5291,7 @@ Time O(N)
|
|
|
5344
5291
|
protected _clone(cloned): void;
|
|
5345
5292
|
```
|
|
5346
5293
|
|
|
5347
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5294
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2392](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2392)
|
|
5348
5295
|
|
|
5349
5296
|
(Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
5350
5297
|
|
|
@@ -5376,7 +5323,7 @@ Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
|
5376
5323
|
protected _compare(a, b): number;
|
|
5377
5324
|
```
|
|
5378
5325
|
|
|
5379
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5326
|
+
Defined in: [data-structures/binary-tree/bst.ts:2517](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2517)
|
|
5380
5327
|
|
|
5381
5328
|
(Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
5382
5329
|
|
|
@@ -5416,7 +5363,7 @@ Time O(1) Space O(1)
|
|
|
5416
5363
|
protected _createDefaultComparator(): Comparator<K>;
|
|
5417
5364
|
```
|
|
5418
5365
|
|
|
5419
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5366
|
+
Defined in: [data-structures/binary-tree/bst.ts:1866](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1866)
|
|
5420
5367
|
|
|
5421
5368
|
(Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
5422
5369
|
|
|
@@ -5442,7 +5389,7 @@ Time O(1) Space O(1)
|
|
|
5442
5389
|
protected _createInstance<TK, TV, TR>(options?): this;
|
|
5443
5390
|
```
|
|
5444
5391
|
|
|
5445
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5392
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:489](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L489)
|
|
5446
5393
|
|
|
5447
5394
|
(Protected) Creates a new, empty instance of the same AVLTree constructor.
|
|
5448
5395
|
|
|
@@ -5490,7 +5437,7 @@ Time O(1)
|
|
|
5490
5437
|
protected _createLike<TK, TV, TR>(iter?, options?): AVLTree<TK, TV, TR>;
|
|
5491
5438
|
```
|
|
5492
5439
|
|
|
5493
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5440
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:506](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L506)
|
|
5494
5441
|
|
|
5495
5442
|
(Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
|
|
5496
5443
|
|
|
@@ -5550,7 +5497,7 @@ Time O(N log N) (from constructor) due to processing the iterable.
|
|
|
5550
5497
|
protected _deleteByKey(key): boolean;
|
|
5551
5498
|
```
|
|
5552
5499
|
|
|
5553
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5500
|
+
Defined in: [data-structures/binary-tree/bst.ts:2528](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2528)
|
|
5554
5501
|
|
|
5555
5502
|
(Private) Deletes a node by its key.
|
|
5556
5503
|
|
|
@@ -5584,7 +5531,7 @@ Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
|
|
|
5584
5531
|
protected _deleteInternal(keyNodeEntryRawOrPredicate): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
5585
5532
|
```
|
|
5586
5533
|
|
|
5587
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5534
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2056](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2056)
|
|
5588
5535
|
|
|
5589
5536
|
**`Internal`**
|
|
5590
5537
|
|
|
@@ -5632,7 +5579,7 @@ protected _dfs<C>(
|
|
|
5632
5579
|
shouldProcessRoot?): ReturnType<C>[];
|
|
5633
5580
|
```
|
|
5634
5581
|
|
|
5635
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5582
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2109](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2109)
|
|
5636
5583
|
|
|
5637
5584
|
#### Type Parameters
|
|
5638
5585
|
|
|
@@ -5725,7 +5672,7 @@ Array of callback results.
|
|
|
5725
5672
|
protected _displayAux(node, options): NodeDisplayLayout;
|
|
5726
5673
|
```
|
|
5727
5674
|
|
|
5728
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5675
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2416](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2416)
|
|
5729
5676
|
|
|
5730
5677
|
(Protected) Recursive helper for `toVisual`.
|
|
5731
5678
|
|
|
@@ -5765,7 +5712,7 @@ Time O(N), Space O(N*H) or O(N^2)
|
|
|
5765
5712
|
protected _ensurePredicate(keyNodeEntryOrPredicate): NodePredicate<BinaryTreeNode<K, V>>;
|
|
5766
5713
|
```
|
|
5767
5714
|
|
|
5768
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5715
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2607](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2607)
|
|
5769
5716
|
|
|
5770
5717
|
(Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
5771
5718
|
|
|
@@ -5804,7 +5751,7 @@ Time O(1)
|
|
|
5804
5751
|
protected _extractKey(keyNodeOrEntry): K | null | undefined;
|
|
5805
5752
|
```
|
|
5806
5753
|
|
|
5807
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5754
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2667](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2667)
|
|
5808
5755
|
|
|
5809
5756
|
(Protected) Extracts the key from a key, node, or entry.
|
|
5810
5757
|
|
|
@@ -5842,7 +5789,7 @@ Time O(1)
|
|
|
5842
5789
|
protected _floorByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5843
5790
|
```
|
|
5844
5791
|
|
|
5845
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5792
|
+
Defined in: [data-structures/binary-tree/bst.ts:1904](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1904)
|
|
5846
5793
|
|
|
5847
5794
|
(Protected) Binary search for floor by key with pruning optimization.
|
|
5848
5795
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5884,7 +5831,7 @@ Time O(h) where h is tree height.
|
|
|
5884
5831
|
protected _floorByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5885
5832
|
```
|
|
5886
5833
|
|
|
5887
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5834
|
+
Defined in: [data-structures/binary-tree/bst.ts:1957](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1957)
|
|
5888
5835
|
|
|
5889
5836
|
(Protected) In-order traversal search for floor by predicate.
|
|
5890
5837
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5927,7 +5874,7 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5927
5874
|
protected _getByRankIterative(node, k): BSTNode<K, V> | undefined;
|
|
5928
5875
|
```
|
|
5929
5876
|
|
|
5930
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5877
|
+
Defined in: [data-structures/binary-tree/bst.ts:2406](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2406)
|
|
5931
5878
|
|
|
5932
5879
|
(Protected) Finds the node at position k in tree order (iterative).
|
|
5933
5880
|
|
|
@@ -5961,7 +5908,7 @@ Time O(log n), Space O(1)
|
|
|
5961
5908
|
protected _getByRankRecursive(node, k): BSTNode<K, V> | undefined;
|
|
5962
5909
|
```
|
|
5963
5910
|
|
|
5964
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5911
|
+
Defined in: [data-structures/binary-tree/bst.ts:2427](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2427)
|
|
5965
5912
|
|
|
5966
5913
|
(Protected) Finds the node at position k in tree order (recursive).
|
|
5967
5914
|
|
|
@@ -5995,7 +5942,7 @@ Time O(log n), Space O(log n) call stack
|
|
|
5995
5942
|
protected _getIterator(node?): IterableIterator<[K, V | undefined]>;
|
|
5996
5943
|
```
|
|
5997
5944
|
|
|
5998
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5945
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2254](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2254)
|
|
5999
5946
|
|
|
6000
5947
|
(Protected) Gets the iterator for the tree (default in-order).
|
|
6001
5948
|
|
|
@@ -6029,7 +5976,7 @@ Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the
|
|
|
6029
5976
|
protected _getRankIterative(node, key): number;
|
|
6030
5977
|
```
|
|
6031
5978
|
|
|
6032
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5979
|
+
Defined in: [data-structures/binary-tree/bst.ts:2439](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2439)
|
|
6033
5980
|
|
|
6034
5981
|
(Protected) Computes the rank of a key iteratively.
|
|
6035
5982
|
|
|
@@ -6063,7 +6010,7 @@ Time O(log n), Space O(1)
|
|
|
6063
6010
|
protected _getRankRecursive(node, key): number;
|
|
6064
6011
|
```
|
|
6065
6012
|
|
|
6066
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6013
|
+
Defined in: [data-structures/binary-tree/bst.ts:2465](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2465)
|
|
6067
6014
|
|
|
6068
6015
|
(Protected) Computes the rank of a key recursively.
|
|
6069
6016
|
|
|
@@ -6097,7 +6044,7 @@ Time O(log n), Space O(log n) call stack
|
|
|
6097
6044
|
protected _isDisplayLeaf(node, options): boolean;
|
|
6098
6045
|
```
|
|
6099
6046
|
|
|
6100
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6047
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2482](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2482)
|
|
6101
6048
|
|
|
6102
6049
|
Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
6103
6050
|
|
|
@@ -6127,7 +6074,7 @@ Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
|
6127
6074
|
protected _isPredicate(p): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
6128
6075
|
```
|
|
6129
6076
|
|
|
6130
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6077
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2656](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2656)
|
|
6131
6078
|
|
|
6132
6079
|
(Protected) Checks if an item is a predicate function.
|
|
6133
6080
|
|
|
@@ -6161,7 +6108,7 @@ Time O(1)
|
|
|
6161
6108
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value?): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
6162
6109
|
```
|
|
6163
6110
|
|
|
6164
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6111
|
+
Defined in: [data-structures/binary-tree/bst.ts:2364](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2364)
|
|
6165
6112
|
|
|
6166
6113
|
(Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
6167
6114
|
|
|
@@ -6205,7 +6152,7 @@ Time O(1)
|
|
|
6205
6152
|
protected _lowerByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
6206
6153
|
```
|
|
6207
6154
|
|
|
6208
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6155
|
+
Defined in: [data-structures/binary-tree/bst.ts:2022](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2022)
|
|
6209
6156
|
|
|
6210
6157
|
(Protected) Binary search for lower by key with pruning optimization.
|
|
6211
6158
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -6247,7 +6194,7 @@ Time O(h) where h is tree height.
|
|
|
6247
6194
|
protected _lowerByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
6248
6195
|
```
|
|
6249
6196
|
|
|
6250
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6197
|
+
Defined in: [data-structures/binary-tree/bst.ts:2075](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2075)
|
|
6251
6198
|
|
|
6252
6199
|
(Protected) In-order traversal search for lower by predicate.
|
|
6253
6200
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -6290,7 +6237,7 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
6290
6237
|
protected _next(node): BSTNode<K, V> | undefined;
|
|
6291
6238
|
```
|
|
6292
6239
|
|
|
6293
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6240
|
+
Defined in: [data-structures/binary-tree/bst.ts:2485](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2485)
|
|
6294
6241
|
|
|
6295
6242
|
(Protected) Finds the in-order successor of a node.
|
|
6296
6243
|
|
|
@@ -6320,7 +6267,7 @@ Time O(log n), Space O(1)
|
|
|
6320
6267
|
protected _replaceNode(oldNode, newNode): AVLTreeNode<K, V>;
|
|
6321
6268
|
```
|
|
6322
6269
|
|
|
6323
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
6270
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:802](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L802)
|
|
6324
6271
|
|
|
6325
6272
|
(Protected) Replaces a node, ensuring height is copied.
|
|
6326
6273
|
|
|
@@ -6363,7 +6310,7 @@ protected _resolveDisplayLeaf(
|
|
|
6363
6310
|
emptyDisplayLayout): NodeDisplayLayout;
|
|
6364
6311
|
```
|
|
6365
6312
|
|
|
6366
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6313
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2509](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2509)
|
|
6367
6314
|
|
|
6368
6315
|
Resolve a display leaf node to its layout.
|
|
6369
6316
|
|
|
@@ -6397,7 +6344,7 @@ Resolve a display leaf node to its layout.
|
|
|
6397
6344
|
protected _setRoot(v): void;
|
|
6398
6345
|
```
|
|
6399
6346
|
|
|
6400
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6347
|
+
Defined in: [data-structures/binary-tree/bst.ts:2504](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2504)
|
|
6401
6348
|
|
|
6402
6349
|
(Protected) Sets the root node and clears its parent reference.
|
|
6403
6350
|
|
|
@@ -6429,7 +6376,7 @@ Time O(1)
|
|
|
6429
6376
|
protected _setValue(key, value): boolean;
|
|
6430
6377
|
```
|
|
6431
6378
|
|
|
6432
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6379
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2688)
|
|
6433
6380
|
|
|
6434
6381
|
(Protected) Sets a value in the external store (Map mode).
|
|
6435
6382
|
|
|
@@ -6469,7 +6416,7 @@ Time O(1) (average for Map.set).
|
|
|
6469
6416
|
protected _snapshotOptions<TK, TV, TR>(): BSTOptions<TK, TV, TR>;
|
|
6470
6417
|
```
|
|
6471
6418
|
|
|
6472
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6419
|
+
Defined in: [data-structures/binary-tree/bst.ts:2348](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2348)
|
|
6473
6420
|
|
|
6474
6421
|
(Protected) Snapshots the current BST's configuration options.
|
|
6475
6422
|
|
|
@@ -6509,7 +6456,7 @@ Time O(1)
|
|
|
6509
6456
|
protected _swapProperties(srcNode, destNode): AVLTreeNode<K, V> | undefined;
|
|
6510
6457
|
```
|
|
6511
6458
|
|
|
6512
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
6459
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:525](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L525)
|
|
6513
6460
|
|
|
6514
6461
|
(Protected) Swaps properties of two nodes, including height.
|
|
6515
6462
|
|
|
@@ -6549,7 +6496,7 @@ Time O(H) (due to `ensureNode`), but O(1) if nodes are passed directly.
|
|
|
6549
6496
|
protected _updateCount(node): void;
|
|
6550
6497
|
```
|
|
6551
6498
|
|
|
6552
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6499
|
+
Defined in: [data-structures/binary-tree/bst.ts:2383](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2383)
|
|
6553
6500
|
|
|
6554
6501
|
(Protected) Recalculates the subtree count for a single node.
|
|
6555
6502
|
|
|
@@ -6579,7 +6526,7 @@ Time O(1). Only active when enableOrderStatistic is true.
|
|
|
6579
6526
|
protected _updateCountAlongPath(node): void;
|
|
6580
6527
|
```
|
|
6581
6528
|
|
|
6582
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6529
|
+
Defined in: [data-structures/binary-tree/bst.ts:2393](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2393)
|
|
6583
6530
|
|
|
6584
6531
|
(Protected) Updates subtree counts from a node up to the root.
|
|
6585
6532
|
|
|
@@ -6609,7 +6556,7 @@ Time O(log n). Only active when enableOrderStatistic is true.
|
|
|
6609
6556
|
protected _updateHeight(node): void;
|
|
6610
6557
|
```
|
|
6611
6558
|
|
|
6612
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
6559
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:570](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L570)
|
|
6613
6560
|
|
|
6614
6561
|
(Protected) Recalculates and updates the height of a node based on its children's heights.
|
|
6615
6562
|
|