data-structure-typed 2.5.1 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/MIGRATION.md +169 -0
- package/README.md +135 -23
- package/README_CN.md +551 -143
- package/SPECIFICATION.md +20 -14
- package/SPECIFICATION.zh-CN.md +20 -14
- package/dist/cjs/binary-tree.cjs +6460 -1591
- package/dist/cjs/graph.cjs +440 -20
- package/dist/cjs/hash.cjs +125 -22
- package/dist/cjs/heap.cjs +196 -47
- package/dist/cjs/index.cjs +8486 -2429
- package/dist/cjs/linked-list.cjs +456 -31
- package/dist/cjs/matrix.cjs +79 -9
- package/dist/cjs/priority-queue.cjs +193 -44
- package/dist/cjs/queue.cjs +391 -2
- package/dist/cjs/stack.cjs +92 -6
- package/dist/cjs/trie.cjs +122 -28
- package/dist/cjs-legacy/binary-tree.cjs +6484 -1612
- package/dist/cjs-legacy/graph.cjs +440 -20
- package/dist/cjs-legacy/hash.cjs +125 -22
- package/dist/cjs-legacy/heap.cjs +196 -47
- package/dist/cjs-legacy/index.cjs +8654 -2594
- package/dist/cjs-legacy/linked-list.cjs +456 -31
- package/dist/cjs-legacy/matrix.cjs +79 -9
- package/dist/cjs-legacy/priority-queue.cjs +193 -44
- package/dist/cjs-legacy/queue.cjs +391 -2
- package/dist/cjs-legacy/stack.cjs +92 -6
- package/dist/cjs-legacy/trie.cjs +122 -28
- package/dist/esm/binary-tree.mjs +6460 -1591
- package/dist/esm/graph.mjs +440 -20
- package/dist/esm/hash.mjs +125 -22
- package/dist/esm/heap.mjs +196 -47
- package/dist/esm/index.mjs +8486 -2430
- package/dist/esm/linked-list.mjs +456 -31
- package/dist/esm/matrix.mjs +79 -9
- package/dist/esm/priority-queue.mjs +193 -44
- package/dist/esm/queue.mjs +391 -2
- package/dist/esm/stack.mjs +92 -6
- package/dist/esm/trie.mjs +122 -28
- package/dist/esm-legacy/binary-tree.mjs +6484 -1612
- package/dist/esm-legacy/graph.mjs +440 -20
- package/dist/esm-legacy/hash.mjs +125 -22
- package/dist/esm-legacy/heap.mjs +196 -47
- package/dist/esm-legacy/index.mjs +8654 -2595
- package/dist/esm-legacy/linked-list.mjs +456 -31
- package/dist/esm-legacy/matrix.mjs +79 -9
- package/dist/esm-legacy/priority-queue.mjs +193 -44
- package/dist/esm-legacy/queue.mjs +391 -2
- package/dist/esm-legacy/stack.mjs +92 -6
- package/dist/esm-legacy/trie.mjs +122 -28
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +98 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +112 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +214 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +294 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +155 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +48 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1370 -323
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1329 -316
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +1116 -295
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1330 -326
- package/dist/types/data-structures/graph/directed-graph.d.ts +80 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +72 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +95 -6
- package/dist/types/data-structures/heap/heap.d.ts +154 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +143 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +144 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +64 -0
- package/dist/types/data-structures/queue/deque.d.ts +142 -0
- package/dist/types/data-structures/queue/queue.d.ts +109 -0
- package/dist/types/data-structures/stack/stack.d.ts +82 -2
- package/dist/types/data-structures/trie/trie.d.ts +96 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/data-structure-typed.js +8623 -2564
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +696 -194
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +71 -71
- package/docs-site-docusaurus/docs/api/classes/BST.md +639 -189
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +148 -160
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +105 -91
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +104 -74
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +51 -51
- package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +33 -33
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +50 -50
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +78 -78
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
- package/docs-site-docusaurus/docs/api/classes/Queue.md +112 -60
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +708 -206
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +79 -79
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +44 -44
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +236 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +162 -46
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +232 -32
- package/docs-site-docusaurus/docs/api/classes/Trie.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +81 -81
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -5
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -3
- package/docs-site-docusaurus/docs/guide/faq.md +233 -0
- package/docs-site-docusaurus/docs/guide/guides.md +43 -58
- package/docs-site-docusaurus/docs/guide/installation.md +2 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +75 -176
- package/docs-site-docusaurus/docs/guide/overview.md +132 -11
- package/docs-site-docusaurus/docs/guide/performance.md +2 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +31 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
- package/docs-site-docusaurus/docusaurus.config.ts +1 -1
- package/docs-site-docusaurus/src/pages/index.tsx +55 -2
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/llms.txt +37 -0
- package/package.json +65 -56
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: RedBlackTree\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:254](https://github.com/zrwusa/data-structure-typed/blob/
|
|
9
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:254](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L254)
|
|
10
10
|
|
|
11
11
|
Represents a Red-Black Tree (self-balancing BST) supporting map-like mode and stable O(log n) updates.
|
|
12
12
|
|
|
@@ -132,7 +132,7 @@ Operation complexity depends on the method; see each method's docs.
|
|
|
132
132
|
get comparator(): Comparator<K>;
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
135
|
+
Defined in: [data-structures/binary-tree/bst.ts:384](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L384)
|
|
136
136
|
|
|
137
137
|
Gets the comparator function used by the tree.
|
|
138
138
|
|
|
@@ -160,7 +160,7 @@ The comparator function.
|
|
|
160
160
|
get isDuplicate(): boolean;
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:322](https://github.com/zrwusa/data-structure-typed/blob/
|
|
163
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:322](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L322)
|
|
164
164
|
|
|
165
165
|
Gets whether the tree allows duplicate keys.
|
|
166
166
|
|
|
@@ -194,7 +194,7 @@ IBinaryTree.isDuplicate
|
|
|
194
194
|
get isMapMode(): boolean;
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:310](https://github.com/zrwusa/data-structure-typed/blob/
|
|
197
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:310](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L310)
|
|
198
198
|
|
|
199
199
|
Gets whether the tree is in Map mode.
|
|
200
200
|
|
|
@@ -228,7 +228,7 @@ IBinaryTree.isMapMode
|
|
|
228
228
|
get NIL(): BinaryTreeNode<K, V>;
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:373](https://github.com/zrwusa/data-structure-typed/blob/
|
|
231
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:373](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L373)
|
|
232
232
|
|
|
233
233
|
Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
234
234
|
|
|
@@ -262,7 +262,7 @@ IBinaryTree.NIL
|
|
|
262
262
|
get root(): RedBlackTreeNode<K, V> | undefined;
|
|
263
263
|
```
|
|
264
264
|
|
|
265
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:305](https://github.com/zrwusa/data-structure-typed/blob/
|
|
265
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:305](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L305)
|
|
266
266
|
|
|
267
267
|
Get the current root node.
|
|
268
268
|
|
|
@@ -296,7 +296,7 @@ IBinaryTree.root
|
|
|
296
296
|
get size(): number;
|
|
297
297
|
```
|
|
298
298
|
|
|
299
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:361](https://github.com/zrwusa/data-structure-typed/blob/
|
|
299
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:361](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L361)
|
|
300
300
|
|
|
301
301
|
Gets the number of nodes in the tree.
|
|
302
302
|
|
|
@@ -330,7 +330,7 @@ IBinaryTree.size
|
|
|
330
330
|
get store(): Map<K, BinaryTreeNode<K, V>>;
|
|
331
331
|
```
|
|
332
332
|
|
|
333
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:337](https://github.com/zrwusa/data-structure-typed/blob/
|
|
333
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:337](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L337)
|
|
334
334
|
|
|
335
335
|
Gets the external value store (used in Map mode).
|
|
336
336
|
|
|
@@ -364,7 +364,7 @@ IBinaryTree.store
|
|
|
364
364
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
365
365
|
```
|
|
366
366
|
|
|
367
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:385](https://github.com/zrwusa/data-structure-typed/blob/
|
|
367
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:385](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L385)
|
|
368
368
|
|
|
369
369
|
Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
370
370
|
|
|
@@ -396,7 +396,7 @@ IBinaryTree.toEntryFn
|
|
|
396
396
|
iterator: IterableIterator<[K, V | undefined]>;
|
|
397
397
|
```
|
|
398
398
|
|
|
399
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/
|
|
399
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L22)
|
|
400
400
|
|
|
401
401
|
Default iterator yielding `[key, value]` entries.
|
|
402
402
|
|
|
@@ -404,7 +404,7 @@ Default iterator yielding `[key, value]` entries.
|
|
|
404
404
|
|
|
405
405
|
##### args
|
|
406
406
|
|
|
407
|
-
...`
|
|
407
|
+
...`unknown`[]
|
|
408
408
|
|
|
409
409
|
#### Returns
|
|
410
410
|
|
|
@@ -434,7 +434,7 @@ IBinaryTree.[iterator]
|
|
|
434
434
|
add(keyNodeOrEntry): boolean;
|
|
435
435
|
```
|
|
436
436
|
|
|
437
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
437
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:612](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L612)
|
|
438
438
|
|
|
439
439
|
Adds a new node to the tree.
|
|
440
440
|
|
|
@@ -460,7 +460,7 @@ True if the addition was successful, false otherwise.
|
|
|
460
460
|
|
|
461
461
|
#### Remarks
|
|
462
462
|
|
|
463
|
-
Time O(
|
|
463
|
+
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).
|
|
464
464
|
|
|
465
465
|
#### Example
|
|
466
466
|
|
|
@@ -492,7 +492,7 @@ IBinaryTree.add
|
|
|
492
492
|
addMany(keysNodesEntriesOrRaws): boolean[];
|
|
493
493
|
```
|
|
494
494
|
|
|
495
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
495
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:793](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L793)
|
|
496
496
|
|
|
497
497
|
Adds multiple items to the tree.
|
|
498
498
|
|
|
@@ -573,7 +573,7 @@ The traversal method.
|
|
|
573
573
|
bfs(): (K | undefined)[];
|
|
574
574
|
```
|
|
575
575
|
|
|
576
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
576
|
+
Defined in: [data-structures/binary-tree/bst.ts:635](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L635)
|
|
577
577
|
|
|
578
578
|
BinaryTree level-order traversal
|
|
579
579
|
|
|
@@ -611,7 +611,7 @@ bfs<C>(
|
|
|
611
611
|
iterationType?): ReturnType<C>[];
|
|
612
612
|
```
|
|
613
613
|
|
|
614
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
614
|
+
Defined in: [data-structures/binary-tree/bst.ts:636](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L636)
|
|
615
615
|
|
|
616
616
|
BinaryTree level-order traversal
|
|
617
617
|
|
|
@@ -673,7 +673,7 @@ IBinaryTree.bfs
|
|
|
673
673
|
ceiling(keyNodeEntryOrPredicate): K | undefined;
|
|
674
674
|
```
|
|
675
675
|
|
|
676
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
676
|
+
Defined in: [data-structures/binary-tree/bst.ts:1849](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1849)
|
|
677
677
|
|
|
678
678
|
Returns the first key with a value >= target.
|
|
679
679
|
Equivalent to Java TreeMap.ceiling.
|
|
@@ -720,7 +720,7 @@ ceiling<C>(
|
|
|
720
720
|
iterationType?): ReturnType<C>;
|
|
721
721
|
```
|
|
722
722
|
|
|
723
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
723
|
+
Defined in: [data-structures/binary-tree/bst.ts:1864](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1864)
|
|
724
724
|
|
|
725
725
|
Returns the first node with a key >= target and applies callback.
|
|
726
726
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -767,9 +767,9 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
767
767
|
clear(): void;
|
|
768
768
|
```
|
|
769
769
|
|
|
770
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
770
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:490](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L490)
|
|
771
771
|
|
|
772
|
-
Remove all nodes and
|
|
772
|
+
Remove all nodes, clear the key→value store (if in map mode) and internal caches.
|
|
773
773
|
|
|
774
774
|
#### Returns
|
|
775
775
|
|
|
@@ -777,7 +777,7 @@ Remove all nodes and clear internal caches.
|
|
|
777
777
|
|
|
778
778
|
#### Remarks
|
|
779
779
|
|
|
780
|
-
Time O(n)
|
|
780
|
+
Time O(n), Space O(1)
|
|
781
781
|
|
|
782
782
|
*
|
|
783
783
|
|
|
@@ -808,7 +808,7 @@ IBinaryTree.clear
|
|
|
808
808
|
clone(): this;
|
|
809
809
|
```
|
|
810
810
|
|
|
811
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
811
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2771](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2771)
|
|
812
812
|
|
|
813
813
|
Clones the tree.
|
|
814
814
|
|
|
@@ -855,7 +855,7 @@ createNode(
|
|
|
855
855
|
color?): RedBlackTreeNode<K, V>;
|
|
856
856
|
```
|
|
857
857
|
|
|
858
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:317](https://github.com/zrwusa/data-structure-typed/blob/
|
|
858
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:317](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L317)
|
|
859
859
|
|
|
860
860
|
Create a red-black node for the given key/value (value ignored in map mode).
|
|
861
861
|
|
|
@@ -907,7 +907,7 @@ IBinaryTree.createNode
|
|
|
907
907
|
createTree(options?): this;
|
|
908
908
|
```
|
|
909
909
|
|
|
910
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:408](https://github.com/zrwusa/data-structure-typed/blob/
|
|
910
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:408](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L408)
|
|
911
911
|
|
|
912
912
|
Creates a new, empty tree of the same type and configuration.
|
|
913
913
|
|
|
@@ -944,10 +944,10 @@ IBinaryTree.createTree
|
|
|
944
944
|
### delete()
|
|
945
945
|
|
|
946
946
|
```ts
|
|
947
|
-
delete(keyNodeEntryRawOrPredicate):
|
|
947
|
+
delete(keyNodeEntryRawOrPredicate): boolean;
|
|
948
948
|
```
|
|
949
949
|
|
|
950
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
950
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1267](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1267)
|
|
951
951
|
|
|
952
952
|
Delete a node by key/node/entry and rebalance as needed.
|
|
953
953
|
|
|
@@ -962,7 +962,7 @@ Key, node, or [key, value] entry identifying the node to delete.
|
|
|
962
962
|
|
|
963
963
|
#### Returns
|
|
964
964
|
|
|
965
|
-
`
|
|
965
|
+
`boolean`
|
|
966
966
|
|
|
967
967
|
Array with deletion metadata (removed node, rebalancing hint if any).
|
|
968
968
|
|
|
@@ -1001,10 +1001,10 @@ deleteWhere(
|
|
|
1001
1001
|
keyNodeEntryOrPredicate,
|
|
1002
1002
|
onlyOne?,
|
|
1003
1003
|
startNode?,
|
|
1004
|
-
iterationType?):
|
|
1004
|
+
iterationType?): boolean;
|
|
1005
1005
|
```
|
|
1006
1006
|
|
|
1007
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1007
|
+
Defined in: [data-structures/binary-tree/bst.ts:2692](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2692)
|
|
1008
1008
|
|
|
1009
1009
|
Deletes nodes that match a key, node, entry, predicate, or range.
|
|
1010
1010
|
|
|
@@ -1059,7 +1059,7 @@ Controls the internal traversal implementation:
|
|
|
1059
1059
|
|
|
1060
1060
|
#### Returns
|
|
1061
1061
|
|
|
1062
|
-
`
|
|
1062
|
+
`boolean`
|
|
1063
1063
|
|
|
1064
1064
|
A Map<K, boolean> containing the deletion results:
|
|
1065
1065
|
- Key: the matched node's key.
|
|
@@ -1115,7 +1115,7 @@ The traversal method.
|
|
|
1115
1115
|
dfs(): (K | undefined)[];
|
|
1116
1116
|
```
|
|
1117
1117
|
|
|
1118
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1118
|
+
Defined in: [data-structures/binary-tree/bst.ts:525](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L525)
|
|
1119
1119
|
|
|
1120
1120
|
Depth-first search traversal
|
|
1121
1121
|
|
|
@@ -1155,7 +1155,7 @@ dfs<C>(
|
|
|
1155
1155
|
iterationType?): ReturnType<C>[];
|
|
1156
1156
|
```
|
|
1157
1157
|
|
|
1158
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1158
|
+
Defined in: [data-structures/binary-tree/bst.ts:527](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L527)
|
|
1159
1159
|
|
|
1160
1160
|
Depth-first search traversal
|
|
1161
1161
|
|
|
@@ -1223,7 +1223,7 @@ IBinaryTree.dfs
|
|
|
1223
1223
|
ensureNode(keyNodeOrEntry, iterationType?): OptNode<BSTNode<K, V>>;
|
|
1224
1224
|
```
|
|
1225
1225
|
|
|
1226
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1226
|
+
Defined in: [data-structures/binary-tree/bst.ts:408](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L408)
|
|
1227
1227
|
|
|
1228
1228
|
Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
1229
1229
|
|
|
@@ -1267,7 +1267,7 @@ Time O(log N) (height of the tree), O(N) worst-case.
|
|
|
1267
1267
|
entries(): IterableIterator<[K, V | undefined]>;
|
|
1268
1268
|
```
|
|
1269
1269
|
|
|
1270
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1270
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L31)
|
|
1271
1271
|
|
|
1272
1272
|
Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
1273
1273
|
|
|
@@ -1299,7 +1299,7 @@ IBinaryTree.entries
|
|
|
1299
1299
|
every(predicate, thisArg?): boolean;
|
|
1300
1300
|
```
|
|
1301
1301
|
|
|
1302
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1302
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L66)
|
|
1303
1303
|
|
|
1304
1304
|
Test whether all entries satisfy the predicate.
|
|
1305
1305
|
|
|
@@ -1313,7 +1313,7 @@ Test whether all entries satisfy the predicate.
|
|
|
1313
1313
|
|
|
1314
1314
|
##### thisArg?
|
|
1315
1315
|
|
|
1316
|
-
`
|
|
1316
|
+
`unknown`
|
|
1317
1317
|
|
|
1318
1318
|
Optional `this` for callback.
|
|
1319
1319
|
|
|
@@ -1345,7 +1345,7 @@ IBinaryTree.every
|
|
|
1345
1345
|
filter(predicate, thisArg?): this;
|
|
1346
1346
|
```
|
|
1347
1347
|
|
|
1348
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1348
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2827](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2827)
|
|
1349
1349
|
|
|
1350
1350
|
Creates a new tree containing only the entries that satisfy the predicate.
|
|
1351
1351
|
|
|
@@ -1402,7 +1402,7 @@ IBinaryTree.filter
|
|
|
1402
1402
|
find(callbackfn, thisArg?): [K, V | undefined] | undefined;
|
|
1403
1403
|
```
|
|
1404
1404
|
|
|
1405
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1405
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L114)
|
|
1406
1406
|
|
|
1407
1407
|
Find the first entry that matches a predicate.
|
|
1408
1408
|
|
|
@@ -1416,7 +1416,7 @@ Find the first entry that matches a predicate.
|
|
|
1416
1416
|
|
|
1417
1417
|
##### thisArg?
|
|
1418
1418
|
|
|
1419
|
-
`
|
|
1419
|
+
`unknown`
|
|
1420
1420
|
|
|
1421
1421
|
Optional `this` for callback.
|
|
1422
1422
|
|
|
@@ -1450,7 +1450,7 @@ IBinaryTree.find
|
|
|
1450
1450
|
floor(keyNodeEntryOrPredicate): K | undefined;
|
|
1451
1451
|
```
|
|
1452
1452
|
|
|
1453
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1453
|
+
Defined in: [data-structures/binary-tree/bst.ts:2068](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2068)
|
|
1454
1454
|
|
|
1455
1455
|
Returns the first key with a value <= target.
|
|
1456
1456
|
Equivalent to Java TreeMap.floor.
|
|
@@ -1497,7 +1497,7 @@ floor<C>(
|
|
|
1497
1497
|
iterationType?): ReturnType<C>;
|
|
1498
1498
|
```
|
|
1499
1499
|
|
|
1500
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1500
|
+
Defined in: [data-structures/binary-tree/bst.ts:2083](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2083)
|
|
1501
1501
|
|
|
1502
1502
|
Returns the first node with a key <= target and applies callback.
|
|
1503
1503
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -1544,7 +1544,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
1544
1544
|
forEach(callbackfn, thisArg?): void;
|
|
1545
1545
|
```
|
|
1546
1546
|
|
|
1547
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1547
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L99)
|
|
1548
1548
|
|
|
1549
1549
|
Visit each entry, left-to-right.
|
|
1550
1550
|
|
|
@@ -1558,7 +1558,7 @@ Visit each entry, left-to-right.
|
|
|
1558
1558
|
|
|
1559
1559
|
##### thisArg?
|
|
1560
1560
|
|
|
1561
|
-
`
|
|
1561
|
+
`unknown`
|
|
1562
1562
|
|
|
1563
1563
|
Optional `this` for callback.
|
|
1564
1564
|
|
|
@@ -1591,7 +1591,7 @@ get(
|
|
|
1591
1591
|
iterationType?): V | undefined;
|
|
1592
1592
|
```
|
|
1593
1593
|
|
|
1594
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1594
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1375](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1375)
|
|
1595
1595
|
|
|
1596
1596
|
Gets the value associated with a key.
|
|
1597
1597
|
|
|
@@ -1632,7 +1632,7 @@ The associated value, or undefined.
|
|
|
1632
1632
|
|
|
1633
1633
|
#### Remarks
|
|
1634
1634
|
|
|
1635
|
-
Time O(
|
|
1635
|
+
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).
|
|
1636
1636
|
|
|
1637
1637
|
#### Example
|
|
1638
1638
|
|
|
@@ -1655,13 +1655,114 @@ IBinaryTree.get
|
|
|
1655
1655
|
|
|
1656
1656
|
***
|
|
1657
1657
|
|
|
1658
|
+
### getByRank()
|
|
1659
|
+
|
|
1660
|
+
#### Call Signature
|
|
1661
|
+
|
|
1662
|
+
```ts
|
|
1663
|
+
getByRank(k): K | undefined;
|
|
1664
|
+
```
|
|
1665
|
+
|
|
1666
|
+
Defined in: [data-structures/binary-tree/bst.ts:1240](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1240)
|
|
1667
|
+
|
|
1668
|
+
Returns the element at the k-th position in tree order (0-indexed).
|
|
1669
|
+
|
|
1670
|
+
##### Parameters
|
|
1671
|
+
|
|
1672
|
+
###### k
|
|
1673
|
+
|
|
1674
|
+
`number`
|
|
1675
|
+
|
|
1676
|
+
The 0-based position in tree order (0 = first element).
|
|
1677
|
+
|
|
1678
|
+
##### Returns
|
|
1679
|
+
|
|
1680
|
+
`K` \| `undefined`
|
|
1681
|
+
|
|
1682
|
+
The key at position k, or `undefined` if out of bounds.
|
|
1683
|
+
*
|
|
1684
|
+
|
|
1685
|
+
##### Remarks
|
|
1686
|
+
|
|
1687
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
1688
|
+
Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
1689
|
+
|
|
1690
|
+
##### Example
|
|
1691
|
+
|
|
1692
|
+
```ts
|
|
1693
|
+
// Order-statistic on BST
|
|
1694
|
+
const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
1695
|
+
console.log(tree.getByRank(0)); // 10;
|
|
1696
|
+
console.log(tree.getByRank(4)); // 50;
|
|
1697
|
+
console.log(tree.getRank(30)); // 2;
|
|
1698
|
+
```
|
|
1699
|
+
|
|
1700
|
+
##### Inherited from
|
|
1701
|
+
|
|
1702
|
+
[`BST`](BST.md).[`getByRank`](BST.md#getbyrank)
|
|
1703
|
+
|
|
1704
|
+
#### Call Signature
|
|
1705
|
+
|
|
1706
|
+
```ts
|
|
1707
|
+
getByRank<C>(
|
|
1708
|
+
k,
|
|
1709
|
+
callback,
|
|
1710
|
+
iterationType?): ReturnType<C> | undefined;
|
|
1711
|
+
```
|
|
1712
|
+
|
|
1713
|
+
Defined in: [data-structures/binary-tree/bst.ts:1251](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1251)
|
|
1714
|
+
|
|
1715
|
+
Returns the element at the k-th position in tree order and applies a callback.
|
|
1716
|
+
|
|
1717
|
+
##### Type Parameters
|
|
1718
|
+
|
|
1719
|
+
###### C
|
|
1720
|
+
|
|
1721
|
+
`C` *extends* `NodeCallback`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
1722
|
+
|
|
1723
|
+
##### Parameters
|
|
1724
|
+
|
|
1725
|
+
###### k
|
|
1726
|
+
|
|
1727
|
+
`number`
|
|
1728
|
+
|
|
1729
|
+
The 0-based position in tree order (0 = first element).
|
|
1730
|
+
|
|
1731
|
+
###### callback
|
|
1732
|
+
|
|
1733
|
+
`C`
|
|
1734
|
+
|
|
1735
|
+
Callback to apply to the found node.
|
|
1736
|
+
|
|
1737
|
+
###### iterationType?
|
|
1738
|
+
|
|
1739
|
+
`IterationType`
|
|
1740
|
+
|
|
1741
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
1742
|
+
|
|
1743
|
+
##### Returns
|
|
1744
|
+
|
|
1745
|
+
`ReturnType`\<`C`\> \| `undefined`
|
|
1746
|
+
|
|
1747
|
+
The callback result, or `undefined` if out of bounds.
|
|
1748
|
+
|
|
1749
|
+
##### Remarks
|
|
1750
|
+
|
|
1751
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
1752
|
+
|
|
1753
|
+
##### Inherited from
|
|
1754
|
+
|
|
1755
|
+
[`BST`](BST.md).[`getByRank`](BST.md#getbyrank)
|
|
1756
|
+
|
|
1757
|
+
***
|
|
1758
|
+
|
|
1658
1759
|
### getDepth()
|
|
1659
1760
|
|
|
1660
1761
|
```ts
|
|
1661
1762
|
getDepth(dist, startNode?): number;
|
|
1662
1763
|
```
|
|
1663
1764
|
|
|
1664
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1765
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1756](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1756)
|
|
1665
1766
|
|
|
1666
1767
|
Gets the depth of a node (distance from `startNode`).
|
|
1667
1768
|
|
|
@@ -1725,7 +1826,7 @@ IBinaryTree.getDepth
|
|
|
1725
1826
|
getHeight(startNode?, iterationType?): number;
|
|
1726
1827
|
```
|
|
1727
1828
|
|
|
1728
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1829
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1824](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1824)
|
|
1729
1830
|
|
|
1730
1831
|
Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
1731
1832
|
|
|
@@ -1808,7 +1909,7 @@ The traversal method.
|
|
|
1808
1909
|
getLeftMost(): K | undefined;
|
|
1809
1910
|
```
|
|
1810
1911
|
|
|
1811
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1912
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1951](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1951)
|
|
1812
1913
|
|
|
1813
1914
|
##### Returns
|
|
1814
1915
|
|
|
@@ -1833,7 +1934,7 @@ getLeftMost<C>(
|
|
|
1833
1934
|
iterationType?): ReturnType<C>;
|
|
1834
1935
|
```
|
|
1835
1936
|
|
|
1836
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1937
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1953](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1953)
|
|
1837
1938
|
|
|
1838
1939
|
##### Type Parameters
|
|
1839
1940
|
|
|
@@ -1880,7 +1981,7 @@ IBinaryTree.getLeftMost
|
|
|
1880
1981
|
getMinHeight(startNode?, iterationType?): number;
|
|
1881
1982
|
```
|
|
1882
1983
|
|
|
1883
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1984
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1866](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1866)
|
|
1884
1985
|
|
|
1885
1986
|
Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
1886
1987
|
|
|
@@ -1932,7 +2033,7 @@ getNode(
|
|
|
1932
2033
|
iterationType?): OptNode<BSTNode<K, V>>;
|
|
1933
2034
|
```
|
|
1934
2035
|
|
|
1935
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2036
|
+
Defined in: [data-structures/binary-tree/bst.ts:860](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L860)
|
|
1936
2037
|
|
|
1937
2038
|
Gets the first node matching a predicate.
|
|
1938
2039
|
|
|
@@ -2005,7 +2106,7 @@ getNodes(
|
|
|
2005
2106
|
iterationType?): BinaryTreeNode<K, V>[];
|
|
2006
2107
|
```
|
|
2007
2108
|
|
|
2008
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2109
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1223](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1223)
|
|
2009
2110
|
|
|
2010
2111
|
Gets all nodes matching a predicate.
|
|
2011
2112
|
|
|
@@ -2100,7 +2201,7 @@ If true, returns the path from root-to-node.
|
|
|
2100
2201
|
getPathToRoot(beginNode): (K | undefined)[];
|
|
2101
2202
|
```
|
|
2102
2203
|
|
|
2103
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2204
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1913](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1913)
|
|
2104
2205
|
|
|
2105
2206
|
##### Parameters
|
|
2106
2207
|
|
|
@@ -2135,7 +2236,7 @@ getPathToRoot<C>(
|
|
|
2135
2236
|
isReverse?): ReturnType<C>[];
|
|
2136
2237
|
```
|
|
2137
2238
|
|
|
2138
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2239
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1917](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1917)
|
|
2139
2240
|
|
|
2140
2241
|
##### Type Parameters
|
|
2141
2242
|
|
|
@@ -2183,7 +2284,7 @@ IBinaryTree.getPathToRoot
|
|
|
2183
2284
|
getPredecessor(node): BinaryTreeNode<K, V>;
|
|
2184
2285
|
```
|
|
2185
2286
|
|
|
2186
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2287
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2051](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2051)
|
|
2187
2288
|
|
|
2188
2289
|
Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
2189
2290
|
|
|
@@ -2211,6 +2312,91 @@ This is primarily a helper for Morris traversal. Time O(H), where H is the heigh
|
|
|
2211
2312
|
|
|
2212
2313
|
***
|
|
2213
2314
|
|
|
2315
|
+
### getRank()
|
|
2316
|
+
|
|
2317
|
+
#### Call Signature
|
|
2318
|
+
|
|
2319
|
+
```ts
|
|
2320
|
+
getRank(keyNodeEntryOrPredicate): number;
|
|
2321
|
+
```
|
|
2322
|
+
|
|
2323
|
+
Defined in: [data-structures/binary-tree/bst.ts:1295](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1295)
|
|
2324
|
+
|
|
2325
|
+
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
2326
|
+
|
|
2327
|
+
##### Parameters
|
|
2328
|
+
|
|
2329
|
+
###### keyNodeEntryOrPredicate
|
|
2330
|
+
|
|
2331
|
+
\| `K`
|
|
2332
|
+
\| [`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
2333
|
+
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
2334
|
+
\| `NodePredicate`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
2335
|
+
\| `null`
|
|
2336
|
+
\| `undefined`
|
|
2337
|
+
|
|
2338
|
+
The key, node, entry `[K, V]`, or predicate to find.
|
|
2339
|
+
|
|
2340
|
+
##### Returns
|
|
2341
|
+
|
|
2342
|
+
`number`
|
|
2343
|
+
|
|
2344
|
+
The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
2345
|
+
|
|
2346
|
+
##### Remarks
|
|
2347
|
+
|
|
2348
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
2349
|
+
Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
2350
|
+
|
|
2351
|
+
##### Inherited from
|
|
2352
|
+
|
|
2353
|
+
[`BST`](BST.md).[`getRank`](BST.md#getrank)
|
|
2354
|
+
|
|
2355
|
+
#### Call Signature
|
|
2356
|
+
|
|
2357
|
+
```ts
|
|
2358
|
+
getRank(keyNodeEntryOrPredicate, iterationType): number;
|
|
2359
|
+
```
|
|
2360
|
+
|
|
2361
|
+
Defined in: [data-structures/binary-tree/bst.ts:1313](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1313)
|
|
2362
|
+
|
|
2363
|
+
Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
2364
|
+
|
|
2365
|
+
##### Parameters
|
|
2366
|
+
|
|
2367
|
+
###### keyNodeEntryOrPredicate
|
|
2368
|
+
|
|
2369
|
+
\| `K`
|
|
2370
|
+
\| [`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
2371
|
+
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
2372
|
+
\| `NodePredicate`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
2373
|
+
\| `null`
|
|
2374
|
+
\| `undefined`
|
|
2375
|
+
|
|
2376
|
+
The key, node, entry, or predicate to find.
|
|
2377
|
+
|
|
2378
|
+
###### iterationType
|
|
2379
|
+
|
|
2380
|
+
`IterationType`
|
|
2381
|
+
|
|
2382
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
2383
|
+
|
|
2384
|
+
##### Returns
|
|
2385
|
+
|
|
2386
|
+
`number`
|
|
2387
|
+
|
|
2388
|
+
The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
2389
|
+
|
|
2390
|
+
##### Remarks
|
|
2391
|
+
|
|
2392
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
2393
|
+
|
|
2394
|
+
##### Inherited from
|
|
2395
|
+
|
|
2396
|
+
[`BST`](BST.md).[`getRank`](BST.md#getrank)
|
|
2397
|
+
|
|
2398
|
+
***
|
|
2399
|
+
|
|
2214
2400
|
### getRightMost()
|
|
2215
2401
|
|
|
2216
2402
|
Finds the rightmost node in a subtree (the node with the largest key in a BST).
|
|
@@ -2241,7 +2427,7 @@ The traversal method.
|
|
|
2241
2427
|
getRightMost(): K | undefined;
|
|
2242
2428
|
```
|
|
2243
2429
|
|
|
2244
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2430
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1998](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1998)
|
|
2245
2431
|
|
|
2246
2432
|
##### Returns
|
|
2247
2433
|
|
|
@@ -2266,7 +2452,7 @@ getRightMost<C>(
|
|
|
2266
2452
|
iterationType?): ReturnType<C>;
|
|
2267
2453
|
```
|
|
2268
2454
|
|
|
2269
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2455
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2000](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2000)
|
|
2270
2456
|
|
|
2271
2457
|
##### Type Parameters
|
|
2272
2458
|
|
|
@@ -2313,7 +2499,7 @@ IBinaryTree.getRightMost
|
|
|
2313
2499
|
getSuccessor(x?): BinaryTreeNode<K, V> | null | undefined;
|
|
2314
2500
|
```
|
|
2315
2501
|
|
|
2316
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2502
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2072](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2072)
|
|
2317
2503
|
|
|
2318
2504
|
Gets the in-order successor of a node in a BST.
|
|
2319
2505
|
|
|
@@ -2350,7 +2536,7 @@ has(
|
|
|
2350
2536
|
iterationType?): boolean;
|
|
2351
2537
|
```
|
|
2352
2538
|
|
|
2353
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2539
|
+
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)
|
|
2354
2540
|
|
|
2355
2541
|
Checks if a node matching the predicate exists in the tree.
|
|
2356
2542
|
|
|
@@ -2391,7 +2577,7 @@ True if a matching node exists, false otherwise.
|
|
|
2391
2577
|
|
|
2392
2578
|
#### Remarks
|
|
2393
2579
|
|
|
2394
|
-
Time O(
|
|
2580
|
+
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.
|
|
2395
2581
|
|
|
2396
2582
|
#### Example
|
|
2397
2583
|
|
|
@@ -2443,7 +2629,7 @@ IBinaryTree.has
|
|
|
2443
2629
|
hasValue(value): boolean;
|
|
2444
2630
|
```
|
|
2445
2631
|
|
|
2446
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2632
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L143)
|
|
2447
2633
|
|
|
2448
2634
|
Whether there exists an entry with the given value.
|
|
2449
2635
|
|
|
@@ -2485,7 +2671,7 @@ IBinaryTree.hasValue
|
|
|
2485
2671
|
higher(keyNodeEntryOrPredicate): K | undefined;
|
|
2486
2672
|
```
|
|
2487
2673
|
|
|
2488
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2674
|
+
Defined in: [data-structures/binary-tree/bst.ts:1958](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1958)
|
|
2489
2675
|
|
|
2490
2676
|
Returns the first key with a value > target.
|
|
2491
2677
|
Equivalent to Java TreeMap.higher.
|
|
@@ -2531,7 +2717,7 @@ higher<C>(
|
|
|
2531
2717
|
iterationType?): ReturnType<C>;
|
|
2532
2718
|
```
|
|
2533
2719
|
|
|
2534
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2720
|
+
Defined in: [data-structures/binary-tree/bst.ts:1973](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1973)
|
|
2535
2721
|
|
|
2536
2722
|
Returns the first node with a key > target and applies callback.
|
|
2537
2723
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -2578,7 +2764,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
2578
2764
|
isAVLBalanced(iterationType?): boolean;
|
|
2579
2765
|
```
|
|
2580
2766
|
|
|
2581
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2767
|
+
Defined in: [data-structures/binary-tree/bst.ts:2505](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2505)
|
|
2582
2768
|
|
|
2583
2769
|
Checks if the tree meets the AVL balance condition (height difference <= 1).
|
|
2584
2770
|
|
|
@@ -2622,7 +2808,7 @@ Time O(N), as it must visit every node to compute height. Space O(log N) for rec
|
|
|
2622
2808
|
isBST(startNode?, iterationType?): boolean;
|
|
2623
2809
|
```
|
|
2624
2810
|
|
|
2625
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2811
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1661](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1661)
|
|
2626
2812
|
|
|
2627
2813
|
Checks if the tree is a valid Binary Search Tree (BST).
|
|
2628
2814
|
|
|
@@ -2682,7 +2868,7 @@ IBinaryTree.isBST
|
|
|
2682
2868
|
isEmpty(): boolean;
|
|
2683
2869
|
```
|
|
2684
2870
|
|
|
2685
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2871
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1594](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1594)
|
|
2686
2872
|
|
|
2687
2873
|
Checks if the tree is empty.
|
|
2688
2874
|
|
|
@@ -2723,7 +2909,7 @@ IBinaryTree.isEmpty
|
|
|
2723
2909
|
isEntry(keyNodeOrEntry): keyNodeOrEntry is BTNEntry<K, V>;
|
|
2724
2910
|
```
|
|
2725
2911
|
|
|
2726
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:545](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2912
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:545](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L545)
|
|
2727
2913
|
|
|
2728
2914
|
Checks if the given item is a [key, value] entry pair.
|
|
2729
2915
|
|
|
@@ -2761,7 +2947,7 @@ Time O(1), Space O(1)
|
|
|
2761
2947
|
isLeaf(keyNodeOrEntry): boolean;
|
|
2762
2948
|
```
|
|
2763
2949
|
|
|
2764
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:531](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2950
|
+
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)
|
|
2765
2951
|
|
|
2766
2952
|
Checks if a node is a leaf (has no real children).
|
|
2767
2953
|
|
|
@@ -2799,7 +2985,7 @@ Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is pass
|
|
|
2799
2985
|
isNIL(keyNodeOrEntry): boolean;
|
|
2800
2986
|
```
|
|
2801
2987
|
|
|
2802
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:500](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2988
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:500](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L500)
|
|
2803
2989
|
|
|
2804
2990
|
Checks if the given item is the sentinel NIL node.
|
|
2805
2991
|
|
|
@@ -2837,7 +3023,7 @@ Time O(1), Space O(1)
|
|
|
2837
3023
|
isNode(keyNodeOrEntry): keyNodeOrEntry is RedBlackTreeNode<K, V>;
|
|
2838
3024
|
```
|
|
2839
3025
|
|
|
2840
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:328](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3026
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:328](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L328)
|
|
2841
3027
|
|
|
2842
3028
|
Type guard: check whether the input is a RedBlackTreeNode.
|
|
2843
3029
|
|
|
@@ -2875,7 +3061,7 @@ Time O(1), Space O(1)
|
|
|
2875
3061
|
isPerfectlyBalanced(startNode?): boolean;
|
|
2876
3062
|
```
|
|
2877
3063
|
|
|
2878
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3064
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1605](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1605)
|
|
2879
3065
|
|
|
2880
3066
|
Checks if the tree is perfectly balanced.
|
|
2881
3067
|
|
|
@@ -2918,7 +3104,7 @@ IBinaryTree.isPerfectlyBalanced
|
|
|
2918
3104
|
isRange(keyNodeEntryOrPredicate): keyNodeEntryOrPredicate is Range<K>;
|
|
2919
3105
|
```
|
|
2920
3106
|
|
|
2921
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:511](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3107
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:511](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L511)
|
|
2922
3108
|
|
|
2923
3109
|
Checks if the given item is a `Range` object.
|
|
2924
3110
|
|
|
@@ -2958,7 +3144,7 @@ Time O(1), Space O(1)
|
|
|
2958
3144
|
isRaw(keyNodeEntryOrRaw): keyNodeEntryOrRaw is R;
|
|
2959
3145
|
```
|
|
2960
3146
|
|
|
2961
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:460](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3147
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:460](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L460)
|
|
2962
3148
|
|
|
2963
3149
|
Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
2964
3150
|
|
|
@@ -2997,7 +3183,7 @@ Time O(1), Space O(1)
|
|
|
2997
3183
|
isRealNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
2998
3184
|
```
|
|
2999
3185
|
|
|
3000
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:473](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3186
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:473](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L473)
|
|
3001
3187
|
|
|
3002
3188
|
Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
3003
3189
|
|
|
@@ -3035,7 +3221,7 @@ Time O(1), Space O(1)
|
|
|
3035
3221
|
isRealNodeOrNull(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
3036
3222
|
```
|
|
3037
3223
|
|
|
3038
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:487](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3224
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:487](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L487)
|
|
3039
3225
|
|
|
3040
3226
|
Checks if the given item is either a "real" node or null.
|
|
3041
3227
|
|
|
@@ -3073,7 +3259,7 @@ Time O(1), Space O(1)
|
|
|
3073
3259
|
isValidKey(key): key is K;
|
|
3074
3260
|
```
|
|
3075
3261
|
|
|
3076
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3262
|
+
Defined in: [data-structures/binary-tree/bst.ts:435](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L435)
|
|
3077
3263
|
|
|
3078
3264
|
Checks if the given key is valid (comparable).
|
|
3079
3265
|
|
|
@@ -3081,7 +3267,7 @@ Checks if the given key is valid (comparable).
|
|
|
3081
3267
|
|
|
3082
3268
|
##### key
|
|
3083
3269
|
|
|
3084
|
-
`
|
|
3270
|
+
`unknown`
|
|
3085
3271
|
|
|
3086
3272
|
The key to validate.
|
|
3087
3273
|
|
|
@@ -3107,7 +3293,7 @@ Time O(1)
|
|
|
3107
3293
|
keys(): IterableIterator<K>;
|
|
3108
3294
|
```
|
|
3109
3295
|
|
|
3110
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3296
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L42)
|
|
3111
3297
|
|
|
3112
3298
|
Iterate over keys only.
|
|
3113
3299
|
|
|
@@ -3163,7 +3349,7 @@ The traversal method.
|
|
|
3163
3349
|
leaves(): (K | undefined)[];
|
|
3164
3350
|
```
|
|
3165
3351
|
|
|
3166
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3352
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2378](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2378)
|
|
3167
3353
|
|
|
3168
3354
|
Get leaf nodes
|
|
3169
3355
|
|
|
@@ -3201,7 +3387,7 @@ leaves<C>(
|
|
|
3201
3387
|
iterationType?): ReturnType<C>[];
|
|
3202
3388
|
```
|
|
3203
3389
|
|
|
3204
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3390
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2380](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2380)
|
|
3205
3391
|
|
|
3206
3392
|
Get leaf nodes
|
|
3207
3393
|
|
|
@@ -3289,7 +3475,7 @@ The traversal method.
|
|
|
3289
3475
|
lesserOrGreaterTraverse(): (K | undefined)[];
|
|
3290
3476
|
```
|
|
3291
3477
|
|
|
3292
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3478
|
+
Defined in: [data-structures/binary-tree/bst.ts:2323](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2323)
|
|
3293
3479
|
|
|
3294
3480
|
##### Returns
|
|
3295
3481
|
|
|
@@ -3309,7 +3495,7 @@ lesserOrGreaterTraverse<C>(
|
|
|
3309
3495
|
iterationType?): ReturnType<C>[];
|
|
3310
3496
|
```
|
|
3311
3497
|
|
|
3312
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3498
|
+
Defined in: [data-structures/binary-tree/bst.ts:2325](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2325)
|
|
3313
3499
|
|
|
3314
3500
|
##### Type Parameters
|
|
3315
3501
|
|
|
@@ -3378,7 +3564,7 @@ The traversal method.
|
|
|
3378
3564
|
listLevels(): (K | undefined)[][];
|
|
3379
3565
|
```
|
|
3380
3566
|
|
|
3381
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3567
|
+
Defined in: [data-structures/binary-tree/bst.ts:744](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L744)
|
|
3382
3568
|
|
|
3383
3569
|
Level-order grouping
|
|
3384
3570
|
|
|
@@ -3394,7 +3580,7 @@ Level-order grouping
|
|
|
3394
3580
|
// Level-order grouping
|
|
3395
3581
|
const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
3396
3582
|
const levels = bst.listLevels(node => node.key);
|
|
3397
|
-
console.log(levels
|
|
3583
|
+
console.log(levels); // toBeInstanceOf;
|
|
3398
3584
|
console.log(levels[0].length); // 1; // root level has 1 node
|
|
3399
3585
|
const allKeys = levels.flat().sort((a, b) => a - b);
|
|
3400
3586
|
console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -3419,7 +3605,7 @@ listLevels<C>(
|
|
|
3419
3605
|
iterationType?): ReturnType<C>[][];
|
|
3420
3606
|
```
|
|
3421
3607
|
|
|
3422
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3608
|
+
Defined in: [data-structures/binary-tree/bst.ts:746](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L746)
|
|
3423
3609
|
|
|
3424
3610
|
Level-order grouping
|
|
3425
3611
|
|
|
@@ -3458,7 +3644,7 @@ Level-order grouping
|
|
|
3458
3644
|
// Level-order grouping
|
|
3459
3645
|
const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
3460
3646
|
const levels = bst.listLevels(node => node.key);
|
|
3461
|
-
console.log(levels
|
|
3647
|
+
console.log(levels); // toBeInstanceOf;
|
|
3462
3648
|
console.log(levels[0].length); // 1; // root level has 1 node
|
|
3463
3649
|
const allKeys = levels.flat().sort((a, b) => a - b);
|
|
3464
3650
|
console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -3484,7 +3670,7 @@ IBinaryTree.listLevels
|
|
|
3484
3670
|
lower(keyNodeEntryOrPredicate): K | undefined;
|
|
3485
3671
|
```
|
|
3486
3672
|
|
|
3487
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3673
|
+
Defined in: [data-structures/binary-tree/bst.ts:2220](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2220)
|
|
3488
3674
|
|
|
3489
3675
|
Returns the first key with a value < target.
|
|
3490
3676
|
Equivalent to Java TreeMap.lower.
|
|
@@ -3530,7 +3716,7 @@ lower<C>(
|
|
|
3530
3716
|
iterationType?): ReturnType<C>;
|
|
3531
3717
|
```
|
|
3532
3718
|
|
|
3533
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3719
|
+
Defined in: [data-structures/binary-tree/bst.ts:2235](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2235)
|
|
3534
3720
|
|
|
3535
3721
|
Returns the first node with a key < target and applies callback.
|
|
3536
3722
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -3580,7 +3766,7 @@ map<MK, MV, MR>(
|
|
|
3580
3766
|
thisArg?): RedBlackTree<MK, MV, MR>;
|
|
3581
3767
|
```
|
|
3582
3768
|
|
|
3583
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
3769
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1652](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1652)
|
|
3584
3770
|
|
|
3585
3771
|
Transform to new tree
|
|
3586
3772
|
|
|
@@ -3645,7 +3831,7 @@ IBinaryTree.map
|
|
|
3645
3831
|
merge(anotherTree): void;
|
|
3646
3832
|
```
|
|
3647
3833
|
|
|
3648
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3834
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:922](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L922)
|
|
3649
3835
|
|
|
3650
3836
|
Merges another tree into this one by seting all its nodes.
|
|
3651
3837
|
|
|
@@ -3719,7 +3905,7 @@ The node to start from.
|
|
|
3719
3905
|
morris(): (K | undefined)[];
|
|
3720
3906
|
```
|
|
3721
3907
|
|
|
3722
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3908
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2604](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2604)
|
|
3723
3909
|
|
|
3724
3910
|
Morris traversal (O(1) space)
|
|
3725
3911
|
|
|
@@ -3757,7 +3943,7 @@ morris<C>(
|
|
|
3757
3943
|
startNode?): ReturnType<C>[];
|
|
3758
3944
|
```
|
|
3759
3945
|
|
|
3760
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3946
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2606](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2606)
|
|
3761
3947
|
|
|
3762
3948
|
Morris traversal (O(1) space)
|
|
3763
3949
|
|
|
@@ -3817,7 +4003,7 @@ IBinaryTree.morris
|
|
|
3817
4003
|
perfectlyBalance(_iterationType?): boolean;
|
|
3818
4004
|
```
|
|
3819
4005
|
|
|
3820
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
4006
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1483](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1483)
|
|
3821
4007
|
|
|
3822
4008
|
Red-Black trees are self-balancing — `perfectlyBalance` rebuilds via
|
|
3823
4009
|
sorted bulk insert, which naturally produces a balanced RBT.
|
|
@@ -3859,7 +4045,7 @@ Time O(N), Space O(N)
|
|
|
3859
4045
|
print(options?, startNode?): void;
|
|
3860
4046
|
```
|
|
3861
4047
|
|
|
3862
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4048
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2981](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2981)
|
|
3863
4049
|
|
|
3864
4050
|
Prints a visual representation of the tree to the console.
|
|
3865
4051
|
|
|
@@ -3904,6 +4090,108 @@ Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
|
3904
4090
|
|
|
3905
4091
|
***
|
|
3906
4092
|
|
|
4093
|
+
### rangeByRank()
|
|
4094
|
+
|
|
4095
|
+
#### Call Signature
|
|
4096
|
+
|
|
4097
|
+
```ts
|
|
4098
|
+
rangeByRank(start, end): (K | undefined)[];
|
|
4099
|
+
```
|
|
4100
|
+
|
|
4101
|
+
Defined in: [data-structures/binary-tree/bst.ts:1375](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1375)
|
|
4102
|
+
|
|
4103
|
+
Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
4104
|
+
|
|
4105
|
+
##### Parameters
|
|
4106
|
+
|
|
4107
|
+
###### start
|
|
4108
|
+
|
|
4109
|
+
`number`
|
|
4110
|
+
|
|
4111
|
+
Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
4112
|
+
|
|
4113
|
+
###### end
|
|
4114
|
+
|
|
4115
|
+
`number`
|
|
4116
|
+
|
|
4117
|
+
End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
4118
|
+
|
|
4119
|
+
##### Returns
|
|
4120
|
+
|
|
4121
|
+
(`K` \| `undefined`)[]
|
|
4122
|
+
|
|
4123
|
+
Array of keys in tree order within the specified range.
|
|
4124
|
+
|
|
4125
|
+
##### Remarks
|
|
4126
|
+
|
|
4127
|
+
Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
4128
|
+
|
|
4129
|
+
##### Inherited from
|
|
4130
|
+
|
|
4131
|
+
[`BST`](BST.md).[`rangeByRank`](BST.md#rangebyrank)
|
|
4132
|
+
|
|
4133
|
+
#### Call Signature
|
|
4134
|
+
|
|
4135
|
+
```ts
|
|
4136
|
+
rangeByRank<C>(
|
|
4137
|
+
start,
|
|
4138
|
+
end,
|
|
4139
|
+
callback,
|
|
4140
|
+
iterationType?): ReturnType<C>[];
|
|
4141
|
+
```
|
|
4142
|
+
|
|
4143
|
+
Defined in: [data-structures/binary-tree/bst.ts:1387](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1387)
|
|
4144
|
+
|
|
4145
|
+
Returns elements by position range in tree order with callback and optional iteration type.
|
|
4146
|
+
|
|
4147
|
+
##### Type Parameters
|
|
4148
|
+
|
|
4149
|
+
###### C
|
|
4150
|
+
|
|
4151
|
+
`C` *extends* `NodeCallback`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
4152
|
+
|
|
4153
|
+
##### Parameters
|
|
4154
|
+
|
|
4155
|
+
###### start
|
|
4156
|
+
|
|
4157
|
+
`number`
|
|
4158
|
+
|
|
4159
|
+
Start rank (inclusive, 0-indexed).
|
|
4160
|
+
|
|
4161
|
+
###### end
|
|
4162
|
+
|
|
4163
|
+
`number`
|
|
4164
|
+
|
|
4165
|
+
End rank (inclusive, 0-indexed).
|
|
4166
|
+
|
|
4167
|
+
###### callback
|
|
4168
|
+
|
|
4169
|
+
`C`
|
|
4170
|
+
|
|
4171
|
+
Callback to apply to each node in the range.
|
|
4172
|
+
|
|
4173
|
+
###### iterationType?
|
|
4174
|
+
|
|
4175
|
+
`IterationType`
|
|
4176
|
+
|
|
4177
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
4178
|
+
|
|
4179
|
+
##### Returns
|
|
4180
|
+
|
|
4181
|
+
`ReturnType`\<`C`\>[]
|
|
4182
|
+
|
|
4183
|
+
Array of callback results for nodes in the rank range.
|
|
4184
|
+
|
|
4185
|
+
##### Remarks
|
|
4186
|
+
|
|
4187
|
+
Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
4188
|
+
|
|
4189
|
+
##### Inherited from
|
|
4190
|
+
|
|
4191
|
+
[`BST`](BST.md).[`rangeByRank`](BST.md#rangebyrank)
|
|
4192
|
+
|
|
4193
|
+
***
|
|
4194
|
+
|
|
3907
4195
|
### rangeSearch()
|
|
3908
4196
|
|
|
3909
4197
|
Performs an optimized search for nodes within a given key range.
|
|
@@ -3938,7 +4226,7 @@ The traversal method.
|
|
|
3938
4226
|
rangeSearch(range): (K | undefined)[];
|
|
3939
4227
|
```
|
|
3940
4228
|
|
|
3941
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4229
|
+
Defined in: [data-structures/binary-tree/bst.ts:1194](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1194)
|
|
3942
4230
|
|
|
3943
4231
|
Find all keys in a range
|
|
3944
4232
|
|
|
@@ -3976,7 +4264,7 @@ rangeSearch<C>(
|
|
|
3976
4264
|
iterationType?): ReturnType<C>[];
|
|
3977
4265
|
```
|
|
3978
4266
|
|
|
3979
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4267
|
+
Defined in: [data-structures/binary-tree/bst.ts:1196](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1196)
|
|
3980
4268
|
|
|
3981
4269
|
Find all keys in a range
|
|
3982
4270
|
|
|
@@ -4033,7 +4321,7 @@ Find all keys in a range
|
|
|
4033
4321
|
reduce<U>(callbackfn, initialValue): U;
|
|
4034
4322
|
```
|
|
4035
4323
|
|
|
4036
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4324
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L171)
|
|
4037
4325
|
|
|
4038
4326
|
Reduce entries into a single accumulator.
|
|
4039
4327
|
|
|
@@ -4079,56 +4367,6 @@ IBinaryTree.reduce
|
|
|
4079
4367
|
|
|
4080
4368
|
***
|
|
4081
4369
|
|
|
4082
|
-
### refill()
|
|
4083
|
-
|
|
4084
|
-
```ts
|
|
4085
|
-
refill(keysNodesEntriesOrRaws, values?): void;
|
|
4086
|
-
```
|
|
4087
|
-
|
|
4088
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:878](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/binary-tree.ts#L878)
|
|
4089
|
-
|
|
4090
|
-
Clears the tree and refills it with new items.
|
|
4091
|
-
|
|
4092
|
-
#### Parameters
|
|
4093
|
-
|
|
4094
|
-
##### keysNodesEntriesOrRaws
|
|
4095
|
-
|
|
4096
|
-
`Iterable`\<
|
|
4097
|
-
\| `K`
|
|
4098
|
-
\| `R`
|
|
4099
|
-
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
4100
|
-
\| [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>
|
|
4101
|
-
\| `null`
|
|
4102
|
-
\| `undefined`\>
|
|
4103
|
-
|
|
4104
|
-
An iterable of items to set.
|
|
4105
|
-
|
|
4106
|
-
##### values?
|
|
4107
|
-
|
|
4108
|
-
`Iterable`\<`V` \| `undefined`, `any`, `any`\>
|
|
4109
|
-
|
|
4110
|
-
An optional parallel iterable of values.
|
|
4111
|
-
|
|
4112
|
-
#### Returns
|
|
4113
|
-
|
|
4114
|
-
`void`
|
|
4115
|
-
|
|
4116
|
-
#### Remarks
|
|
4117
|
-
|
|
4118
|
-
Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
4119
|
-
|
|
4120
|
-
#### Implementation of
|
|
4121
|
-
|
|
4122
|
-
```ts
|
|
4123
|
-
IBinaryTree.refill
|
|
4124
|
-
```
|
|
4125
|
-
|
|
4126
|
-
#### Inherited from
|
|
4127
|
-
|
|
4128
|
-
[`BST`](BST.md).[`refill`](BST.md#refill)
|
|
4129
|
-
|
|
4130
|
-
***
|
|
4131
|
-
|
|
4132
4370
|
### search()
|
|
4133
4371
|
|
|
4134
4372
|
Searches the tree for nodes matching a predicate, key, or range.
|
|
@@ -4169,7 +4407,7 @@ Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
|
4169
4407
|
search(keyNodeEntryOrPredicate, onlyOne?): (K | undefined)[];
|
|
4170
4408
|
```
|
|
4171
4409
|
|
|
4172
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4410
|
+
Defined in: [data-structures/binary-tree/bst.ts:996](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L996)
|
|
4173
4411
|
|
|
4174
4412
|
Search nodes by predicate
|
|
4175
4413
|
|
|
@@ -4225,7 +4463,7 @@ search<C>(
|
|
|
4225
4463
|
iterationType?): ReturnType<C>[];
|
|
4226
4464
|
```
|
|
4227
4465
|
|
|
4228
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4466
|
+
Defined in: [data-structures/binary-tree/bst.ts:1008](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1008)
|
|
4229
4467
|
|
|
4230
4468
|
Search nodes by predicate
|
|
4231
4469
|
|
|
@@ -4299,7 +4537,7 @@ IBinaryTree.search
|
|
|
4299
4537
|
set(keyNodeOrEntry, value?): boolean;
|
|
4300
4538
|
```
|
|
4301
4539
|
|
|
4302
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
4540
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1050](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1050)
|
|
4303
4541
|
|
|
4304
4542
|
Insert or update a key/value (map mode) or key-only (set mode).
|
|
4305
4543
|
|
|
@@ -4374,7 +4612,7 @@ setMany(
|
|
|
4374
4612
|
iterationType?): boolean[];
|
|
4375
4613
|
```
|
|
4376
4614
|
|
|
4377
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4615
|
+
Defined in: [data-structures/binary-tree/bst.ts:1706](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1706)
|
|
4378
4616
|
|
|
4379
4617
|
Adds multiple items to the tree.
|
|
4380
4618
|
|
|
@@ -4443,7 +4681,7 @@ setWithHint(
|
|
|
4443
4681
|
hint?): boolean;
|
|
4444
4682
|
```
|
|
4445
4683
|
|
|
4446
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
4684
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:872](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L872)
|
|
4447
4685
|
|
|
4448
4686
|
Boolean wrapper for setWithHintNode.
|
|
4449
4687
|
|
|
@@ -4480,7 +4718,7 @@ setWithHintNode(
|
|
|
4480
4718
|
hint?): RedBlackTreeNode<K, V> | undefined;
|
|
4481
4719
|
```
|
|
4482
4720
|
|
|
4483
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
4721
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:772](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L772)
|
|
4484
4722
|
|
|
4485
4723
|
Insert/update using a hint node to speed up nearby insertions.
|
|
4486
4724
|
|
|
@@ -4521,7 +4759,7 @@ Time O(log n) average, Space O(1)
|
|
|
4521
4759
|
some(predicate, thisArg?): boolean;
|
|
4522
4760
|
```
|
|
4523
4761
|
|
|
4524
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4762
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L83)
|
|
4525
4763
|
|
|
4526
4764
|
Test whether any entry satisfies the predicate.
|
|
4527
4765
|
|
|
@@ -4535,7 +4773,7 @@ Test whether any entry satisfies the predicate.
|
|
|
4535
4773
|
|
|
4536
4774
|
##### thisArg?
|
|
4537
4775
|
|
|
4538
|
-
`
|
|
4776
|
+
`unknown`
|
|
4539
4777
|
|
|
4540
4778
|
Optional `this` for callback.
|
|
4541
4779
|
|
|
@@ -4567,7 +4805,7 @@ IBinaryTree.some
|
|
|
4567
4805
|
toArray(): [K, V | undefined][];
|
|
4568
4806
|
```
|
|
4569
4807
|
|
|
4570
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4808
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L186)
|
|
4571
4809
|
|
|
4572
4810
|
Converts data structure to `[key, value]` pairs.
|
|
4573
4811
|
|
|
@@ -4593,7 +4831,7 @@ Time O(n), Space O(n)
|
|
|
4593
4831
|
toVisual(startNode?, options?): string;
|
|
4594
4832
|
```
|
|
4595
4833
|
|
|
4596
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4834
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2907](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2907)
|
|
4597
4835
|
|
|
4598
4836
|
Generates a string representation of the tree for visualization.
|
|
4599
4837
|
|
|
@@ -4636,7 +4874,7 @@ Time O(N), visits every node. Space O(N*H) or O(N^2) in the worst case, as the s
|
|
|
4636
4874
|
values(): IterableIterator<V | undefined>;
|
|
4637
4875
|
```
|
|
4638
4876
|
|
|
4639
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4877
|
+
Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/base/iterable-entry-base.ts#L53)
|
|
4640
4878
|
|
|
4641
4879
|
Iterate over values only.
|
|
4642
4880
|
|
|
@@ -4671,7 +4909,7 @@ IBinaryTree.values
|
|
|
4671
4909
|
protected readonly _comparator: Comparator<K>;
|
|
4672
4910
|
```
|
|
4673
4911
|
|
|
4674
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4912
|
+
Defined in: [data-structures/binary-tree/bst.ts:376](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L376)
|
|
4675
4913
|
|
|
4676
4914
|
The comparator function used to determine the order of keys in the tree.
|
|
4677
4915
|
|
|
@@ -4691,7 +4929,7 @@ Time O(1) Space O(1)
|
|
|
4691
4929
|
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
4692
4930
|
```
|
|
4693
4931
|
|
|
4694
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4932
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3177](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3177)
|
|
4695
4933
|
|
|
4696
4934
|
(Protected) Default callback function, returns the node's key.
|
|
4697
4935
|
|
|
@@ -4719,7 +4957,7 @@ The node's key or undefined.
|
|
|
4719
4957
|
protected _header: RedBlackTreeNode<K, V>;
|
|
4720
4958
|
```
|
|
4721
4959
|
|
|
4722
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:291](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4960
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:291](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L291)
|
|
4723
4961
|
|
|
4724
4962
|
(Internal) Header sentinel:
|
|
4725
4963
|
- header.parent -> root
|
|
@@ -4739,7 +4977,7 @@ IMPORTANT:
|
|
|
4739
4977
|
protected _minNode: RedBlackTreeNode<K, V> | undefined;
|
|
4740
4978
|
```
|
|
4741
4979
|
|
|
4742
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:297](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4980
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:297](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L297)
|
|
4743
4981
|
|
|
4744
4982
|
(Internal) Cache of the current minimum and maximum nodes.
|
|
4745
4983
|
Used for fast-path insert/update when keys are monotonic or near-boundary.
|
|
@@ -4755,7 +4993,7 @@ protected _attachNewNode(
|
|
|
4755
4993
|
node): void;
|
|
4756
4994
|
```
|
|
4757
4995
|
|
|
4758
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
4996
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:571](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L571)
|
|
4759
4997
|
|
|
4760
4998
|
(Internal) Attach a new node directly under a known parent/side (no search).
|
|
4761
4999
|
|
|
@@ -4800,7 +5038,7 @@ protected _bound(
|
|
|
4800
5038
|
iterationType): BSTNode<K, V> | undefined;
|
|
4801
5039
|
```
|
|
4802
5040
|
|
|
4803
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5041
|
+
Defined in: [data-structures/binary-tree/bst.ts:2993](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2993)
|
|
4804
5042
|
|
|
4805
5043
|
(Protected) Core bound search implementation supporting all parameter types.
|
|
4806
5044
|
Unified logic for both lowerBound and upperBound.
|
|
@@ -4852,7 +5090,7 @@ protected _boundByKey(
|
|
|
4852
5090
|
iterationType): BSTNode<K, V> | undefined;
|
|
4853
5091
|
```
|
|
4854
5092
|
|
|
4855
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5093
|
+
Defined in: [data-structures/binary-tree/bst.ts:3050](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3050)
|
|
4856
5094
|
|
|
4857
5095
|
(Protected) Binary search for bound by key with pruning optimization.
|
|
4858
5096
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -4897,7 +5135,7 @@ The first node matching the bound condition, or undefined if none exists.
|
|
|
4897
5135
|
protected _boundByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
4898
5136
|
```
|
|
4899
5137
|
|
|
4900
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5138
|
+
Defined in: [data-structures/binary-tree/bst.ts:3105](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3105)
|
|
4901
5139
|
|
|
4902
5140
|
(Protected) In-order traversal search by predicate.
|
|
4903
5141
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -4937,7 +5175,7 @@ The first node satisfying predicate, or undefined if none found.
|
|
|
4937
5175
|
protected _clearNodes(): void;
|
|
4938
5176
|
```
|
|
4939
5177
|
|
|
4940
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5178
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3611](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3611)
|
|
4941
5179
|
|
|
4942
5180
|
(Protected) Clears all nodes from the tree.
|
|
4943
5181
|
|
|
@@ -4961,7 +5199,7 @@ Time O(1)
|
|
|
4961
5199
|
protected _clearValues(): void;
|
|
4962
5200
|
```
|
|
4963
5201
|
|
|
4964
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5202
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3620](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3620)
|
|
4965
5203
|
|
|
4966
5204
|
(Protected) Clears all values from the external store.
|
|
4967
5205
|
|
|
@@ -4985,7 +5223,7 @@ Time O(N)
|
|
|
4985
5223
|
protected _clone(cloned): void;
|
|
4986
5224
|
```
|
|
4987
5225
|
|
|
4988
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5226
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3270](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3270)
|
|
4989
5227
|
|
|
4990
5228
|
(Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
4991
5229
|
|
|
@@ -5017,7 +5255,7 @@ Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
|
5017
5255
|
protected _compare(a, b): number;
|
|
5018
5256
|
```
|
|
5019
5257
|
|
|
5020
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5258
|
+
Defined in: [data-structures/binary-tree/bst.ts:3369](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3369)
|
|
5021
5259
|
|
|
5022
5260
|
(Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
5023
5261
|
|
|
@@ -5057,7 +5295,7 @@ Time O(1) Space O(1)
|
|
|
5057
5295
|
protected _createDefaultComparator(): Comparator<K>;
|
|
5058
5296
|
```
|
|
5059
5297
|
|
|
5060
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5298
|
+
Defined in: [data-structures/binary-tree/bst.ts:2720](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2720)
|
|
5061
5299
|
|
|
5062
5300
|
(Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
5063
5301
|
|
|
@@ -5083,7 +5321,7 @@ Time O(1) Space O(1)
|
|
|
5083
5321
|
protected _createInstance<TK, TV, TR>(options?): this;
|
|
5084
5322
|
```
|
|
5085
5323
|
|
|
5086
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
5324
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1670](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1670)
|
|
5087
5325
|
|
|
5088
5326
|
(Internal) Create an empty instance of the same concrete tree type.
|
|
5089
5327
|
|
|
@@ -5127,7 +5365,7 @@ Time O(1) average, Space O(1)
|
|
|
5127
5365
|
protected _createLike<TK, TV, TR>(iter?, options?): RedBlackTree<TK, TV, TR>;
|
|
5128
5366
|
```
|
|
5129
5367
|
|
|
5130
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
5368
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1682](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1682)
|
|
5131
5369
|
|
|
5132
5370
|
(Internal) Create a like-kind tree (same concrete class) populated from an iterable.
|
|
5133
5371
|
|
|
@@ -5181,7 +5419,7 @@ Time O(m log m) average (m = iterable length), Space O(m)
|
|
|
5181
5419
|
protected _deleteByKey(key): boolean;
|
|
5182
5420
|
```
|
|
5183
5421
|
|
|
5184
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5422
|
+
Defined in: [data-structures/binary-tree/bst.ts:3380](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3380)
|
|
5185
5423
|
|
|
5186
5424
|
(Private) Deletes a node by its key.
|
|
5187
5425
|
|
|
@@ -5215,7 +5453,7 @@ Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
|
|
|
5215
5453
|
protected _deleteFixup(node): void;
|
|
5216
5454
|
```
|
|
5217
5455
|
|
|
5218
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
5456
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1867](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1867)
|
|
5219
5457
|
|
|
5220
5458
|
(Protected) Restore red-black properties after deletion (recolor/rotate).
|
|
5221
5459
|
|
|
@@ -5239,6 +5477,44 @@ Time O(log n) average, Space O(1)
|
|
|
5239
5477
|
|
|
5240
5478
|
***
|
|
5241
5479
|
|
|
5480
|
+
### \_deleteInternal()
|
|
5481
|
+
|
|
5482
|
+
```ts
|
|
5483
|
+
protected _deleteInternal(keyNodeEntryRawOrPredicate): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
5484
|
+
```
|
|
5485
|
+
|
|
5486
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:934](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L934)
|
|
5487
|
+
|
|
5488
|
+
**`Internal`**
|
|
5489
|
+
|
|
5490
|
+
Deletes a node from the tree (internal, returns balancing metadata).
|
|
5491
|
+
|
|
5492
|
+
#### Parameters
|
|
5493
|
+
|
|
5494
|
+
##### keyNodeEntryRawOrPredicate
|
|
5495
|
+
|
|
5496
|
+
\| `BTNRep`\<`K`, `V`, [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>
|
|
5497
|
+
\| `NodePredicate`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\> \| `null`\>
|
|
5498
|
+
|
|
5499
|
+
The node to delete.
|
|
5500
|
+
|
|
5501
|
+
#### Returns
|
|
5502
|
+
|
|
5503
|
+
`BinaryTreeDeleteResult`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>[]
|
|
5504
|
+
|
|
5505
|
+
An array containing deletion results with balancing metadata.
|
|
5506
|
+
|
|
5507
|
+
#### Remarks
|
|
5508
|
+
|
|
5509
|
+
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).
|
|
5510
|
+
Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
5511
|
+
|
|
5512
|
+
#### Inherited from
|
|
5513
|
+
|
|
5514
|
+
[`BST`](BST.md).[`_deleteInternal`](BST.md#_deleteinternal)
|
|
5515
|
+
|
|
5516
|
+
***
|
|
5517
|
+
|
|
5242
5518
|
### \_dfs()
|
|
5243
5519
|
|
|
5244
5520
|
```ts
|
|
@@ -5255,7 +5531,7 @@ protected _dfs<C>(
|
|
|
5255
5531
|
shouldProcessRoot?): ReturnType<C>[];
|
|
5256
5532
|
```
|
|
5257
5533
|
|
|
5258
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5534
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2988](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2988)
|
|
5259
5535
|
|
|
5260
5536
|
#### Type Parameters
|
|
5261
5537
|
|
|
@@ -5348,7 +5624,7 @@ Array of callback results.
|
|
|
5348
5624
|
protected _displayAux(node, options): NodeDisplayLayout;
|
|
5349
5625
|
```
|
|
5350
5626
|
|
|
5351
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5627
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3294](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3294)
|
|
5352
5628
|
|
|
5353
5629
|
(Protected) Recursive helper for `toVisual`.
|
|
5354
5630
|
|
|
@@ -5388,7 +5664,7 @@ Time O(N), Space O(N*H) or O(N^2)
|
|
|
5388
5664
|
protected _ensurePredicate(keyNodeEntryOrPredicate): NodePredicate<BinaryTreeNode<K, V>>;
|
|
5389
5665
|
```
|
|
5390
5666
|
|
|
5391
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5667
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3517](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3517)
|
|
5392
5668
|
|
|
5393
5669
|
(Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
5394
5670
|
|
|
@@ -5427,7 +5703,7 @@ Time O(1)
|
|
|
5427
5703
|
protected _extractKey(keyNodeOrEntry): K | null | undefined;
|
|
5428
5704
|
```
|
|
5429
5705
|
|
|
5430
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5706
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3577](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3577)
|
|
5431
5707
|
|
|
5432
5708
|
(Protected) Extracts the key from a key, node, or entry.
|
|
5433
5709
|
|
|
@@ -5465,7 +5741,7 @@ Time O(1)
|
|
|
5465
5741
|
protected _findNodeByKey(key): RedBlackTreeNode<K, V> | undefined;
|
|
5466
5742
|
```
|
|
5467
5743
|
|
|
5468
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
5744
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:505](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L505)
|
|
5469
5745
|
|
|
5470
5746
|
(Internal) Find a node by key using a tight BST walk (no allocations).
|
|
5471
5747
|
|
|
@@ -5493,7 +5769,7 @@ Time O(log n) average, Space O(1)
|
|
|
5493
5769
|
protected _floorByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5494
5770
|
```
|
|
5495
5771
|
|
|
5496
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5772
|
+
Defined in: [data-structures/binary-tree/bst.ts:2758](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2758)
|
|
5497
5773
|
|
|
5498
5774
|
(Protected) Binary search for floor by key with pruning optimization.
|
|
5499
5775
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5535,7 +5811,7 @@ Time O(h) where h is tree height.
|
|
|
5535
5811
|
protected _floorByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5536
5812
|
```
|
|
5537
5813
|
|
|
5538
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5814
|
+
Defined in: [data-structures/binary-tree/bst.ts:2811](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2811)
|
|
5539
5815
|
|
|
5540
5816
|
(Protected) In-order traversal search for floor by predicate.
|
|
5541
5817
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5572,13 +5848,81 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5572
5848
|
|
|
5573
5849
|
***
|
|
5574
5850
|
|
|
5851
|
+
### \_getByRankIterative()
|
|
5852
|
+
|
|
5853
|
+
```ts
|
|
5854
|
+
protected _getByRankIterative(node, k): BSTNode<K, V> | undefined;
|
|
5855
|
+
```
|
|
5856
|
+
|
|
5857
|
+
Defined in: [data-structures/binary-tree/bst.ts:3261](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3261)
|
|
5858
|
+
|
|
5859
|
+
(Protected) Finds the node at position k in tree order (iterative).
|
|
5860
|
+
|
|
5861
|
+
#### Parameters
|
|
5862
|
+
|
|
5863
|
+
##### node
|
|
5864
|
+
|
|
5865
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5866
|
+
|
|
5867
|
+
##### k
|
|
5868
|
+
|
|
5869
|
+
`number`
|
|
5870
|
+
|
|
5871
|
+
#### Returns
|
|
5872
|
+
|
|
5873
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5874
|
+
|
|
5875
|
+
#### Remarks
|
|
5876
|
+
|
|
5877
|
+
Time O(log n), Space O(1)
|
|
5878
|
+
|
|
5879
|
+
#### Inherited from
|
|
5880
|
+
|
|
5881
|
+
[`BST`](BST.md).[`_getByRankIterative`](BST.md#_getbyrankiterative)
|
|
5882
|
+
|
|
5883
|
+
***
|
|
5884
|
+
|
|
5885
|
+
### \_getByRankRecursive()
|
|
5886
|
+
|
|
5887
|
+
```ts
|
|
5888
|
+
protected _getByRankRecursive(node, k): BSTNode<K, V> | undefined;
|
|
5889
|
+
```
|
|
5890
|
+
|
|
5891
|
+
Defined in: [data-structures/binary-tree/bst.ts:3282](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3282)
|
|
5892
|
+
|
|
5893
|
+
(Protected) Finds the node at position k in tree order (recursive).
|
|
5894
|
+
|
|
5895
|
+
#### Parameters
|
|
5896
|
+
|
|
5897
|
+
##### node
|
|
5898
|
+
|
|
5899
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5900
|
+
|
|
5901
|
+
##### k
|
|
5902
|
+
|
|
5903
|
+
`number`
|
|
5904
|
+
|
|
5905
|
+
#### Returns
|
|
5906
|
+
|
|
5907
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5908
|
+
|
|
5909
|
+
#### Remarks
|
|
5910
|
+
|
|
5911
|
+
Time O(log n), Space O(log n) call stack
|
|
5912
|
+
|
|
5913
|
+
#### Inherited from
|
|
5914
|
+
|
|
5915
|
+
[`BST`](BST.md).[`_getByRankRecursive`](BST.md#_getbyrankrecursive)
|
|
5916
|
+
|
|
5917
|
+
***
|
|
5918
|
+
|
|
5575
5919
|
### \_getIterator()
|
|
5576
5920
|
|
|
5577
5921
|
```ts
|
|
5578
5922
|
protected _getIterator(node?): IterableIterator<[K, V | undefined]>;
|
|
5579
5923
|
```
|
|
5580
5924
|
|
|
5581
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5925
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3133](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3133)
|
|
5582
5926
|
|
|
5583
5927
|
(Protected) Gets the iterator for the tree (default in-order).
|
|
5584
5928
|
|
|
@@ -5606,13 +5950,81 @@ Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the
|
|
|
5606
5950
|
|
|
5607
5951
|
***
|
|
5608
5952
|
|
|
5953
|
+
### \_getRankIterative()
|
|
5954
|
+
|
|
5955
|
+
```ts
|
|
5956
|
+
protected _getRankIterative(node, key): number;
|
|
5957
|
+
```
|
|
5958
|
+
|
|
5959
|
+
Defined in: [data-structures/binary-tree/bst.ts:3294](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3294)
|
|
5960
|
+
|
|
5961
|
+
(Protected) Computes the rank of a key iteratively.
|
|
5962
|
+
|
|
5963
|
+
#### Parameters
|
|
5964
|
+
|
|
5965
|
+
##### node
|
|
5966
|
+
|
|
5967
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5968
|
+
|
|
5969
|
+
##### key
|
|
5970
|
+
|
|
5971
|
+
`K`
|
|
5972
|
+
|
|
5973
|
+
#### Returns
|
|
5974
|
+
|
|
5975
|
+
`number`
|
|
5976
|
+
|
|
5977
|
+
#### Remarks
|
|
5978
|
+
|
|
5979
|
+
Time O(log n), Space O(1)
|
|
5980
|
+
|
|
5981
|
+
#### Inherited from
|
|
5982
|
+
|
|
5983
|
+
[`BST`](BST.md).[`_getRankIterative`](BST.md#_getrankiterative)
|
|
5984
|
+
|
|
5985
|
+
***
|
|
5986
|
+
|
|
5987
|
+
### \_getRankRecursive()
|
|
5988
|
+
|
|
5989
|
+
```ts
|
|
5990
|
+
protected _getRankRecursive(node, key): number;
|
|
5991
|
+
```
|
|
5992
|
+
|
|
5993
|
+
Defined in: [data-structures/binary-tree/bst.ts:3320](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3320)
|
|
5994
|
+
|
|
5995
|
+
(Protected) Computes the rank of a key recursively.
|
|
5996
|
+
|
|
5997
|
+
#### Parameters
|
|
5998
|
+
|
|
5999
|
+
##### node
|
|
6000
|
+
|
|
6001
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
6002
|
+
|
|
6003
|
+
##### key
|
|
6004
|
+
|
|
6005
|
+
`K`
|
|
6006
|
+
|
|
6007
|
+
#### Returns
|
|
6008
|
+
|
|
6009
|
+
`number`
|
|
6010
|
+
|
|
6011
|
+
#### Remarks
|
|
6012
|
+
|
|
6013
|
+
Time O(log n), Space O(log n) call stack
|
|
6014
|
+
|
|
6015
|
+
#### Inherited from
|
|
6016
|
+
|
|
6017
|
+
[`BST`](BST.md).[`_getRankRecursive`](BST.md#_getrankrecursive)
|
|
6018
|
+
|
|
6019
|
+
***
|
|
6020
|
+
|
|
5609
6021
|
### \_insert()
|
|
5610
6022
|
|
|
5611
6023
|
```ts
|
|
5612
6024
|
protected _insert(node): CRUD;
|
|
5613
6025
|
```
|
|
5614
6026
|
|
|
5615
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6027
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1729](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1729)
|
|
5616
6028
|
|
|
5617
6029
|
(Protected) Standard BST insert followed by red-black fix-up.
|
|
5618
6030
|
|
|
@@ -5642,7 +6054,7 @@ Time O(log n) average, Space O(1)
|
|
|
5642
6054
|
protected _insertFixup(z): void;
|
|
5643
6055
|
```
|
|
5644
6056
|
|
|
5645
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6057
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1798](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1798)
|
|
5646
6058
|
|
|
5647
6059
|
(Protected) Restore red-black properties after insertion (recolor/rotate).
|
|
5648
6060
|
|
|
@@ -5672,7 +6084,7 @@ Time O(log n) average, Space O(1)
|
|
|
5672
6084
|
protected _isDisplayLeaf(node, options): boolean;
|
|
5673
6085
|
```
|
|
5674
6086
|
|
|
5675
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6087
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3389](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3389)
|
|
5676
6088
|
|
|
5677
6089
|
Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
5678
6090
|
|
|
@@ -5702,7 +6114,7 @@ Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
|
5702
6114
|
protected _isPredicate(p): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
5703
6115
|
```
|
|
5704
6116
|
|
|
5705
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6117
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3566](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3566)
|
|
5706
6118
|
|
|
5707
6119
|
(Protected) Checks if an item is a predicate function.
|
|
5708
6120
|
|
|
@@ -5710,7 +6122,7 @@ Defined in: [data-structures/binary-tree/binary-tree.ts:3305](https://github.com
|
|
|
5710
6122
|
|
|
5711
6123
|
##### p
|
|
5712
6124
|
|
|
5713
|
-
`
|
|
6125
|
+
`unknown`
|
|
5714
6126
|
|
|
5715
6127
|
The item to check.
|
|
5716
6128
|
|
|
@@ -5736,7 +6148,7 @@ Time O(1)
|
|
|
5736
6148
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value?): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
5737
6149
|
```
|
|
5738
6150
|
|
|
5739
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6151
|
+
Defined in: [data-structures/binary-tree/bst.ts:3218](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3218)
|
|
5740
6152
|
|
|
5741
6153
|
(Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
5742
6154
|
|
|
@@ -5780,7 +6192,7 @@ Time O(1)
|
|
|
5780
6192
|
protected _leftRotate(x): void;
|
|
5781
6193
|
```
|
|
5782
6194
|
|
|
5783
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6195
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1946](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1946)
|
|
5784
6196
|
|
|
5785
6197
|
(Protected) Perform a left rotation around x.
|
|
5786
6198
|
|
|
@@ -5810,7 +6222,7 @@ Time O(1), Space O(1)
|
|
|
5810
6222
|
protected _lowerByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5811
6223
|
```
|
|
5812
6224
|
|
|
5813
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6225
|
+
Defined in: [data-structures/binary-tree/bst.ts:2876](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2876)
|
|
5814
6226
|
|
|
5815
6227
|
(Protected) Binary search for lower by key with pruning optimization.
|
|
5816
6228
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5852,7 +6264,7 @@ Time O(h) where h is tree height.
|
|
|
5852
6264
|
protected _lowerByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5853
6265
|
```
|
|
5854
6266
|
|
|
5855
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6267
|
+
Defined in: [data-structures/binary-tree/bst.ts:2929](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2929)
|
|
5856
6268
|
|
|
5857
6269
|
(Protected) In-order traversal search for lower by predicate.
|
|
5858
6270
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5889,13 +6301,43 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5889
6301
|
|
|
5890
6302
|
***
|
|
5891
6303
|
|
|
6304
|
+
### \_next()
|
|
6305
|
+
|
|
6306
|
+
```ts
|
|
6307
|
+
protected _next(node): BSTNode<K, V> | undefined;
|
|
6308
|
+
```
|
|
6309
|
+
|
|
6310
|
+
Defined in: [data-structures/binary-tree/bst.ts:3337](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3337)
|
|
6311
|
+
|
|
6312
|
+
(Protected) Finds the in-order successor of a node.
|
|
6313
|
+
|
|
6314
|
+
#### Parameters
|
|
6315
|
+
|
|
6316
|
+
##### node
|
|
6317
|
+
|
|
6318
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
6319
|
+
|
|
6320
|
+
#### Returns
|
|
6321
|
+
|
|
6322
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
6323
|
+
|
|
6324
|
+
#### Remarks
|
|
6325
|
+
|
|
6326
|
+
Time O(log n), Space O(1)
|
|
6327
|
+
|
|
6328
|
+
#### Inherited from
|
|
6329
|
+
|
|
6330
|
+
[`BST`](BST.md).[`_next`](BST.md#_next)
|
|
6331
|
+
|
|
6332
|
+
***
|
|
6333
|
+
|
|
5892
6334
|
### \_predecessorOf()
|
|
5893
6335
|
|
|
5894
6336
|
```ts
|
|
5895
6337
|
protected _predecessorOf(node): RedBlackTreeNode<K, V> | undefined;
|
|
5896
6338
|
```
|
|
5897
6339
|
|
|
5898
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6340
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:523](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L523)
|
|
5899
6341
|
|
|
5900
6342
|
(Internal) In-order predecessor of a node in a BST.
|
|
5901
6343
|
|
|
@@ -5921,7 +6363,7 @@ Time O(log n) average, Space O(1)
|
|
|
5921
6363
|
protected _replaceNode(oldNode, newNode): RedBlackTreeNode<K, V>;
|
|
5922
6364
|
```
|
|
5923
6365
|
|
|
5924
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6366
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1714](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1714)
|
|
5925
6367
|
|
|
5926
6368
|
(Internal) Replace a node in place while preserving its color.
|
|
5927
6369
|
|
|
@@ -5958,7 +6400,7 @@ protected _resolveDisplayLeaf(
|
|
|
5958
6400
|
emptyDisplayLayout): NodeDisplayLayout;
|
|
5959
6401
|
```
|
|
5960
6402
|
|
|
5961
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6403
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3419](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3419)
|
|
5962
6404
|
|
|
5963
6405
|
Resolve a display leaf node to its layout.
|
|
5964
6406
|
|
|
@@ -5992,7 +6434,7 @@ Resolve a display leaf node to its layout.
|
|
|
5992
6434
|
protected _rightRotate(y): void;
|
|
5993
6435
|
```
|
|
5994
6436
|
|
|
5995
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6437
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1982](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1982)
|
|
5996
6438
|
|
|
5997
6439
|
(Protected) Perform a right rotation around y.
|
|
5998
6440
|
|
|
@@ -6022,7 +6464,7 @@ Time O(1), Space O(1)
|
|
|
6022
6464
|
protected _setKV(key, nextValue?): boolean;
|
|
6023
6465
|
```
|
|
6024
6466
|
|
|
6025
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6467
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:748](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L748)
|
|
6026
6468
|
|
|
6027
6469
|
(Internal) Boolean wrapper around `_setKVNode`.
|
|
6028
6470
|
|
|
@@ -6063,7 +6505,7 @@ protected _setKVNode(key, nextValue?):
|
|
|
6063
6505
|
| undefined;
|
|
6064
6506
|
```
|
|
6065
6507
|
|
|
6066
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6508
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:621](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L621)
|
|
6067
6509
|
|
|
6068
6510
|
(Internal) Core set implementation returning the affected node.
|
|
6069
6511
|
|
|
@@ -6107,7 +6549,7 @@ Time O(log n) average, Space O(1)
|
|
|
6107
6549
|
protected _setMaxCache(node): void;
|
|
6108
6550
|
```
|
|
6109
6551
|
|
|
6110
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6552
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:602](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L602)
|
|
6111
6553
|
|
|
6112
6554
|
(Internal) Update max cache pointers (header._right is the canonical max pointer).
|
|
6113
6555
|
|
|
@@ -6133,7 +6575,7 @@ Time O(1), Space O(1)
|
|
|
6133
6575
|
protected _setMinCache(node): void;
|
|
6134
6576
|
```
|
|
6135
6577
|
|
|
6136
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6578
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:593](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L593)
|
|
6137
6579
|
|
|
6138
6580
|
(Internal) Update min cache pointers (header._left is the canonical min pointer).
|
|
6139
6581
|
|
|
@@ -6159,7 +6601,7 @@ Time O(1), Space O(1)
|
|
|
6159
6601
|
protected _setRoot(v): void;
|
|
6160
6602
|
```
|
|
6161
6603
|
|
|
6162
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6604
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1699](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1699)
|
|
6163
6605
|
|
|
6164
6606
|
(Internal) Set the root pointer and keep header.parent in sync.
|
|
6165
6607
|
|
|
@@ -6189,7 +6631,7 @@ Time O(1), Space O(1)
|
|
|
6189
6631
|
protected _setValue(key, value): boolean;
|
|
6190
6632
|
```
|
|
6191
6633
|
|
|
6192
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6634
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3598](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3598)
|
|
6193
6635
|
|
|
6194
6636
|
(Protected) Sets a value in the external store (Map mode).
|
|
6195
6637
|
|
|
@@ -6229,7 +6671,7 @@ Time O(1) (average for Map.set).
|
|
|
6229
6671
|
protected _snapshotOptions<TK, TV, TR>(): BSTOptions<TK, TV, TR>;
|
|
6230
6672
|
```
|
|
6231
6673
|
|
|
6232
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6674
|
+
Defined in: [data-structures/binary-tree/bst.ts:3202](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3202)
|
|
6233
6675
|
|
|
6234
6676
|
(Protected) Snapshots the current BST's configuration options.
|
|
6235
6677
|
|
|
@@ -6269,7 +6711,7 @@ Time O(1)
|
|
|
6269
6711
|
protected _successorOf(node): RedBlackTreeNode<K, V> | undefined;
|
|
6270
6712
|
```
|
|
6271
6713
|
|
|
6272
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6714
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:543](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L543)
|
|
6273
6715
|
|
|
6274
6716
|
(Internal) In-order successor of a node in a BST.
|
|
6275
6717
|
|
|
@@ -6295,7 +6737,7 @@ Time O(log n) average, Space O(1)
|
|
|
6295
6737
|
protected _swapProperties(srcNode, destNode): BinaryTreeNode<K, V> | undefined;
|
|
6296
6738
|
```
|
|
6297
6739
|
|
|
6298
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6740
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3445](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3445)
|
|
6299
6741
|
|
|
6300
6742
|
(Protected) Swaps the key/value properties of two nodes.
|
|
6301
6743
|
|
|
@@ -6343,7 +6785,7 @@ Time O(1)
|
|
|
6343
6785
|
protected _transplant(u, v): void;
|
|
6344
6786
|
```
|
|
6345
6787
|
|
|
6346
|
-
Defined in: [data-structures/binary-tree/red-black-tree.ts:
|
|
6788
|
+
Defined in: [data-structures/binary-tree/red-black-tree.ts:1778](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/red-black-tree.ts#L1778)
|
|
6347
6789
|
|
|
6348
6790
|
(Protected) Transplant a subtree in place of another during deletion.
|
|
6349
6791
|
|
|
@@ -6372,3 +6814,63 @@ void
|
|
|
6372
6814
|
Time O(1), Space O(1)
|
|
6373
6815
|
|
|
6374
6816
|
***
|
|
6817
|
+
|
|
6818
|
+
### \_updateCount()
|
|
6819
|
+
|
|
6820
|
+
```ts
|
|
6821
|
+
protected _updateCount(node): void;
|
|
6822
|
+
```
|
|
6823
|
+
|
|
6824
|
+
Defined in: [data-structures/binary-tree/bst.ts:3237](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3237)
|
|
6825
|
+
|
|
6826
|
+
(Protected) Recalculates the subtree count for a single node.
|
|
6827
|
+
|
|
6828
|
+
#### Parameters
|
|
6829
|
+
|
|
6830
|
+
##### node
|
|
6831
|
+
|
|
6832
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
6833
|
+
|
|
6834
|
+
#### Returns
|
|
6835
|
+
|
|
6836
|
+
`void`
|
|
6837
|
+
|
|
6838
|
+
#### Remarks
|
|
6839
|
+
|
|
6840
|
+
Time O(1). Only active when enableOrderStatistic is true.
|
|
6841
|
+
|
|
6842
|
+
#### Inherited from
|
|
6843
|
+
|
|
6844
|
+
[`BST`](BST.md).[`_updateCount`](BST.md#_updatecount)
|
|
6845
|
+
|
|
6846
|
+
***
|
|
6847
|
+
|
|
6848
|
+
### \_updateCountAlongPath()
|
|
6849
|
+
|
|
6850
|
+
```ts
|
|
6851
|
+
protected _updateCountAlongPath(node): void;
|
|
6852
|
+
```
|
|
6853
|
+
|
|
6854
|
+
Defined in: [data-structures/binary-tree/bst.ts:3248](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3248)
|
|
6855
|
+
|
|
6856
|
+
(Protected) Updates subtree counts from a node up to the root.
|
|
6857
|
+
|
|
6858
|
+
#### Parameters
|
|
6859
|
+
|
|
6860
|
+
##### node
|
|
6861
|
+
|
|
6862
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
6863
|
+
|
|
6864
|
+
#### Returns
|
|
6865
|
+
|
|
6866
|
+
`void`
|
|
6867
|
+
|
|
6868
|
+
#### Remarks
|
|
6869
|
+
|
|
6870
|
+
Time O(log n). Only active when enableOrderStatistic is true.
|
|
6871
|
+
|
|
6872
|
+
#### Inherited from
|
|
6873
|
+
|
|
6874
|
+
[`BST`](BST.md).[`_updateCountAlongPath`](BST.md#_updatecountalongpath)
|
|
6875
|
+
|
|
6876
|
+
***
|