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: BST\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
9
|
+
Defined in: [data-structures/binary-tree/bst.ts:326](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L326)
|
|
10
10
|
|
|
11
11
|
Represents a Binary Search Tree (BST).
|
|
12
12
|
Keys are ordered, allowing for faster search operations compared to a standard Binary Tree.
|
|
@@ -188,7 +188,7 @@ The type of the raw data object (if using `toEntryFn`).
|
|
|
188
188
|
new BST<K, V, R>(keysNodesEntriesOrRaws?, options?): BST<K, V, R>;
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
191
|
+
Defined in: [data-structures/binary-tree/bst.ts:334](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L334)
|
|
192
192
|
|
|
193
193
|
Creates an instance of BST.
|
|
194
194
|
|
|
@@ -234,7 +234,7 @@ Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input ord
|
|
|
234
234
|
get comparator(): Comparator<K>;
|
|
235
235
|
```
|
|
236
236
|
|
|
237
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
237
|
+
Defined in: [data-structures/binary-tree/bst.ts:384](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L384)
|
|
238
238
|
|
|
239
239
|
Gets the comparator function used by the tree.
|
|
240
240
|
|
|
@@ -258,7 +258,7 @@ The comparator function.
|
|
|
258
258
|
get isDuplicate(): boolean;
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:322](https://github.com/zrwusa/data-structure-typed/blob/
|
|
261
|
+
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)
|
|
262
262
|
|
|
263
263
|
Gets whether the tree allows duplicate keys.
|
|
264
264
|
|
|
@@ -292,7 +292,7 @@ IBinaryTree.isDuplicate
|
|
|
292
292
|
get isMapMode(): boolean;
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:310](https://github.com/zrwusa/data-structure-typed/blob/
|
|
295
|
+
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)
|
|
296
296
|
|
|
297
297
|
Gets whether the tree is in Map mode.
|
|
298
298
|
|
|
@@ -326,7 +326,7 @@ IBinaryTree.isMapMode
|
|
|
326
326
|
get NIL(): BinaryTreeNode<K, V>;
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:373](https://github.com/zrwusa/data-structure-typed/blob/
|
|
329
|
+
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)
|
|
330
330
|
|
|
331
331
|
Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
332
332
|
|
|
@@ -360,7 +360,7 @@ IBinaryTree.NIL
|
|
|
360
360
|
get root(): OptNode<BSTNode<K, V>>;
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
363
|
+
Defined in: [data-structures/binary-tree/bst.ts:367](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L367)
|
|
364
364
|
|
|
365
365
|
Gets the root node of the tree.
|
|
366
366
|
|
|
@@ -394,7 +394,7 @@ IBinaryTree.root
|
|
|
394
394
|
get size(): number;
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:361](https://github.com/zrwusa/data-structure-typed/blob/
|
|
397
|
+
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)
|
|
398
398
|
|
|
399
399
|
Gets the number of nodes in the tree.
|
|
400
400
|
|
|
@@ -428,7 +428,7 @@ IBinaryTree.size
|
|
|
428
428
|
get store(): Map<K, BinaryTreeNode<K, V>>;
|
|
429
429
|
```
|
|
430
430
|
|
|
431
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:337](https://github.com/zrwusa/data-structure-typed/blob/
|
|
431
|
+
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)
|
|
432
432
|
|
|
433
433
|
Gets the external value store (used in Map mode).
|
|
434
434
|
|
|
@@ -462,7 +462,7 @@ IBinaryTree.store
|
|
|
462
462
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
463
463
|
```
|
|
464
464
|
|
|
465
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:385](https://github.com/zrwusa/data-structure-typed/blob/
|
|
465
|
+
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)
|
|
466
466
|
|
|
467
467
|
Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
468
468
|
|
|
@@ -494,7 +494,7 @@ IBinaryTree.toEntryFn
|
|
|
494
494
|
iterator: IterableIterator<[K, V | undefined]>;
|
|
495
495
|
```
|
|
496
496
|
|
|
497
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/
|
|
497
|
+
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)
|
|
498
498
|
|
|
499
499
|
Default iterator yielding `[key, value]` entries.
|
|
500
500
|
|
|
@@ -502,7 +502,7 @@ Default iterator yielding `[key, value]` entries.
|
|
|
502
502
|
|
|
503
503
|
##### args
|
|
504
504
|
|
|
505
|
-
...`
|
|
505
|
+
...`unknown`[]
|
|
506
506
|
|
|
507
507
|
#### Returns
|
|
508
508
|
|
|
@@ -532,7 +532,7 @@ IBinaryTree.[iterator]
|
|
|
532
532
|
add(keyNodeOrEntry): boolean;
|
|
533
533
|
```
|
|
534
534
|
|
|
535
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
535
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:612](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L612)
|
|
536
536
|
|
|
537
537
|
Adds a new node to the tree.
|
|
538
538
|
|
|
@@ -558,7 +558,7 @@ True if the addition was successful, false otherwise.
|
|
|
558
558
|
|
|
559
559
|
#### Remarks
|
|
560
560
|
|
|
561
|
-
Time O(
|
|
561
|
+
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).
|
|
562
562
|
|
|
563
563
|
#### Example
|
|
564
564
|
|
|
@@ -590,7 +590,7 @@ IBinaryTree.add
|
|
|
590
590
|
addMany(keysNodesEntriesOrRaws): boolean[];
|
|
591
591
|
```
|
|
592
592
|
|
|
593
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
593
|
+
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)
|
|
594
594
|
|
|
595
595
|
Adds multiple items to the tree.
|
|
596
596
|
|
|
@@ -671,7 +671,7 @@ The traversal method.
|
|
|
671
671
|
bfs(): (K | undefined)[];
|
|
672
672
|
```
|
|
673
673
|
|
|
674
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
674
|
+
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)
|
|
675
675
|
|
|
676
676
|
BinaryTree level-order traversal
|
|
677
677
|
|
|
@@ -709,7 +709,7 @@ bfs<C>(
|
|
|
709
709
|
iterationType?): ReturnType<C>[];
|
|
710
710
|
```
|
|
711
711
|
|
|
712
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
712
|
+
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)
|
|
713
713
|
|
|
714
714
|
BinaryTree level-order traversal
|
|
715
715
|
|
|
@@ -771,7 +771,7 @@ IBinaryTree.bfs
|
|
|
771
771
|
ceiling(keyNodeEntryOrPredicate): K | undefined;
|
|
772
772
|
```
|
|
773
773
|
|
|
774
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
774
|
+
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)
|
|
775
775
|
|
|
776
776
|
Returns the first key with a value >= target.
|
|
777
777
|
Equivalent to Java TreeMap.ceiling.
|
|
@@ -814,7 +814,7 @@ ceiling<C>(
|
|
|
814
814
|
iterationType?): ReturnType<C>;
|
|
815
815
|
```
|
|
816
816
|
|
|
817
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
817
|
+
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)
|
|
818
818
|
|
|
819
819
|
Returns the first node with a key >= target and applies callback.
|
|
820
820
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -857,7 +857,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
857
857
|
clear(): void;
|
|
858
858
|
```
|
|
859
859
|
|
|
860
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
860
|
+
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)
|
|
861
861
|
|
|
862
862
|
Clears the tree of all nodes and values.
|
|
863
863
|
|
|
@@ -898,7 +898,7 @@ IBinaryTree.clear
|
|
|
898
898
|
clone(): this;
|
|
899
899
|
```
|
|
900
900
|
|
|
901
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
901
|
+
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)
|
|
902
902
|
|
|
903
903
|
Clones the tree.
|
|
904
904
|
|
|
@@ -942,7 +942,7 @@ IBinaryTree.clone
|
|
|
942
942
|
createNode(key, value?): BSTNode<K, V>;
|
|
943
943
|
```
|
|
944
944
|
|
|
945
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
945
|
+
Defined in: [data-structures/binary-tree/bst.ts:396](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L396)
|
|
946
946
|
|
|
947
947
|
(Protected) Creates a new BST node.
|
|
948
948
|
|
|
@@ -988,7 +988,7 @@ IBinaryTree.createNode
|
|
|
988
988
|
createTree(options?): this;
|
|
989
989
|
```
|
|
990
990
|
|
|
991
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:408](https://github.com/zrwusa/data-structure-typed/blob/
|
|
991
|
+
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)
|
|
992
992
|
|
|
993
993
|
Creates a new, empty tree of the same type and configuration.
|
|
994
994
|
|
|
@@ -1025,10 +1025,10 @@ IBinaryTree.createTree
|
|
|
1025
1025
|
### delete()
|
|
1026
1026
|
|
|
1027
1027
|
```ts
|
|
1028
|
-
delete(keyNodeEntryRawOrPredicate):
|
|
1028
|
+
delete(keyNodeEntryRawOrPredicate): boolean;
|
|
1029
1029
|
```
|
|
1030
1030
|
|
|
1031
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1031
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1039)
|
|
1032
1032
|
|
|
1033
1033
|
Deletes a node from the tree.
|
|
1034
1034
|
|
|
@@ -1043,15 +1043,15 @@ The node to delete.
|
|
|
1043
1043
|
|
|
1044
1044
|
#### Returns
|
|
1045
1045
|
|
|
1046
|
-
`
|
|
1046
|
+
`boolean`
|
|
1047
1047
|
|
|
1048
|
-
|
|
1048
|
+
True if the node was found and deleted, false otherwise.
|
|
1049
1049
|
|
|
1050
1050
|
*
|
|
1051
1051
|
|
|
1052
1052
|
#### Remarks
|
|
1053
1053
|
|
|
1054
|
-
Time O(
|
|
1054
|
+
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).
|
|
1055
1055
|
|
|
1056
1056
|
#### Example
|
|
1057
1057
|
|
|
@@ -1082,10 +1082,10 @@ deleteWhere(
|
|
|
1082
1082
|
keyNodeEntryOrPredicate,
|
|
1083
1083
|
onlyOne?,
|
|
1084
1084
|
startNode?,
|
|
1085
|
-
iterationType?):
|
|
1085
|
+
iterationType?): boolean;
|
|
1086
1086
|
```
|
|
1087
1087
|
|
|
1088
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1088
|
+
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)
|
|
1089
1089
|
|
|
1090
1090
|
Deletes nodes that match a key, node, entry, predicate, or range.
|
|
1091
1091
|
|
|
@@ -1140,7 +1140,7 @@ Controls the internal traversal implementation:
|
|
|
1140
1140
|
|
|
1141
1141
|
#### Returns
|
|
1142
1142
|
|
|
1143
|
-
`
|
|
1143
|
+
`boolean`
|
|
1144
1144
|
|
|
1145
1145
|
A Map<K, boolean> containing the deletion results:
|
|
1146
1146
|
- Key: the matched node's key.
|
|
@@ -1192,7 +1192,7 @@ The traversal method.
|
|
|
1192
1192
|
dfs(): (K | undefined)[];
|
|
1193
1193
|
```
|
|
1194
1194
|
|
|
1195
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1195
|
+
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)
|
|
1196
1196
|
|
|
1197
1197
|
Depth-first search traversal
|
|
1198
1198
|
|
|
@@ -1232,7 +1232,7 @@ dfs<C>(
|
|
|
1232
1232
|
iterationType?): ReturnType<C>[];
|
|
1233
1233
|
```
|
|
1234
1234
|
|
|
1235
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1235
|
+
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)
|
|
1236
1236
|
|
|
1237
1237
|
Depth-first search traversal
|
|
1238
1238
|
|
|
@@ -1300,7 +1300,7 @@ IBinaryTree.dfs
|
|
|
1300
1300
|
ensureNode(keyNodeOrEntry, iterationType?): OptNode<BSTNode<K, V>>;
|
|
1301
1301
|
```
|
|
1302
1302
|
|
|
1303
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1303
|
+
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)
|
|
1304
1304
|
|
|
1305
1305
|
Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
1306
1306
|
|
|
@@ -1344,7 +1344,7 @@ Time O(log N) (height of the tree), O(N) worst-case.
|
|
|
1344
1344
|
entries(): IterableIterator<[K, V | undefined]>;
|
|
1345
1345
|
```
|
|
1346
1346
|
|
|
1347
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1347
|
+
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)
|
|
1348
1348
|
|
|
1349
1349
|
Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
1350
1350
|
|
|
@@ -1376,7 +1376,7 @@ IBinaryTree.entries
|
|
|
1376
1376
|
every(predicate, thisArg?): boolean;
|
|
1377
1377
|
```
|
|
1378
1378
|
|
|
1379
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1379
|
+
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)
|
|
1380
1380
|
|
|
1381
1381
|
Test whether all entries satisfy the predicate.
|
|
1382
1382
|
|
|
@@ -1390,7 +1390,7 @@ Test whether all entries satisfy the predicate.
|
|
|
1390
1390
|
|
|
1391
1391
|
##### thisArg?
|
|
1392
1392
|
|
|
1393
|
-
`
|
|
1393
|
+
`unknown`
|
|
1394
1394
|
|
|
1395
1395
|
Optional `this` for callback.
|
|
1396
1396
|
|
|
@@ -1422,7 +1422,7 @@ IBinaryTree.every
|
|
|
1422
1422
|
filter(predicate, thisArg?): this;
|
|
1423
1423
|
```
|
|
1424
1424
|
|
|
1425
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1425
|
+
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)
|
|
1426
1426
|
|
|
1427
1427
|
Creates a new tree containing only the entries that satisfy the predicate.
|
|
1428
1428
|
|
|
@@ -1479,7 +1479,7 @@ IBinaryTree.filter
|
|
|
1479
1479
|
find(callbackfn, thisArg?): [K, V | undefined] | undefined;
|
|
1480
1480
|
```
|
|
1481
1481
|
|
|
1482
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1482
|
+
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)
|
|
1483
1483
|
|
|
1484
1484
|
Find the first entry that matches a predicate.
|
|
1485
1485
|
|
|
@@ -1493,7 +1493,7 @@ Find the first entry that matches a predicate.
|
|
|
1493
1493
|
|
|
1494
1494
|
##### thisArg?
|
|
1495
1495
|
|
|
1496
|
-
`
|
|
1496
|
+
`unknown`
|
|
1497
1497
|
|
|
1498
1498
|
Optional `this` for callback.
|
|
1499
1499
|
|
|
@@ -1527,7 +1527,7 @@ IBinaryTree.find
|
|
|
1527
1527
|
floor(keyNodeEntryOrPredicate): K | undefined;
|
|
1528
1528
|
```
|
|
1529
1529
|
|
|
1530
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1530
|
+
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)
|
|
1531
1531
|
|
|
1532
1532
|
Returns the first key with a value <= target.
|
|
1533
1533
|
Equivalent to Java TreeMap.floor.
|
|
@@ -1570,7 +1570,7 @@ floor<C>(
|
|
|
1570
1570
|
iterationType?): ReturnType<C>;
|
|
1571
1571
|
```
|
|
1572
1572
|
|
|
1573
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
1573
|
+
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)
|
|
1574
1574
|
|
|
1575
1575
|
Returns the first node with a key <= target and applies callback.
|
|
1576
1576
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -1613,7 +1613,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
1613
1613
|
forEach(callbackfn, thisArg?): void;
|
|
1614
1614
|
```
|
|
1615
1615
|
|
|
1616
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1616
|
+
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)
|
|
1617
1617
|
|
|
1618
1618
|
Visit each entry, left-to-right.
|
|
1619
1619
|
|
|
@@ -1627,7 +1627,7 @@ Visit each entry, left-to-right.
|
|
|
1627
1627
|
|
|
1628
1628
|
##### thisArg?
|
|
1629
1629
|
|
|
1630
|
-
`
|
|
1630
|
+
`unknown`
|
|
1631
1631
|
|
|
1632
1632
|
Optional `this` for callback.
|
|
1633
1633
|
|
|
@@ -1660,7 +1660,7 @@ get(
|
|
|
1660
1660
|
iterationType?): V | undefined;
|
|
1661
1661
|
```
|
|
1662
1662
|
|
|
1663
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1663
|
+
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)
|
|
1664
1664
|
|
|
1665
1665
|
Gets the value associated with a key.
|
|
1666
1666
|
|
|
@@ -1701,7 +1701,7 @@ The associated value, or undefined.
|
|
|
1701
1701
|
|
|
1702
1702
|
#### Remarks
|
|
1703
1703
|
|
|
1704
|
-
Time O(
|
|
1704
|
+
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).
|
|
1705
1705
|
|
|
1706
1706
|
#### Example
|
|
1707
1707
|
|
|
@@ -1724,13 +1724,106 @@ IBinaryTree.get
|
|
|
1724
1724
|
|
|
1725
1725
|
***
|
|
1726
1726
|
|
|
1727
|
+
### getByRank()
|
|
1728
|
+
|
|
1729
|
+
#### Call Signature
|
|
1730
|
+
|
|
1731
|
+
```ts
|
|
1732
|
+
getByRank(k): K | undefined;
|
|
1733
|
+
```
|
|
1734
|
+
|
|
1735
|
+
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)
|
|
1736
|
+
|
|
1737
|
+
Returns the element at the k-th position in tree order (0-indexed).
|
|
1738
|
+
|
|
1739
|
+
##### Parameters
|
|
1740
|
+
|
|
1741
|
+
###### k
|
|
1742
|
+
|
|
1743
|
+
`number`
|
|
1744
|
+
|
|
1745
|
+
The 0-based position in tree order (0 = first element).
|
|
1746
|
+
|
|
1747
|
+
##### Returns
|
|
1748
|
+
|
|
1749
|
+
`K` \| `undefined`
|
|
1750
|
+
|
|
1751
|
+
The key at position k, or `undefined` if out of bounds.
|
|
1752
|
+
*
|
|
1753
|
+
|
|
1754
|
+
##### Remarks
|
|
1755
|
+
|
|
1756
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
1757
|
+
Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
1758
|
+
|
|
1759
|
+
##### Example
|
|
1760
|
+
|
|
1761
|
+
```ts
|
|
1762
|
+
// Order-statistic on BST
|
|
1763
|
+
const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
1764
|
+
console.log(tree.getByRank(0)); // 10;
|
|
1765
|
+
console.log(tree.getByRank(4)); // 50;
|
|
1766
|
+
console.log(tree.getRank(30)); // 2;
|
|
1767
|
+
```
|
|
1768
|
+
|
|
1769
|
+
#### Call Signature
|
|
1770
|
+
|
|
1771
|
+
```ts
|
|
1772
|
+
getByRank<C>(
|
|
1773
|
+
k,
|
|
1774
|
+
callback,
|
|
1775
|
+
iterationType?): ReturnType<C> | undefined;
|
|
1776
|
+
```
|
|
1777
|
+
|
|
1778
|
+
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)
|
|
1779
|
+
|
|
1780
|
+
Returns the element at the k-th position in tree order and applies a callback.
|
|
1781
|
+
|
|
1782
|
+
##### Type Parameters
|
|
1783
|
+
|
|
1784
|
+
###### C
|
|
1785
|
+
|
|
1786
|
+
`C` *extends* `NodeCallback`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
1787
|
+
|
|
1788
|
+
##### Parameters
|
|
1789
|
+
|
|
1790
|
+
###### k
|
|
1791
|
+
|
|
1792
|
+
`number`
|
|
1793
|
+
|
|
1794
|
+
The 0-based position in tree order (0 = first element).
|
|
1795
|
+
|
|
1796
|
+
###### callback
|
|
1797
|
+
|
|
1798
|
+
`C`
|
|
1799
|
+
|
|
1800
|
+
Callback to apply to the found node.
|
|
1801
|
+
|
|
1802
|
+
###### iterationType?
|
|
1803
|
+
|
|
1804
|
+
`IterationType`
|
|
1805
|
+
|
|
1806
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
1807
|
+
|
|
1808
|
+
##### Returns
|
|
1809
|
+
|
|
1810
|
+
`ReturnType`\<`C`\> \| `undefined`
|
|
1811
|
+
|
|
1812
|
+
The callback result, or `undefined` if out of bounds.
|
|
1813
|
+
|
|
1814
|
+
##### Remarks
|
|
1815
|
+
|
|
1816
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
1817
|
+
|
|
1818
|
+
***
|
|
1819
|
+
|
|
1727
1820
|
### getDepth()
|
|
1728
1821
|
|
|
1729
1822
|
```ts
|
|
1730
1823
|
getDepth(dist, startNode?): number;
|
|
1731
1824
|
```
|
|
1732
1825
|
|
|
1733
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1826
|
+
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)
|
|
1734
1827
|
|
|
1735
1828
|
Gets the depth of a node (distance from `startNode`).
|
|
1736
1829
|
|
|
@@ -1794,7 +1887,7 @@ IBinaryTree.getDepth
|
|
|
1794
1887
|
getHeight(startNode?, iterationType?): number;
|
|
1795
1888
|
```
|
|
1796
1889
|
|
|
1797
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1890
|
+
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)
|
|
1798
1891
|
|
|
1799
1892
|
Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
1800
1893
|
|
|
@@ -1877,7 +1970,7 @@ The traversal method.
|
|
|
1877
1970
|
getLeftMost(): K | undefined;
|
|
1878
1971
|
```
|
|
1879
1972
|
|
|
1880
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1973
|
+
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)
|
|
1881
1974
|
|
|
1882
1975
|
##### Returns
|
|
1883
1976
|
|
|
@@ -1902,7 +1995,7 @@ getLeftMost<C>(
|
|
|
1902
1995
|
iterationType?): ReturnType<C>;
|
|
1903
1996
|
```
|
|
1904
1997
|
|
|
1905
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1998
|
+
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)
|
|
1906
1999
|
|
|
1907
2000
|
##### Type Parameters
|
|
1908
2001
|
|
|
@@ -1949,7 +2042,7 @@ IBinaryTree.getLeftMost
|
|
|
1949
2042
|
getMinHeight(startNode?, iterationType?): number;
|
|
1950
2043
|
```
|
|
1951
2044
|
|
|
1952
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2045
|
+
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)
|
|
1953
2046
|
|
|
1954
2047
|
Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
1955
2048
|
|
|
@@ -2001,7 +2094,7 @@ getNode(
|
|
|
2001
2094
|
iterationType?): OptNode<BSTNode<K, V>>;
|
|
2002
2095
|
```
|
|
2003
2096
|
|
|
2004
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2097
|
+
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)
|
|
2005
2098
|
|
|
2006
2099
|
Gets the first node matching a predicate.
|
|
2007
2100
|
|
|
@@ -2074,7 +2167,7 @@ getNodes(
|
|
|
2074
2167
|
iterationType?): BinaryTreeNode<K, V>[];
|
|
2075
2168
|
```
|
|
2076
2169
|
|
|
2077
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2170
|
+
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)
|
|
2078
2171
|
|
|
2079
2172
|
Gets all nodes matching a predicate.
|
|
2080
2173
|
|
|
@@ -2169,7 +2262,7 @@ If true, returns the path from root-to-node.
|
|
|
2169
2262
|
getPathToRoot(beginNode): (K | undefined)[];
|
|
2170
2263
|
```
|
|
2171
2264
|
|
|
2172
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2265
|
+
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)
|
|
2173
2266
|
|
|
2174
2267
|
##### Parameters
|
|
2175
2268
|
|
|
@@ -2204,7 +2297,7 @@ getPathToRoot<C>(
|
|
|
2204
2297
|
isReverse?): ReturnType<C>[];
|
|
2205
2298
|
```
|
|
2206
2299
|
|
|
2207
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2300
|
+
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)
|
|
2208
2301
|
|
|
2209
2302
|
##### Type Parameters
|
|
2210
2303
|
|
|
@@ -2252,7 +2345,7 @@ IBinaryTree.getPathToRoot
|
|
|
2252
2345
|
getPredecessor(node): BinaryTreeNode<K, V>;
|
|
2253
2346
|
```
|
|
2254
2347
|
|
|
2255
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2348
|
+
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)
|
|
2256
2349
|
|
|
2257
2350
|
Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
2258
2351
|
|
|
@@ -2280,6 +2373,83 @@ This is primarily a helper for Morris traversal. Time O(H), where H is the heigh
|
|
|
2280
2373
|
|
|
2281
2374
|
***
|
|
2282
2375
|
|
|
2376
|
+
### getRank()
|
|
2377
|
+
|
|
2378
|
+
#### Call Signature
|
|
2379
|
+
|
|
2380
|
+
```ts
|
|
2381
|
+
getRank(keyNodeEntryOrPredicate): number;
|
|
2382
|
+
```
|
|
2383
|
+
|
|
2384
|
+
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)
|
|
2385
|
+
|
|
2386
|
+
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
2387
|
+
|
|
2388
|
+
##### Parameters
|
|
2389
|
+
|
|
2390
|
+
###### keyNodeEntryOrPredicate
|
|
2391
|
+
|
|
2392
|
+
\| `K`
|
|
2393
|
+
\| [`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
2394
|
+
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
2395
|
+
\| `NodePredicate`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
2396
|
+
\| `null`
|
|
2397
|
+
\| `undefined`
|
|
2398
|
+
|
|
2399
|
+
The key, node, entry `[K, V]`, or predicate to find.
|
|
2400
|
+
|
|
2401
|
+
##### Returns
|
|
2402
|
+
|
|
2403
|
+
`number`
|
|
2404
|
+
|
|
2405
|
+
The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
2406
|
+
|
|
2407
|
+
##### Remarks
|
|
2408
|
+
|
|
2409
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
2410
|
+
Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
2411
|
+
|
|
2412
|
+
#### Call Signature
|
|
2413
|
+
|
|
2414
|
+
```ts
|
|
2415
|
+
getRank(keyNodeEntryOrPredicate, iterationType): number;
|
|
2416
|
+
```
|
|
2417
|
+
|
|
2418
|
+
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)
|
|
2419
|
+
|
|
2420
|
+
Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
2421
|
+
|
|
2422
|
+
##### Parameters
|
|
2423
|
+
|
|
2424
|
+
###### keyNodeEntryOrPredicate
|
|
2425
|
+
|
|
2426
|
+
\| `K`
|
|
2427
|
+
\| [`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
2428
|
+
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
2429
|
+
\| `NodePredicate`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
2430
|
+
\| `null`
|
|
2431
|
+
\| `undefined`
|
|
2432
|
+
|
|
2433
|
+
The key, node, entry, or predicate to find.
|
|
2434
|
+
|
|
2435
|
+
###### iterationType
|
|
2436
|
+
|
|
2437
|
+
`IterationType`
|
|
2438
|
+
|
|
2439
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
2440
|
+
|
|
2441
|
+
##### Returns
|
|
2442
|
+
|
|
2443
|
+
`number`
|
|
2444
|
+
|
|
2445
|
+
The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
2446
|
+
|
|
2447
|
+
##### Remarks
|
|
2448
|
+
|
|
2449
|
+
Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
2450
|
+
|
|
2451
|
+
***
|
|
2452
|
+
|
|
2283
2453
|
### getRightMost()
|
|
2284
2454
|
|
|
2285
2455
|
Finds the rightmost node in a subtree (the node with the largest key in a BST).
|
|
@@ -2310,7 +2480,7 @@ The traversal method.
|
|
|
2310
2480
|
getRightMost(): K | undefined;
|
|
2311
2481
|
```
|
|
2312
2482
|
|
|
2313
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2483
|
+
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)
|
|
2314
2484
|
|
|
2315
2485
|
##### Returns
|
|
2316
2486
|
|
|
@@ -2335,7 +2505,7 @@ getRightMost<C>(
|
|
|
2335
2505
|
iterationType?): ReturnType<C>;
|
|
2336
2506
|
```
|
|
2337
2507
|
|
|
2338
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2508
|
+
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)
|
|
2339
2509
|
|
|
2340
2510
|
##### Type Parameters
|
|
2341
2511
|
|
|
@@ -2382,7 +2552,7 @@ IBinaryTree.getRightMost
|
|
|
2382
2552
|
getSuccessor(x?): BinaryTreeNode<K, V> | null | undefined;
|
|
2383
2553
|
```
|
|
2384
2554
|
|
|
2385
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2555
|
+
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)
|
|
2386
2556
|
|
|
2387
2557
|
Gets the in-order successor of a node in a BST.
|
|
2388
2558
|
|
|
@@ -2419,7 +2589,7 @@ has(
|
|
|
2419
2589
|
iterationType?): boolean;
|
|
2420
2590
|
```
|
|
2421
2591
|
|
|
2422
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2592
|
+
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)
|
|
2423
2593
|
|
|
2424
2594
|
Checks if a node matching the predicate exists in the tree.
|
|
2425
2595
|
|
|
@@ -2460,7 +2630,7 @@ True if a matching node exists, false otherwise.
|
|
|
2460
2630
|
|
|
2461
2631
|
#### Remarks
|
|
2462
2632
|
|
|
2463
|
-
Time O(
|
|
2633
|
+
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.
|
|
2464
2634
|
|
|
2465
2635
|
#### Example
|
|
2466
2636
|
|
|
@@ -2512,7 +2682,7 @@ IBinaryTree.has
|
|
|
2512
2682
|
hasValue(value): boolean;
|
|
2513
2683
|
```
|
|
2514
2684
|
|
|
2515
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2685
|
+
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)
|
|
2516
2686
|
|
|
2517
2687
|
Whether there exists an entry with the given value.
|
|
2518
2688
|
|
|
@@ -2554,7 +2724,7 @@ IBinaryTree.hasValue
|
|
|
2554
2724
|
higher(keyNodeEntryOrPredicate): K | undefined;
|
|
2555
2725
|
```
|
|
2556
2726
|
|
|
2557
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2727
|
+
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)
|
|
2558
2728
|
|
|
2559
2729
|
Returns the first key with a value > target.
|
|
2560
2730
|
Equivalent to Java TreeMap.higher.
|
|
@@ -2596,7 +2766,7 @@ higher<C>(
|
|
|
2596
2766
|
iterationType?): ReturnType<C>;
|
|
2597
2767
|
```
|
|
2598
2768
|
|
|
2599
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2769
|
+
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)
|
|
2600
2770
|
|
|
2601
2771
|
Returns the first node with a key > target and applies callback.
|
|
2602
2772
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -2639,7 +2809,7 @@ Space Complexity: O(h) for recursion, O(1) for iteration.
|
|
|
2639
2809
|
isAVLBalanced(iterationType?): boolean;
|
|
2640
2810
|
```
|
|
2641
2811
|
|
|
2642
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
2812
|
+
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)
|
|
2643
2813
|
|
|
2644
2814
|
Checks if the tree meets the AVL balance condition (height difference <= 1).
|
|
2645
2815
|
|
|
@@ -2679,7 +2849,7 @@ Time O(N), as it must visit every node to compute height. Space O(log N) for rec
|
|
|
2679
2849
|
isBST(startNode?, iterationType?): boolean;
|
|
2680
2850
|
```
|
|
2681
2851
|
|
|
2682
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2852
|
+
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)
|
|
2683
2853
|
|
|
2684
2854
|
Checks if the tree is a valid Binary Search Tree (BST).
|
|
2685
2855
|
|
|
@@ -2739,7 +2909,7 @@ IBinaryTree.isBST
|
|
|
2739
2909
|
isEmpty(): boolean;
|
|
2740
2910
|
```
|
|
2741
2911
|
|
|
2742
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2912
|
+
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)
|
|
2743
2913
|
|
|
2744
2914
|
Checks if the tree is empty.
|
|
2745
2915
|
|
|
@@ -2780,7 +2950,7 @@ IBinaryTree.isEmpty
|
|
|
2780
2950
|
isEntry(keyNodeOrEntry): keyNodeOrEntry is BTNEntry<K, V>;
|
|
2781
2951
|
```
|
|
2782
2952
|
|
|
2783
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:545](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2953
|
+
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)
|
|
2784
2954
|
|
|
2785
2955
|
Checks if the given item is a [key, value] entry pair.
|
|
2786
2956
|
|
|
@@ -2818,7 +2988,7 @@ Time O(1), Space O(1)
|
|
|
2818
2988
|
isLeaf(keyNodeOrEntry): boolean;
|
|
2819
2989
|
```
|
|
2820
2990
|
|
|
2821
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:531](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2991
|
+
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)
|
|
2822
2992
|
|
|
2823
2993
|
Checks if a node is a leaf (has no real children).
|
|
2824
2994
|
|
|
@@ -2856,7 +3026,7 @@ Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is pass
|
|
|
2856
3026
|
isNIL(keyNodeOrEntry): boolean;
|
|
2857
3027
|
```
|
|
2858
3028
|
|
|
2859
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:500](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3029
|
+
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)
|
|
2860
3030
|
|
|
2861
3031
|
Checks if the given item is the sentinel NIL node.
|
|
2862
3032
|
|
|
@@ -2894,7 +3064,7 @@ Time O(1), Space O(1)
|
|
|
2894
3064
|
isNode(keyNodeOrEntry): keyNodeOrEntry is BSTNode<K, V>;
|
|
2895
3065
|
```
|
|
2896
3066
|
|
|
2897
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3067
|
+
Defined in: [data-structures/binary-tree/bst.ts:422](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L422)
|
|
2898
3068
|
|
|
2899
3069
|
Checks if the given item is a `BSTNode` instance.
|
|
2900
3070
|
|
|
@@ -2932,7 +3102,7 @@ Time O(1), Space O(1)
|
|
|
2932
3102
|
isPerfectlyBalanced(startNode?): boolean;
|
|
2933
3103
|
```
|
|
2934
3104
|
|
|
2935
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3105
|
+
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)
|
|
2936
3106
|
|
|
2937
3107
|
Checks if the tree is perfectly balanced.
|
|
2938
3108
|
|
|
@@ -2975,7 +3145,7 @@ IBinaryTree.isPerfectlyBalanced
|
|
|
2975
3145
|
isRange(keyNodeEntryOrPredicate): keyNodeEntryOrPredicate is Range<K>;
|
|
2976
3146
|
```
|
|
2977
3147
|
|
|
2978
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:511](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3148
|
+
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)
|
|
2979
3149
|
|
|
2980
3150
|
Checks if the given item is a `Range` object.
|
|
2981
3151
|
|
|
@@ -3015,7 +3185,7 @@ Time O(1), Space O(1)
|
|
|
3015
3185
|
isRaw(keyNodeEntryOrRaw): keyNodeEntryOrRaw is R;
|
|
3016
3186
|
```
|
|
3017
3187
|
|
|
3018
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:460](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3188
|
+
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)
|
|
3019
3189
|
|
|
3020
3190
|
Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
3021
3191
|
|
|
@@ -3054,7 +3224,7 @@ Time O(1), Space O(1)
|
|
|
3054
3224
|
isRealNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
3055
3225
|
```
|
|
3056
3226
|
|
|
3057
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:473](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3227
|
+
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)
|
|
3058
3228
|
|
|
3059
3229
|
Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
3060
3230
|
|
|
@@ -3092,7 +3262,7 @@ Time O(1), Space O(1)
|
|
|
3092
3262
|
isRealNodeOrNull(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
3093
3263
|
```
|
|
3094
3264
|
|
|
3095
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:487](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3265
|
+
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)
|
|
3096
3266
|
|
|
3097
3267
|
Checks if the given item is either a "real" node or null.
|
|
3098
3268
|
|
|
@@ -3130,7 +3300,7 @@ Time O(1), Space O(1)
|
|
|
3130
3300
|
isValidKey(key): key is K;
|
|
3131
3301
|
```
|
|
3132
3302
|
|
|
3133
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3303
|
+
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)
|
|
3134
3304
|
|
|
3135
3305
|
Checks if the given key is valid (comparable).
|
|
3136
3306
|
|
|
@@ -3138,7 +3308,7 @@ Checks if the given key is valid (comparable).
|
|
|
3138
3308
|
|
|
3139
3309
|
##### key
|
|
3140
3310
|
|
|
3141
|
-
`
|
|
3311
|
+
`unknown`
|
|
3142
3312
|
|
|
3143
3313
|
The key to validate.
|
|
3144
3314
|
|
|
@@ -3164,7 +3334,7 @@ Time O(1)
|
|
|
3164
3334
|
keys(): IterableIterator<K>;
|
|
3165
3335
|
```
|
|
3166
3336
|
|
|
3167
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3337
|
+
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)
|
|
3168
3338
|
|
|
3169
3339
|
Iterate over keys only.
|
|
3170
3340
|
|
|
@@ -3220,7 +3390,7 @@ The traversal method.
|
|
|
3220
3390
|
leaves(): (K | undefined)[];
|
|
3221
3391
|
```
|
|
3222
3392
|
|
|
3223
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3393
|
+
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)
|
|
3224
3394
|
|
|
3225
3395
|
Get leaf nodes
|
|
3226
3396
|
|
|
@@ -3258,7 +3428,7 @@ leaves<C>(
|
|
|
3258
3428
|
iterationType?): ReturnType<C>[];
|
|
3259
3429
|
```
|
|
3260
3430
|
|
|
3261
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3431
|
+
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)
|
|
3262
3432
|
|
|
3263
3433
|
Get leaf nodes
|
|
3264
3434
|
|
|
@@ -3346,7 +3516,7 @@ The traversal method.
|
|
|
3346
3516
|
lesserOrGreaterTraverse(): (K | undefined)[];
|
|
3347
3517
|
```
|
|
3348
3518
|
|
|
3349
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3519
|
+
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)
|
|
3350
3520
|
|
|
3351
3521
|
##### Returns
|
|
3352
3522
|
|
|
@@ -3362,7 +3532,7 @@ lesserOrGreaterTraverse<C>(
|
|
|
3362
3532
|
iterationType?): ReturnType<C>[];
|
|
3363
3533
|
```
|
|
3364
3534
|
|
|
3365
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3535
|
+
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)
|
|
3366
3536
|
|
|
3367
3537
|
##### Type Parameters
|
|
3368
3538
|
|
|
@@ -3427,7 +3597,7 @@ The traversal method.
|
|
|
3427
3597
|
listLevels(): (K | undefined)[][];
|
|
3428
3598
|
```
|
|
3429
3599
|
|
|
3430
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3600
|
+
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)
|
|
3431
3601
|
|
|
3432
3602
|
Level-order grouping
|
|
3433
3603
|
|
|
@@ -3443,7 +3613,7 @@ Level-order grouping
|
|
|
3443
3613
|
// Level-order grouping
|
|
3444
3614
|
const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
3445
3615
|
const levels = bst.listLevels(node => node.key);
|
|
3446
|
-
console.log(levels
|
|
3616
|
+
console.log(levels); // toBeInstanceOf;
|
|
3447
3617
|
console.log(levels[0].length); // 1; // root level has 1 node
|
|
3448
3618
|
const allKeys = levels.flat().sort((a, b) => a - b);
|
|
3449
3619
|
console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -3468,7 +3638,7 @@ listLevels<C>(
|
|
|
3468
3638
|
iterationType?): ReturnType<C>[][];
|
|
3469
3639
|
```
|
|
3470
3640
|
|
|
3471
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3641
|
+
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)
|
|
3472
3642
|
|
|
3473
3643
|
Level-order grouping
|
|
3474
3644
|
|
|
@@ -3507,7 +3677,7 @@ Level-order grouping
|
|
|
3507
3677
|
// Level-order grouping
|
|
3508
3678
|
const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
3509
3679
|
const levels = bst.listLevels(node => node.key);
|
|
3510
|
-
console.log(levels
|
|
3680
|
+
console.log(levels); // toBeInstanceOf;
|
|
3511
3681
|
console.log(levels[0].length); // 1; // root level has 1 node
|
|
3512
3682
|
const allKeys = levels.flat().sort((a, b) => a - b);
|
|
3513
3683
|
console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -3533,7 +3703,7 @@ IBinaryTree.listLevels
|
|
|
3533
3703
|
lower(keyNodeEntryOrPredicate): K | undefined;
|
|
3534
3704
|
```
|
|
3535
3705
|
|
|
3536
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3706
|
+
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)
|
|
3537
3707
|
|
|
3538
3708
|
Returns the first key with a value < target.
|
|
3539
3709
|
Equivalent to Java TreeMap.lower.
|
|
@@ -3575,7 +3745,7 @@ lower<C>(
|
|
|
3575
3745
|
iterationType?): ReturnType<C>;
|
|
3576
3746
|
```
|
|
3577
3747
|
|
|
3578
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3748
|
+
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)
|
|
3579
3749
|
|
|
3580
3750
|
Returns the first node with a key < target and applies callback.
|
|
3581
3751
|
Time Complexity: O(log n) average, O(h) worst case.
|
|
@@ -3621,7 +3791,7 @@ map<MK, MV, MR>(
|
|
|
3621
3791
|
thisArg?): BST<MK, MV, MR>;
|
|
3622
3792
|
```
|
|
3623
3793
|
|
|
3624
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
3794
|
+
Defined in: [data-structures/binary-tree/bst.ts:2642](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2642)
|
|
3625
3795
|
|
|
3626
3796
|
Creates a new BST by mapping each [key, value] pair to a new entry.
|
|
3627
3797
|
|
|
@@ -3705,7 +3875,7 @@ IBinaryTree.map
|
|
|
3705
3875
|
merge(anotherTree): void;
|
|
3706
3876
|
```
|
|
3707
3877
|
|
|
3708
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3878
|
+
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)
|
|
3709
3879
|
|
|
3710
3880
|
Merges another tree into this one by seting all its nodes.
|
|
3711
3881
|
|
|
@@ -3779,7 +3949,7 @@ The node to start from.
|
|
|
3779
3949
|
morris(): (K | undefined)[];
|
|
3780
3950
|
```
|
|
3781
3951
|
|
|
3782
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3952
|
+
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)
|
|
3783
3953
|
|
|
3784
3954
|
Morris traversal (O(1) space)
|
|
3785
3955
|
|
|
@@ -3817,7 +3987,7 @@ morris<C>(
|
|
|
3817
3987
|
startNode?): ReturnType<C>[];
|
|
3818
3988
|
```
|
|
3819
3989
|
|
|
3820
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3990
|
+
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)
|
|
3821
3991
|
|
|
3822
3992
|
Morris traversal (O(1) space)
|
|
3823
3993
|
|
|
@@ -3877,7 +4047,7 @@ IBinaryTree.morris
|
|
|
3877
4047
|
perfectlyBalance(iterationType?): boolean;
|
|
3878
4048
|
```
|
|
3879
4049
|
|
|
3880
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4050
|
+
Defined in: [data-structures/binary-tree/bst.ts:2432](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L2432)
|
|
3881
4051
|
|
|
3882
4052
|
Rebuilds the tree to be perfectly balanced.
|
|
3883
4053
|
|
|
@@ -3921,7 +4091,7 @@ Time O(N) (O(N) for DFS, O(N) for sorted build). Space O(N) for node array and r
|
|
|
3921
4091
|
print(options?, startNode?): void;
|
|
3922
4092
|
```
|
|
3923
4093
|
|
|
3924
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4094
|
+
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)
|
|
3925
4095
|
|
|
3926
4096
|
Prints a visual representation of the tree to the console.
|
|
3927
4097
|
|
|
@@ -3966,6 +4136,100 @@ Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
|
3966
4136
|
|
|
3967
4137
|
***
|
|
3968
4138
|
|
|
4139
|
+
### rangeByRank()
|
|
4140
|
+
|
|
4141
|
+
#### Call Signature
|
|
4142
|
+
|
|
4143
|
+
```ts
|
|
4144
|
+
rangeByRank(start, end): (K | undefined)[];
|
|
4145
|
+
```
|
|
4146
|
+
|
|
4147
|
+
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)
|
|
4148
|
+
|
|
4149
|
+
Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
4150
|
+
|
|
4151
|
+
##### Parameters
|
|
4152
|
+
|
|
4153
|
+
###### start
|
|
4154
|
+
|
|
4155
|
+
`number`
|
|
4156
|
+
|
|
4157
|
+
Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
4158
|
+
|
|
4159
|
+
###### end
|
|
4160
|
+
|
|
4161
|
+
`number`
|
|
4162
|
+
|
|
4163
|
+
End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
4164
|
+
|
|
4165
|
+
##### Returns
|
|
4166
|
+
|
|
4167
|
+
(`K` \| `undefined`)[]
|
|
4168
|
+
|
|
4169
|
+
Array of keys in tree order within the specified range.
|
|
4170
|
+
|
|
4171
|
+
##### Remarks
|
|
4172
|
+
|
|
4173
|
+
Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
4174
|
+
|
|
4175
|
+
#### Call Signature
|
|
4176
|
+
|
|
4177
|
+
```ts
|
|
4178
|
+
rangeByRank<C>(
|
|
4179
|
+
start,
|
|
4180
|
+
end,
|
|
4181
|
+
callback,
|
|
4182
|
+
iterationType?): ReturnType<C>[];
|
|
4183
|
+
```
|
|
4184
|
+
|
|
4185
|
+
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)
|
|
4186
|
+
|
|
4187
|
+
Returns elements by position range in tree order with callback and optional iteration type.
|
|
4188
|
+
|
|
4189
|
+
##### Type Parameters
|
|
4190
|
+
|
|
4191
|
+
###### C
|
|
4192
|
+
|
|
4193
|
+
`C` *extends* `NodeCallback`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
4194
|
+
|
|
4195
|
+
##### Parameters
|
|
4196
|
+
|
|
4197
|
+
###### start
|
|
4198
|
+
|
|
4199
|
+
`number`
|
|
4200
|
+
|
|
4201
|
+
Start rank (inclusive, 0-indexed).
|
|
4202
|
+
|
|
4203
|
+
###### end
|
|
4204
|
+
|
|
4205
|
+
`number`
|
|
4206
|
+
|
|
4207
|
+
End rank (inclusive, 0-indexed).
|
|
4208
|
+
|
|
4209
|
+
###### callback
|
|
4210
|
+
|
|
4211
|
+
`C`
|
|
4212
|
+
|
|
4213
|
+
Callback to apply to each node in the range.
|
|
4214
|
+
|
|
4215
|
+
###### iterationType?
|
|
4216
|
+
|
|
4217
|
+
`IterationType`
|
|
4218
|
+
|
|
4219
|
+
Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
4220
|
+
|
|
4221
|
+
##### Returns
|
|
4222
|
+
|
|
4223
|
+
`ReturnType`\<`C`\>[]
|
|
4224
|
+
|
|
4225
|
+
Array of callback results for nodes in the rank range.
|
|
4226
|
+
|
|
4227
|
+
##### Remarks
|
|
4228
|
+
|
|
4229
|
+
Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
4230
|
+
|
|
4231
|
+
***
|
|
4232
|
+
|
|
3969
4233
|
### rangeSearch()
|
|
3970
4234
|
|
|
3971
4235
|
Performs an optimized search for nodes within a given key range.
|
|
@@ -4000,7 +4264,7 @@ The traversal method.
|
|
|
4000
4264
|
rangeSearch(range): (K | undefined)[];
|
|
4001
4265
|
```
|
|
4002
4266
|
|
|
4003
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4267
|
+
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)
|
|
4004
4268
|
|
|
4005
4269
|
Find all keys in a range
|
|
4006
4270
|
|
|
@@ -4034,7 +4298,7 @@ rangeSearch<C>(
|
|
|
4034
4298
|
iterationType?): ReturnType<C>[];
|
|
4035
4299
|
```
|
|
4036
4300
|
|
|
4037
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4301
|
+
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)
|
|
4038
4302
|
|
|
4039
4303
|
Find all keys in a range
|
|
4040
4304
|
|
|
@@ -4087,7 +4351,7 @@ Find all keys in a range
|
|
|
4087
4351
|
reduce<U>(callbackfn, initialValue): U;
|
|
4088
4352
|
```
|
|
4089
4353
|
|
|
4090
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4354
|
+
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)
|
|
4091
4355
|
|
|
4092
4356
|
Reduce entries into a single accumulator.
|
|
4093
4357
|
|
|
@@ -4133,56 +4397,6 @@ IBinaryTree.reduce
|
|
|
4133
4397
|
|
|
4134
4398
|
***
|
|
4135
4399
|
|
|
4136
|
-
### refill()
|
|
4137
|
-
|
|
4138
|
-
```ts
|
|
4139
|
-
refill(keysNodesEntriesOrRaws, values?): void;
|
|
4140
|
-
```
|
|
4141
|
-
|
|
4142
|
-
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)
|
|
4143
|
-
|
|
4144
|
-
Clears the tree and refills it with new items.
|
|
4145
|
-
|
|
4146
|
-
#### Parameters
|
|
4147
|
-
|
|
4148
|
-
##### keysNodesEntriesOrRaws
|
|
4149
|
-
|
|
4150
|
-
`Iterable`\<
|
|
4151
|
-
\| `K`
|
|
4152
|
-
\| `R`
|
|
4153
|
-
\| [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>
|
|
4154
|
-
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
4155
|
-
\| `null`
|
|
4156
|
-
\| `undefined`\>
|
|
4157
|
-
|
|
4158
|
-
An iterable of items to set.
|
|
4159
|
-
|
|
4160
|
-
##### values?
|
|
4161
|
-
|
|
4162
|
-
`Iterable`\<`V` \| `undefined`, `any`, `any`\>
|
|
4163
|
-
|
|
4164
|
-
An optional parallel iterable of values.
|
|
4165
|
-
|
|
4166
|
-
#### Returns
|
|
4167
|
-
|
|
4168
|
-
`void`
|
|
4169
|
-
|
|
4170
|
-
#### Remarks
|
|
4171
|
-
|
|
4172
|
-
Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
4173
|
-
|
|
4174
|
-
#### Implementation of
|
|
4175
|
-
|
|
4176
|
-
```ts
|
|
4177
|
-
IBinaryTree.refill
|
|
4178
|
-
```
|
|
4179
|
-
|
|
4180
|
-
#### Inherited from
|
|
4181
|
-
|
|
4182
|
-
[`BinaryTree`](BinaryTree.md).[`refill`](BinaryTree.md#refill)
|
|
4183
|
-
|
|
4184
|
-
***
|
|
4185
|
-
|
|
4186
4400
|
### search()
|
|
4187
4401
|
|
|
4188
4402
|
Searches the tree for nodes matching a predicate, key, or range.
|
|
@@ -4223,7 +4437,7 @@ Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
|
4223
4437
|
search(keyNodeEntryOrPredicate, onlyOne?): (K | undefined)[];
|
|
4224
4438
|
```
|
|
4225
4439
|
|
|
4226
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4440
|
+
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)
|
|
4227
4441
|
|
|
4228
4442
|
Search nodes by predicate
|
|
4229
4443
|
|
|
@@ -4279,7 +4493,7 @@ search<C>(
|
|
|
4279
4493
|
iterationType?): ReturnType<C>[];
|
|
4280
4494
|
```
|
|
4281
4495
|
|
|
4282
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4496
|
+
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)
|
|
4283
4497
|
|
|
4284
4498
|
Search nodes by predicate
|
|
4285
4499
|
|
|
@@ -4353,7 +4567,7 @@ IBinaryTree.search
|
|
|
4353
4567
|
set(keyNodeOrEntry, value?): boolean;
|
|
4354
4568
|
```
|
|
4355
4569
|
|
|
4356
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4570
|
+
Defined in: [data-structures/binary-tree/bst.ts:1573](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L1573)
|
|
4357
4571
|
|
|
4358
4572
|
Adds a new node to the BST based on key comparison.
|
|
4359
4573
|
|
|
@@ -4419,7 +4633,7 @@ setMany(
|
|
|
4419
4633
|
iterationType?): boolean[];
|
|
4420
4634
|
```
|
|
4421
4635
|
|
|
4422
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4636
|
+
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)
|
|
4423
4637
|
|
|
4424
4638
|
Adds multiple items to the tree.
|
|
4425
4639
|
|
|
@@ -4485,7 +4699,7 @@ Space O(N) for sorting and recursion/iteration stack.
|
|
|
4485
4699
|
some(predicate, thisArg?): boolean;
|
|
4486
4700
|
```
|
|
4487
4701
|
|
|
4488
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4702
|
+
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)
|
|
4489
4703
|
|
|
4490
4704
|
Test whether any entry satisfies the predicate.
|
|
4491
4705
|
|
|
@@ -4499,7 +4713,7 @@ Test whether any entry satisfies the predicate.
|
|
|
4499
4713
|
|
|
4500
4714
|
##### thisArg?
|
|
4501
4715
|
|
|
4502
|
-
`
|
|
4716
|
+
`unknown`
|
|
4503
4717
|
|
|
4504
4718
|
Optional `this` for callback.
|
|
4505
4719
|
|
|
@@ -4531,7 +4745,7 @@ IBinaryTree.some
|
|
|
4531
4745
|
toArray(): [K, V | undefined][];
|
|
4532
4746
|
```
|
|
4533
4747
|
|
|
4534
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4748
|
+
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)
|
|
4535
4749
|
|
|
4536
4750
|
Converts data structure to `[key, value]` pairs.
|
|
4537
4751
|
|
|
@@ -4557,7 +4771,7 @@ Time O(n), Space O(n)
|
|
|
4557
4771
|
toVisual(startNode?, options?): string;
|
|
4558
4772
|
```
|
|
4559
4773
|
|
|
4560
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4774
|
+
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)
|
|
4561
4775
|
|
|
4562
4776
|
Generates a string representation of the tree for visualization.
|
|
4563
4777
|
|
|
@@ -4600,7 +4814,7 @@ Time O(N), visits every node. Space O(N*H) or O(N^2) in the worst case, as the s
|
|
|
4600
4814
|
values(): IterableIterator<V | undefined>;
|
|
4601
4815
|
```
|
|
4602
4816
|
|
|
4603
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/
|
|
4817
|
+
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)
|
|
4604
4818
|
|
|
4605
4819
|
Iterate over values only.
|
|
4606
4820
|
|
|
@@ -4635,7 +4849,7 @@ IBinaryTree.values
|
|
|
4635
4849
|
protected readonly _comparator: Comparator<K>;
|
|
4636
4850
|
```
|
|
4637
4851
|
|
|
4638
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4852
|
+
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)
|
|
4639
4853
|
|
|
4640
4854
|
The comparator function used to determine the order of keys in the tree.
|
|
4641
4855
|
|
|
@@ -4651,7 +4865,7 @@ Time O(1) Space O(1)
|
|
|
4651
4865
|
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
4652
4866
|
```
|
|
4653
4867
|
|
|
4654
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4868
|
+
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)
|
|
4655
4869
|
|
|
4656
4870
|
(Protected) Default callback function, returns the node's key.
|
|
4657
4871
|
|
|
@@ -4682,7 +4896,7 @@ protected _bound(
|
|
|
4682
4896
|
iterationType): BSTNode<K, V> | undefined;
|
|
4683
4897
|
```
|
|
4684
4898
|
|
|
4685
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4899
|
+
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)
|
|
4686
4900
|
|
|
4687
4901
|
(Protected) Core bound search implementation supporting all parameter types.
|
|
4688
4902
|
Unified logic for both lowerBound and upperBound.
|
|
@@ -4730,7 +4944,7 @@ protected _boundByKey(
|
|
|
4730
4944
|
iterationType): BSTNode<K, V> | undefined;
|
|
4731
4945
|
```
|
|
4732
4946
|
|
|
4733
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4947
|
+
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)
|
|
4734
4948
|
|
|
4735
4949
|
(Protected) Binary search for bound by key with pruning optimization.
|
|
4736
4950
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -4771,7 +4985,7 @@ The first node matching the bound condition, or undefined if none exists.
|
|
|
4771
4985
|
protected _boundByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
4772
4986
|
```
|
|
4773
4987
|
|
|
4774
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
4988
|
+
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)
|
|
4775
4989
|
|
|
4776
4990
|
(Protected) In-order traversal search by predicate.
|
|
4777
4991
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -4807,7 +5021,7 @@ The first node satisfying predicate, or undefined if none found.
|
|
|
4807
5021
|
protected _clearNodes(): void;
|
|
4808
5022
|
```
|
|
4809
5023
|
|
|
4810
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5024
|
+
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)
|
|
4811
5025
|
|
|
4812
5026
|
(Protected) Clears all nodes from the tree.
|
|
4813
5027
|
|
|
@@ -4831,7 +5045,7 @@ Time O(1)
|
|
|
4831
5045
|
protected _clearValues(): void;
|
|
4832
5046
|
```
|
|
4833
5047
|
|
|
4834
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5048
|
+
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)
|
|
4835
5049
|
|
|
4836
5050
|
(Protected) Clears all values from the external store.
|
|
4837
5051
|
|
|
@@ -4855,7 +5069,7 @@ Time O(N)
|
|
|
4855
5069
|
protected _clone(cloned): void;
|
|
4856
5070
|
```
|
|
4857
5071
|
|
|
4858
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5072
|
+
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)
|
|
4859
5073
|
|
|
4860
5074
|
(Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
4861
5075
|
|
|
@@ -4887,7 +5101,7 @@ Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
|
4887
5101
|
protected _compare(a, b): number;
|
|
4888
5102
|
```
|
|
4889
5103
|
|
|
4890
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5104
|
+
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)
|
|
4891
5105
|
|
|
4892
5106
|
(Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
4893
5107
|
|
|
@@ -4923,7 +5137,7 @@ Time O(1) Space O(1)
|
|
|
4923
5137
|
protected _createDefaultComparator(): Comparator<K>;
|
|
4924
5138
|
```
|
|
4925
5139
|
|
|
4926
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5140
|
+
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)
|
|
4927
5141
|
|
|
4928
5142
|
(Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
4929
5143
|
|
|
@@ -4945,7 +5159,7 @@ Time O(1) Space O(1)
|
|
|
4945
5159
|
protected _createInstance<TK, TV, TR>(options?): this;
|
|
4946
5160
|
```
|
|
4947
5161
|
|
|
4948
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5162
|
+
Defined in: [data-structures/binary-tree/bst.ts:3167](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3167)
|
|
4949
5163
|
|
|
4950
5164
|
(Protected) Creates a new, empty instance of the same BST constructor.
|
|
4951
5165
|
|
|
@@ -4993,7 +5207,7 @@ Time O(1)
|
|
|
4993
5207
|
protected _createLike<TK, TV, TR>(iter?, options?): BST<TK, TV, TR>;
|
|
4994
5208
|
```
|
|
4995
5209
|
|
|
4996
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5210
|
+
Defined in: [data-structures/binary-tree/bst.ts:3184](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/bst.ts#L3184)
|
|
4997
5211
|
|
|
4998
5212
|
(Protected) Creates a new instance of the same BST constructor, potentially with different generic types.
|
|
4999
5213
|
|
|
@@ -5053,7 +5267,7 @@ Time O(N log N) or O(N^2) (from constructor) due to processing the iterable.
|
|
|
5053
5267
|
protected _deleteByKey(key): boolean;
|
|
5054
5268
|
```
|
|
5055
5269
|
|
|
5056
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5270
|
+
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)
|
|
5057
5271
|
|
|
5058
5272
|
(Private) Deletes a node by its key.
|
|
5059
5273
|
|
|
@@ -5077,6 +5291,44 @@ Standard BST deletion algorithm. Time O(log N), O(N) worst-case. Space O(1).
|
|
|
5077
5291
|
|
|
5078
5292
|
***
|
|
5079
5293
|
|
|
5294
|
+
### \_deleteInternal()
|
|
5295
|
+
|
|
5296
|
+
```ts
|
|
5297
|
+
protected _deleteInternal(keyNodeEntryRawOrPredicate): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
5298
|
+
```
|
|
5299
|
+
|
|
5300
|
+
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)
|
|
5301
|
+
|
|
5302
|
+
**`Internal`**
|
|
5303
|
+
|
|
5304
|
+
Deletes a node from the tree (internal, returns balancing metadata).
|
|
5305
|
+
|
|
5306
|
+
#### Parameters
|
|
5307
|
+
|
|
5308
|
+
##### keyNodeEntryRawOrPredicate
|
|
5309
|
+
|
|
5310
|
+
\| `NodePredicate`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\> \| `null`\>
|
|
5311
|
+
\| `BTNRep`\<`K`, `V`, [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>
|
|
5312
|
+
|
|
5313
|
+
The node to delete.
|
|
5314
|
+
|
|
5315
|
+
#### Returns
|
|
5316
|
+
|
|
5317
|
+
`BinaryTreeDeleteResult`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>[]
|
|
5318
|
+
|
|
5319
|
+
An array containing deletion results with balancing metadata.
|
|
5320
|
+
|
|
5321
|
+
#### Remarks
|
|
5322
|
+
|
|
5323
|
+
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).
|
|
5324
|
+
Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
5325
|
+
|
|
5326
|
+
#### Inherited from
|
|
5327
|
+
|
|
5328
|
+
[`BinaryTree`](BinaryTree.md).[`_deleteInternal`](BinaryTree.md#_deleteinternal)
|
|
5329
|
+
|
|
5330
|
+
***
|
|
5331
|
+
|
|
5080
5332
|
### \_dfs()
|
|
5081
5333
|
|
|
5082
5334
|
```ts
|
|
@@ -5093,7 +5345,7 @@ protected _dfs<C>(
|
|
|
5093
5345
|
shouldProcessRoot?): ReturnType<C>[];
|
|
5094
5346
|
```
|
|
5095
5347
|
|
|
5096
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5348
|
+
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)
|
|
5097
5349
|
|
|
5098
5350
|
#### Type Parameters
|
|
5099
5351
|
|
|
@@ -5186,7 +5438,7 @@ Array of callback results.
|
|
|
5186
5438
|
protected _displayAux(node, options): NodeDisplayLayout;
|
|
5187
5439
|
```
|
|
5188
5440
|
|
|
5189
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5441
|
+
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)
|
|
5190
5442
|
|
|
5191
5443
|
(Protected) Recursive helper for `toVisual`.
|
|
5192
5444
|
|
|
@@ -5226,7 +5478,7 @@ Time O(N), Space O(N*H) or O(N^2)
|
|
|
5226
5478
|
protected _ensurePredicate(keyNodeEntryOrPredicate): NodePredicate<BinaryTreeNode<K, V>>;
|
|
5227
5479
|
```
|
|
5228
5480
|
|
|
5229
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5481
|
+
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)
|
|
5230
5482
|
|
|
5231
5483
|
(Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
5232
5484
|
|
|
@@ -5265,7 +5517,7 @@ Time O(1)
|
|
|
5265
5517
|
protected _extractKey(keyNodeOrEntry): K | null | undefined;
|
|
5266
5518
|
```
|
|
5267
5519
|
|
|
5268
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5520
|
+
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)
|
|
5269
5521
|
|
|
5270
5522
|
(Protected) Extracts the key from a key, node, or entry.
|
|
5271
5523
|
|
|
@@ -5303,7 +5555,7 @@ Time O(1)
|
|
|
5303
5555
|
protected _floorByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5304
5556
|
```
|
|
5305
5557
|
|
|
5306
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5558
|
+
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)
|
|
5307
5559
|
|
|
5308
5560
|
(Protected) Binary search for floor by key with pruning optimization.
|
|
5309
5561
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5341,7 +5593,7 @@ Time O(h) where h is tree height.
|
|
|
5341
5593
|
protected _floorByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5342
5594
|
```
|
|
5343
5595
|
|
|
5344
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5596
|
+
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)
|
|
5345
5597
|
|
|
5346
5598
|
(Protected) In-order traversal search for floor by predicate.
|
|
5347
5599
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5374,13 +5626,73 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5374
5626
|
|
|
5375
5627
|
***
|
|
5376
5628
|
|
|
5629
|
+
### \_getByRankIterative()
|
|
5630
|
+
|
|
5631
|
+
```ts
|
|
5632
|
+
protected _getByRankIterative(node, k): BSTNode<K, V> | undefined;
|
|
5633
|
+
```
|
|
5634
|
+
|
|
5635
|
+
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)
|
|
5636
|
+
|
|
5637
|
+
(Protected) Finds the node at position k in tree order (iterative).
|
|
5638
|
+
|
|
5639
|
+
#### Parameters
|
|
5640
|
+
|
|
5641
|
+
##### node
|
|
5642
|
+
|
|
5643
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5644
|
+
|
|
5645
|
+
##### k
|
|
5646
|
+
|
|
5647
|
+
`number`
|
|
5648
|
+
|
|
5649
|
+
#### Returns
|
|
5650
|
+
|
|
5651
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5652
|
+
|
|
5653
|
+
#### Remarks
|
|
5654
|
+
|
|
5655
|
+
Time O(log n), Space O(1)
|
|
5656
|
+
|
|
5657
|
+
***
|
|
5658
|
+
|
|
5659
|
+
### \_getByRankRecursive()
|
|
5660
|
+
|
|
5661
|
+
```ts
|
|
5662
|
+
protected _getByRankRecursive(node, k): BSTNode<K, V> | undefined;
|
|
5663
|
+
```
|
|
5664
|
+
|
|
5665
|
+
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)
|
|
5666
|
+
|
|
5667
|
+
(Protected) Finds the node at position k in tree order (recursive).
|
|
5668
|
+
|
|
5669
|
+
#### Parameters
|
|
5670
|
+
|
|
5671
|
+
##### node
|
|
5672
|
+
|
|
5673
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5674
|
+
|
|
5675
|
+
##### k
|
|
5676
|
+
|
|
5677
|
+
`number`
|
|
5678
|
+
|
|
5679
|
+
#### Returns
|
|
5680
|
+
|
|
5681
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5682
|
+
|
|
5683
|
+
#### Remarks
|
|
5684
|
+
|
|
5685
|
+
Time O(log n), Space O(log n) call stack
|
|
5686
|
+
|
|
5687
|
+
***
|
|
5688
|
+
|
|
5377
5689
|
### \_getIterator()
|
|
5378
5690
|
|
|
5379
5691
|
```ts
|
|
5380
5692
|
protected _getIterator(node?): IterableIterator<[K, V | undefined]>;
|
|
5381
5693
|
```
|
|
5382
5694
|
|
|
5383
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5695
|
+
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)
|
|
5384
5696
|
|
|
5385
5697
|
(Protected) Gets the iterator for the tree (default in-order).
|
|
5386
5698
|
|
|
@@ -5408,13 +5720,73 @@ Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the
|
|
|
5408
5720
|
|
|
5409
5721
|
***
|
|
5410
5722
|
|
|
5723
|
+
### \_getRankIterative()
|
|
5724
|
+
|
|
5725
|
+
```ts
|
|
5726
|
+
protected _getRankIterative(node, key): number;
|
|
5727
|
+
```
|
|
5728
|
+
|
|
5729
|
+
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)
|
|
5730
|
+
|
|
5731
|
+
(Protected) Computes the rank of a key iteratively.
|
|
5732
|
+
|
|
5733
|
+
#### Parameters
|
|
5734
|
+
|
|
5735
|
+
##### node
|
|
5736
|
+
|
|
5737
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5738
|
+
|
|
5739
|
+
##### key
|
|
5740
|
+
|
|
5741
|
+
`K`
|
|
5742
|
+
|
|
5743
|
+
#### Returns
|
|
5744
|
+
|
|
5745
|
+
`number`
|
|
5746
|
+
|
|
5747
|
+
#### Remarks
|
|
5748
|
+
|
|
5749
|
+
Time O(log n), Space O(1)
|
|
5750
|
+
|
|
5751
|
+
***
|
|
5752
|
+
|
|
5753
|
+
### \_getRankRecursive()
|
|
5754
|
+
|
|
5755
|
+
```ts
|
|
5756
|
+
protected _getRankRecursive(node, key): number;
|
|
5757
|
+
```
|
|
5758
|
+
|
|
5759
|
+
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)
|
|
5760
|
+
|
|
5761
|
+
(Protected) Computes the rank of a key recursively.
|
|
5762
|
+
|
|
5763
|
+
#### Parameters
|
|
5764
|
+
|
|
5765
|
+
##### node
|
|
5766
|
+
|
|
5767
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
5768
|
+
|
|
5769
|
+
##### key
|
|
5770
|
+
|
|
5771
|
+
`K`
|
|
5772
|
+
|
|
5773
|
+
#### Returns
|
|
5774
|
+
|
|
5775
|
+
`number`
|
|
5776
|
+
|
|
5777
|
+
#### Remarks
|
|
5778
|
+
|
|
5779
|
+
Time O(log n), Space O(log n) call stack
|
|
5780
|
+
|
|
5781
|
+
***
|
|
5782
|
+
|
|
5411
5783
|
### \_isDisplayLeaf()
|
|
5412
5784
|
|
|
5413
5785
|
```ts
|
|
5414
5786
|
protected _isDisplayLeaf(node, options): boolean;
|
|
5415
5787
|
```
|
|
5416
5788
|
|
|
5417
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5789
|
+
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)
|
|
5418
5790
|
|
|
5419
5791
|
Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
5420
5792
|
|
|
@@ -5444,7 +5816,7 @@ Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
|
5444
5816
|
protected _isPredicate(p): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
5445
5817
|
```
|
|
5446
5818
|
|
|
5447
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
5819
|
+
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)
|
|
5448
5820
|
|
|
5449
5821
|
(Protected) Checks if an item is a predicate function.
|
|
5450
5822
|
|
|
@@ -5452,7 +5824,7 @@ Defined in: [data-structures/binary-tree/binary-tree.ts:3305](https://github.com
|
|
|
5452
5824
|
|
|
5453
5825
|
##### p
|
|
5454
5826
|
|
|
5455
|
-
`
|
|
5827
|
+
`unknown`
|
|
5456
5828
|
|
|
5457
5829
|
The item to check.
|
|
5458
5830
|
|
|
@@ -5478,7 +5850,7 @@ Time O(1)
|
|
|
5478
5850
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value?): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
5479
5851
|
```
|
|
5480
5852
|
|
|
5481
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5853
|
+
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)
|
|
5482
5854
|
|
|
5483
5855
|
(Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
5484
5856
|
|
|
@@ -5522,7 +5894,7 @@ Time O(1)
|
|
|
5522
5894
|
protected _lowerByKey(key, iterationType): BSTNode<K, V> | undefined;
|
|
5523
5895
|
```
|
|
5524
5896
|
|
|
5525
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5897
|
+
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)
|
|
5526
5898
|
|
|
5527
5899
|
(Protected) Binary search for lower by key with pruning optimization.
|
|
5528
5900
|
Performs standard BST binary search, choosing left or right subtree based on comparator result.
|
|
@@ -5560,7 +5932,7 @@ Time O(h) where h is tree height.
|
|
|
5560
5932
|
protected _lowerByPredicate(predicate, iterationType): BSTNode<K, V> | undefined;
|
|
5561
5933
|
```
|
|
5562
5934
|
|
|
5563
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
5935
|
+
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)
|
|
5564
5936
|
|
|
5565
5937
|
(Protected) In-order traversal search for lower by predicate.
|
|
5566
5938
|
Falls back to linear in-order traversal when predicate-based search is required.
|
|
@@ -5593,13 +5965,39 @@ Space Complexity: O(h) for recursion, O(h) for iterative stack.
|
|
|
5593
5965
|
|
|
5594
5966
|
***
|
|
5595
5967
|
|
|
5968
|
+
### \_next()
|
|
5969
|
+
|
|
5970
|
+
```ts
|
|
5971
|
+
protected _next(node): BSTNode<K, V> | undefined;
|
|
5972
|
+
```
|
|
5973
|
+
|
|
5974
|
+
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)
|
|
5975
|
+
|
|
5976
|
+
(Protected) Finds the in-order successor of a node.
|
|
5977
|
+
|
|
5978
|
+
#### Parameters
|
|
5979
|
+
|
|
5980
|
+
##### node
|
|
5981
|
+
|
|
5982
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
5983
|
+
|
|
5984
|
+
#### Returns
|
|
5985
|
+
|
|
5986
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\> \| `undefined`
|
|
5987
|
+
|
|
5988
|
+
#### Remarks
|
|
5989
|
+
|
|
5990
|
+
Time O(log n), Space O(1)
|
|
5991
|
+
|
|
5992
|
+
***
|
|
5993
|
+
|
|
5596
5994
|
### \_replaceNode()
|
|
5597
5995
|
|
|
5598
5996
|
```ts
|
|
5599
5997
|
protected _replaceNode(oldNode, newNode): BinaryTreeNode<K, V>;
|
|
5600
5998
|
```
|
|
5601
5999
|
|
|
5602
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6000
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3479](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3479)
|
|
5603
6001
|
|
|
5604
6002
|
(Protected) Replaces a node in the tree with a new node, maintaining children and parent links.
|
|
5605
6003
|
|
|
@@ -5642,7 +6040,7 @@ protected _resolveDisplayLeaf(
|
|
|
5642
6040
|
emptyDisplayLayout): NodeDisplayLayout;
|
|
5643
6041
|
```
|
|
5644
6042
|
|
|
5645
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6043
|
+
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)
|
|
5646
6044
|
|
|
5647
6045
|
Resolve a display leaf node to its layout.
|
|
5648
6046
|
|
|
@@ -5676,7 +6074,7 @@ Resolve a display leaf node to its layout.
|
|
|
5676
6074
|
protected _setRoot(v): void;
|
|
5677
6075
|
```
|
|
5678
6076
|
|
|
5679
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6077
|
+
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)
|
|
5680
6078
|
|
|
5681
6079
|
(Protected) Sets the root node and clears its parent reference.
|
|
5682
6080
|
|
|
@@ -5708,7 +6106,7 @@ Time O(1)
|
|
|
5708
6106
|
protected _setValue(key, value): boolean;
|
|
5709
6107
|
```
|
|
5710
6108
|
|
|
5711
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6109
|
+
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)
|
|
5712
6110
|
|
|
5713
6111
|
(Protected) Sets a value in the external store (Map mode).
|
|
5714
6112
|
|
|
@@ -5748,7 +6146,7 @@ Time O(1) (average for Map.set).
|
|
|
5748
6146
|
protected _snapshotOptions<TK, TV, TR>(): BSTOptions<TK, TV, TR>;
|
|
5749
6147
|
```
|
|
5750
6148
|
|
|
5751
|
-
Defined in: [data-structures/binary-tree/bst.ts:
|
|
6149
|
+
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)
|
|
5752
6150
|
|
|
5753
6151
|
(Protected) Snapshots the current BST's configuration options.
|
|
5754
6152
|
|
|
@@ -5788,7 +6186,7 @@ Time O(1)
|
|
|
5788
6186
|
protected _swapProperties(srcNode, destNode): BinaryTreeNode<K, V> | undefined;
|
|
5789
6187
|
```
|
|
5790
6188
|
|
|
5791
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
6189
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3445](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3445)
|
|
5792
6190
|
|
|
5793
6191
|
(Protected) Swaps the key/value properties of two nodes.
|
|
5794
6192
|
|
|
@@ -5829,3 +6227,55 @@ Time O(1)
|
|
|
5829
6227
|
[`BinaryTree`](BinaryTree.md).[`_swapProperties`](BinaryTree.md#_swapproperties)
|
|
5830
6228
|
|
|
5831
6229
|
***
|
|
6230
|
+
|
|
6231
|
+
### \_updateCount()
|
|
6232
|
+
|
|
6233
|
+
```ts
|
|
6234
|
+
protected _updateCount(node): void;
|
|
6235
|
+
```
|
|
6236
|
+
|
|
6237
|
+
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)
|
|
6238
|
+
|
|
6239
|
+
(Protected) Recalculates the subtree count for a single node.
|
|
6240
|
+
|
|
6241
|
+
#### Parameters
|
|
6242
|
+
|
|
6243
|
+
##### node
|
|
6244
|
+
|
|
6245
|
+
[`BSTNode`](BSTNode.md)\<`K`, `V`\>
|
|
6246
|
+
|
|
6247
|
+
#### Returns
|
|
6248
|
+
|
|
6249
|
+
`void`
|
|
6250
|
+
|
|
6251
|
+
#### Remarks
|
|
6252
|
+
|
|
6253
|
+
Time O(1). Only active when enableOrderStatistic is true.
|
|
6254
|
+
|
|
6255
|
+
***
|
|
6256
|
+
|
|
6257
|
+
### \_updateCountAlongPath()
|
|
6258
|
+
|
|
6259
|
+
```ts
|
|
6260
|
+
protected _updateCountAlongPath(node): void;
|
|
6261
|
+
```
|
|
6262
|
+
|
|
6263
|
+
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)
|
|
6264
|
+
|
|
6265
|
+
(Protected) Updates subtree counts from a node up to the root.
|
|
6266
|
+
|
|
6267
|
+
#### Parameters
|
|
6268
|
+
|
|
6269
|
+
##### node
|
|
6270
|
+
|
|
6271
|
+
`OptNode`\<[`BSTNode`](BSTNode.md)\<`K`, `V`\>\>
|
|
6272
|
+
|
|
6273
|
+
#### Returns
|
|
6274
|
+
|
|
6275
|
+
`void`
|
|
6276
|
+
|
|
6277
|
+
#### Remarks
|
|
6278
|
+
|
|
6279
|
+
Time O(log n). Only active when enableOrderStatistic is true.
|
|
6280
|
+
|
|
6281
|
+
***
|