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: AVLTree\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
9
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:311](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L311)
|
|
10
10
|
|
|
11
11
|
Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
|
|
12
12
|
This tree extends BST and performs rotations on set/delete to maintain balance.
|
|
@@ -182,7 +182,7 @@ The type of the raw data object (if using `toEntryFn`).
|
|
|
182
182
|
new AVLTree<K, V, R>(keysNodesEntriesOrRaws?, options?): AVLTree<K, V, R>;
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
185
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:319](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L319)
|
|
186
186
|
|
|
187
187
|
Creates an instance of AVLTree.
|
|
188
188
|
|
|
@@ -228,7 +228,7 @@ Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
|
228
228
|
get comparator(): Comparator<K>;
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
231
|
+
Defined in: [data-structures/binary-tree/bst.ts:384](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L384)
|
|
232
232
|
|
|
233
233
|
Gets the comparator function used by the tree.
|
|
234
234
|
|
|
@@ -256,7 +256,7 @@ The comparator function.
|
|
|
256
256
|
get isDuplicate(): boolean;
|
|
257
257
|
```
|
|
258
258
|
|
|
259
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:322](https://github.com/zrwusa/data-structure-typed/blob/
|
|
259
|
+
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)
|
|
260
260
|
|
|
261
261
|
Gets whether the tree allows duplicate keys.
|
|
262
262
|
|
|
@@ -290,7 +290,7 @@ IBinaryTree.isDuplicate
|
|
|
290
290
|
get isMapMode(): boolean;
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:310](https://github.com/zrwusa/data-structure-typed/blob/
|
|
293
|
+
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)
|
|
294
294
|
|
|
295
295
|
Gets whether the tree is in Map mode.
|
|
296
296
|
|
|
@@ -324,7 +324,7 @@ IBinaryTree.isMapMode
|
|
|
324
324
|
get NIL(): BinaryTreeNode<K, V>;
|
|
325
325
|
```
|
|
326
326
|
|
|
327
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:373](https://github.com/zrwusa/data-structure-typed/blob/
|
|
327
|
+
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)
|
|
328
328
|
|
|
329
329
|
Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
330
330
|
|
|
@@ -358,7 +358,7 @@ IBinaryTree.NIL
|
|
|
358
358
|
get root(): OptNode<BSTNode<K, V>>;
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
361
|
+
Defined in: [data-structures/binary-tree/bst.ts:367](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L367)
|
|
362
362
|
|
|
363
363
|
Gets the root node of the tree.
|
|
364
364
|
|
|
@@ -392,7 +392,7 @@ IBinaryTree.root
|
|
|
392
392
|
get size(): number;
|
|
393
393
|
```
|
|
394
394
|
|
|
395
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:361](https://github.com/zrwusa/data-structure-typed/blob/
|
|
395
|
+
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)
|
|
396
396
|
|
|
397
397
|
Gets the number of nodes in the tree.
|
|
398
398
|
|
|
@@ -426,7 +426,7 @@ IBinaryTree.size
|
|
|
426
426
|
get store(): Map<K, BinaryTreeNode<K, V>>;
|
|
427
427
|
```
|
|
428
428
|
|
|
429
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:337](https://github.com/zrwusa/data-structure-typed/blob/
|
|
429
|
+
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)
|
|
430
430
|
|
|
431
431
|
Gets the external value store (used in Map mode).
|
|
432
432
|
|
|
@@ -460,7 +460,7 @@ IBinaryTree.store
|
|
|
460
460
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
461
461
|
```
|
|
462
462
|
|
|
463
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:385](https://github.com/zrwusa/data-structure-typed/blob/
|
|
463
|
+
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)
|
|
464
464
|
|
|
465
465
|
Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
466
466
|
|
|
@@ -492,7 +492,7 @@ IBinaryTree.toEntryFn
|
|
|
492
492
|
iterator: IterableIterator<[K, V | undefined]>;
|
|
493
493
|
```
|
|
494
494
|
|
|
495
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/
|
|
495
|
+
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)
|
|
496
496
|
|
|
497
497
|
Default iterator yielding `[key, value]` entries.
|
|
498
498
|
|
|
@@ -500,7 +500,7 @@ Default iterator yielding `[key, value]` entries.
|
|
|
500
500
|
|
|
501
501
|
##### args
|
|
502
502
|
|
|
503
|
-
...`
|
|
503
|
+
...`unknown`[]
|
|
504
504
|
|
|
505
505
|
#### Returns
|
|
506
506
|
|
|
@@ -530,7 +530,7 @@ IBinaryTree.[iterator]
|
|
|
530
530
|
add(keyNodeOrEntry): boolean;
|
|
531
531
|
```
|
|
532
532
|
|
|
533
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
533
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:612](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L612)
|
|
534
534
|
|
|
535
535
|
Adds a new node to the tree.
|
|
536
536
|
|
|
@@ -556,7 +556,7 @@ True if the addition was successful, false otherwise.
|
|
|
556
556
|
|
|
557
557
|
#### Remarks
|
|
558
558
|
|
|
559
|
-
Time O(
|
|
559
|
+
Time O(N) — level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
560
560
|
|
|
561
561
|
#### Example
|
|
562
562
|
|
|
@@ -588,7 +588,7 @@ IBinaryTree.add
|
|
|
588
588
|
addMany(keysNodesEntriesOrRaws): boolean[];
|
|
589
589
|
```
|
|
590
590
|
|
|
591
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
591
|
+
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)
|
|
592
592
|
|
|
593
593
|
Adds multiple items to the tree.
|
|
594
594
|
|
|
@@ -669,7 +669,7 @@ The traversal method.
|
|
|
669
669
|
bfs(): (K | undefined)[];
|
|
670
670
|
```
|
|
671
671
|
|
|
672
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
672
|
+
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)
|
|
673
673
|
|
|
674
674
|
BinaryTree level-order traversal
|
|
675
675
|
|
|
@@ -707,7 +707,7 @@ bfs<C>(
|
|
|
707
707
|
iterationType?): ReturnType<C>[];
|
|
708
708
|
```
|
|
709
709
|
|
|
710
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
710
|
+
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)
|
|
711
711
|
|
|
712
712
|
BinaryTree level-order traversal
|
|
713
713
|
|
|
@@ -769,7 +769,7 @@ IBinaryTree.bfs
|
|
|
769
769
|
ceiling(keyNodeEntryOrPredicate): K | undefined;
|
|
770
770
|
```
|
|
771
771
|
|
|
772
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
772
|
+
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)
|
|
773
773
|
|
|
774
774
|
Returns the first key with a value >= target.
|
|
775
775
|
Equivalent to Java TreeMap.ceiling.
|
|
@@ -816,7 +816,7 @@ ceiling<C>(
|
|
|
816
816
|
iterationType?): ReturnType<C>;
|
|
817
817
|
```
|
|
818
818
|
|
|
819
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
819
|
+
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)
|
|
820
820
|
|
|
821
821
|
Returns the first node with a key >= target and applies callback.
|
|
822
822
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -863,7 +863,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
863
863
|
clear(): void;
|
|
864
864
|
```
|
|
865
865
|
|
|
866
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
866
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1543](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1543)
|
|
867
867
|
|
|
868
868
|
Clears the tree of all nodes and values.
|
|
869
869
|
|
|
@@ -904,7 +904,7 @@ IBinaryTree.clear
|
|
|
904
904
|
clone(): this;
|
|
905
905
|
```
|
|
906
906
|
|
|
907
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
907
|
+
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)
|
|
908
908
|
|
|
909
909
|
Clones the tree.
|
|
910
910
|
|
|
@@ -948,7 +948,7 @@ IBinaryTree.clone
|
|
|
948
948
|
createNode(key, value?): AVLTreeNode<K, V>;
|
|
949
949
|
```
|
|
950
950
|
|
|
951
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
951
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:338](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L338)
|
|
952
952
|
|
|
953
953
|
(Protected) Creates a new AVL tree node.
|
|
954
954
|
|
|
@@ -994,7 +994,7 @@ IBinaryTree.createNode
|
|
|
994
994
|
createTree(options?): this;
|
|
995
995
|
```
|
|
996
996
|
|
|
997
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:408](https://github.com/zrwusa/data-structure-typed/blob/
|
|
997
|
+
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)
|
|
998
998
|
|
|
999
999
|
Creates a new, empty tree of the same type and configuration.
|
|
1000
1000
|
|
|
@@ -1031,10 +1031,10 @@ IBinaryTree.createTree
|
|
|
1031
1031
|
### delete()
|
|
1032
1032
|
|
|
1033
1033
|
```ts
|
|
1034
|
-
delete(keyNodeOrEntry):
|
|
1034
|
+
delete(keyNodeOrEntry): boolean;
|
|
1035
1035
|
```
|
|
1036
1036
|
|
|
1037
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
1037
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:658](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L658)
|
|
1038
1038
|
|
|
1039
1039
|
Deletes a node from the AVL tree and re-balances the tree.
|
|
1040
1040
|
|
|
@@ -1052,7 +1052,7 @@ The node to delete.
|
|
|
1052
1052
|
|
|
1053
1053
|
#### Returns
|
|
1054
1054
|
|
|
1055
|
-
`
|
|
1055
|
+
`boolean`
|
|
1056
1056
|
|
|
1057
1057
|
An array containing deletion results.
|
|
1058
1058
|
|
|
@@ -1091,10 +1091,10 @@ deleteWhere(
|
|
|
1091
1091
|
keyNodeEntryOrPredicate,
|
|
1092
1092
|
onlyOne?,
|
|
1093
1093
|
startNode?,
|
|
1094
|
-
iterationType?):
|
|
1094
|
+
iterationType?): boolean;
|
|
1095
1095
|
```
|
|
1096
1096
|
|
|
1097
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1097
|
+
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)
|
|
1098
1098
|
|
|
1099
1099
|
Deletes nodes that match a key, node, entry, predicate, or range.
|
|
1100
1100
|
|
|
@@ -1149,7 +1149,7 @@ Controls the internal traversal implementation:
|
|
|
1149
1149
|
|
|
1150
1150
|
#### Returns
|
|
1151
1151
|
|
|
1152
|
-
`
|
|
1152
|
+
`boolean`
|
|
1153
1153
|
|
|
1154
1154
|
A Map<K, boolean> containing the deletion results:
|
|
1155
1155
|
- Key: the matched node's key.
|
|
@@ -1205,7 +1205,7 @@ The traversal method.
|
|
|
1205
1205
|
dfs(): (K | undefined)[];
|
|
1206
1206
|
```
|
|
1207
1207
|
|
|
1208
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1208
|
+
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)
|
|
1209
1209
|
|
|
1210
1210
|
Depth-first search traversal
|
|
1211
1211
|
|
|
@@ -1245,7 +1245,7 @@ dfs<C>(
|
|
|
1245
1245
|
iterationType?): ReturnType<C>[];
|
|
1246
1246
|
```
|
|
1247
1247
|
|
|
1248
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1248
|
+
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)
|
|
1249
1249
|
|
|
1250
1250
|
Depth-first search traversal
|
|
1251
1251
|
|
|
@@ -1313,7 +1313,7 @@ IBinaryTree.dfs
|
|
|
1313
1313
|
ensureNode(keyNodeOrEntry, iterationType?): OptNode<BSTNode<K, V>>;
|
|
1314
1314
|
```
|
|
1315
1315
|
|
|
1316
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1316
|
+
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)
|
|
1317
1317
|
|
|
1318
1318
|
Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
1319
1319
|
|
|
@@ -1357,7 +1357,7 @@ Time O(log N) (height of the tree), O(N) worst-case.
|
|
|
1357
1357
|
entries(): IterableIterator<[K, V | undefined]>;
|
|
1358
1358
|
```
|
|
1359
1359
|
|
|
1360
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1360
|
+
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)
|
|
1361
1361
|
|
|
1362
1362
|
Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
1363
1363
|
|
|
@@ -1389,7 +1389,7 @@ IBinaryTree.entries
|
|
|
1389
1389
|
every(predicate, thisArg?): boolean;
|
|
1390
1390
|
```
|
|
1391
1391
|
|
|
1392
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1392
|
+
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)
|
|
1393
1393
|
|
|
1394
1394
|
Test whether all entries satisfy the predicate.
|
|
1395
1395
|
|
|
@@ -1403,7 +1403,7 @@ Test whether all entries satisfy the predicate.
|
|
|
1403
1403
|
|
|
1404
1404
|
##### thisArg?
|
|
1405
1405
|
|
|
1406
|
-
`
|
|
1406
|
+
`unknown`
|
|
1407
1407
|
|
|
1408
1408
|
Optional `this` for callback.
|
|
1409
1409
|
|
|
@@ -1435,7 +1435,7 @@ IBinaryTree.every
|
|
|
1435
1435
|
filter(predicate, thisArg?): this;
|
|
1436
1436
|
```
|
|
1437
1437
|
|
|
1438
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1438
|
+
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)
|
|
1439
1439
|
|
|
1440
1440
|
Creates a new tree containing only the entries that satisfy the predicate.
|
|
1441
1441
|
|
|
@@ -1492,7 +1492,7 @@ IBinaryTree.filter
|
|
|
1492
1492
|
find(callbackfn, thisArg?): [K, V | undefined] | undefined;
|
|
1493
1493
|
```
|
|
1494
1494
|
|
|
1495
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1495
|
+
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)
|
|
1496
1496
|
|
|
1497
1497
|
Find the first entry that matches a predicate.
|
|
1498
1498
|
|
|
@@ -1506,7 +1506,7 @@ Find the first entry that matches a predicate.
|
|
|
1506
1506
|
|
|
1507
1507
|
##### thisArg?
|
|
1508
1508
|
|
|
1509
|
-
`
|
|
1509
|
+
`unknown`
|
|
1510
1510
|
|
|
1511
1511
|
Optional `this` for callback.
|
|
1512
1512
|
|
|
@@ -1540,7 +1540,7 @@ IBinaryTree.find
|
|
|
1540
1540
|
floor(keyNodeEntryOrPredicate): K | undefined;
|
|
1541
1541
|
```
|
|
1542
1542
|
|
|
1543
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1543
|
+
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)
|
|
1544
1544
|
|
|
1545
1545
|
Returns the first key with a value <= target.
|
|
1546
1546
|
Equivalent to Java TreeMap.floor.
|
|
@@ -1587,7 +1587,7 @@ floor<C>(
|
|
|
1587
1587
|
iterationType?): ReturnType<C>;
|
|
1588
1588
|
```
|
|
1589
1589
|
|
|
1590
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1590
|
+
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)
|
|
1591
1591
|
|
|
1592
1592
|
Returns the first node with a key <= target and applies callback.
|
|
1593
1593
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -1634,7 +1634,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
1634
1634
|
forEach(callbackfn, thisArg?): void;
|
|
1635
1635
|
```
|
|
1636
1636
|
|
|
1637
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1637
|
+
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)
|
|
1638
1638
|
|
|
1639
1639
|
Visit each entry, left-to-right.
|
|
1640
1640
|
|
|
@@ -1648,7 +1648,7 @@ Visit each entry, left-to-right.
|
|
|
1648
1648
|
|
|
1649
1649
|
##### thisArg?
|
|
1650
1650
|
|
|
1651
|
-
`
|
|
1651
|
+
`unknown`
|
|
1652
1652
|
|
|
1653
1653
|
Optional `this` for callback.
|
|
1654
1654
|
|
|
@@ -1681,7 +1681,7 @@ get(
|
|
|
1681
1681
|
iterationType?): V | undefined;
|
|
1682
1682
|
```
|
|
1683
1683
|
|
|
1684
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1684
|
+
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)
|
|
1685
1685
|
|
|
1686
1686
|
Gets the value associated with a key.
|
|
1687
1687
|
|
|
@@ -1722,7 +1722,7 @@ The associated value, or undefined.
|
|
|
1722
1722
|
|
|
1723
1723
|
#### Remarks
|
|
1724
1724
|
|
|
1725
|
-
Time O(
|
|
1725
|
+
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).
|
|
1726
1726
|
|
|
1727
1727
|
#### Example
|
|
1728
1728
|
|
|
@@ -1745,13 +1745,114 @@ IBinaryTree.get
|
|
|
1745
1745
|
|
|
1746
1746
|
***
|
|
1747
1747
|
|
|
1748
|
+
### getByRank()
|
|
1749
|
+
|
|
1750
|
+
#### Call Signature
|
|
1751
|
+
|
|
1752
|
+
```ts
|
|
1753
|
+
getByRank(k): K | undefined;
|
|
1754
|
+
```
|
|
1755
|
+
|
|
1756
|
+
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)
|
|
1757
|
+
|
|
1758
|
+
Returns the element at the k-th position in tree order (0-indexed).
|
|
1759
|
+
|
|
1760
|
+
##### Parameters
|
|
1761
|
+
|
|
1762
|
+
###### k
|
|
1763
|
+
|
|
1764
|
+
`number`
|
|
1765
|
+
|
|
1766
|
+
The 0-based position in tree order (0 = first element).
|
|
1767
|
+
|
|
1768
|
+
##### Returns
|
|
1769
|
+
|
|
1770
|
+
`K` \| `undefined`
|
|
1771
|
+
|
|
1772
|
+
The key at position k, or `undefined` if out of bounds.
|
|
1773
|
+
*
|
|
1774
|
+
|
|
1775
|
+
##### Remarks
|
|
1776
|
+
|
|
1777
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
1778
|
+
Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
1779
|
+
|
|
1780
|
+
##### Example
|
|
1781
|
+
|
|
1782
|
+
```ts
|
|
1783
|
+
// Order-statistic on BST
|
|
1784
|
+
const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
1785
|
+
console.log(tree.getByRank(0)); // 10;
|
|
1786
|
+
console.log(tree.getByRank(4)); // 50;
|
|
1787
|
+
console.log(tree.getRank(30)); // 2;
|
|
1788
|
+
```
|
|
1789
|
+
|
|
1790
|
+
##### Inherited from
|
|
1791
|
+
|
|
1792
|
+
[`BST`](BST.md).[`getByRank`](BST.md#getbyrank)
|
|
1793
|
+
|
|
1794
|
+
#### Call Signature
|
|
1795
|
+
|
|
1796
|
+
```ts
|
|
1797
|
+
getByRank<C>(
|
|
1798
|
+
k,
|
|
1799
|
+
callback,
|
|
1800
|
+
iterationType?): ReturnType<C> | undefined;
|
|
1801
|
+
```
|
|
1802
|
+
|
|
1803
|
+
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)
|
|
1804
|
+
|
|
1805
|
+
Returns the element at the k-th position in tree order and applies a callback.
|
|
1806
|
+
|
|
1807
|
+
##### Type Parameters
|
|
1808
|
+
|
|
1809
|
+
###### C
|
|
1810
|
+
|
|
1811
|
+
`C` *extends* `NodeCallback`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
1812
|
+
|
|
1813
|
+
##### Parameters
|
|
1814
|
+
|
|
1815
|
+
###### k
|
|
1816
|
+
|
|
1817
|
+
`number`
|
|
1818
|
+
|
|
1819
|
+
The 0-based position in tree order (0 = first element).
|
|
1820
|
+
|
|
1821
|
+
###### callback
|
|
1822
|
+
|
|
1823
|
+
`C`
|
|
1824
|
+
|
|
1825
|
+
Callback to apply to the found node.
|
|
1826
|
+
|
|
1827
|
+
###### iterationType?
|
|
1828
|
+
|
|
1829
|
+
`IterationType`
|
|
1830
|
+
|
|
1831
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
1832
|
+
|
|
1833
|
+
##### Returns
|
|
1834
|
+
|
|
1835
|
+
`ReturnType`\<`C`\> \| `undefined`
|
|
1836
|
+
|
|
1837
|
+
The callback result, or `undefined` if out of bounds.
|
|
1838
|
+
|
|
1839
|
+
##### Remarks
|
|
1840
|
+
|
|
1841
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
1842
|
+
|
|
1843
|
+
##### Inherited from
|
|
1844
|
+
|
|
1845
|
+
[`BST`](BST.md).[`getByRank`](BST.md#getbyrank)
|
|
1846
|
+
|
|
1847
|
+
***
|
|
1848
|
+
|
|
1748
1849
|
### getDepth()
|
|
1749
1850
|
|
|
1750
1851
|
```ts
|
|
1751
1852
|
getDepth(dist, startNode?): number;
|
|
1752
1853
|
```
|
|
1753
1854
|
|
|
1754
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1855
|
+
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)
|
|
1755
1856
|
|
|
1756
1857
|
Gets the depth of a node (distance from `startNode`).
|
|
1757
1858
|
|
|
@@ -1815,7 +1916,7 @@ IBinaryTree.getDepth
|
|
|
1815
1916
|
getHeight(startNode?, iterationType?): number;
|
|
1816
1917
|
```
|
|
1817
1918
|
|
|
1818
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1919
|
+
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)
|
|
1819
1920
|
|
|
1820
1921
|
Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
1821
1922
|
|
|
@@ -1898,7 +1999,7 @@ The traversal method.
|
|
|
1898
1999
|
getLeftMost(): K | undefined;
|
|
1899
2000
|
```
|
|
1900
2001
|
|
|
1901
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2002
|
+
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)
|
|
1902
2003
|
|
|
1903
2004
|
##### Returns
|
|
1904
2005
|
|
|
@@ -1923,7 +2024,7 @@ getLeftMost<C>(
|
|
|
1923
2024
|
iterationType?): ReturnType<C>;
|
|
1924
2025
|
```
|
|
1925
2026
|
|
|
1926
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2027
|
+
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)
|
|
1927
2028
|
|
|
1928
2029
|
##### Type Parameters
|
|
1929
2030
|
|
|
@@ -1970,7 +2071,7 @@ IBinaryTree.getLeftMost
|
|
|
1970
2071
|
getMinHeight(startNode?, iterationType?): number;
|
|
1971
2072
|
```
|
|
1972
2073
|
|
|
1973
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2074
|
+
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)
|
|
1974
2075
|
|
|
1975
2076
|
Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
1976
2077
|
|
|
@@ -2022,7 +2123,7 @@ getNode(
|
|
|
2022
2123
|
iterationType?): OptNode<BSTNode<K, V>>;
|
|
2023
2124
|
```
|
|
2024
2125
|
|
|
2025
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2126
|
+
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)
|
|
2026
2127
|
|
|
2027
2128
|
Gets the first node matching a predicate.
|
|
2028
2129
|
|
|
@@ -2095,7 +2196,7 @@ getNodes(
|
|
|
2095
2196
|
iterationType?): BinaryTreeNode<K, V>[];
|
|
2096
2197
|
```
|
|
2097
2198
|
|
|
2098
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2199
|
+
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)
|
|
2099
2200
|
|
|
2100
2201
|
Gets all nodes matching a predicate.
|
|
2101
2202
|
|
|
@@ -2190,7 +2291,7 @@ If true, returns the path from root-to-node.
|
|
|
2190
2291
|
getPathToRoot(beginNode): (K | undefined)[];
|
|
2191
2292
|
```
|
|
2192
2293
|
|
|
2193
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2294
|
+
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)
|
|
2194
2295
|
|
|
2195
2296
|
##### Parameters
|
|
2196
2297
|
|
|
@@ -2225,7 +2326,7 @@ getPathToRoot<C>(
|
|
|
2225
2326
|
isReverse?): ReturnType<C>[];
|
|
2226
2327
|
```
|
|
2227
2328
|
|
|
2228
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2329
|
+
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)
|
|
2229
2330
|
|
|
2230
2331
|
##### Type Parameters
|
|
2231
2332
|
|
|
@@ -2273,7 +2374,7 @@ IBinaryTree.getPathToRoot
|
|
|
2273
2374
|
getPredecessor(node): BinaryTreeNode<K, V>;
|
|
2274
2375
|
```
|
|
2275
2376
|
|
|
2276
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2377
|
+
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)
|
|
2277
2378
|
|
|
2278
2379
|
Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
2279
2380
|
|
|
@@ -2301,6 +2402,91 @@ This is primarily a helper for Morris traversal. Time O(H), where H is the heigh
|
|
|
2301
2402
|
|
|
2302
2403
|
***
|
|
2303
2404
|
|
|
2405
|
+
### getRank()
|
|
2406
|
+
|
|
2407
|
+
#### Call Signature
|
|
2408
|
+
|
|
2409
|
+
```ts
|
|
2410
|
+
getRank(keyNodeEntryOrPredicate): number;
|
|
2411
|
+
```
|
|
2412
|
+
|
|
2413
|
+
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)
|
|
2414
|
+
|
|
2415
|
+
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
2416
|
+
|
|
2417
|
+
##### Parameters
|
|
2418
|
+
|
|
2419
|
+
###### keyNodeEntryOrPredicate
|
|
2420
|
+
|
|
2421
|
+
\| `K`
|
|
2422
|
+
\| [`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
2423
|
+
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
2424
|
+
\| `NodePredicate`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
2425
|
+
\| `null`
|
|
2426
|
+
\| `undefined`
|
|
2427
|
+
|
|
2428
|
+
The key, node, entry `[K, V]`, or predicate to find.
|
|
2429
|
+
|
|
2430
|
+
##### Returns
|
|
2431
|
+
|
|
2432
|
+
`number`
|
|
2433
|
+
|
|
2434
|
+
The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
2435
|
+
|
|
2436
|
+
##### Remarks
|
|
2437
|
+
|
|
2438
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
2439
|
+
Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
2440
|
+
|
|
2441
|
+
##### Inherited from
|
|
2442
|
+
|
|
2443
|
+
[`BST`](BST.md).[`getRank`](BST.md#getrank)
|
|
2444
|
+
|
|
2445
|
+
#### Call Signature
|
|
2446
|
+
|
|
2447
|
+
```ts
|
|
2448
|
+
getRank(keyNodeEntryOrPredicate, iterationType): number;
|
|
2449
|
+
```
|
|
2450
|
+
|
|
2451
|
+
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)
|
|
2452
|
+
|
|
2453
|
+
Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
2454
|
+
|
|
2455
|
+
##### Parameters
|
|
2456
|
+
|
|
2457
|
+
###### keyNodeEntryOrPredicate
|
|
2458
|
+
|
|
2459
|
+
\| `K`
|
|
2460
|
+
\| [`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
2461
|
+
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
2462
|
+
\| `NodePredicate`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
2463
|
+
\| `null`
|
|
2464
|
+
\| `undefined`
|
|
2465
|
+
|
|
2466
|
+
The key, node, entry, or predicate to find.
|
|
2467
|
+
|
|
2468
|
+
###### iterationType
|
|
2469
|
+
|
|
2470
|
+
`IterationType`
|
|
2471
|
+
|
|
2472
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
2473
|
+
|
|
2474
|
+
##### Returns
|
|
2475
|
+
|
|
2476
|
+
`number`
|
|
2477
|
+
|
|
2478
|
+
The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
2479
|
+
|
|
2480
|
+
##### Remarks
|
|
2481
|
+
|
|
2482
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
2483
|
+
|
|
2484
|
+
##### Inherited from
|
|
2485
|
+
|
|
2486
|
+
[`BST`](BST.md).[`getRank`](BST.md#getrank)
|
|
2487
|
+
|
|
2488
|
+
***
|
|
2489
|
+
|
|
2304
2490
|
### getRightMost()
|
|
2305
2491
|
|
|
2306
2492
|
Finds the rightmost node in a subtree (the node with the largest key in a BST).
|
|
@@ -2331,7 +2517,7 @@ The traversal method.
|
|
|
2331
2517
|
getRightMost(): K | undefined;
|
|
2332
2518
|
```
|
|
2333
2519
|
|
|
2334
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2520
|
+
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)
|
|
2335
2521
|
|
|
2336
2522
|
##### Returns
|
|
2337
2523
|
|
|
@@ -2356,7 +2542,7 @@ getRightMost<C>(
|
|
|
2356
2542
|
iterationType?): ReturnType<C>;
|
|
2357
2543
|
```
|
|
2358
2544
|
|
|
2359
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2545
|
+
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)
|
|
2360
2546
|
|
|
2361
2547
|
##### Type Parameters
|
|
2362
2548
|
|
|
@@ -2403,7 +2589,7 @@ IBinaryTree.getRightMost
|
|
|
2403
2589
|
getSuccessor(x?): BinaryTreeNode<K, V> | null | undefined;
|
|
2404
2590
|
```
|
|
2405
2591
|
|
|
2406
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2592
|
+
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)
|
|
2407
2593
|
|
|
2408
2594
|
Gets the in-order successor of a node in a BST.
|
|
2409
2595
|
|
|
@@ -2440,7 +2626,7 @@ has(
|
|
|
2440
2626
|
iterationType?): boolean;
|
|
2441
2627
|
```
|
|
2442
2628
|
|
|
2443
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2629
|
+
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)
|
|
2444
2630
|
|
|
2445
2631
|
Checks if a node matching the predicate exists in the tree.
|
|
2446
2632
|
|
|
@@ -2481,7 +2667,7 @@ True if a matching node exists, false otherwise.
|
|
|
2481
2667
|
|
|
2482
2668
|
#### Remarks
|
|
2483
2669
|
|
|
2484
|
-
Time O(
|
|
2670
|
+
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.
|
|
2485
2671
|
|
|
2486
2672
|
#### Example
|
|
2487
2673
|
|
|
@@ -2533,7 +2719,7 @@ IBinaryTree.has
|
|
|
2533
2719
|
hasValue(value): boolean;
|
|
2534
2720
|
```
|
|
2535
2721
|
|
|
2536
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2722
|
+
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)
|
|
2537
2723
|
|
|
2538
2724
|
Whether there exists an entry with the given value.
|
|
2539
2725
|
|
|
@@ -2575,7 +2761,7 @@ IBinaryTree.hasValue
|
|
|
2575
2761
|
higher(keyNodeEntryOrPredicate): K | undefined;
|
|
2576
2762
|
```
|
|
2577
2763
|
|
|
2578
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2764
|
+
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)
|
|
2579
2765
|
|
|
2580
2766
|
Returns the first key with a value > target.
|
|
2581
2767
|
Equivalent to Java TreeMap.higher.
|
|
@@ -2621,7 +2807,7 @@ higher<C>(
|
|
|
2621
2807
|
iterationType?): ReturnType<C>;
|
|
2622
2808
|
```
|
|
2623
2809
|
|
|
2624
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2810
|
+
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)
|
|
2625
2811
|
|
|
2626
2812
|
Returns the first node with a key > target and applies callback.
|
|
2627
2813
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -2668,7 +2854,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
2668
2854
|
isAVLBalanced(iterationType?): boolean;
|
|
2669
2855
|
```
|
|
2670
2856
|
|
|
2671
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2857
|
+
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)
|
|
2672
2858
|
|
|
2673
2859
|
Checks if the tree meets the AVL balance condition (height difference <= 1).
|
|
2674
2860
|
|
|
@@ -2712,7 +2898,7 @@ Time O(N), as it must visit every node to compute height. Space O(log N) for rec
|
|
|
2712
2898
|
isBST(startNode?, iterationType?): boolean;
|
|
2713
2899
|
```
|
|
2714
2900
|
|
|
2715
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2901
|
+
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)
|
|
2716
2902
|
|
|
2717
2903
|
Checks if the tree is a valid Binary Search Tree (BST).
|
|
2718
2904
|
|
|
@@ -2772,7 +2958,7 @@ IBinaryTree.isBST
|
|
|
2772
2958
|
isEmpty(): boolean;
|
|
2773
2959
|
```
|
|
2774
2960
|
|
|
2775
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2961
|
+
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)
|
|
2776
2962
|
|
|
2777
2963
|
Checks if the tree is empty.
|
|
2778
2964
|
|
|
@@ -2813,7 +2999,7 @@ IBinaryTree.isEmpty
|
|
|
2813
2999
|
isEntry(keyNodeOrEntry): keyNodeOrEntry is BTNEntry<K, V>;
|
|
2814
3000
|
```
|
|
2815
3001
|
|
|
2816
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:545](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3002
|
+
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)
|
|
2817
3003
|
|
|
2818
3004
|
Checks if the given item is a [key, value] entry pair.
|
|
2819
3005
|
|
|
@@ -2851,7 +3037,7 @@ Time O(1), Space O(1)
|
|
|
2851
3037
|
isLeaf(keyNodeOrEntry): boolean;
|
|
2852
3038
|
```
|
|
2853
3039
|
|
|
2854
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:531](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3040
|
+
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)
|
|
2855
3041
|
|
|
2856
3042
|
Checks if a node is a leaf (has no real children).
|
|
2857
3043
|
|
|
@@ -2889,7 +3075,7 @@ Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is pass
|
|
|
2889
3075
|
isNIL(keyNodeOrEntry): boolean;
|
|
2890
3076
|
```
|
|
2891
3077
|
|
|
2892
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:500](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3078
|
+
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)
|
|
2893
3079
|
|
|
2894
3080
|
Checks if the given item is the sentinel NIL node.
|
|
2895
3081
|
|
|
@@ -2927,7 +3113,7 @@ Time O(1), Space O(1)
|
|
|
2927
3113
|
isNode(keyNodeOrEntry): keyNodeOrEntry is AVLTreeNode<K, V>;
|
|
2928
3114
|
```
|
|
2929
3115
|
|
|
2930
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
3116
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:349](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L349)
|
|
2931
3117
|
|
|
2932
3118
|
Checks if the given item is an `AVLTreeNode` instance.
|
|
2933
3119
|
|
|
@@ -2965,7 +3151,7 @@ Time O(1), Space O(1)
|
|
|
2965
3151
|
isPerfectlyBalanced(startNode?): boolean;
|
|
2966
3152
|
```
|
|
2967
3153
|
|
|
2968
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3154
|
+
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)
|
|
2969
3155
|
|
|
2970
3156
|
Checks if the tree is perfectly balanced.
|
|
2971
3157
|
|
|
@@ -3008,7 +3194,7 @@ IBinaryTree.isPerfectlyBalanced
|
|
|
3008
3194
|
isRange(keyNodeEntryOrPredicate): keyNodeEntryOrPredicate is Range<K>;
|
|
3009
3195
|
```
|
|
3010
3196
|
|
|
3011
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:511](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3197
|
+
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)
|
|
3012
3198
|
|
|
3013
3199
|
Checks if the given item is a `Range` object.
|
|
3014
3200
|
|
|
@@ -3048,7 +3234,7 @@ Time O(1), Space O(1)
|
|
|
3048
3234
|
isRaw(keyNodeEntryOrRaw): keyNodeEntryOrRaw is R;
|
|
3049
3235
|
```
|
|
3050
3236
|
|
|
3051
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:460](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3237
|
+
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)
|
|
3052
3238
|
|
|
3053
3239
|
Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
3054
3240
|
|
|
@@ -3087,7 +3273,7 @@ Time O(1), Space O(1)
|
|
|
3087
3273
|
isRealNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
3088
3274
|
```
|
|
3089
3275
|
|
|
3090
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:473](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3276
|
+
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)
|
|
3091
3277
|
|
|
3092
3278
|
Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
3093
3279
|
|
|
@@ -3125,7 +3311,7 @@ Time O(1), Space O(1)
|
|
|
3125
3311
|
isRealNodeOrNull(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
3126
3312
|
```
|
|
3127
3313
|
|
|
3128
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:487](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3314
|
+
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)
|
|
3129
3315
|
|
|
3130
3316
|
Checks if the given item is either a "real" node or null.
|
|
3131
3317
|
|
|
@@ -3163,7 +3349,7 @@ Time O(1), Space O(1)
|
|
|
3163
3349
|
isValidKey(key): key is K;
|
|
3164
3350
|
```
|
|
3165
3351
|
|
|
3166
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3352
|
+
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)
|
|
3167
3353
|
|
|
3168
3354
|
Checks if the given key is valid (comparable).
|
|
3169
3355
|
|
|
@@ -3171,7 +3357,7 @@ Checks if the given key is valid (comparable).
|
|
|
3171
3357
|
|
|
3172
3358
|
##### key
|
|
3173
3359
|
|
|
3174
|
-
`
|
|
3360
|
+
`unknown`
|
|
3175
3361
|
|
|
3176
3362
|
The key to validate.
|
|
3177
3363
|
|
|
@@ -3197,7 +3383,7 @@ Time O(1)
|
|
|
3197
3383
|
keys(): IterableIterator<K>;
|
|
3198
3384
|
```
|
|
3199
3385
|
|
|
3200
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3386
|
+
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)
|
|
3201
3387
|
|
|
3202
3388
|
Iterate over keys only.
|
|
3203
3389
|
|
|
@@ -3253,7 +3439,7 @@ The traversal method.
|
|
|
3253
3439
|
leaves(): (K | undefined)[];
|
|
3254
3440
|
```
|
|
3255
3441
|
|
|
3256
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3442
|
+
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)
|
|
3257
3443
|
|
|
3258
3444
|
Get leaf nodes
|
|
3259
3445
|
|
|
@@ -3291,7 +3477,7 @@ leaves<C>(
|
|
|
3291
3477
|
iterationType?): ReturnType<C>[];
|
|
3292
3478
|
```
|
|
3293
3479
|
|
|
3294
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3480
|
+
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)
|
|
3295
3481
|
|
|
3296
3482
|
Get leaf nodes
|
|
3297
3483
|
|
|
@@ -3379,7 +3565,7 @@ The traversal method.
|
|
|
3379
3565
|
lesserOrGreaterTraverse(): (K | undefined)[];
|
|
3380
3566
|
```
|
|
3381
3567
|
|
|
3382
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3568
|
+
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)
|
|
3383
3569
|
|
|
3384
3570
|
##### Returns
|
|
3385
3571
|
|
|
@@ -3399,7 +3585,7 @@ lesserOrGreaterTraverse<C>(
|
|
|
3399
3585
|
iterationType?): ReturnType<C>[];
|
|
3400
3586
|
```
|
|
3401
3587
|
|
|
3402
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3588
|
+
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)
|
|
3403
3589
|
|
|
3404
3590
|
##### Type Parameters
|
|
3405
3591
|
|
|
@@ -3468,7 +3654,7 @@ The traversal method.
|
|
|
3468
3654
|
listLevels(): (K | undefined)[][];
|
|
3469
3655
|
```
|
|
3470
3656
|
|
|
3471
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3657
|
+
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)
|
|
3472
3658
|
|
|
3473
3659
|
Level-order grouping
|
|
3474
3660
|
|
|
@@ -3484,7 +3670,7 @@ Level-order grouping
|
|
|
3484
3670
|
// Level-order grouping
|
|
3485
3671
|
const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
3486
3672
|
const levels = bst.listLevels(node => node.key);
|
|
3487
|
-
console.log(levels
|
|
3673
|
+
console.log(levels); // toBeInstanceOf;
|
|
3488
3674
|
console.log(levels[0].length); // 1; // root level has 1 node
|
|
3489
3675
|
const allKeys = levels.flat().sort((a, b) => a - b);
|
|
3490
3676
|
console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -3509,7 +3695,7 @@ listLevels<C>(
|
|
|
3509
3695
|
iterationType?): ReturnType<C>[][];
|
|
3510
3696
|
```
|
|
3511
3697
|
|
|
3512
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3698
|
+
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)
|
|
3513
3699
|
|
|
3514
3700
|
Level-order grouping
|
|
3515
3701
|
|
|
@@ -3548,7 +3734,7 @@ Level-order grouping
|
|
|
3548
3734
|
// Level-order grouping
|
|
3549
3735
|
const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
3550
3736
|
const levels = bst.listLevels(node => node.key);
|
|
3551
|
-
console.log(levels
|
|
3737
|
+
console.log(levels); // toBeInstanceOf;
|
|
3552
3738
|
console.log(levels[0].length); // 1; // root level has 1 node
|
|
3553
3739
|
const allKeys = levels.flat().sort((a, b) => a - b);
|
|
3554
3740
|
console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -3574,7 +3760,7 @@ IBinaryTree.listLevels
|
|
|
3574
3760
|
lower(keyNodeEntryOrPredicate): K | undefined;
|
|
3575
3761
|
```
|
|
3576
3762
|
|
|
3577
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3763
|
+
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)
|
|
3578
3764
|
|
|
3579
3765
|
Returns the first key with a value < target.
|
|
3580
3766
|
Equivalent to Java TreeMap.lower.
|
|
@@ -3620,7 +3806,7 @@ lower<C>(
|
|
|
3620
3806
|
iterationType?): ReturnType<C>;
|
|
3621
3807
|
```
|
|
3622
3808
|
|
|
3623
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3809
|
+
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)
|
|
3624
3810
|
|
|
3625
3811
|
Returns the first node with a key < target and applies callback.
|
|
3626
3812
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -3670,7 +3856,7 @@ map<MK, MV, MR>(
|
|
|
3670
3856
|
thisArg?): AVLTree<MK, MV, MR>;
|
|
3671
3857
|
```
|
|
3672
3858
|
|
|
3673
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
3859
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:907](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L907)
|
|
3674
3860
|
|
|
3675
3861
|
Creates a new AVLTree by mapping each [key, value] pair.
|
|
3676
3862
|
|
|
@@ -3753,7 +3939,7 @@ IBinaryTree.map
|
|
|
3753
3939
|
merge(anotherTree): void;
|
|
3754
3940
|
```
|
|
3755
3941
|
|
|
3756
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3942
|
+
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)
|
|
3757
3943
|
|
|
3758
3944
|
Merges another tree into this one by seting all its nodes.
|
|
3759
3945
|
|
|
@@ -3827,7 +4013,7 @@ The node to start from.
|
|
|
3827
4013
|
morris(): (K | undefined)[];
|
|
3828
4014
|
```
|
|
3829
4015
|
|
|
3830
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4016
|
+
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)
|
|
3831
4017
|
|
|
3832
4018
|
Morris traversal (O(1) space)
|
|
3833
4019
|
|
|
@@ -3865,7 +4051,7 @@ morris<C>(
|
|
|
3865
4051
|
startNode?): ReturnType<C>[];
|
|
3866
4052
|
```
|
|
3867
4053
|
|
|
3868
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4054
|
+
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)
|
|
3869
4055
|
|
|
3870
4056
|
Morris traversal (O(1) space)
|
|
3871
4057
|
|
|
@@ -3925,7 +4111,7 @@ IBinaryTree.morris
|
|
|
3925
4111
|
perfectlyBalance(iterationType?): boolean;
|
|
3926
4112
|
```
|
|
3927
4113
|
|
|
3928
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4114
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:755](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L755)
|
|
3929
4115
|
|
|
3930
4116
|
Rebuilds the tree to be perfectly balanced.
|
|
3931
4117
|
|
|
@@ -3974,7 +4160,7 @@ Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and r
|
|
|
3974
4160
|
print(options?, startNode?): void;
|
|
3975
4161
|
```
|
|
3976
4162
|
|
|
3977
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4163
|
+
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)
|
|
3978
4164
|
|
|
3979
4165
|
Prints a visual representation of the tree to the console.
|
|
3980
4166
|
|
|
@@ -4019,6 +4205,108 @@ Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
|
4019
4205
|
|
|
4020
4206
|
***
|
|
4021
4207
|
|
|
4208
|
+
### rangeByRank()
|
|
4209
|
+
|
|
4210
|
+
#### Call Signature
|
|
4211
|
+
|
|
4212
|
+
```ts
|
|
4213
|
+
rangeByRank(start, end): (K | undefined)[];
|
|
4214
|
+
```
|
|
4215
|
+
|
|
4216
|
+
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)
|
|
4217
|
+
|
|
4218
|
+
Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
4219
|
+
|
|
4220
|
+
##### Parameters
|
|
4221
|
+
|
|
4222
|
+
###### start
|
|
4223
|
+
|
|
4224
|
+
`number`
|
|
4225
|
+
|
|
4226
|
+
Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
4227
|
+
|
|
4228
|
+
###### end
|
|
4229
|
+
|
|
4230
|
+
`number`
|
|
4231
|
+
|
|
4232
|
+
End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
4233
|
+
|
|
4234
|
+
##### Returns
|
|
4235
|
+
|
|
4236
|
+
(`K` \| `undefined`)[]
|
|
4237
|
+
|
|
4238
|
+
Array of keys in tree order within the specified range.
|
|
4239
|
+
|
|
4240
|
+
##### Remarks
|
|
4241
|
+
|
|
4242
|
+
Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
4243
|
+
|
|
4244
|
+
##### Inherited from
|
|
4245
|
+
|
|
4246
|
+
[`BST`](BST.md).[`rangeByRank`](BST.md#rangebyrank)
|
|
4247
|
+
|
|
4248
|
+
#### Call Signature
|
|
4249
|
+
|
|
4250
|
+
```ts
|
|
4251
|
+
rangeByRank<C>(
|
|
4252
|
+
start,
|
|
4253
|
+
end,
|
|
4254
|
+
callback,
|
|
4255
|
+
iterationType?): ReturnType<C>[];
|
|
4256
|
+
```
|
|
4257
|
+
|
|
4258
|
+
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)
|
|
4259
|
+
|
|
4260
|
+
Returns elements by position range in tree order with callback and optional iteration type.
|
|
4261
|
+
|
|
4262
|
+
##### Type Parameters
|
|
4263
|
+
|
|
4264
|
+
###### C
|
|
4265
|
+
|
|
4266
|
+
`C` *extends* `NodeCallback`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
4267
|
+
|
|
4268
|
+
##### Parameters
|
|
4269
|
+
|
|
4270
|
+
###### start
|
|
4271
|
+
|
|
4272
|
+
`number`
|
|
4273
|
+
|
|
4274
|
+
Start rank (inclusive, 0-indexed).
|
|
4275
|
+
|
|
4276
|
+
###### end
|
|
4277
|
+
|
|
4278
|
+
`number`
|
|
4279
|
+
|
|
4280
|
+
End rank (inclusive, 0-indexed).
|
|
4281
|
+
|
|
4282
|
+
###### callback
|
|
4283
|
+
|
|
4284
|
+
`C`
|
|
4285
|
+
|
|
4286
|
+
Callback to apply to each node in the range.
|
|
4287
|
+
|
|
4288
|
+
###### iterationType?
|
|
4289
|
+
|
|
4290
|
+
`IterationType`
|
|
4291
|
+
|
|
4292
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
4293
|
+
|
|
4294
|
+
##### Returns
|
|
4295
|
+
|
|
4296
|
+
`ReturnType`\<`C`\>[]
|
|
4297
|
+
|
|
4298
|
+
Array of callback results for nodes in the rank range.
|
|
4299
|
+
|
|
4300
|
+
##### Remarks
|
|
4301
|
+
|
|
4302
|
+
Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
4303
|
+
|
|
4304
|
+
##### Inherited from
|
|
4305
|
+
|
|
4306
|
+
[`BST`](BST.md).[`rangeByRank`](BST.md#rangebyrank)
|
|
4307
|
+
|
|
4308
|
+
***
|
|
4309
|
+
|
|
4022
4310
|
### rangeSearch()
|
|
4023
4311
|
|
|
4024
4312
|
Performs an optimized search for nodes within a given key range.
|
|
@@ -4053,7 +4341,7 @@ The traversal method.
|
|
|
4053
4341
|
rangeSearch(range): (K | undefined)[];
|
|
4054
4342
|
```
|
|
4055
4343
|
|
|
4056
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4344
|
+
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)
|
|
4057
4345
|
|
|
4058
4346
|
Find all keys in a range
|
|
4059
4347
|
|
|
@@ -4091,7 +4379,7 @@ rangeSearch<C>(
|
|
|
4091
4379
|
iterationType?): ReturnType<C>[];
|
|
4092
4380
|
```
|
|
4093
4381
|
|
|
4094
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4382
|
+
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)
|
|
4095
4383
|
|
|
4096
4384
|
Find all keys in a range
|
|
4097
4385
|
|
|
@@ -4148,7 +4436,7 @@ Find all keys in a range
|
|
|
4148
4436
|
reduce<U>(callbackfn, initialValue): U;
|
|
4149
4437
|
```
|
|
4150
4438
|
|
|
4151
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4439
|
+
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)
|
|
4152
4440
|
|
|
4153
4441
|
Reduce entries into a single accumulator.
|
|
4154
4442
|
|
|
@@ -4194,56 +4482,6 @@ IBinaryTree.reduce
|
|
|
4194
4482
|
|
|
4195
4483
|
***
|
|
4196
4484
|
|
|
4197
|
-
### refill()
|
|
4198
|
-
|
|
4199
|
-
```ts
|
|
4200
|
-
refill(keysNodesEntriesOrRaws, values?): void;
|
|
4201
|
-
```
|
|
4202
|
-
|
|
4203
|
-
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)
|
|
4204
|
-
|
|
4205
|
-
Clears the tree and refills it with new items.
|
|
4206
|
-
|
|
4207
|
-
#### Parameters
|
|
4208
|
-
|
|
4209
|
-
##### keysNodesEntriesOrRaws
|
|
4210
|
-
|
|
4211
|
-
`Iterable`\<
|
|
4212
|
-
\| `K`
|
|
4213
|
-
\| `R`
|
|
4214
|
-
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
4215
|
-
\| [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>
|
|
4216
|
-
\| `null`
|
|
4217
|
-
\| `undefined`\>
|
|
4218
|
-
|
|
4219
|
-
An iterable of items to set.
|
|
4220
|
-
|
|
4221
|
-
##### values?
|
|
4222
|
-
|
|
4223
|
-
`Iterable`\<`V` \| `undefined`, `any`, `any`\>
|
|
4224
|
-
|
|
4225
|
-
An optional parallel iterable of values.
|
|
4226
|
-
|
|
4227
|
-
#### Returns
|
|
4228
|
-
|
|
4229
|
-
`void`
|
|
4230
|
-
|
|
4231
|
-
#### Remarks
|
|
4232
|
-
|
|
4233
|
-
Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
4234
|
-
|
|
4235
|
-
#### Implementation of
|
|
4236
|
-
|
|
4237
|
-
```ts
|
|
4238
|
-
IBinaryTree.refill
|
|
4239
|
-
```
|
|
4240
|
-
|
|
4241
|
-
#### Inherited from
|
|
4242
|
-
|
|
4243
|
-
[`BST`](BST.md).[`refill`](BST.md#refill)
|
|
4244
|
-
|
|
4245
|
-
***
|
|
4246
|
-
|
|
4247
4485
|
### search()
|
|
4248
4486
|
|
|
4249
4487
|
Searches the tree for nodes matching a predicate, key, or range.
|
|
@@ -4284,7 +4522,7 @@ Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
|
4284
4522
|
search(keyNodeEntryOrPredicate, onlyOne?): (K | undefined)[];
|
|
4285
4523
|
```
|
|
4286
4524
|
|
|
4287
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4525
|
+
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)
|
|
4288
4526
|
|
|
4289
4527
|
Search nodes by predicate
|
|
4290
4528
|
|
|
@@ -4340,7 +4578,7 @@ search<C>(
|
|
|
4340
4578
|
iterationType?): ReturnType<C>[];
|
|
4341
4579
|
```
|
|
4342
4580
|
|
|
4343
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4581
|
+
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)
|
|
4344
4582
|
|
|
4345
4583
|
Search nodes by predicate
|
|
4346
4584
|
|
|
@@ -4414,7 +4652,7 @@ IBinaryTree.search
|
|
|
4414
4652
|
set(keyNodeOrEntry, value?): boolean;
|
|
4415
4653
|
```
|
|
4416
4654
|
|
|
4417
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4655
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:517](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L517)
|
|
4418
4656
|
|
|
4419
4657
|
Sets a new node to the AVL tree and balances the tree path.
|
|
4420
4658
|
|
|
@@ -4480,7 +4718,7 @@ setMany(
|
|
|
4480
4718
|
iterationType?): boolean[];
|
|
4481
4719
|
```
|
|
4482
4720
|
|
|
4483
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4721
|
+
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)
|
|
4484
4722
|
|
|
4485
4723
|
Adds multiple items to the tree.
|
|
4486
4724
|
|
|
@@ -4546,7 +4784,7 @@ Space O(N) for sorting and recursion/iteration stack.
|
|
|
4546
4784
|
some(predicate, thisArg?): boolean;
|
|
4547
4785
|
```
|
|
4548
4786
|
|
|
4549
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4787
|
+
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)
|
|
4550
4788
|
|
|
4551
4789
|
Test whether any entry satisfies the predicate.
|
|
4552
4790
|
|
|
@@ -4560,7 +4798,7 @@ Test whether any entry satisfies the predicate.
|
|
|
4560
4798
|
|
|
4561
4799
|
##### thisArg?
|
|
4562
4800
|
|
|
4563
|
-
`
|
|
4801
|
+
`unknown`
|
|
4564
4802
|
|
|
4565
4803
|
Optional `this` for callback.
|
|
4566
4804
|
|
|
@@ -4592,7 +4830,7 @@ IBinaryTree.some
|
|
|
4592
4830
|
toArray(): [K, V | undefined][];
|
|
4593
4831
|
```
|
|
4594
4832
|
|
|
4595
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4833
|
+
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)
|
|
4596
4834
|
|
|
4597
4835
|
Converts data structure to `[key, value]` pairs.
|
|
4598
4836
|
|
|
@@ -4618,7 +4856,7 @@ Time O(n), Space O(n)
|
|
|
4618
4856
|
toVisual(startNode?, options?): string;
|
|
4619
4857
|
```
|
|
4620
4858
|
|
|
4621
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4859
|
+
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)
|
|
4622
4860
|
|
|
4623
4861
|
Generates a string representation of the tree for visualization.
|
|
4624
4862
|
|
|
@@ -4661,7 +4899,7 @@ Time O(N), visits every node. Space O(N*H) or O(N^2) in the worst case, as the s
|
|
|
4661
4899
|
values(): IterableIterator<V | undefined>;
|
|
4662
4900
|
```
|
|
4663
4901
|
|
|
4664
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4902
|
+
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)
|
|
4665
4903
|
|
|
4666
4904
|
Iterate over values only.
|
|
4667
4905
|
|
|
@@ -4696,7 +4934,7 @@ IBinaryTree.values
|
|
|
4696
4934
|
protected readonly _comparator: Comparator<K>;
|
|
4697
4935
|
```
|
|
4698
4936
|
|
|
4699
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4937
|
+
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)
|
|
4700
4938
|
|
|
4701
4939
|
The comparator function used to determine the order of keys in the tree.
|
|
4702
4940
|
|
|
@@ -4716,7 +4954,7 @@ Time O(1) Space O(1)
|
|
|
4716
4954
|
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
4717
4955
|
```
|
|
4718
4956
|
|
|
4719
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4957
|
+
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)
|
|
4720
4958
|
|
|
4721
4959
|
(Protected) Default callback function, returns the node's key.
|
|
4722
4960
|
|
|
@@ -4744,7 +4982,7 @@ The node's key or undefined.
|
|
|
4744
4982
|
protected _balanceFactor(node): number;
|
|
4745
4983
|
```
|
|
4746
4984
|
|
|
4747
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
4985
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1005](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1005)
|
|
4748
4986
|
|
|
4749
4987
|
(Protected) Calculates the balance factor (height(right) - height(left)).
|
|
4750
4988
|
|
|
@@ -4774,7 +5012,7 @@ Time O(1) (assumes heights are stored).
|
|
|
4774
5012
|
protected _balanceLL(A): void;
|
|
4775
5013
|
```
|
|
4776
5014
|
|
|
4777
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5015
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1029](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1029)
|
|
4778
5016
|
|
|
4779
5017
|
(Protected) Performs a Left-Left (LL) rotation (a single right rotation).
|
|
4780
5018
|
|
|
@@ -4802,7 +5040,7 @@ Time O(1), Space O(1)
|
|
|
4802
5040
|
protected _balanceLR(A): void;
|
|
4803
5041
|
```
|
|
4804
5042
|
|
|
4805
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5043
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1066](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1066)
|
|
4806
5044
|
|
|
4807
5045
|
(Protected) Performs a Left-Right (LR) double rotation.
|
|
4808
5046
|
|
|
@@ -4830,7 +5068,7 @@ Time O(1), Space O(1)
|
|
|
4830
5068
|
protected _balancePath(node): void;
|
|
4831
5069
|
```
|
|
4832
5070
|
|
|
4833
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5071
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1216](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1216)
|
|
4834
5072
|
|
|
4835
5073
|
(Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
|
|
4836
5074
|
|
|
@@ -4862,7 +5100,7 @@ Time O(log N) (O(H)), as it traverses the path to root. Space O(H) for the path
|
|
|
4862
5100
|
protected _balanceRL(A): void;
|
|
4863
5101
|
```
|
|
4864
5102
|
|
|
4865
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5103
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1162](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1162)
|
|
4866
5104
|
|
|
4867
5105
|
(Protected) Performs a Right-Left (RL) double rotation.
|
|
4868
5106
|
|
|
@@ -4890,7 +5128,7 @@ Time O(1), Space O(1)
|
|
|
4890
5128
|
protected _balanceRR(A): void;
|
|
4891
5129
|
```
|
|
4892
5130
|
|
|
4893
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5131
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1121](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1121)
|
|
4894
5132
|
|
|
4895
5133
|
(Protected) Performs a Right-Right (RR) rotation (a single left rotation).
|
|
4896
5134
|
|
|
@@ -4921,7 +5159,7 @@ protected _bound(
|
|
|
4921
5159
|
iterationType): BSTNode<K, V> | undefined;
|
|
4922
5160
|
```
|
|
4923
5161
|
|
|
4924
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5162
|
+
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)
|
|
4925
5163
|
|
|
4926
5164
|
(Protected) Core bound search implementation supporting all parameter types.
|
|
4927
5165
|
Unified logic for both lowerBound and upperBound.
|
|
@@ -4973,7 +5211,7 @@ protected _boundByKey(
|
|
|
4973
5211
|
iterationType): BSTNode<K, V> | undefined;
|
|
4974
5212
|
```
|
|
4975
5213
|
|
|
4976
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5214
|
+
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)
|
|
4977
5215
|
|
|
4978
5216
|
(Protected) Binary search for bound by key with pruning optimization.
|
|
4979
5217
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5018,7 +5256,7 @@ The first node matching the bound condition, or undefined if none exists.
|
|
|
5018
5256
|
protected _boundByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5019
5257
|
```
|
|
5020
5258
|
|
|
5021
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5259
|
+
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)
|
|
5022
5260
|
|
|
5023
5261
|
(Protected) In-order traversal search by predicate.
|
|
5024
5262
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5058,7 +5296,7 @@ The first node satisfying predicate, or undefined if none found.
|
|
|
5058
5296
|
protected _clearNodes(): void;
|
|
5059
5297
|
```
|
|
5060
5298
|
|
|
5061
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5299
|
+
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)
|
|
5062
5300
|
|
|
5063
5301
|
(Protected) Clears all nodes from the tree.
|
|
5064
5302
|
|
|
@@ -5082,7 +5320,7 @@ Time O(1)
|
|
|
5082
5320
|
protected _clearValues(): void;
|
|
5083
5321
|
```
|
|
5084
5322
|
|
|
5085
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5323
|
+
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)
|
|
5086
5324
|
|
|
5087
5325
|
(Protected) Clears all values from the external store.
|
|
5088
5326
|
|
|
@@ -5106,7 +5344,7 @@ Time O(N)
|
|
|
5106
5344
|
protected _clone(cloned): void;
|
|
5107
5345
|
```
|
|
5108
5346
|
|
|
5109
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5347
|
+
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)
|
|
5110
5348
|
|
|
5111
5349
|
(Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
5112
5350
|
|
|
@@ -5138,7 +5376,7 @@ Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
|
5138
5376
|
protected _compare(a, b): number;
|
|
5139
5377
|
```
|
|
5140
5378
|
|
|
5141
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5379
|
+
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)
|
|
5142
5380
|
|
|
5143
5381
|
(Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
5144
5382
|
|
|
@@ -5178,7 +5416,7 @@ Time O(1) Space O(1)
|
|
|
5178
5416
|
protected _createDefaultComparator(): Comparator<K>;
|
|
5179
5417
|
```
|
|
5180
5418
|
|
|
5181
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5419
|
+
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)
|
|
5182
5420
|
|
|
5183
5421
|
(Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
5184
5422
|
|
|
@@ -5204,7 +5442,7 @@ Time O(1) Space O(1)
|
|
|
5204
5442
|
protected _createInstance<TK, TV, TR>(options?): this;
|
|
5205
5443
|
```
|
|
5206
5444
|
|
|
5207
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5445
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:931](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L931)
|
|
5208
5446
|
|
|
5209
5447
|
(Protected) Creates a new, empty instance of the same AVLTree constructor.
|
|
5210
5448
|
|
|
@@ -5252,7 +5490,7 @@ Time O(1)
|
|
|
5252
5490
|
protected _createLike<TK, TV, TR>(iter?, options?): AVLTree<TK, TV, TR>;
|
|
5253
5491
|
```
|
|
5254
5492
|
|
|
5255
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
5493
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:948](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L948)
|
|
5256
5494
|
|
|
5257
5495
|
(Protected) Creates a new instance of the same AVLTree constructor, potentially with different generic types.
|
|
5258
5496
|
|
|
@@ -5312,7 +5550,7 @@ Time O(N log N) (from constructor) due to processing the iterable.
|
|
|
5312
5550
|
protected _deleteByKey(key): boolean;
|
|
5313
5551
|
```
|
|
5314
5552
|
|
|
5315
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5553
|
+
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)
|
|
5316
5554
|
|
|
5317
5555
|
(Private) Deletes a node by its key.
|
|
5318
5556
|
|
|
@@ -5340,6 +5578,44 @@ Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
|
|
|
5340
5578
|
|
|
5341
5579
|
***
|
|
5342
5580
|
|
|
5581
|
+
### \_deleteInternal()
|
|
5582
|
+
|
|
5583
|
+
```ts
|
|
5584
|
+
protected _deleteInternal(keyNodeEntryRawOrPredicate): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
5585
|
+
```
|
|
5586
|
+
|
|
5587
|
+
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)
|
|
5588
|
+
|
|
5589
|
+
**`Internal`**
|
|
5590
|
+
|
|
5591
|
+
Deletes a node from the tree (internal, returns balancing metadata).
|
|
5592
|
+
|
|
5593
|
+
#### Parameters
|
|
5594
|
+
|
|
5595
|
+
##### keyNodeEntryRawOrPredicate
|
|
5596
|
+
|
|
5597
|
+
\| `BTNRep`\<`K`, `V`, [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>
|
|
5598
|
+
\| `NodePredicate`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\> \| `null`\>
|
|
5599
|
+
|
|
5600
|
+
The node to delete.
|
|
5601
|
+
|
|
5602
|
+
#### Returns
|
|
5603
|
+
|
|
5604
|
+
`BinaryTreeDeleteResult`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>[]
|
|
5605
|
+
|
|
5606
|
+
An array containing deletion results with balancing metadata.
|
|
5607
|
+
|
|
5608
|
+
#### Remarks
|
|
5609
|
+
|
|
5610
|
+
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).
|
|
5611
|
+
Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
5612
|
+
|
|
5613
|
+
#### Inherited from
|
|
5614
|
+
|
|
5615
|
+
[`BST`](BST.md).[`_deleteInternal`](BST.md#_deleteinternal)
|
|
5616
|
+
|
|
5617
|
+
***
|
|
5618
|
+
|
|
5343
5619
|
### \_dfs()
|
|
5344
5620
|
|
|
5345
5621
|
```ts
|
|
@@ -5356,7 +5632,7 @@ protected _dfs<C>(
|
|
|
5356
5632
|
shouldProcessRoot?): ReturnType<C>[];
|
|
5357
5633
|
```
|
|
5358
5634
|
|
|
5359
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5635
|
+
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)
|
|
5360
5636
|
|
|
5361
5637
|
#### Type Parameters
|
|
5362
5638
|
|
|
@@ -5449,7 +5725,7 @@ Array of callback results.
|
|
|
5449
5725
|
protected _displayAux(node, options): NodeDisplayLayout;
|
|
5450
5726
|
```
|
|
5451
5727
|
|
|
5452
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5728
|
+
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)
|
|
5453
5729
|
|
|
5454
5730
|
(Protected) Recursive helper for `toVisual`.
|
|
5455
5731
|
|
|
@@ -5489,7 +5765,7 @@ Time O(N), Space O(N*H) or O(N^2)
|
|
|
5489
5765
|
protected _ensurePredicate(keyNodeEntryOrPredicate): NodePredicate<BinaryTreeNode<K, V>>;
|
|
5490
5766
|
```
|
|
5491
5767
|
|
|
5492
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5768
|
+
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)
|
|
5493
5769
|
|
|
5494
5770
|
(Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
5495
5771
|
|
|
@@ -5528,7 +5804,7 @@ Time O(1)
|
|
|
5528
5804
|
protected _extractKey(keyNodeOrEntry): K | null | undefined;
|
|
5529
5805
|
```
|
|
5530
5806
|
|
|
5531
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5807
|
+
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)
|
|
5532
5808
|
|
|
5533
5809
|
(Protected) Extracts the key from a key, node, or entry.
|
|
5534
5810
|
|
|
@@ -5566,7 +5842,7 @@ Time O(1)
|
|
|
5566
5842
|
protected _floorByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5567
5843
|
```
|
|
5568
5844
|
|
|
5569
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5845
|
+
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)
|
|
5570
5846
|
|
|
5571
5847
|
(Protected) Binary search for floor by key with pruning optimization.
|
|
5572
5848
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5608,7 +5884,7 @@ Time O(h) where h is tree height.
|
|
|
5608
5884
|
protected _floorByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5609
5885
|
```
|
|
5610
5886
|
|
|
5611
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5887
|
+
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)
|
|
5612
5888
|
|
|
5613
5889
|
(Protected) In-order traversal search for floor by predicate.
|
|
5614
5890
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5645,13 +5921,81 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5645
5921
|
|
|
5646
5922
|
***
|
|
5647
5923
|
|
|
5924
|
+
### \_getByRankIterative()
|
|
5925
|
+
|
|
5926
|
+
```ts
|
|
5927
|
+
protected _getByRankIterative(node, k): BSTNode<K, V> | undefined;
|
|
5928
|
+
```
|
|
5929
|
+
|
|
5930
|
+
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)
|
|
5931
|
+
|
|
5932
|
+
(Protected) Finds the node at position k in tree order (iterative).
|
|
5933
|
+
|
|
5934
|
+
#### Parameters
|
|
5935
|
+
|
|
5936
|
+
##### node
|
|
5937
|
+
|
|
5938
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5939
|
+
|
|
5940
|
+
##### k
|
|
5941
|
+
|
|
5942
|
+
`number`
|
|
5943
|
+
|
|
5944
|
+
#### Returns
|
|
5945
|
+
|
|
5946
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5947
|
+
|
|
5948
|
+
#### Remarks
|
|
5949
|
+
|
|
5950
|
+
Time O(log n), Space O(1)
|
|
5951
|
+
|
|
5952
|
+
#### Inherited from
|
|
5953
|
+
|
|
5954
|
+
[`BST`](BST.md).[`_getByRankIterative`](BST.md#_getbyrankiterative)
|
|
5955
|
+
|
|
5956
|
+
***
|
|
5957
|
+
|
|
5958
|
+
### \_getByRankRecursive()
|
|
5959
|
+
|
|
5960
|
+
```ts
|
|
5961
|
+
protected _getByRankRecursive(node, k): BSTNode<K, V> | undefined;
|
|
5962
|
+
```
|
|
5963
|
+
|
|
5964
|
+
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)
|
|
5965
|
+
|
|
5966
|
+
(Protected) Finds the node at position k in tree order (recursive).
|
|
5967
|
+
|
|
5968
|
+
#### Parameters
|
|
5969
|
+
|
|
5970
|
+
##### node
|
|
5971
|
+
|
|
5972
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5973
|
+
|
|
5974
|
+
##### k
|
|
5975
|
+
|
|
5976
|
+
`number`
|
|
5977
|
+
|
|
5978
|
+
#### Returns
|
|
5979
|
+
|
|
5980
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5981
|
+
|
|
5982
|
+
#### Remarks
|
|
5983
|
+
|
|
5984
|
+
Time O(log n), Space O(log n) call stack
|
|
5985
|
+
|
|
5986
|
+
#### Inherited from
|
|
5987
|
+
|
|
5988
|
+
[`BST`](BST.md).[`_getByRankRecursive`](BST.md#_getbyrankrecursive)
|
|
5989
|
+
|
|
5990
|
+
***
|
|
5991
|
+
|
|
5648
5992
|
### \_getIterator()
|
|
5649
5993
|
|
|
5650
5994
|
```ts
|
|
5651
5995
|
protected _getIterator(node?): IterableIterator<[K, V | undefined]>;
|
|
5652
5996
|
```
|
|
5653
5997
|
|
|
5654
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5998
|
+
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)
|
|
5655
5999
|
|
|
5656
6000
|
(Protected) Gets the iterator for the tree (default in-order).
|
|
5657
6001
|
|
|
@@ -5679,13 +6023,81 @@ Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the
|
|
|
5679
6023
|
|
|
5680
6024
|
***
|
|
5681
6025
|
|
|
6026
|
+
### \_getRankIterative()
|
|
6027
|
+
|
|
6028
|
+
```ts
|
|
6029
|
+
protected _getRankIterative(node, key): number;
|
|
6030
|
+
```
|
|
6031
|
+
|
|
6032
|
+
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)
|
|
6033
|
+
|
|
6034
|
+
(Protected) Computes the rank of a key iteratively.
|
|
6035
|
+
|
|
6036
|
+
#### Parameters
|
|
6037
|
+
|
|
6038
|
+
##### node
|
|
6039
|
+
|
|
6040
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
6041
|
+
|
|
6042
|
+
##### key
|
|
6043
|
+
|
|
6044
|
+
`K`
|
|
6045
|
+
|
|
6046
|
+
#### Returns
|
|
6047
|
+
|
|
6048
|
+
`number`
|
|
6049
|
+
|
|
6050
|
+
#### Remarks
|
|
6051
|
+
|
|
6052
|
+
Time O(log n), Space O(1)
|
|
6053
|
+
|
|
6054
|
+
#### Inherited from
|
|
6055
|
+
|
|
6056
|
+
[`BST`](BST.md).[`_getRankIterative`](BST.md#_getrankiterative)
|
|
6057
|
+
|
|
6058
|
+
***
|
|
6059
|
+
|
|
6060
|
+
### \_getRankRecursive()
|
|
6061
|
+
|
|
6062
|
+
```ts
|
|
6063
|
+
protected _getRankRecursive(node, key): number;
|
|
6064
|
+
```
|
|
6065
|
+
|
|
6066
|
+
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)
|
|
6067
|
+
|
|
6068
|
+
(Protected) Computes the rank of a key recursively.
|
|
6069
|
+
|
|
6070
|
+
#### Parameters
|
|
6071
|
+
|
|
6072
|
+
##### node
|
|
6073
|
+
|
|
6074
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
6075
|
+
|
|
6076
|
+
##### key
|
|
6077
|
+
|
|
6078
|
+
`K`
|
|
6079
|
+
|
|
6080
|
+
#### Returns
|
|
6081
|
+
|
|
6082
|
+
`number`
|
|
6083
|
+
|
|
6084
|
+
#### Remarks
|
|
6085
|
+
|
|
6086
|
+
Time O(log n), Space O(log n) call stack
|
|
6087
|
+
|
|
6088
|
+
#### Inherited from
|
|
6089
|
+
|
|
6090
|
+
[`BST`](BST.md).[`_getRankRecursive`](BST.md#_getrankrecursive)
|
|
6091
|
+
|
|
6092
|
+
***
|
|
6093
|
+
|
|
5682
6094
|
### \_isDisplayLeaf()
|
|
5683
6095
|
|
|
5684
6096
|
```ts
|
|
5685
6097
|
protected _isDisplayLeaf(node, options): boolean;
|
|
5686
6098
|
```
|
|
5687
6099
|
|
|
5688
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6100
|
+
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)
|
|
5689
6101
|
|
|
5690
6102
|
Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
5691
6103
|
|
|
@@ -5715,7 +6127,7 @@ Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
|
5715
6127
|
protected _isPredicate(p): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
5716
6128
|
```
|
|
5717
6129
|
|
|
5718
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6130
|
+
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)
|
|
5719
6131
|
|
|
5720
6132
|
(Protected) Checks if an item is a predicate function.
|
|
5721
6133
|
|
|
@@ -5723,7 +6135,7 @@ Defined in: [data-structures/binary-tree/binary-tree.ts:3305](https://github.com
|
|
|
5723
6135
|
|
|
5724
6136
|
##### p
|
|
5725
6137
|
|
|
5726
|
-
`
|
|
6138
|
+
`unknown`
|
|
5727
6139
|
|
|
5728
6140
|
The item to check.
|
|
5729
6141
|
|
|
@@ -5749,7 +6161,7 @@ Time O(1)
|
|
|
5749
6161
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value?): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
5750
6162
|
```
|
|
5751
6163
|
|
|
5752
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6164
|
+
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)
|
|
5753
6165
|
|
|
5754
6166
|
(Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
5755
6167
|
|
|
@@ -5793,7 +6205,7 @@ Time O(1)
|
|
|
5793
6205
|
protected _lowerByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5794
6206
|
```
|
|
5795
6207
|
|
|
5796
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6208
|
+
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)
|
|
5797
6209
|
|
|
5798
6210
|
(Protected) Binary search for lower by key with pruning optimization.
|
|
5799
6211
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5835,7 +6247,7 @@ Time O(h) where h is tree height.
|
|
|
5835
6247
|
protected _lowerByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5836
6248
|
```
|
|
5837
6249
|
|
|
5838
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6250
|
+
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)
|
|
5839
6251
|
|
|
5840
6252
|
(Protected) In-order traversal search for lower by predicate.
|
|
5841
6253
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5872,13 +6284,43 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5872
6284
|
|
|
5873
6285
|
***
|
|
5874
6286
|
|
|
6287
|
+
### \_next()
|
|
6288
|
+
|
|
6289
|
+
```ts
|
|
6290
|
+
protected _next(node): BSTNode<K, V> | undefined;
|
|
6291
|
+
```
|
|
6292
|
+
|
|
6293
|
+
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)
|
|
6294
|
+
|
|
6295
|
+
(Protected) Finds the in-order successor of a node.
|
|
6296
|
+
|
|
6297
|
+
#### Parameters
|
|
6298
|
+
|
|
6299
|
+
##### node
|
|
6300
|
+
|
|
6301
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
6302
|
+
|
|
6303
|
+
#### Returns
|
|
6304
|
+
|
|
6305
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
6306
|
+
|
|
6307
|
+
#### Remarks
|
|
6308
|
+
|
|
6309
|
+
Time O(log n), Space O(1)
|
|
6310
|
+
|
|
6311
|
+
#### Inherited from
|
|
6312
|
+
|
|
6313
|
+
[`BST`](BST.md).[`_next`](BST.md#_next)
|
|
6314
|
+
|
|
6315
|
+
***
|
|
6316
|
+
|
|
5875
6317
|
### \_replaceNode()
|
|
5876
6318
|
|
|
5877
6319
|
```ts
|
|
5878
6320
|
protected _replaceNode(oldNode, newNode): AVLTreeNode<K, V>;
|
|
5879
6321
|
```
|
|
5880
6322
|
|
|
5881
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
6323
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1264](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1264)
|
|
5882
6324
|
|
|
5883
6325
|
(Protected) Replaces a node, ensuring height is copied.
|
|
5884
6326
|
|
|
@@ -5921,7 +6363,7 @@ protected _resolveDisplayLeaf(
|
|
|
5921
6363
|
emptyDisplayLayout): NodeDisplayLayout;
|
|
5922
6364
|
```
|
|
5923
6365
|
|
|
5924
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6366
|
+
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)
|
|
5925
6367
|
|
|
5926
6368
|
Resolve a display leaf node to its layout.
|
|
5927
6369
|
|
|
@@ -5955,7 +6397,7 @@ Resolve a display leaf node to its layout.
|
|
|
5955
6397
|
protected _setRoot(v): void;
|
|
5956
6398
|
```
|
|
5957
6399
|
|
|
5958
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6400
|
+
Defined in: [data-structures/binary-tree/bst.ts:3356](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3356)
|
|
5959
6401
|
|
|
5960
6402
|
(Protected) Sets the root node and clears its parent reference.
|
|
5961
6403
|
|
|
@@ -5987,7 +6429,7 @@ Time O(1)
|
|
|
5987
6429
|
protected _setValue(key, value): boolean;
|
|
5988
6430
|
```
|
|
5989
6431
|
|
|
5990
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6432
|
+
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)
|
|
5991
6433
|
|
|
5992
6434
|
(Protected) Sets a value in the external store (Map mode).
|
|
5993
6435
|
|
|
@@ -6027,7 +6469,7 @@ Time O(1) (average for Map.set).
|
|
|
6027
6469
|
protected _snapshotOptions<TK, TV, TR>(): BSTOptions<TK, TV, TR>;
|
|
6028
6470
|
```
|
|
6029
6471
|
|
|
6030
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6472
|
+
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)
|
|
6031
6473
|
|
|
6032
6474
|
(Protected) Snapshots the current BST's configuration options.
|
|
6033
6475
|
|
|
@@ -6067,7 +6509,7 @@ Time O(1)
|
|
|
6067
6509
|
protected _swapProperties(srcNode, destNode): AVLTreeNode<K, V> | undefined;
|
|
6068
6510
|
```
|
|
6069
6511
|
|
|
6070
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
6512
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:967](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L967)
|
|
6071
6513
|
|
|
6072
6514
|
(Protected) Swaps properties of two nodes, including height.
|
|
6073
6515
|
|
|
@@ -6101,13 +6543,73 @@ Time O(H) (due to `ensureNode`), but O(1) if nodes are passed directly.
|
|
|
6101
6543
|
|
|
6102
6544
|
***
|
|
6103
6545
|
|
|
6546
|
+
### \_updateCount()
|
|
6547
|
+
|
|
6548
|
+
```ts
|
|
6549
|
+
protected _updateCount(node): void;
|
|
6550
|
+
```
|
|
6551
|
+
|
|
6552
|
+
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)
|
|
6553
|
+
|
|
6554
|
+
(Protected) Recalculates the subtree count for a single node.
|
|
6555
|
+
|
|
6556
|
+
#### Parameters
|
|
6557
|
+
|
|
6558
|
+
##### node
|
|
6559
|
+
|
|
6560
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
6561
|
+
|
|
6562
|
+
#### Returns
|
|
6563
|
+
|
|
6564
|
+
`void`
|
|
6565
|
+
|
|
6566
|
+
#### Remarks
|
|
6567
|
+
|
|
6568
|
+
Time O(1). Only active when enableOrderStatistic is true.
|
|
6569
|
+
|
|
6570
|
+
#### Inherited from
|
|
6571
|
+
|
|
6572
|
+
[`BST`](BST.md).[`_updateCount`](BST.md#_updatecount)
|
|
6573
|
+
|
|
6574
|
+
***
|
|
6575
|
+
|
|
6576
|
+
### \_updateCountAlongPath()
|
|
6577
|
+
|
|
6578
|
+
```ts
|
|
6579
|
+
protected _updateCountAlongPath(node): void;
|
|
6580
|
+
```
|
|
6581
|
+
|
|
6582
|
+
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)
|
|
6583
|
+
|
|
6584
|
+
(Protected) Updates subtree counts from a node up to the root.
|
|
6585
|
+
|
|
6586
|
+
#### Parameters
|
|
6587
|
+
|
|
6588
|
+
##### node
|
|
6589
|
+
|
|
6590
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
6591
|
+
|
|
6592
|
+
#### Returns
|
|
6593
|
+
|
|
6594
|
+
`void`
|
|
6595
|
+
|
|
6596
|
+
#### Remarks
|
|
6597
|
+
|
|
6598
|
+
Time O(log n). Only active when enableOrderStatistic is true.
|
|
6599
|
+
|
|
6600
|
+
#### Inherited from
|
|
6601
|
+
|
|
6602
|
+
[`BST`](BST.md).[`_updateCountAlongPath`](BST.md#_updatecountalongpath)
|
|
6603
|
+
|
|
6604
|
+
***
|
|
6605
|
+
|
|
6104
6606
|
### \_updateHeight()
|
|
6105
6607
|
|
|
6106
6608
|
```ts
|
|
6107
6609
|
protected _updateHeight(node): void;
|
|
6108
6610
|
```
|
|
6109
6611
|
|
|
6110
|
-
Defined in: [data-structures/binary-tree/avl-tree.ts:
|
|
6612
|
+
Defined in: [data-structures/binary-tree/avl-tree.ts:1017](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/avl-tree.ts#L1017)
|
|
6111
6613
|
|
|
6112
6614
|
(Protected) Recalculates and updates the height of a node based on its children's heights.
|
|
6113
6615
|
|