data-structure-typed 2.6.1 → 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/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 +72 -104
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +67 -101
- 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 +40 -68
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +17 -17
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +38 -38
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +68 -96
- 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 +38 -66
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +41 -74
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +38 -66
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +46 -79
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +40 -68
- package/docs-site-docusaurus/docs/api/classes/Queue.md +54 -78
- 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 +68 -98
- 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 +33 -53
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +57 -124
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +45 -116
- package/docs-site-docusaurus/docs/api/classes/Trie.md +37 -61
- 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 +1 -1
- package/src/data-structures/binary-tree/tree-multi-set.ts +15 -11
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: BST\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
9
|
+
Defined in: [data-structures/binary-tree/bst.ts:332](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L332)
|
|
10
10
|
|
|
11
11
|
Represents a Binary Search Tree (BST).
|
|
12
12
|
Keys are ordered, allowing for faster search operations compared to a standard Binary Tree.
|
|
@@ -188,7 +188,7 @@ The type of the raw data object (if using `toEntryFn`).
|
|
|
188
188
|
new BST<K, V, R>(keysNodesEntriesOrRaws?, options?): BST<K, V, R>;
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
191
|
+
Defined in: [data-structures/binary-tree/bst.ts:349](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L349)
|
|
192
192
|
|
|
193
193
|
Creates an instance of BST.
|
|
194
194
|
|
|
@@ -234,7 +234,7 @@ Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input ord
|
|
|
234
234
|
get comparator(): Comparator<K>;
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
237
|
+
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)
|
|
238
238
|
|
|
239
239
|
Gets the comparator function used by the tree.
|
|
240
240
|
|
|
@@ -258,7 +258,7 @@ The comparator function.
|
|
|
258
258
|
get isDuplicate(): boolean;
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
261
|
+
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)
|
|
262
262
|
|
|
263
263
|
Gets whether the tree allows duplicate keys.
|
|
264
264
|
|
|
@@ -292,7 +292,7 @@ IBinaryTree.isDuplicate
|
|
|
292
292
|
get isMapMode(): boolean;
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
295
|
+
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)
|
|
296
296
|
|
|
297
297
|
Gets whether the tree is in Map mode.
|
|
298
298
|
|
|
@@ -360,7 +360,7 @@ IBinaryTree.NIL
|
|
|
360
360
|
get root(): OptNode<BSTNode<K, V>>;
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
363
|
+
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)
|
|
364
364
|
|
|
365
365
|
Gets the root node of the tree.
|
|
366
366
|
|
|
@@ -394,7 +394,7 @@ IBinaryTree.root
|
|
|
394
394
|
get size(): number;
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
397
|
+
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)
|
|
398
398
|
|
|
399
399
|
Gets the number of nodes in the tree.
|
|
400
400
|
|
|
@@ -428,7 +428,7 @@ IBinaryTree.size
|
|
|
428
428
|
get store(): Map<K, BinaryTreeNode<K, V>>;
|
|
429
429
|
```
|
|
430
430
|
|
|
431
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
431
|
+
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)
|
|
432
432
|
|
|
433
433
|
Gets the external value store (used in Map mode).
|
|
434
434
|
|
|
@@ -462,7 +462,7 @@ IBinaryTree.store
|
|
|
462
462
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
463
463
|
```
|
|
464
464
|
|
|
465
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
465
|
+
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)
|
|
466
466
|
|
|
467
467
|
Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
468
468
|
|
|
@@ -532,7 +532,7 @@ IBinaryTree.[iterator]
|
|
|
532
532
|
add(keyNodeOrEntry): boolean;
|
|
533
533
|
```
|
|
534
534
|
|
|
535
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
535
|
+
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)
|
|
536
536
|
|
|
537
537
|
Adds a new node to the tree.
|
|
538
538
|
|
|
@@ -554,8 +554,6 @@ The key, node, or entry to add.
|
|
|
554
554
|
|
|
555
555
|
True if the addition was successful, false otherwise.
|
|
556
556
|
|
|
557
|
-
*
|
|
558
|
-
|
|
559
557
|
#### Remarks
|
|
560
558
|
|
|
561
559
|
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).
|
|
@@ -590,7 +588,7 @@ IBinaryTree.add
|
|
|
590
588
|
addMany(keysNodesEntriesOrRaws): boolean[];
|
|
591
589
|
```
|
|
592
590
|
|
|
593
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
591
|
+
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)
|
|
594
592
|
|
|
595
593
|
Adds multiple items to the tree.
|
|
596
594
|
|
|
@@ -614,8 +612,6 @@ An iterable of items to set.
|
|
|
614
612
|
|
|
615
613
|
An array of booleans indicating the success of each individual `set` operation.
|
|
616
614
|
|
|
617
|
-
*
|
|
618
|
-
|
|
619
615
|
#### Remarks
|
|
620
616
|
|
|
621
617
|
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).
|
|
@@ -671,12 +667,10 @@ The traversal method.
|
|
|
671
667
|
bfs(): (K | undefined)[];
|
|
672
668
|
```
|
|
673
669
|
|
|
674
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
670
|
+
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)
|
|
675
671
|
|
|
676
672
|
BinaryTree level-order traversal
|
|
677
673
|
|
|
678
|
-
*
|
|
679
|
-
|
|
680
674
|
##### Returns
|
|
681
675
|
|
|
682
676
|
(`K` \| `undefined`)[]
|
|
@@ -709,12 +703,10 @@ bfs<C>(
|
|
|
709
703
|
iterationType?): ReturnType<C>[];
|
|
710
704
|
```
|
|
711
705
|
|
|
712
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
706
|
+
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)
|
|
713
707
|
|
|
714
708
|
BinaryTree level-order traversal
|
|
715
709
|
|
|
716
|
-
*
|
|
717
|
-
|
|
718
710
|
##### Type Parameters
|
|
719
711
|
|
|
720
712
|
###### C
|
|
@@ -771,15 +763,13 @@ IBinaryTree.bfs
|
|
|
771
763
|
ceiling(keyNodeEntryOrPredicate): K | undefined;
|
|
772
764
|
```
|
|
773
765
|
|
|
774
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
766
|
+
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)
|
|
775
767
|
|
|
776
768
|
Returns the first key with a value >= target.
|
|
777
769
|
Equivalent to Java TreeMap.ceiling.
|
|
778
770
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
779
771
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
780
772
|
|
|
781
|
-
*
|
|
782
|
-
|
|
783
773
|
##### Parameters
|
|
784
774
|
|
|
785
775
|
###### keyNodeEntryOrPredicate
|
|
@@ -814,7 +804,7 @@ ceiling<C>(
|
|
|
814
804
|
iterationType?): ReturnType<C>;
|
|
815
805
|
```
|
|
816
806
|
|
|
817
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
807
|
+
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)
|
|
818
808
|
|
|
819
809
|
Returns the first node with a key >= target and applies callback.
|
|
820
810
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -857,7 +847,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
857
847
|
clear(): void;
|
|
858
848
|
```
|
|
859
849
|
|
|
860
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
850
|
+
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)
|
|
861
851
|
|
|
862
852
|
Clears the tree of all nodes and values.
|
|
863
853
|
|
|
@@ -869,8 +859,6 @@ Clears the tree of all nodes and values.
|
|
|
869
859
|
|
|
870
860
|
Time O(N) if in Map mode (due to `_store.clear()`), O(1) otherwise. Space O(1)
|
|
871
861
|
|
|
872
|
-
*
|
|
873
|
-
|
|
874
862
|
#### Example
|
|
875
863
|
|
|
876
864
|
```ts
|
|
@@ -898,7 +886,7 @@ IBinaryTree.clear
|
|
|
898
886
|
clone(): this;
|
|
899
887
|
```
|
|
900
888
|
|
|
901
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
889
|
+
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)
|
|
902
890
|
|
|
903
891
|
Clones the tree.
|
|
904
892
|
|
|
@@ -908,8 +896,6 @@ Clones the tree.
|
|
|
908
896
|
|
|
909
897
|
A new, cloned instance of the tree.
|
|
910
898
|
|
|
911
|
-
*
|
|
912
|
-
|
|
913
899
|
#### Remarks
|
|
914
900
|
|
|
915
901
|
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.
|
|
@@ -942,7 +928,7 @@ IBinaryTree.clone
|
|
|
942
928
|
createNode(key, value?): BSTNode<K, V>;
|
|
943
929
|
```
|
|
944
930
|
|
|
945
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
931
|
+
Defined in: [data-structures/binary-tree/bst.ts:402](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L402)
|
|
946
932
|
|
|
947
933
|
(Protected) Creates a new BST node.
|
|
948
934
|
|
|
@@ -988,7 +974,7 @@ IBinaryTree.createNode
|
|
|
988
974
|
createTree(options?): this;
|
|
989
975
|
```
|
|
990
976
|
|
|
991
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
977
|
+
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)
|
|
992
978
|
|
|
993
979
|
Creates a new, empty tree of the same type and configuration.
|
|
994
980
|
|
|
@@ -1028,7 +1014,7 @@ IBinaryTree.createTree
|
|
|
1028
1014
|
delete(keyNodeEntryRawOrPredicate): boolean;
|
|
1029
1015
|
```
|
|
1030
1016
|
|
|
1031
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1017
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:794](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L794)
|
|
1032
1018
|
|
|
1033
1019
|
Deletes a node from the tree.
|
|
1034
1020
|
|
|
@@ -1047,8 +1033,6 @@ The node to delete.
|
|
|
1047
1033
|
|
|
1048
1034
|
True if the node was found and deleted, false otherwise.
|
|
1049
1035
|
|
|
1050
|
-
*
|
|
1051
|
-
|
|
1052
1036
|
#### Remarks
|
|
1053
1037
|
|
|
1054
1038
|
Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
@@ -1085,7 +1069,7 @@ deleteWhere(
|
|
|
1085
1069
|
iterationType?): boolean;
|
|
1086
1070
|
```
|
|
1087
1071
|
|
|
1088
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1072
|
+
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)
|
|
1089
1073
|
|
|
1090
1074
|
Deletes nodes that match a key, node, entry, predicate, or range.
|
|
1091
1075
|
|
|
@@ -1192,12 +1176,10 @@ The traversal method.
|
|
|
1192
1176
|
dfs(): (K | undefined)[];
|
|
1193
1177
|
```
|
|
1194
1178
|
|
|
1195
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1179
|
+
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)
|
|
1196
1180
|
|
|
1197
1181
|
Depth-first search traversal
|
|
1198
1182
|
|
|
1199
|
-
*
|
|
1200
|
-
|
|
1201
1183
|
##### Returns
|
|
1202
1184
|
|
|
1203
1185
|
(`K` \| `undefined`)[]
|
|
@@ -1232,12 +1214,10 @@ dfs<C>(
|
|
|
1232
1214
|
iterationType?): ReturnType<C>[];
|
|
1233
1215
|
```
|
|
1234
1216
|
|
|
1235
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1217
|
+
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)
|
|
1236
1218
|
|
|
1237
1219
|
Depth-first search traversal
|
|
1238
1220
|
|
|
1239
|
-
*
|
|
1240
|
-
|
|
1241
1221
|
##### Type Parameters
|
|
1242
1222
|
|
|
1243
1223
|
###### C
|
|
@@ -1300,7 +1280,7 @@ IBinaryTree.dfs
|
|
|
1300
1280
|
ensureNode(keyNodeOrEntry, iterationType?): OptNode<BSTNode<K, V>>;
|
|
1301
1281
|
```
|
|
1302
1282
|
|
|
1303
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1283
|
+
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)
|
|
1304
1284
|
|
|
1305
1285
|
Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
1306
1286
|
|
|
@@ -1422,7 +1402,7 @@ IBinaryTree.every
|
|
|
1422
1402
|
filter(predicate, thisArg?): this;
|
|
1423
1403
|
```
|
|
1424
1404
|
|
|
1425
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1405
|
+
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)
|
|
1426
1406
|
|
|
1427
1407
|
Creates a new tree containing only the entries that satisfy the predicate.
|
|
1428
1408
|
|
|
@@ -1446,8 +1426,6 @@ A function to test each [key, value] pair.
|
|
|
1446
1426
|
|
|
1447
1427
|
A new, filtered tree.
|
|
1448
1428
|
|
|
1449
|
-
*
|
|
1450
|
-
|
|
1451
1429
|
#### Remarks
|
|
1452
1430
|
|
|
1453
1431
|
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.
|
|
@@ -1527,15 +1505,13 @@ IBinaryTree.find
|
|
|
1527
1505
|
floor(keyNodeEntryOrPredicate): K | undefined;
|
|
1528
1506
|
```
|
|
1529
1507
|
|
|
1530
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1508
|
+
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)
|
|
1531
1509
|
|
|
1532
1510
|
Returns the first key with a value <= target.
|
|
1533
1511
|
Equivalent to Java TreeMap.floor.
|
|
1534
1512
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
1535
1513
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
1536
1514
|
|
|
1537
|
-
*
|
|
1538
|
-
|
|
1539
1515
|
##### Parameters
|
|
1540
1516
|
|
|
1541
1517
|
###### keyNodeEntryOrPredicate
|
|
@@ -1570,7 +1546,7 @@ floor<C>(
|
|
|
1570
1546
|
iterationType?): ReturnType<C>;
|
|
1571
1547
|
```
|
|
1572
1548
|
|
|
1573
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1549
|
+
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)
|
|
1574
1550
|
|
|
1575
1551
|
Returns the first node with a key <= target and applies callback.
|
|
1576
1552
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -1660,7 +1636,7 @@ get(
|
|
|
1660
1636
|
iterationType?): V | undefined;
|
|
1661
1637
|
```
|
|
1662
1638
|
|
|
1663
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1639
|
+
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)
|
|
1664
1640
|
|
|
1665
1641
|
Gets the value associated with a key.
|
|
1666
1642
|
|
|
@@ -1697,8 +1673,6 @@ The traversal method (if not in Map mode).
|
|
|
1697
1673
|
|
|
1698
1674
|
The associated value, or undefined.
|
|
1699
1675
|
|
|
1700
|
-
*
|
|
1701
|
-
|
|
1702
1676
|
#### Remarks
|
|
1703
1677
|
|
|
1704
1678
|
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).
|
|
@@ -1707,7 +1681,11 @@ Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O
|
|
|
1707
1681
|
|
|
1708
1682
|
```ts
|
|
1709
1683
|
// Retrieve value by key
|
|
1710
|
-
const tree = new BinaryTree<number, string>([
|
|
1684
|
+
const tree = new BinaryTree<number, string>([
|
|
1685
|
+
[1, 'root'],
|
|
1686
|
+
[2, 'left'],
|
|
1687
|
+
[3, 'right']
|
|
1688
|
+
]);
|
|
1711
1689
|
console.log(tree.get(2)); // 'left';
|
|
1712
1690
|
console.log(tree.get(99)); // undefined;
|
|
1713
1691
|
```
|
|
@@ -1732,7 +1710,7 @@ IBinaryTree.get
|
|
|
1732
1710
|
getByRank(k): K | undefined;
|
|
1733
1711
|
```
|
|
1734
1712
|
|
|
1735
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1713
|
+
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)
|
|
1736
1714
|
|
|
1737
1715
|
Returns the element at the k-th position in tree order (0-indexed).
|
|
1738
1716
|
|
|
@@ -1749,7 +1727,6 @@ The 0-based position in tree order (0 = first element).
|
|
|
1749
1727
|
`K` \| `undefined`
|
|
1750
1728
|
|
|
1751
1729
|
The key at position k, or `undefined` if out of bounds.
|
|
1752
|
-
*
|
|
1753
1730
|
|
|
1754
1731
|
##### Remarks
|
|
1755
1732
|
|
|
@@ -1775,7 +1752,7 @@ getByRank<C>(
|
|
|
1775
1752
|
iterationType?): ReturnType<C> | undefined;
|
|
1776
1753
|
```
|
|
1777
1754
|
|
|
1778
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1755
|
+
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)
|
|
1779
1756
|
|
|
1780
1757
|
Returns the element at the k-th position in tree order and applies a callback.
|
|
1781
1758
|
|
|
@@ -1823,7 +1800,7 @@ Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderS
|
|
|
1823
1800
|
getDepth(dist, startNode?): number;
|
|
1824
1801
|
```
|
|
1825
1802
|
|
|
1826
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1803
|
+
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)
|
|
1827
1804
|
|
|
1828
1805
|
Gets the depth of a node (distance from `startNode`).
|
|
1829
1806
|
|
|
@@ -1854,8 +1831,6 @@ The node to measure depth from (defaults to root).
|
|
|
1854
1831
|
|
|
1855
1832
|
The depth (0 if `dist` is `startNode`).
|
|
1856
1833
|
|
|
1857
|
-
*
|
|
1858
|
-
|
|
1859
1834
|
#### Remarks
|
|
1860
1835
|
|
|
1861
1836
|
Time O(H), where H is the depth of the `dist` node relative to `startNode`. O(N) worst-case. Space O(1).
|
|
@@ -1887,7 +1862,7 @@ IBinaryTree.getDepth
|
|
|
1887
1862
|
getHeight(startNode?, iterationType?): number;
|
|
1888
1863
|
```
|
|
1889
1864
|
|
|
1890
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1865
|
+
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)
|
|
1891
1866
|
|
|
1892
1867
|
Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
1893
1868
|
|
|
@@ -1914,8 +1889,6 @@ The traversal method.
|
|
|
1914
1889
|
|
|
1915
1890
|
The height ( -1 for an empty tree, 0 for a single-node tree).
|
|
1916
1891
|
|
|
1917
|
-
*
|
|
1918
|
-
|
|
1919
1892
|
#### Remarks
|
|
1920
1893
|
|
|
1921
1894
|
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).
|
|
@@ -1970,7 +1943,7 @@ The traversal method.
|
|
|
1970
1943
|
getLeftMost(): K | undefined;
|
|
1971
1944
|
```
|
|
1972
1945
|
|
|
1973
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1946
|
+
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)
|
|
1974
1947
|
|
|
1975
1948
|
##### Returns
|
|
1976
1949
|
|
|
@@ -1995,7 +1968,7 @@ getLeftMost<C>(
|
|
|
1995
1968
|
iterationType?): ReturnType<C>;
|
|
1996
1969
|
```
|
|
1997
1970
|
|
|
1998
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1971
|
+
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)
|
|
1999
1972
|
|
|
2000
1973
|
##### Type Parameters
|
|
2001
1974
|
|
|
@@ -2042,7 +2015,7 @@ IBinaryTree.getLeftMost
|
|
|
2042
2015
|
getMinHeight(startNode?, iterationType?): number;
|
|
2043
2016
|
```
|
|
2044
2017
|
|
|
2045
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2018
|
+
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)
|
|
2046
2019
|
|
|
2047
2020
|
Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
2048
2021
|
|
|
@@ -2094,7 +2067,7 @@ getNode(
|
|
|
2094
2067
|
iterationType?): OptNode<BSTNode<K, V>>;
|
|
2095
2068
|
```
|
|
2096
2069
|
|
|
2097
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2070
|
+
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)
|
|
2098
2071
|
|
|
2099
2072
|
Gets the first node matching a predicate.
|
|
2100
2073
|
|
|
@@ -2129,8 +2102,6 @@ The traversal method.
|
|
|
2129
2102
|
|
|
2130
2103
|
The first matching node, or undefined if not found.
|
|
2131
2104
|
|
|
2132
|
-
*
|
|
2133
|
-
|
|
2134
2105
|
#### Remarks
|
|
2135
2106
|
|
|
2136
2107
|
Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N) or O(N).
|
|
@@ -2139,7 +2110,11 @@ Time O(log N) if searching by key, O(N) if searching by predicate. Space O(log N
|
|
|
2139
2110
|
|
|
2140
2111
|
```ts
|
|
2141
2112
|
// Get node object by key
|
|
2142
|
-
const bst = new BST<number, string>([
|
|
2113
|
+
const bst = new BST<number, string>([
|
|
2114
|
+
[5, 'root'],
|
|
2115
|
+
[3, 'left'],
|
|
2116
|
+
[7, 'right']
|
|
2117
|
+
]);
|
|
2143
2118
|
const node = bst.getNode(3);
|
|
2144
2119
|
console.log(node?.key); // 3;
|
|
2145
2120
|
console.log(node?.value); // 'left';
|
|
@@ -2167,7 +2142,7 @@ getNodes(
|
|
|
2167
2142
|
iterationType?): BinaryTreeNode<K, V>[];
|
|
2168
2143
|
```
|
|
2169
2144
|
|
|
2170
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2145
|
+
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)
|
|
2171
2146
|
|
|
2172
2147
|
Gets all nodes matching a predicate.
|
|
2173
2148
|
|
|
@@ -2211,8 +2186,6 @@ The traversal method.
|
|
|
2211
2186
|
|
|
2212
2187
|
An array of matching nodes.
|
|
2213
2188
|
|
|
2214
|
-
*
|
|
2215
|
-
|
|
2216
2189
|
#### Remarks
|
|
2217
2190
|
|
|
2218
2191
|
Time O(N) (via `search`). Space O(H) or O(N) (via `search`).
|
|
@@ -2262,7 +2235,7 @@ If true, returns the path from root-to-node.
|
|
|
2262
2235
|
getPathToRoot(beginNode): (K | undefined)[];
|
|
2263
2236
|
```
|
|
2264
2237
|
|
|
2265
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2238
|
+
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)
|
|
2266
2239
|
|
|
2267
2240
|
##### Parameters
|
|
2268
2241
|
|
|
@@ -2297,7 +2270,7 @@ getPathToRoot<C>(
|
|
|
2297
2270
|
isReverse?): ReturnType<C>[];
|
|
2298
2271
|
```
|
|
2299
2272
|
|
|
2300
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2273
|
+
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)
|
|
2301
2274
|
|
|
2302
2275
|
##### Type Parameters
|
|
2303
2276
|
|
|
@@ -2345,7 +2318,7 @@ IBinaryTree.getPathToRoot
|
|
|
2345
2318
|
getPredecessor(node): BinaryTreeNode<K, V>;
|
|
2346
2319
|
```
|
|
2347
2320
|
|
|
2348
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2321
|
+
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)
|
|
2349
2322
|
|
|
2350
2323
|
Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
2351
2324
|
|
|
@@ -2381,7 +2354,7 @@ This is primarily a helper for Morris traversal. Time O(H), where H is the heigh
|
|
|
2381
2354
|
getRank(keyNodeEntryOrPredicate): number;
|
|
2382
2355
|
```
|
|
2383
2356
|
|
|
2384
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2357
|
+
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)
|
|
2385
2358
|
|
|
2386
2359
|
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
2387
2360
|
|
|
@@ -2415,7 +2388,7 @@ Tree order is defined by the comparator. When the key is not found, returns the
|
|
|
2415
2388
|
getRank(keyNodeEntryOrPredicate, iterationType): number;
|
|
2416
2389
|
```
|
|
2417
2390
|
|
|
2418
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2391
|
+
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)
|
|
2419
2392
|
|
|
2420
2393
|
Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
2421
2394
|
|
|
@@ -2480,7 +2453,7 @@ The traversal method.
|
|
|
2480
2453
|
getRightMost(): K | undefined;
|
|
2481
2454
|
```
|
|
2482
2455
|
|
|
2483
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2456
|
+
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)
|
|
2484
2457
|
|
|
2485
2458
|
##### Returns
|
|
2486
2459
|
|
|
@@ -2505,7 +2478,7 @@ getRightMost<C>(
|
|
|
2505
2478
|
iterationType?): ReturnType<C>;
|
|
2506
2479
|
```
|
|
2507
2480
|
|
|
2508
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2481
|
+
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)
|
|
2509
2482
|
|
|
2510
2483
|
##### Type Parameters
|
|
2511
2484
|
|
|
@@ -2552,7 +2525,7 @@ IBinaryTree.getRightMost
|
|
|
2552
2525
|
getSuccessor(x?): BinaryTreeNode<K, V> | null | undefined;
|
|
2553
2526
|
```
|
|
2554
2527
|
|
|
2555
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2528
|
+
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)
|
|
2556
2529
|
|
|
2557
2530
|
Gets the in-order successor of a node in a BST.
|
|
2558
2531
|
|
|
@@ -2589,7 +2562,7 @@ has(
|
|
|
2589
2562
|
iterationType?): boolean;
|
|
2590
2563
|
```
|
|
2591
2564
|
|
|
2592
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2565
|
+
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)
|
|
2593
2566
|
|
|
2594
2567
|
Checks if a node matching the predicate exists in the tree.
|
|
2595
2568
|
|
|
@@ -2626,8 +2599,6 @@ The traversal method.
|
|
|
2626
2599
|
|
|
2627
2600
|
True if a matching node exists, false otherwise.
|
|
2628
2601
|
|
|
2629
|
-
*
|
|
2630
|
-
|
|
2631
2602
|
#### Remarks
|
|
2632
2603
|
|
|
2633
2604
|
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.
|
|
@@ -2724,15 +2695,13 @@ IBinaryTree.hasValue
|
|
|
2724
2695
|
higher(keyNodeEntryOrPredicate): K | undefined;
|
|
2725
2696
|
```
|
|
2726
2697
|
|
|
2727
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2698
|
+
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)
|
|
2728
2699
|
|
|
2729
2700
|
Returns the first key with a value > target.
|
|
2730
2701
|
Equivalent to Java TreeMap.higher.
|
|
2731
2702
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
2732
2703
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
2733
2704
|
|
|
2734
|
-
*
|
|
2735
|
-
|
|
2736
2705
|
##### Parameters
|
|
2737
2706
|
|
|
2738
2707
|
###### keyNodeEntryOrPredicate
|
|
@@ -2766,7 +2735,7 @@ higher<C>(
|
|
|
2766
2735
|
iterationType?): ReturnType<C>;
|
|
2767
2736
|
```
|
|
2768
2737
|
|
|
2769
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2738
|
+
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)
|
|
2770
2739
|
|
|
2771
2740
|
Returns the first node with a key > target and applies callback.
|
|
2772
2741
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -2809,7 +2778,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
2809
2778
|
isAVLBalanced(iterationType?): boolean;
|
|
2810
2779
|
```
|
|
2811
2780
|
|
|
2812
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2781
|
+
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)
|
|
2813
2782
|
|
|
2814
2783
|
Checks if the tree meets the AVL balance condition (height difference <= 1).
|
|
2815
2784
|
|
|
@@ -2827,8 +2796,6 @@ The traversal method.
|
|
|
2827
2796
|
|
|
2828
2797
|
True if the tree is AVL balanced, false otherwise.
|
|
2829
2798
|
|
|
2830
|
-
*
|
|
2831
|
-
|
|
2832
2799
|
#### Remarks
|
|
2833
2800
|
|
|
2834
2801
|
Time O(N), as it must visit every node to compute height. Space O(log N) for recursion or O(N) for iterative map.
|
|
@@ -2849,7 +2816,7 @@ Time O(N), as it must visit every node to compute height. Space O(log N) for rec
|
|
|
2849
2816
|
isBST(startNode?, iterationType?): boolean;
|
|
2850
2817
|
```
|
|
2851
2818
|
|
|
2852
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2819
|
+
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)
|
|
2853
2820
|
|
|
2854
2821
|
Checks if the tree is a valid Binary Search Tree (BST).
|
|
2855
2822
|
|
|
@@ -2876,8 +2843,6 @@ The traversal method.
|
|
|
2876
2843
|
|
|
2877
2844
|
True if it's a valid BST, false otherwise.
|
|
2878
2845
|
|
|
2879
|
-
*
|
|
2880
|
-
|
|
2881
2846
|
#### Remarks
|
|
2882
2847
|
|
|
2883
2848
|
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).
|
|
@@ -2909,7 +2874,7 @@ IBinaryTree.isBST
|
|
|
2909
2874
|
isEmpty(): boolean;
|
|
2910
2875
|
```
|
|
2911
2876
|
|
|
2912
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2877
|
+
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)
|
|
2913
2878
|
|
|
2914
2879
|
Checks if the tree is empty.
|
|
2915
2880
|
|
|
@@ -2919,8 +2884,6 @@ Checks if the tree is empty.
|
|
|
2919
2884
|
|
|
2920
2885
|
True if the tree has no nodes, false otherwise.
|
|
2921
2886
|
|
|
2922
|
-
*
|
|
2923
|
-
|
|
2924
2887
|
#### Remarks
|
|
2925
2888
|
|
|
2926
2889
|
Time O(1), Space O(1)
|
|
@@ -2950,7 +2913,7 @@ IBinaryTree.isEmpty
|
|
|
2950
2913
|
isEntry(keyNodeOrEntry): keyNodeOrEntry is BTNEntry<K, V>;
|
|
2951
2914
|
```
|
|
2952
2915
|
|
|
2953
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2916
|
+
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)
|
|
2954
2917
|
|
|
2955
2918
|
Checks if the given item is a [key, value] entry pair.
|
|
2956
2919
|
|
|
@@ -2988,7 +2951,7 @@ Time O(1), Space O(1)
|
|
|
2988
2951
|
isLeaf(keyNodeOrEntry): boolean;
|
|
2989
2952
|
```
|
|
2990
2953
|
|
|
2991
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2954
|
+
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)
|
|
2992
2955
|
|
|
2993
2956
|
Checks if a node is a leaf (has no real children).
|
|
2994
2957
|
|
|
@@ -3026,7 +2989,7 @@ Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is pass
|
|
|
3026
2989
|
isNIL(keyNodeOrEntry): boolean;
|
|
3027
2990
|
```
|
|
3028
2991
|
|
|
3029
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2992
|
+
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)
|
|
3030
2993
|
|
|
3031
2994
|
Checks if the given item is the sentinel NIL node.
|
|
3032
2995
|
|
|
@@ -3064,7 +3027,7 @@ Time O(1), Space O(1)
|
|
|
3064
3027
|
isNode(keyNodeOrEntry): keyNodeOrEntry is BSTNode<K, V>;
|
|
3065
3028
|
```
|
|
3066
3029
|
|
|
3067
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3030
|
+
Defined in: [data-structures/binary-tree/bst.ts:428](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L428)
|
|
3068
3031
|
|
|
3069
3032
|
Checks if the given item is a `BSTNode` instance.
|
|
3070
3033
|
|
|
@@ -3102,7 +3065,7 @@ Time O(1), Space O(1)
|
|
|
3102
3065
|
isPerfectlyBalanced(startNode?): boolean;
|
|
3103
3066
|
```
|
|
3104
3067
|
|
|
3105
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3068
|
+
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)
|
|
3106
3069
|
|
|
3107
3070
|
Checks if the tree is perfectly balanced.
|
|
3108
3071
|
|
|
@@ -3145,7 +3108,7 @@ IBinaryTree.isPerfectlyBalanced
|
|
|
3145
3108
|
isRange(keyNodeEntryOrPredicate): keyNodeEntryOrPredicate is Range<K>;
|
|
3146
3109
|
```
|
|
3147
3110
|
|
|
3148
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3111
|
+
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)
|
|
3149
3112
|
|
|
3150
3113
|
Checks if the given item is a `Range` object.
|
|
3151
3114
|
|
|
@@ -3185,7 +3148,7 @@ Time O(1), Space O(1)
|
|
|
3185
3148
|
isRaw(keyNodeEntryOrRaw): keyNodeEntryOrRaw is R;
|
|
3186
3149
|
```
|
|
3187
3150
|
|
|
3188
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3151
|
+
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)
|
|
3189
3152
|
|
|
3190
3153
|
Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
3191
3154
|
|
|
@@ -3224,7 +3187,7 @@ Time O(1), Space O(1)
|
|
|
3224
3187
|
isRealNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
3225
3188
|
```
|
|
3226
3189
|
|
|
3227
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3190
|
+
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)
|
|
3228
3191
|
|
|
3229
3192
|
Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
3230
3193
|
|
|
@@ -3262,7 +3225,7 @@ Time O(1), Space O(1)
|
|
|
3262
3225
|
isRealNodeOrNull(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
3263
3226
|
```
|
|
3264
3227
|
|
|
3265
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3228
|
+
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)
|
|
3266
3229
|
|
|
3267
3230
|
Checks if the given item is either a "real" node or null.
|
|
3268
3231
|
|
|
@@ -3300,7 +3263,7 @@ Time O(1), Space O(1)
|
|
|
3300
3263
|
isValidKey(key): key is K;
|
|
3301
3264
|
```
|
|
3302
3265
|
|
|
3303
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3266
|
+
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)
|
|
3304
3267
|
|
|
3305
3268
|
Checks if the given key is valid (comparable).
|
|
3306
3269
|
|
|
@@ -3390,12 +3353,10 @@ The traversal method.
|
|
|
3390
3353
|
leaves(): (K | undefined)[];
|
|
3391
3354
|
```
|
|
3392
3355
|
|
|
3393
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3356
|
+
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)
|
|
3394
3357
|
|
|
3395
3358
|
Get leaf nodes
|
|
3396
3359
|
|
|
3397
|
-
*
|
|
3398
|
-
|
|
3399
3360
|
##### Returns
|
|
3400
3361
|
|
|
3401
3362
|
(`K` \| `undefined`)[]
|
|
@@ -3428,12 +3389,10 @@ leaves<C>(
|
|
|
3428
3389
|
iterationType?): ReturnType<C>[];
|
|
3429
3390
|
```
|
|
3430
3391
|
|
|
3431
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3392
|
+
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)
|
|
3432
3393
|
|
|
3433
3394
|
Get leaf nodes
|
|
3434
3395
|
|
|
3435
|
-
*
|
|
3436
|
-
|
|
3437
3396
|
##### Type Parameters
|
|
3438
3397
|
|
|
3439
3398
|
###### C
|
|
@@ -3516,7 +3475,7 @@ The traversal method.
|
|
|
3516
3475
|
lesserOrGreaterTraverse(): (K | undefined)[];
|
|
3517
3476
|
```
|
|
3518
3477
|
|
|
3519
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3478
|
+
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)
|
|
3520
3479
|
|
|
3521
3480
|
##### Returns
|
|
3522
3481
|
|
|
@@ -3532,7 +3491,7 @@ lesserOrGreaterTraverse<C>(
|
|
|
3532
3491
|
iterationType?): ReturnType<C>[];
|
|
3533
3492
|
```
|
|
3534
3493
|
|
|
3535
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3494
|
+
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)
|
|
3536
3495
|
|
|
3537
3496
|
##### Type Parameters
|
|
3538
3497
|
|
|
@@ -3597,12 +3556,10 @@ The traversal method.
|
|
|
3597
3556
|
listLevels(): (K | undefined)[][];
|
|
3598
3557
|
```
|
|
3599
3558
|
|
|
3600
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3559
|
+
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)
|
|
3601
3560
|
|
|
3602
3561
|
Level-order grouping
|
|
3603
3562
|
|
|
3604
|
-
*
|
|
3605
|
-
|
|
3606
3563
|
##### Returns
|
|
3607
3564
|
|
|
3608
3565
|
(`K` \| `undefined`)[][]
|
|
@@ -3638,12 +3595,10 @@ listLevels<C>(
|
|
|
3638
3595
|
iterationType?): ReturnType<C>[][];
|
|
3639
3596
|
```
|
|
3640
3597
|
|
|
3641
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3598
|
+
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)
|
|
3642
3599
|
|
|
3643
3600
|
Level-order grouping
|
|
3644
3601
|
|
|
3645
|
-
*
|
|
3646
|
-
|
|
3647
3602
|
##### Type Parameters
|
|
3648
3603
|
|
|
3649
3604
|
###### C
|
|
@@ -3703,15 +3658,13 @@ IBinaryTree.listLevels
|
|
|
3703
3658
|
lower(keyNodeEntryOrPredicate): K | undefined;
|
|
3704
3659
|
```
|
|
3705
3660
|
|
|
3706
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3661
|
+
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)
|
|
3707
3662
|
|
|
3708
3663
|
Returns the first key with a value < target.
|
|
3709
3664
|
Equivalent to Java TreeMap.lower.
|
|
3710
3665
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
3711
3666
|
Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
3712
3667
|
|
|
3713
|
-
*
|
|
3714
|
-
|
|
3715
3668
|
##### Parameters
|
|
3716
3669
|
|
|
3717
3670
|
###### keyNodeEntryOrPredicate
|
|
@@ -3745,7 +3698,7 @@ lower<C>(
|
|
|
3745
3698
|
iterationType?): ReturnType<C>;
|
|
3746
3699
|
```
|
|
3747
3700
|
|
|
3748
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3701
|
+
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)
|
|
3749
3702
|
|
|
3750
3703
|
Returns the first node with a key < target and applies callback.
|
|
3751
3704
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -3791,7 +3744,7 @@ map<MK, MV, MR>(
|
|
|
3791
3744
|
thisArg?): BST<MK, MV, MR>;
|
|
3792
3745
|
```
|
|
3793
3746
|
|
|
3794
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3747
|
+
Defined in: [data-structures/binary-tree/bst.ts:1788](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1788)
|
|
3795
3748
|
|
|
3796
3749
|
Creates a new BST by mapping each [key, value] pair to a new entry.
|
|
3797
3750
|
|
|
@@ -3841,8 +3794,6 @@ Options for the new BST.
|
|
|
3841
3794
|
|
|
3842
3795
|
A new, mapped BST.
|
|
3843
3796
|
|
|
3844
|
-
*
|
|
3845
|
-
|
|
3846
3797
|
#### Remarks
|
|
3847
3798
|
|
|
3848
3799
|
Time O(N * H), where N is nodes in this tree, and H is height of the new tree during insertion.
|
|
@@ -3852,7 +3803,11 @@ Space O(N) for the new tree.
|
|
|
3852
3803
|
|
|
3853
3804
|
```ts
|
|
3854
3805
|
// Transform to new tree
|
|
3855
|
-
const bst = new BST<number, number>([
|
|
3806
|
+
const bst = new BST<number, number>([
|
|
3807
|
+
[1, 10],
|
|
3808
|
+
[2, 20],
|
|
3809
|
+
[3, 30]
|
|
3810
|
+
]);
|
|
3856
3811
|
const doubled = bst.map((value, key) => [key, (value ?? 0) * 2] as [number, number]);
|
|
3857
3812
|
console.log([...doubled.values()]); // [20, 40, 60];
|
|
3858
3813
|
```
|
|
@@ -3875,7 +3830,7 @@ IBinaryTree.map
|
|
|
3875
3830
|
merge(anotherTree): void;
|
|
3876
3831
|
```
|
|
3877
3832
|
|
|
3878
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3833
|
+
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)
|
|
3879
3834
|
|
|
3880
3835
|
Merges another tree into this one by seting all its nodes.
|
|
3881
3836
|
|
|
@@ -3887,8 +3842,6 @@ Merges another tree into this one by seting all its nodes.
|
|
|
3887
3842
|
|
|
3888
3843
|
The tree to merge.
|
|
3889
3844
|
|
|
3890
|
-
*
|
|
3891
|
-
|
|
3892
3845
|
#### Returns
|
|
3893
3846
|
|
|
3894
3847
|
`void`
|
|
@@ -3949,12 +3902,10 @@ The node to start from.
|
|
|
3949
3902
|
morris(): (K | undefined)[];
|
|
3950
3903
|
```
|
|
3951
3904
|
|
|
3952
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3905
|
+
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)
|
|
3953
3906
|
|
|
3954
3907
|
Morris traversal (O(1) space)
|
|
3955
3908
|
|
|
3956
|
-
*
|
|
3957
|
-
|
|
3958
3909
|
##### Returns
|
|
3959
3910
|
|
|
3960
3911
|
(`K` \| `undefined`)[]
|
|
@@ -3987,12 +3938,10 @@ morris<C>(
|
|
|
3987
3938
|
startNode?): ReturnType<C>[];
|
|
3988
3939
|
```
|
|
3989
3940
|
|
|
3990
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3941
|
+
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)
|
|
3991
3942
|
|
|
3992
3943
|
Morris traversal (O(1) space)
|
|
3993
3944
|
|
|
3994
|
-
*
|
|
3995
|
-
|
|
3996
3945
|
##### Type Parameters
|
|
3997
3946
|
|
|
3998
3947
|
###### C
|
|
@@ -4047,7 +3996,7 @@ IBinaryTree.morris
|
|
|
4047
3996
|
perfectlyBalance(iterationType?): boolean;
|
|
4048
3997
|
```
|
|
4049
3998
|
|
|
4050
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3999
|
+
Defined in: [data-structures/binary-tree/bst.ts:1686](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1686)
|
|
4051
4000
|
|
|
4052
4001
|
Rebuilds the tree to be perfectly balanced.
|
|
4053
4002
|
|
|
@@ -4065,8 +4014,6 @@ The traversal method for the initial node export.
|
|
|
4065
4014
|
|
|
4066
4015
|
True if successful, false if the tree was empty.
|
|
4067
4016
|
|
|
4068
|
-
*
|
|
4069
|
-
|
|
4070
4017
|
#### Remarks
|
|
4071
4018
|
|
|
4072
4019
|
Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and recursion stack.
|
|
@@ -4091,7 +4038,7 @@ Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and r
|
|
|
4091
4038
|
print(options?, startNode?): void;
|
|
4092
4039
|
```
|
|
4093
4040
|
|
|
4094
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4041
|
+
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)
|
|
4095
4042
|
|
|
4096
4043
|
Prints a visual representation of the tree to the console.
|
|
4097
4044
|
|
|
@@ -4112,8 +4059,6 @@ Options to control the output.
|
|
|
4112
4059
|
|
|
4113
4060
|
The node to start printing from.
|
|
4114
4061
|
|
|
4115
|
-
*
|
|
4116
|
-
|
|
4117
4062
|
#### Returns
|
|
4118
4063
|
|
|
4119
4064
|
`void`
|
|
@@ -4144,7 +4089,7 @@ Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
|
4144
4089
|
rangeByRank(start, end): (K | undefined)[];
|
|
4145
4090
|
```
|
|
4146
4091
|
|
|
4147
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4092
|
+
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)
|
|
4148
4093
|
|
|
4149
4094
|
Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
4150
4095
|
|
|
@@ -4182,7 +4127,7 @@ rangeByRank<C>(
|
|
|
4182
4127
|
iterationType?): ReturnType<C>[];
|
|
4183
4128
|
```
|
|
4184
4129
|
|
|
4185
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4130
|
+
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)
|
|
4186
4131
|
|
|
4187
4132
|
Returns elements by position range in tree order with callback and optional iteration type.
|
|
4188
4133
|
|
|
@@ -4264,12 +4209,10 @@ The traversal method.
|
|
|
4264
4209
|
rangeSearch(range): (K | undefined)[];
|
|
4265
4210
|
```
|
|
4266
4211
|
|
|
4267
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4212
|
+
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)
|
|
4268
4213
|
|
|
4269
4214
|
Find all keys in a range
|
|
4270
4215
|
|
|
4271
|
-
*
|
|
4272
|
-
|
|
4273
4216
|
##### Parameters
|
|
4274
4217
|
|
|
4275
4218
|
###### range
|
|
@@ -4298,12 +4241,10 @@ rangeSearch<C>(
|
|
|
4298
4241
|
iterationType?): ReturnType<C>[];
|
|
4299
4242
|
```
|
|
4300
4243
|
|
|
4301
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4244
|
+
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)
|
|
4302
4245
|
|
|
4303
4246
|
Find all keys in a range
|
|
4304
4247
|
|
|
4305
|
-
*
|
|
4306
|
-
|
|
4307
4248
|
##### Type Parameters
|
|
4308
4249
|
|
|
4309
4250
|
###### C
|
|
@@ -4437,12 +4378,10 @@ Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
|
4437
4378
|
search(keyNodeEntryOrPredicate, onlyOne?): (K | undefined)[];
|
|
4438
4379
|
```
|
|
4439
4380
|
|
|
4440
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4381
|
+
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)
|
|
4441
4382
|
|
|
4442
4383
|
Search nodes by predicate
|
|
4443
4384
|
|
|
4444
|
-
*
|
|
4445
|
-
|
|
4446
4385
|
##### Parameters
|
|
4447
4386
|
|
|
4448
4387
|
###### keyNodeEntryOrPredicate
|
|
@@ -4467,7 +4406,12 @@ Search nodes by predicate
|
|
|
4467
4406
|
|
|
4468
4407
|
```ts
|
|
4469
4408
|
// Search nodes by predicate
|
|
4470
|
-
const bst = new BST<number, string>([
|
|
4409
|
+
const bst = new BST<number, string>([
|
|
4410
|
+
[1, 'a'],
|
|
4411
|
+
[2, 'b'],
|
|
4412
|
+
[3, 'c'],
|
|
4413
|
+
[4, 'd']
|
|
4414
|
+
]);
|
|
4471
4415
|
const found = bst.search(node => node.key > 2, true);
|
|
4472
4416
|
console.log(found.length); // >= 1;
|
|
4473
4417
|
```
|
|
@@ -4493,12 +4437,10 @@ search<C>(
|
|
|
4493
4437
|
iterationType?): ReturnType<C>[];
|
|
4494
4438
|
```
|
|
4495
4439
|
|
|
4496
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4440
|
+
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)
|
|
4497
4441
|
|
|
4498
4442
|
Search nodes by predicate
|
|
4499
4443
|
|
|
4500
|
-
*
|
|
4501
|
-
|
|
4502
4444
|
##### Type Parameters
|
|
4503
4445
|
|
|
4504
4446
|
###### C
|
|
@@ -4544,7 +4486,12 @@ Search nodes by predicate
|
|
|
4544
4486
|
|
|
4545
4487
|
```ts
|
|
4546
4488
|
// Search nodes by predicate
|
|
4547
|
-
const bst = new BST<number, string>([
|
|
4489
|
+
const bst = new BST<number, string>([
|
|
4490
|
+
[1, 'a'],
|
|
4491
|
+
[2, 'b'],
|
|
4492
|
+
[3, 'c'],
|
|
4493
|
+
[4, 'd']
|
|
4494
|
+
]);
|
|
4548
4495
|
const found = bst.search(node => node.key > 2, true);
|
|
4549
4496
|
console.log(found.length); // >= 1;
|
|
4550
4497
|
```
|
|
@@ -4567,7 +4514,7 @@ IBinaryTree.search
|
|
|
4567
4514
|
set(keyNodeOrEntry, value?): boolean;
|
|
4568
4515
|
```
|
|
4569
4516
|
|
|
4570
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4517
|
+
Defined in: [data-structures/binary-tree/bst.ts:1079](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1079)
|
|
4571
4518
|
|
|
4572
4519
|
Adds a new node to the BST based on key comparison.
|
|
4573
4520
|
|
|
@@ -4595,8 +4542,6 @@ The value, if providing just a key.
|
|
|
4595
4542
|
|
|
4596
4543
|
True if the addition was successful, false otherwise.
|
|
4597
4544
|
|
|
4598
|
-
*
|
|
4599
|
-
|
|
4600
4545
|
#### Remarks
|
|
4601
4546
|
|
|
4602
4547
|
Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -4633,7 +4578,7 @@ setMany(
|
|
|
4633
4578
|
iterationType?): boolean[];
|
|
4634
4579
|
```
|
|
4635
4580
|
|
|
4636
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4581
|
+
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)
|
|
4637
4582
|
|
|
4638
4583
|
Adds multiple items to the tree.
|
|
4639
4584
|
|
|
@@ -4669,8 +4614,6 @@ The traversal method for balanced set (recursive or iterative).
|
|
|
4669
4614
|
|
|
4670
4615
|
An array of booleans indicating the success of each individual `set` operation.
|
|
4671
4616
|
|
|
4672
|
-
*
|
|
4673
|
-
|
|
4674
4617
|
#### Remarks
|
|
4675
4618
|
|
|
4676
4619
|
If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
@@ -4682,7 +4625,11 @@ Space O(N) for sorting and recursion/iteration stack.
|
|
|
4682
4625
|
```ts
|
|
4683
4626
|
// Set multiple key-value pairs
|
|
4684
4627
|
const bst = new BST<number, string>();
|
|
4685
|
-
bst.setMany([
|
|
4628
|
+
bst.setMany([
|
|
4629
|
+
[1, 'a'],
|
|
4630
|
+
[2, 'b'],
|
|
4631
|
+
[3, 'c']
|
|
4632
|
+
]);
|
|
4686
4633
|
console.log(bst.size); // 3;
|
|
4687
4634
|
console.log(bst.get(2)); // 'b';
|
|
4688
4635
|
```
|
|
@@ -4771,7 +4718,7 @@ Time O(n), Space O(n)
|
|
|
4771
4718
|
toVisual(startNode?, options?): string;
|
|
4772
4719
|
```
|
|
4773
4720
|
|
|
4774
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4721
|
+
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)
|
|
4775
4722
|
|
|
4776
4723
|
Generates a string representation of the tree for visualization.
|
|
4777
4724
|
|
|
@@ -4849,7 +4796,7 @@ IBinaryTree.values
|
|
|
4849
4796
|
protected readonly _comparator: Comparator<K>;
|
|
4850
4797
|
```
|
|
4851
4798
|
|
|
4852
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4799
|
+
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)
|
|
4853
4800
|
|
|
4854
4801
|
The comparator function used to determine the order of keys in the tree.
|
|
4855
4802
|
|
|
@@ -4865,7 +4812,7 @@ Time O(1) Space O(1)
|
|
|
4865
4812
|
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
4866
4813
|
```
|
|
4867
4814
|
|
|
4868
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4815
|
+
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)
|
|
4869
4816
|
|
|
4870
4817
|
(Protected) Default callback function, returns the node's key.
|
|
4871
4818
|
|
|
@@ -4896,7 +4843,7 @@ protected _bound(
|
|
|
4896
4843
|
iterationType): BSTNode<K, V> | undefined;
|
|
4897
4844
|
```
|
|
4898
4845
|
|
|
4899
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4846
|
+
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)
|
|
4900
4847
|
|
|
4901
4848
|
(Protected) Core bound search implementation supporting all parameter types.
|
|
4902
4849
|
Unified logic for both lowerBound and upperBound.
|
|
@@ -4944,7 +4891,7 @@ protected _boundByKey(
|
|
|
4944
4891
|
iterationType): BSTNode<K, V> | undefined;
|
|
4945
4892
|
```
|
|
4946
4893
|
|
|
4947
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4894
|
+
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)
|
|
4948
4895
|
|
|
4949
4896
|
(Protected) Binary search for bound by key with pruning optimization.
|
|
4950
4897
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -4985,7 +4932,7 @@ The first node matching the bound condition, or undefined if none exists.
|
|
|
4985
4932
|
protected _boundByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
4986
4933
|
```
|
|
4987
4934
|
|
|
4988
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4935
|
+
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)
|
|
4989
4936
|
|
|
4990
4937
|
(Protected) In-order traversal search by predicate.
|
|
4991
4938
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5021,7 +4968,7 @@ The first node satisfying predicate, or undefined if none found.
|
|
|
5021
4968
|
protected _clearNodes(): void;
|
|
5022
4969
|
```
|
|
5023
4970
|
|
|
5024
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4971
|
+
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)
|
|
5025
4972
|
|
|
5026
4973
|
(Protected) Clears all nodes from the tree.
|
|
5027
4974
|
|
|
@@ -5045,7 +4992,7 @@ Time O(1)
|
|
|
5045
4992
|
protected _clearValues(): void;
|
|
5046
4993
|
```
|
|
5047
4994
|
|
|
5048
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4995
|
+
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)
|
|
5049
4996
|
|
|
5050
4997
|
(Protected) Clears all values from the external store.
|
|
5051
4998
|
|
|
@@ -5069,7 +5016,7 @@ Time O(N)
|
|
|
5069
5016
|
protected _clone(cloned): void;
|
|
5070
5017
|
```
|
|
5071
5018
|
|
|
5072
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5019
|
+
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)
|
|
5073
5020
|
|
|
5074
5021
|
(Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
5075
5022
|
|
|
@@ -5101,7 +5048,7 @@ Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
|
5101
5048
|
protected _compare(a, b): number;
|
|
5102
5049
|
```
|
|
5103
5050
|
|
|
5104
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5051
|
+
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)
|
|
5105
5052
|
|
|
5106
5053
|
(Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
5107
5054
|
|
|
@@ -5137,7 +5084,7 @@ Time O(1) Space O(1)
|
|
|
5137
5084
|
protected _createDefaultComparator(): Comparator<K>;
|
|
5138
5085
|
```
|
|
5139
5086
|
|
|
5140
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5087
|
+
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)
|
|
5141
5088
|
|
|
5142
5089
|
(Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
5143
5090
|
|
|
@@ -5159,7 +5106,7 @@ Time O(1) Space O(1)
|
|
|
5159
5106
|
protected _createInstance<TK, TV, TR>(options?): this;
|
|
5160
5107
|
```
|
|
5161
5108
|
|
|
5162
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5109
|
+
Defined in: [data-structures/binary-tree/bst.ts:2313](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2313)
|
|
5163
5110
|
|
|
5164
5111
|
(Protected) Creates a new, empty instance of the same BST constructor.
|
|
5165
5112
|
|
|
@@ -5207,7 +5154,7 @@ Time O(1)
|
|
|
5207
5154
|
protected _createLike<TK, TV, TR>(iter?, options?): BST<TK, TV, TR>;
|
|
5208
5155
|
```
|
|
5209
5156
|
|
|
5210
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5157
|
+
Defined in: [data-structures/binary-tree/bst.ts:2330](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2330)
|
|
5211
5158
|
|
|
5212
5159
|
(Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
|
|
5213
5160
|
|
|
@@ -5267,7 +5214,7 @@ Time O(N log N) or O(N^2) (from constructor) due to processing the iterable.
|
|
|
5267
5214
|
protected _deleteByKey(key): boolean;
|
|
5268
5215
|
```
|
|
5269
5216
|
|
|
5270
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5217
|
+
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)
|
|
5271
5218
|
|
|
5272
5219
|
(Private) Deletes a node by its key.
|
|
5273
5220
|
|
|
@@ -5297,7 +5244,7 @@ Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
|
|
|
5297
5244
|
protected _deleteInternal(keyNodeEntryRawOrPredicate): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
5298
5245
|
```
|
|
5299
5246
|
|
|
5300
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5247
|
+
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)
|
|
5301
5248
|
|
|
5302
5249
|
**`Internal`**
|
|
5303
5250
|
|
|
@@ -5345,7 +5292,7 @@ protected _dfs<C>(
|
|
|
5345
5292
|
shouldProcessRoot?): ReturnType<C>[];
|
|
5346
5293
|
```
|
|
5347
5294
|
|
|
5348
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5295
|
+
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)
|
|
5349
5296
|
|
|
5350
5297
|
#### Type Parameters
|
|
5351
5298
|
|
|
@@ -5438,7 +5385,7 @@ Array of callback results.
|
|
|
5438
5385
|
protected _displayAux(node, options): NodeDisplayLayout;
|
|
5439
5386
|
```
|
|
5440
5387
|
|
|
5441
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5388
|
+
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)
|
|
5442
5389
|
|
|
5443
5390
|
(Protected) Recursive helper for `toVisual`.
|
|
5444
5391
|
|
|
@@ -5478,7 +5425,7 @@ Time O(N), Space O(N*H) or O(N^2)
|
|
|
5478
5425
|
protected _ensurePredicate(keyNodeEntryOrPredicate): NodePredicate<BinaryTreeNode<K, V>>;
|
|
5479
5426
|
```
|
|
5480
5427
|
|
|
5481
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5428
|
+
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)
|
|
5482
5429
|
|
|
5483
5430
|
(Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
5484
5431
|
|
|
@@ -5517,7 +5464,7 @@ Time O(1)
|
|
|
5517
5464
|
protected _extractKey(keyNodeOrEntry): K | null | undefined;
|
|
5518
5465
|
```
|
|
5519
5466
|
|
|
5520
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5467
|
+
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)
|
|
5521
5468
|
|
|
5522
5469
|
(Protected) Extracts the key from a key, node, or entry.
|
|
5523
5470
|
|
|
@@ -5555,7 +5502,7 @@ Time O(1)
|
|
|
5555
5502
|
protected _floorByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5556
5503
|
```
|
|
5557
5504
|
|
|
5558
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5505
|
+
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)
|
|
5559
5506
|
|
|
5560
5507
|
(Protected) Binary search for floor by key with pruning optimization.
|
|
5561
5508
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5593,7 +5540,7 @@ Time O(h) where h is tree height.
|
|
|
5593
5540
|
protected _floorByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5594
5541
|
```
|
|
5595
5542
|
|
|
5596
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5543
|
+
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)
|
|
5597
5544
|
|
|
5598
5545
|
(Protected) In-order traversal search for floor by predicate.
|
|
5599
5546
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5632,7 +5579,7 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5632
5579
|
protected _getByRankIterative(node, k): BSTNode<K, V> | undefined;
|
|
5633
5580
|
```
|
|
5634
5581
|
|
|
5635
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5582
|
+
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)
|
|
5636
5583
|
|
|
5637
5584
|
(Protected) Finds the node at position k in tree order (iterative).
|
|
5638
5585
|
|
|
@@ -5662,7 +5609,7 @@ Time O(log n), Space O(1)
|
|
|
5662
5609
|
protected _getByRankRecursive(node, k): BSTNode<K, V> | undefined;
|
|
5663
5610
|
```
|
|
5664
5611
|
|
|
5665
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5612
|
+
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)
|
|
5666
5613
|
|
|
5667
5614
|
(Protected) Finds the node at position k in tree order (recursive).
|
|
5668
5615
|
|
|
@@ -5692,7 +5639,7 @@ Time O(log n), Space O(log n) call stack
|
|
|
5692
5639
|
protected _getIterator(node?): IterableIterator<[K, V | undefined]>;
|
|
5693
5640
|
```
|
|
5694
5641
|
|
|
5695
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5642
|
+
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)
|
|
5696
5643
|
|
|
5697
5644
|
(Protected) Gets the iterator for the tree (default in-order).
|
|
5698
5645
|
|
|
@@ -5726,7 +5673,7 @@ Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the
|
|
|
5726
5673
|
protected _getRankIterative(node, key): number;
|
|
5727
5674
|
```
|
|
5728
5675
|
|
|
5729
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5676
|
+
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)
|
|
5730
5677
|
|
|
5731
5678
|
(Protected) Computes the rank of a key iteratively.
|
|
5732
5679
|
|
|
@@ -5756,7 +5703,7 @@ Time O(log n), Space O(1)
|
|
|
5756
5703
|
protected _getRankRecursive(node, key): number;
|
|
5757
5704
|
```
|
|
5758
5705
|
|
|
5759
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5706
|
+
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)
|
|
5760
5707
|
|
|
5761
5708
|
(Protected) Computes the rank of a key recursively.
|
|
5762
5709
|
|
|
@@ -5786,7 +5733,7 @@ Time O(log n), Space O(log n) call stack
|
|
|
5786
5733
|
protected _isDisplayLeaf(node, options): boolean;
|
|
5787
5734
|
```
|
|
5788
5735
|
|
|
5789
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5736
|
+
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)
|
|
5790
5737
|
|
|
5791
5738
|
Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
5792
5739
|
|
|
@@ -5816,7 +5763,7 @@ Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
|
5816
5763
|
protected _isPredicate(p): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
5817
5764
|
```
|
|
5818
5765
|
|
|
5819
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5766
|
+
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)
|
|
5820
5767
|
|
|
5821
5768
|
(Protected) Checks if an item is a predicate function.
|
|
5822
5769
|
|
|
@@ -5850,7 +5797,7 @@ Time O(1)
|
|
|
5850
5797
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value?): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
5851
5798
|
```
|
|
5852
5799
|
|
|
5853
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5800
|
+
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)
|
|
5854
5801
|
|
|
5855
5802
|
(Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
5856
5803
|
|
|
@@ -5894,7 +5841,7 @@ Time O(1)
|
|
|
5894
5841
|
protected _lowerByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5895
5842
|
```
|
|
5896
5843
|
|
|
5897
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5844
|
+
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)
|
|
5898
5845
|
|
|
5899
5846
|
(Protected) Binary search for lower by key with pruning optimization.
|
|
5900
5847
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5932,7 +5879,7 @@ Time O(h) where h is tree height.
|
|
|
5932
5879
|
protected _lowerByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5933
5880
|
```
|
|
5934
5881
|
|
|
5935
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5882
|
+
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)
|
|
5936
5883
|
|
|
5937
5884
|
(Protected) In-order traversal search for lower by predicate.
|
|
5938
5885
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5971,7 +5918,7 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5971
5918
|
protected _next(node): BSTNode<K, V> | undefined;
|
|
5972
5919
|
```
|
|
5973
5920
|
|
|
5974
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5921
|
+
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)
|
|
5975
5922
|
|
|
5976
5923
|
(Protected) Finds the in-order successor of a node.
|
|
5977
5924
|
|
|
@@ -5997,7 +5944,7 @@ Time O(log n), Space O(1)
|
|
|
5997
5944
|
protected _replaceNode(oldNode, newNode): BinaryTreeNode<K, V>;
|
|
5998
5945
|
```
|
|
5999
5946
|
|
|
6000
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5947
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2569](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2569)
|
|
6001
5948
|
|
|
6002
5949
|
(Protected) Replaces a node in the tree with a new node, maintaining children and parent links.
|
|
6003
5950
|
|
|
@@ -6040,7 +5987,7 @@ protected _resolveDisplayLeaf(
|
|
|
6040
5987
|
emptyDisplayLayout): NodeDisplayLayout;
|
|
6041
5988
|
```
|
|
6042
5989
|
|
|
6043
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5990
|
+
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)
|
|
6044
5991
|
|
|
6045
5992
|
Resolve a display leaf node to its layout.
|
|
6046
5993
|
|
|
@@ -6074,7 +6021,7 @@ Resolve a display leaf node to its layout.
|
|
|
6074
6021
|
protected _setRoot(v): void;
|
|
6075
6022
|
```
|
|
6076
6023
|
|
|
6077
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6024
|
+
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)
|
|
6078
6025
|
|
|
6079
6026
|
(Protected) Sets the root node and clears its parent reference.
|
|
6080
6027
|
|
|
@@ -6106,7 +6053,7 @@ Time O(1)
|
|
|
6106
6053
|
protected _setValue(key, value): boolean;
|
|
6107
6054
|
```
|
|
6108
6055
|
|
|
6109
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6056
|
+
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)
|
|
6110
6057
|
|
|
6111
6058
|
(Protected) Sets a value in the external store (Map mode).
|
|
6112
6059
|
|
|
@@ -6146,7 +6093,7 @@ Time O(1) (average for Map.set).
|
|
|
6146
6093
|
protected _snapshotOptions<TK, TV, TR>(): BSTOptions<TK, TV, TR>;
|
|
6147
6094
|
```
|
|
6148
6095
|
|
|
6149
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6096
|
+
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)
|
|
6150
6097
|
|
|
6151
6098
|
(Protected) Snapshots the current BST's configuration options.
|
|
6152
6099
|
|
|
@@ -6186,7 +6133,7 @@ Time O(1)
|
|
|
6186
6133
|
protected _swapProperties(srcNode, destNode): BinaryTreeNode<K, V> | undefined;
|
|
6187
6134
|
```
|
|
6188
6135
|
|
|
6189
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6136
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2535](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2535)
|
|
6190
6137
|
|
|
6191
6138
|
(Protected) Swaps the key/value properties of two nodes.
|
|
6192
6139
|
|
|
@@ -6234,7 +6181,7 @@ Time O(1)
|
|
|
6234
6181
|
protected _updateCount(node): void;
|
|
6235
6182
|
```
|
|
6236
6183
|
|
|
6237
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6184
|
+
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)
|
|
6238
6185
|
|
|
6239
6186
|
(Protected) Recalculates the subtree count for a single node.
|
|
6240
6187
|
|
|
@@ -6260,7 +6207,7 @@ Time O(1). Only active when enableOrderStatistic is true.
|
|
|
6260
6207
|
protected _updateCountAlongPath(node): void;
|
|
6261
6208
|
```
|
|
6262
6209
|
|
|
6263
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6210
|
+
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)
|
|
6264
6211
|
|
|
6265
6212
|
(Protected) Updates subtree counts from a node up to the root.
|
|
6266
6213
|
|