data-structure-typed 2.5.2 → 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 +3 -1
- package/MIGRATION.md +169 -0
- package/README.md +60 -6
- package/README_CN.md +551 -143
- package/SPECIFICATION.md +20 -14
- package/SPECIFICATION.zh-CN.md +20 -14
- package/dist/cjs/binary-tree.cjs +2417 -132
- package/dist/cjs/graph.cjs +248 -14
- package/dist/cjs/hash.cjs +62 -7
- package/dist/cjs/heap.cjs +103 -16
- package/dist/cjs/index.cjs +3046 -124
- package/dist/cjs/linked-list.cjs +219 -0
- package/dist/cjs/matrix.cjs +32 -0
- package/dist/cjs/priority-queue.cjs +101 -14
- package/dist/cjs/queue.cjs +215 -0
- package/dist/cjs/stack.cjs +44 -4
- package/dist/cjs/trie.cjs +44 -0
- package/dist/cjs-legacy/binary-tree.cjs +2406 -123
- package/dist/cjs-legacy/graph.cjs +248 -14
- package/dist/cjs-legacy/hash.cjs +62 -7
- package/dist/cjs-legacy/heap.cjs +103 -16
- package/dist/cjs-legacy/index.cjs +3105 -185
- package/dist/cjs-legacy/linked-list.cjs +219 -0
- package/dist/cjs-legacy/matrix.cjs +32 -0
- package/dist/cjs-legacy/priority-queue.cjs +101 -14
- package/dist/cjs-legacy/queue.cjs +215 -0
- package/dist/cjs-legacy/stack.cjs +44 -4
- package/dist/cjs-legacy/trie.cjs +44 -0
- package/dist/esm/binary-tree.mjs +2417 -132
- package/dist/esm/graph.mjs +248 -14
- package/dist/esm/hash.mjs +62 -7
- package/dist/esm/heap.mjs +103 -16
- package/dist/esm/index.mjs +3046 -124
- package/dist/esm/linked-list.mjs +219 -0
- package/dist/esm/matrix.mjs +32 -0
- package/dist/esm/priority-queue.mjs +101 -14
- package/dist/esm/queue.mjs +215 -0
- package/dist/esm/stack.mjs +44 -4
- package/dist/esm/trie.mjs +44 -0
- package/dist/esm-legacy/binary-tree.mjs +2406 -123
- package/dist/esm-legacy/graph.mjs +248 -14
- package/dist/esm-legacy/hash.mjs +62 -7
- package/dist/esm-legacy/heap.mjs +103 -16
- package/dist/esm-legacy/index.mjs +3105 -185
- package/dist/esm-legacy/linked-list.mjs +219 -0
- package/dist/esm-legacy/matrix.mjs +32 -0
- package/dist/esm-legacy/priority-queue.mjs +101 -14
- package/dist/esm-legacy/queue.mjs +215 -0
- package/dist/esm-legacy/stack.mjs +44 -4
- package/dist/esm-legacy/trie.mjs +44 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
- package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
- package/dist/types/data-structures/heap/heap.d.ts +98 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
- package/dist/types/data-structures/queue/deque.d.ts +82 -0
- package/dist/types/data-structures/queue/queue.d.ts +61 -0
- package/dist/types/data-structures/stack/stack.d.ts +42 -2
- package/dist/types/data-structures/trie/trie.d.ts +48 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/data-structure-typed.js +3105 -185
- package/dist/umd/data-structure-typed.min.js +4 -4
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +188 -200
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +62 -62
- package/docs-site-docusaurus/docs/api/classes/BST.md +183 -195
- 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 +143 -155
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +99 -85
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +73 -73
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +100 -70
- 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 +38 -38
- 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 +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +48 -48
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +52 -52
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +74 -74
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +73 -73
- 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 +111 -59
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +200 -212
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +75 -75
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +37 -37
- package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +107 -36
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +106 -35
- package/docs-site-docusaurus/docs/api/classes/Trie.md +43 -43
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +72 -72
- package/docs-site-docusaurus/docs/guide/architecture.md +75 -7
- package/docs-site-docusaurus/docs/guide/concepts.md +53 -34
- package/docs-site-docusaurus/docs/guide/faq.md +53 -0
- package/docs-site-docusaurus/docs/guide/guides.md +8 -9
- package/docs-site-docusaurus/docs/guide/integrations.md +74 -177
- package/docs-site-docusaurus/docs/guide/overview.md +131 -17
- package/docs-site-docusaurus/src/pages/index.tsx +4 -0
- package/docs-site-docusaurus/typedoc.json +1 -0
- package/package.json +7 -6
- package/src/data-structures/binary-tree/avl-tree.ts +52 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
- package/src/data-structures/binary-tree/binary-tree.ts +167 -81
- package/src/data-structures/binary-tree/bst.ts +101 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
- package/src/data-structures/binary-tree/segment-tree.ts +24 -0
- package/src/data-structures/binary-tree/tree-map.ts +540 -3
- package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
- package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
- package/src/data-structures/binary-tree/tree-set.ts +520 -3
- package/src/data-structures/graph/directed-graph.ts +41 -1
- package/src/data-structures/graph/undirected-graph.ts +37 -1
- package/src/data-structures/hash/hash-map.ts +67 -12
- package/src/data-structures/heap/heap.ts +107 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
- package/src/data-structures/matrix/matrix.ts +32 -0
- package/src/data-structures/queue/deque.ts +85 -0
- package/src/data-structures/queue/queue.ts +73 -0
- package/src/data-structures/stack/stack.ts +45 -5
- package/src/data-structures/trie/trie.ts +48 -0
- package/src/interfaces/binary-tree.ts +1 -9
- 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: BinaryTree\<K, V, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:270](https://github.com/zrwusa/data-structure-typed/blob/
|
|
9
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:270](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L270)
|
|
10
10
|
|
|
11
11
|
A general Binary Tree implementation.
|
|
12
12
|
|
|
@@ -29,7 +29,7 @@ The `set` operation inserts nodes level-by-level (BFS) into the first available
|
|
|
29
29
|
node?: BinaryTreeNode<string> | null,
|
|
30
30
|
conditions?: { [key: string]: boolean }
|
|
31
31
|
): string {
|
|
32
|
-
if (!node)
|
|
32
|
+
if (!node) throw new Error('Invalid node');
|
|
33
33
|
|
|
34
34
|
// If it's a leaf node, return the decision result
|
|
35
35
|
if (!node.left && !node.right) return node.key;
|
|
@@ -76,7 +76,7 @@ The `set` operation inserts nodes level-by-level (BFS) into the first available
|
|
|
76
76
|
case '/':
|
|
77
77
|
return rightValue !== 0 ? leftValue / rightValue : 0; // Handle division by zero
|
|
78
78
|
default:
|
|
79
|
-
|
|
79
|
+
throw new Error(`Unsupported operator: ${node.key}`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -128,7 +128,7 @@ The type of the raw data object (if using `toEntryFn`).
|
|
|
128
128
|
new BinaryTree<K, V, R>(keysNodesEntriesOrRaws?, options?): BinaryTree<K, V, R>;
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:283](https://github.com/zrwusa/data-structure-typed/blob/
|
|
131
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:283](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L283)
|
|
132
132
|
|
|
133
133
|
Creates an instance of BinaryTree.
|
|
134
134
|
|
|
@@ -176,7 +176,7 @@ IterableEntryBase<K, V | undefined>.constructor
|
|
|
176
176
|
get isDuplicate(): boolean;
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:322](https://github.com/zrwusa/data-structure-typed/blob/
|
|
179
|
+
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)
|
|
180
180
|
|
|
181
181
|
Gets whether the tree allows duplicate keys.
|
|
182
182
|
|
|
@@ -206,7 +206,7 @@ IBinaryTree.isDuplicate
|
|
|
206
206
|
get isMapMode(): boolean;
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:310](https://github.com/zrwusa/data-structure-typed/blob/
|
|
209
|
+
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)
|
|
210
210
|
|
|
211
211
|
Gets whether the tree is in Map mode.
|
|
212
212
|
|
|
@@ -236,7 +236,7 @@ IBinaryTree.isMapMode
|
|
|
236
236
|
get NIL(): BinaryTreeNode<K, V>;
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:373](https://github.com/zrwusa/data-structure-typed/blob/
|
|
239
|
+
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)
|
|
240
240
|
|
|
241
241
|
Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
242
242
|
|
|
@@ -266,7 +266,7 @@ IBinaryTree.NIL
|
|
|
266
266
|
get root(): BinaryTreeNode<K, V> | null | undefined;
|
|
267
267
|
```
|
|
268
268
|
|
|
269
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:349](https://github.com/zrwusa/data-structure-typed/blob/
|
|
269
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:349](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L349)
|
|
270
270
|
|
|
271
271
|
Gets the root node of the tree.
|
|
272
272
|
|
|
@@ -296,7 +296,7 @@ IBinaryTree.root
|
|
|
296
296
|
get size(): number;
|
|
297
297
|
```
|
|
298
298
|
|
|
299
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:361](https://github.com/zrwusa/data-structure-typed/blob/
|
|
299
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:361](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L361)
|
|
300
300
|
|
|
301
301
|
Gets the number of nodes in the tree.
|
|
302
302
|
|
|
@@ -330,7 +330,7 @@ IBinaryTree.size
|
|
|
330
330
|
get store(): Map<K, BinaryTreeNode<K, V>>;
|
|
331
331
|
```
|
|
332
332
|
|
|
333
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:337](https://github.com/zrwusa/data-structure-typed/blob/
|
|
333
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:337](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L337)
|
|
334
334
|
|
|
335
335
|
Gets the external value store (used in Map mode).
|
|
336
336
|
|
|
@@ -360,7 +360,7 @@ IBinaryTree.store
|
|
|
360
360
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
361
361
|
```
|
|
362
362
|
|
|
363
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:385](https://github.com/zrwusa/data-structure-typed/blob/
|
|
363
|
+
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)
|
|
364
364
|
|
|
365
365
|
Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
366
366
|
|
|
@@ -388,7 +388,7 @@ IBinaryTree.toEntryFn
|
|
|
388
388
|
iterator: IterableIterator<[K, V | undefined]>;
|
|
389
389
|
```
|
|
390
390
|
|
|
391
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:22](https://github.com/zrwusa/data-structure-typed/blob/
|
|
391
|
+
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)
|
|
392
392
|
|
|
393
393
|
Default iterator yielding `[key, value]` entries.
|
|
394
394
|
|
|
@@ -426,7 +426,7 @@ IBinaryTree.[iterator]
|
|
|
426
426
|
add(keyNodeOrEntry): boolean;
|
|
427
427
|
```
|
|
428
428
|
|
|
429
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
429
|
+
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)
|
|
430
430
|
|
|
431
431
|
Adds a new node to the tree.
|
|
432
432
|
|
|
@@ -452,7 +452,7 @@ True if the addition was successful, false otherwise.
|
|
|
452
452
|
|
|
453
453
|
#### Remarks
|
|
454
454
|
|
|
455
|
-
Time O(
|
|
455
|
+
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).
|
|
456
456
|
|
|
457
457
|
#### Example
|
|
458
458
|
|
|
@@ -480,7 +480,7 @@ IBinaryTree.add
|
|
|
480
480
|
addMany(keysNodesEntriesOrRaws): boolean[];
|
|
481
481
|
```
|
|
482
482
|
|
|
483
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
483
|
+
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)
|
|
484
484
|
|
|
485
485
|
Adds multiple items to the tree.
|
|
486
486
|
|
|
@@ -561,7 +561,7 @@ If true, includes null nodes in the traversal.
|
|
|
561
561
|
bfs(): (K | undefined)[];
|
|
562
562
|
```
|
|
563
563
|
|
|
564
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
564
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2249](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2249)
|
|
565
565
|
|
|
566
566
|
BinaryTree level-order traversal
|
|
567
567
|
|
|
@@ -618,7 +618,7 @@ bfs<C>(
|
|
|
618
618
|
includeNull?): ReturnType<C>[];
|
|
619
619
|
```
|
|
620
620
|
|
|
621
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
621
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2251](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2251)
|
|
622
622
|
|
|
623
623
|
BinaryTree level-order traversal
|
|
624
624
|
|
|
@@ -702,7 +702,7 @@ bfs<C>(
|
|
|
702
702
|
includeNull?): ReturnType<C>[];
|
|
703
703
|
```
|
|
704
704
|
|
|
705
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
705
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2258](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2258)
|
|
706
706
|
|
|
707
707
|
BinaryTree level-order traversal
|
|
708
708
|
|
|
@@ -784,7 +784,7 @@ IBinaryTree.bfs
|
|
|
784
784
|
clear(): void;
|
|
785
785
|
```
|
|
786
786
|
|
|
787
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
787
|
+
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)
|
|
788
788
|
|
|
789
789
|
Clears the tree of all nodes and values.
|
|
790
790
|
|
|
@@ -825,7 +825,7 @@ IBinaryTree.clear
|
|
|
825
825
|
clone(): this;
|
|
826
826
|
```
|
|
827
827
|
|
|
828
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
828
|
+
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)
|
|
829
829
|
|
|
830
830
|
Clones the tree.
|
|
831
831
|
|
|
@@ -869,7 +869,7 @@ IBinaryTree.clone
|
|
|
869
869
|
createNode(key, value?): BinaryTreeNode<K, V>;
|
|
870
870
|
```
|
|
871
871
|
|
|
872
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:397](https://github.com/zrwusa/data-structure-typed/blob/
|
|
872
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:397](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L397)
|
|
873
873
|
|
|
874
874
|
(Protected) Creates a new node.
|
|
875
875
|
|
|
@@ -911,7 +911,7 @@ IBinaryTree.createNode
|
|
|
911
911
|
createTree(options?): this;
|
|
912
912
|
```
|
|
913
913
|
|
|
914
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:408](https://github.com/zrwusa/data-structure-typed/blob/
|
|
914
|
+
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)
|
|
915
915
|
|
|
916
916
|
Creates a new, empty tree of the same type and configuration.
|
|
917
917
|
|
|
@@ -944,10 +944,10 @@ IBinaryTree.createTree
|
|
|
944
944
|
### delete()
|
|
945
945
|
|
|
946
946
|
```ts
|
|
947
|
-
delete(keyNodeEntryRawOrPredicate):
|
|
947
|
+
delete(keyNodeEntryRawOrPredicate): boolean;
|
|
948
948
|
```
|
|
949
949
|
|
|
950
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
950
|
+
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)
|
|
951
951
|
|
|
952
952
|
Deletes a node from the tree.
|
|
953
953
|
|
|
@@ -962,15 +962,15 @@ The node to delete.
|
|
|
962
962
|
|
|
963
963
|
#### Returns
|
|
964
964
|
|
|
965
|
-
`
|
|
965
|
+
`boolean`
|
|
966
966
|
|
|
967
|
-
|
|
967
|
+
True if the node was found and deleted, false otherwise.
|
|
968
968
|
|
|
969
969
|
*
|
|
970
970
|
|
|
971
971
|
#### Remarks
|
|
972
972
|
|
|
973
|
-
Time O(
|
|
973
|
+
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).
|
|
974
974
|
|
|
975
975
|
#### Example
|
|
976
976
|
|
|
@@ -1032,7 +1032,7 @@ If true, includes null nodes in the traversal.
|
|
|
1032
1032
|
dfs(): (K | undefined)[];
|
|
1033
1033
|
```
|
|
1034
1034
|
|
|
1035
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1035
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2135](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2135)
|
|
1036
1036
|
|
|
1037
1037
|
Depth-first search traversal
|
|
1038
1038
|
|
|
@@ -1068,7 +1068,7 @@ dfs<C>(
|
|
|
1068
1068
|
iterationType?): ReturnType<C>[];
|
|
1069
1069
|
```
|
|
1070
1070
|
|
|
1071
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1071
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2137](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2137)
|
|
1072
1072
|
|
|
1073
1073
|
Depth-first search traversal
|
|
1074
1074
|
|
|
@@ -1136,7 +1136,7 @@ dfs<C>(
|
|
|
1136
1136
|
includeNull?): ReturnType<C>[];
|
|
1137
1137
|
```
|
|
1138
1138
|
|
|
1139
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1139
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2145](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2145)
|
|
1140
1140
|
|
|
1141
1141
|
Depth-first search traversal
|
|
1142
1142
|
|
|
@@ -1204,7 +1204,7 @@ IBinaryTree.dfs
|
|
|
1204
1204
|
ensureNode(keyNodeOrEntry, iterationType?): BinaryTreeNode<K, V> | null | undefined;
|
|
1205
1205
|
```
|
|
1206
1206
|
|
|
1207
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:420](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1207
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:420](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L420)
|
|
1208
1208
|
|
|
1209
1209
|
Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
1210
1210
|
|
|
@@ -1244,7 +1244,7 @@ Time O(1) if a node is passed. O(N) if a key or entry is passed (due to `getNode
|
|
|
1244
1244
|
entries(): IterableIterator<[K, V | undefined]>;
|
|
1245
1245
|
```
|
|
1246
1246
|
|
|
1247
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:31](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1247
|
+
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)
|
|
1248
1248
|
|
|
1249
1249
|
Iterate over `[key, value]` pairs (may yield `undefined` values).
|
|
1250
1250
|
|
|
@@ -1276,7 +1276,7 @@ IBinaryTree.entries
|
|
|
1276
1276
|
every(predicate, thisArg?): boolean;
|
|
1277
1277
|
```
|
|
1278
1278
|
|
|
1279
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:66](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1279
|
+
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)
|
|
1280
1280
|
|
|
1281
1281
|
Test whether all entries satisfy the predicate.
|
|
1282
1282
|
|
|
@@ -1322,7 +1322,7 @@ IBinaryTree.every
|
|
|
1322
1322
|
filter(predicate, thisArg?): this;
|
|
1323
1323
|
```
|
|
1324
1324
|
|
|
1325
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1325
|
+
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)
|
|
1326
1326
|
|
|
1327
1327
|
Creates a new tree containing only the entries that satisfy the predicate.
|
|
1328
1328
|
|
|
@@ -1379,7 +1379,7 @@ IBinaryTree.filter
|
|
|
1379
1379
|
find(callbackfn, thisArg?): [K, V | undefined] | undefined;
|
|
1380
1380
|
```
|
|
1381
1381
|
|
|
1382
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:114](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1382
|
+
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)
|
|
1383
1383
|
|
|
1384
1384
|
Find the first entry that matches a predicate.
|
|
1385
1385
|
|
|
@@ -1425,7 +1425,7 @@ IBinaryTree.find
|
|
|
1425
1425
|
forEach(callbackfn, thisArg?): void;
|
|
1426
1426
|
```
|
|
1427
1427
|
|
|
1428
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:99](https://github.com/zrwusa/data-structure-typed/blob/
|
|
1428
|
+
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)
|
|
1429
1429
|
|
|
1430
1430
|
Visit each entry, left-to-right.
|
|
1431
1431
|
|
|
@@ -1472,7 +1472,7 @@ get(
|
|
|
1472
1472
|
iterationType?): V | undefined;
|
|
1473
1473
|
```
|
|
1474
1474
|
|
|
1475
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1475
|
+
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)
|
|
1476
1476
|
|
|
1477
1477
|
Gets the value associated with a key.
|
|
1478
1478
|
|
|
@@ -1513,7 +1513,7 @@ The associated value, or undefined.
|
|
|
1513
1513
|
|
|
1514
1514
|
#### Remarks
|
|
1515
1515
|
|
|
1516
|
-
Time O(
|
|
1516
|
+
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).
|
|
1517
1517
|
|
|
1518
1518
|
#### Example
|
|
1519
1519
|
|
|
@@ -1542,7 +1542,7 @@ IBinaryTree.get
|
|
|
1542
1542
|
getDepth(dist, startNode?): number;
|
|
1543
1543
|
```
|
|
1544
1544
|
|
|
1545
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1545
|
+
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)
|
|
1546
1546
|
|
|
1547
1547
|
Gets the depth of a node (distance from `startNode`).
|
|
1548
1548
|
|
|
@@ -1602,7 +1602,7 @@ IBinaryTree.getDepth
|
|
|
1602
1602
|
getHeight(startNode?, iterationType?): number;
|
|
1603
1603
|
```
|
|
1604
1604
|
|
|
1605
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1605
|
+
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)
|
|
1606
1606
|
|
|
1607
1607
|
Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
1608
1608
|
|
|
@@ -1681,7 +1681,7 @@ The traversal method.
|
|
|
1681
1681
|
getLeftMost(): K | undefined;
|
|
1682
1682
|
```
|
|
1683
1683
|
|
|
1684
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1684
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1951](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1951)
|
|
1685
1685
|
|
|
1686
1686
|
##### Returns
|
|
1687
1687
|
|
|
@@ -1702,7 +1702,7 @@ getLeftMost<C>(
|
|
|
1702
1702
|
iterationType?): ReturnType<C>;
|
|
1703
1703
|
```
|
|
1704
1704
|
|
|
1705
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1705
|
+
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)
|
|
1706
1706
|
|
|
1707
1707
|
##### Type Parameters
|
|
1708
1708
|
|
|
@@ -1745,7 +1745,7 @@ IBinaryTree.getLeftMost
|
|
|
1745
1745
|
getMinHeight(startNode?, iterationType?): number;
|
|
1746
1746
|
```
|
|
1747
1747
|
|
|
1748
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1748
|
+
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)
|
|
1749
1749
|
|
|
1750
1750
|
Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
1751
1751
|
|
|
@@ -1793,7 +1793,7 @@ getNode(
|
|
|
1793
1793
|
iterationType?): BinaryTreeNode<K, V> | null | undefined;
|
|
1794
1794
|
```
|
|
1795
1795
|
|
|
1796
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1796
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1301](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1301)
|
|
1797
1797
|
|
|
1798
1798
|
Gets the first node matching a predicate.
|
|
1799
1799
|
|
|
@@ -1835,7 +1835,7 @@ The first matching node, or undefined if not found.
|
|
|
1835
1835
|
|
|
1836
1836
|
#### Remarks
|
|
1837
1837
|
|
|
1838
|
-
Time O(
|
|
1838
|
+
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.
|
|
1839
1839
|
|
|
1840
1840
|
#### Example
|
|
1841
1841
|
|
|
@@ -1863,7 +1863,7 @@ getNodes(
|
|
|
1863
1863
|
iterationType?): BinaryTreeNode<K, V>[];
|
|
1864
1864
|
```
|
|
1865
1865
|
|
|
1866
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1866
|
+
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)
|
|
1867
1867
|
|
|
1868
1868
|
Gets all nodes matching a predicate.
|
|
1869
1869
|
|
|
@@ -1954,7 +1954,7 @@ If true, returns the path from root-to-node.
|
|
|
1954
1954
|
getPathToRoot(beginNode): (K | undefined)[];
|
|
1955
1955
|
```
|
|
1956
1956
|
|
|
1957
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1957
|
+
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)
|
|
1958
1958
|
|
|
1959
1959
|
##### Parameters
|
|
1960
1960
|
|
|
@@ -1985,7 +1985,7 @@ getPathToRoot<C>(
|
|
|
1985
1985
|
isReverse?): ReturnType<C>[];
|
|
1986
1986
|
```
|
|
1987
1987
|
|
|
1988
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
1988
|
+
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)
|
|
1989
1989
|
|
|
1990
1990
|
##### Type Parameters
|
|
1991
1991
|
|
|
@@ -2029,7 +2029,7 @@ IBinaryTree.getPathToRoot
|
|
|
2029
2029
|
getPredecessor(node): BinaryTreeNode<K, V>;
|
|
2030
2030
|
```
|
|
2031
2031
|
|
|
2032
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2032
|
+
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)
|
|
2033
2033
|
|
|
2034
2034
|
Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
2035
2035
|
|
|
@@ -2083,7 +2083,7 @@ The traversal method.
|
|
|
2083
2083
|
getRightMost(): K | undefined;
|
|
2084
2084
|
```
|
|
2085
2085
|
|
|
2086
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2086
|
+
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)
|
|
2087
2087
|
|
|
2088
2088
|
##### Returns
|
|
2089
2089
|
|
|
@@ -2104,7 +2104,7 @@ getRightMost<C>(
|
|
|
2104
2104
|
iterationType?): ReturnType<C>;
|
|
2105
2105
|
```
|
|
2106
2106
|
|
|
2107
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2107
|
+
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)
|
|
2108
2108
|
|
|
2109
2109
|
##### Type Parameters
|
|
2110
2110
|
|
|
@@ -2147,7 +2147,7 @@ IBinaryTree.getRightMost
|
|
|
2147
2147
|
getSuccessor(x?): BinaryTreeNode<K, V> | null | undefined;
|
|
2148
2148
|
```
|
|
2149
2149
|
|
|
2150
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2150
|
+
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)
|
|
2151
2151
|
|
|
2152
2152
|
Gets the in-order successor of a node in a BST.
|
|
2153
2153
|
|
|
@@ -2180,7 +2180,7 @@ has(
|
|
|
2180
2180
|
iterationType?): boolean;
|
|
2181
2181
|
```
|
|
2182
2182
|
|
|
2183
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2183
|
+
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)
|
|
2184
2184
|
|
|
2185
2185
|
Checks if a node matching the predicate exists in the tree.
|
|
2186
2186
|
|
|
@@ -2221,7 +2221,7 @@ True if a matching node exists, false otherwise.
|
|
|
2221
2221
|
|
|
2222
2222
|
#### Remarks
|
|
2223
2223
|
|
|
2224
|
-
Time O(
|
|
2224
|
+
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.
|
|
2225
2225
|
|
|
2226
2226
|
#### Example
|
|
2227
2227
|
|
|
@@ -2273,7 +2273,7 @@ IBinaryTree.has
|
|
|
2273
2273
|
hasValue(value): boolean;
|
|
2274
2274
|
```
|
|
2275
2275
|
|
|
2276
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:143](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2276
|
+
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)
|
|
2277
2277
|
|
|
2278
2278
|
Whether there exists an entry with the given value.
|
|
2279
2279
|
|
|
@@ -2313,7 +2313,7 @@ IBinaryTree.hasValue
|
|
|
2313
2313
|
isBST(startNode?, iterationType?): boolean;
|
|
2314
2314
|
```
|
|
2315
2315
|
|
|
2316
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2316
|
+
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)
|
|
2317
2317
|
|
|
2318
2318
|
Checks if the tree is a valid Binary Search Tree (BST).
|
|
2319
2319
|
|
|
@@ -2369,7 +2369,7 @@ IBinaryTree.isBST
|
|
|
2369
2369
|
isEmpty(): boolean;
|
|
2370
2370
|
```
|
|
2371
2371
|
|
|
2372
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2372
|
+
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)
|
|
2373
2373
|
|
|
2374
2374
|
Checks if the tree is empty.
|
|
2375
2375
|
|
|
@@ -2410,7 +2410,7 @@ IBinaryTree.isEmpty
|
|
|
2410
2410
|
isEntry(keyNodeOrEntry): keyNodeOrEntry is BTNEntry<K, V>;
|
|
2411
2411
|
```
|
|
2412
2412
|
|
|
2413
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:545](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2413
|
+
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)
|
|
2414
2414
|
|
|
2415
2415
|
Checks if the given item is a [key, value] entry pair.
|
|
2416
2416
|
|
|
@@ -2444,7 +2444,7 @@ Time O(1), Space O(1)
|
|
|
2444
2444
|
isLeaf(keyNodeOrEntry): boolean;
|
|
2445
2445
|
```
|
|
2446
2446
|
|
|
2447
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:531](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2447
|
+
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)
|
|
2448
2448
|
|
|
2449
2449
|
Checks if a node is a leaf (has no real children).
|
|
2450
2450
|
|
|
@@ -2478,7 +2478,7 @@ Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is pass
|
|
|
2478
2478
|
isNIL(keyNodeOrEntry): boolean;
|
|
2479
2479
|
```
|
|
2480
2480
|
|
|
2481
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:500](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2481
|
+
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)
|
|
2482
2482
|
|
|
2483
2483
|
Checks if the given item is the sentinel NIL node.
|
|
2484
2484
|
|
|
@@ -2512,7 +2512,7 @@ Time O(1), Space O(1)
|
|
|
2512
2512
|
isNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
2513
2513
|
```
|
|
2514
2514
|
|
|
2515
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:447](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2515
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:447](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L447)
|
|
2516
2516
|
|
|
2517
2517
|
Checks if the given item is a `BinaryTreeNode` instance.
|
|
2518
2518
|
|
|
@@ -2546,7 +2546,7 @@ Time O(1), Space O(1)
|
|
|
2546
2546
|
isPerfectlyBalanced(startNode?): boolean;
|
|
2547
2547
|
```
|
|
2548
2548
|
|
|
2549
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2549
|
+
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)
|
|
2550
2550
|
|
|
2551
2551
|
Checks if the tree is perfectly balanced.
|
|
2552
2552
|
|
|
@@ -2585,7 +2585,7 @@ IBinaryTree.isPerfectlyBalanced
|
|
|
2585
2585
|
isRange(keyNodeEntryOrPredicate): keyNodeEntryOrPredicate is Range<K>;
|
|
2586
2586
|
```
|
|
2587
2587
|
|
|
2588
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:511](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2588
|
+
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)
|
|
2589
2589
|
|
|
2590
2590
|
Checks if the given item is a `Range` object.
|
|
2591
2591
|
|
|
@@ -2621,7 +2621,7 @@ Time O(1), Space O(1)
|
|
|
2621
2621
|
isRaw(keyNodeEntryOrRaw): keyNodeEntryOrRaw is R;
|
|
2622
2622
|
```
|
|
2623
2623
|
|
|
2624
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:460](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2624
|
+
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)
|
|
2625
2625
|
|
|
2626
2626
|
Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
2627
2627
|
|
|
@@ -2656,7 +2656,7 @@ Time O(1), Space O(1)
|
|
|
2656
2656
|
isRealNode(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
2657
2657
|
```
|
|
2658
2658
|
|
|
2659
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:473](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2659
|
+
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)
|
|
2660
2660
|
|
|
2661
2661
|
Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
2662
2662
|
|
|
@@ -2690,7 +2690,7 @@ Time O(1), Space O(1)
|
|
|
2690
2690
|
isRealNodeOrNull(keyNodeOrEntry): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
2691
2691
|
```
|
|
2692
2692
|
|
|
2693
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:487](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2693
|
+
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)
|
|
2694
2694
|
|
|
2695
2695
|
Checks if the given item is either a "real" node or null.
|
|
2696
2696
|
|
|
@@ -2724,7 +2724,7 @@ Time O(1), Space O(1)
|
|
|
2724
2724
|
isValidKey(key): key is K;
|
|
2725
2725
|
```
|
|
2726
2726
|
|
|
2727
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:558](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2727
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:558](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L558)
|
|
2728
2728
|
|
|
2729
2729
|
Checks if the given key is valid (comparable or null).
|
|
2730
2730
|
|
|
@@ -2754,7 +2754,7 @@ Time O(1), Space O(1)
|
|
|
2754
2754
|
keys(): IterableIterator<K>;
|
|
2755
2755
|
```
|
|
2756
2756
|
|
|
2757
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:42](https://github.com/zrwusa/data-structure-typed/blob/
|
|
2757
|
+
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)
|
|
2758
2758
|
|
|
2759
2759
|
Iterate over keys only.
|
|
2760
2760
|
|
|
@@ -2810,7 +2810,7 @@ The traversal method.
|
|
|
2810
2810
|
leaves(): (K | undefined)[];
|
|
2811
2811
|
```
|
|
2812
2812
|
|
|
2813
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2813
|
+
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)
|
|
2814
2814
|
|
|
2815
2815
|
Get leaf nodes
|
|
2816
2816
|
|
|
@@ -2844,7 +2844,7 @@ leaves<C>(
|
|
|
2844
2844
|
iterationType?): ReturnType<C>[];
|
|
2845
2845
|
```
|
|
2846
2846
|
|
|
2847
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2847
|
+
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)
|
|
2848
2848
|
|
|
2849
2849
|
Get leaf nodes
|
|
2850
2850
|
|
|
@@ -2928,7 +2928,7 @@ If true, includes null nodes.
|
|
|
2928
2928
|
listLevels(): (K | undefined)[][];
|
|
2929
2929
|
```
|
|
2930
2930
|
|
|
2931
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2931
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2483](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2483)
|
|
2932
2932
|
|
|
2933
2933
|
Level-order grouping
|
|
2934
2934
|
|
|
@@ -2964,7 +2964,7 @@ listLevels<C>(
|
|
|
2964
2964
|
includeNull?): ReturnType<C>[][];
|
|
2965
2965
|
```
|
|
2966
2966
|
|
|
2967
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
2967
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2485](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2485)
|
|
2968
2968
|
|
|
2969
2969
|
Level-order grouping
|
|
2970
2970
|
|
|
@@ -3027,7 +3027,7 @@ listLevels<C>(
|
|
|
3027
3027
|
includeNull?): ReturnType<C>[][];
|
|
3028
3028
|
```
|
|
3029
3029
|
|
|
3030
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3030
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2492](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2492)
|
|
3031
3031
|
|
|
3032
3032
|
Level-order grouping
|
|
3033
3033
|
|
|
@@ -3091,7 +3091,7 @@ map<MK, MV, MR>(
|
|
|
3091
3091
|
thisArg?): BinaryTree<MK, MV, MR>;
|
|
3092
3092
|
```
|
|
3093
3093
|
|
|
3094
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3094
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:2888](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L2888)
|
|
3095
3095
|
|
|
3096
3096
|
Creates a new tree by mapping each [key, value] pair to a new entry.
|
|
3097
3097
|
|
|
@@ -3174,7 +3174,7 @@ IBinaryTree.map
|
|
|
3174
3174
|
merge(anotherTree): void;
|
|
3175
3175
|
```
|
|
3176
3176
|
|
|
3177
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3177
|
+
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)
|
|
3178
3178
|
|
|
3179
3179
|
Merges another tree into this one by seting all its nodes.
|
|
3180
3180
|
|
|
@@ -3244,7 +3244,7 @@ The node to start from.
|
|
|
3244
3244
|
morris(): (K | undefined)[];
|
|
3245
3245
|
```
|
|
3246
3246
|
|
|
3247
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3247
|
+
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)
|
|
3248
3248
|
|
|
3249
3249
|
Morris traversal (O(1) space)
|
|
3250
3250
|
|
|
@@ -3278,7 +3278,7 @@ morris<C>(
|
|
|
3278
3278
|
startNode?): ReturnType<C>[];
|
|
3279
3279
|
```
|
|
3280
3280
|
|
|
3281
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3281
|
+
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)
|
|
3282
3282
|
|
|
3283
3283
|
Morris traversal (O(1) space)
|
|
3284
3284
|
|
|
@@ -3334,7 +3334,7 @@ IBinaryTree.morris
|
|
|
3334
3334
|
print(options?, startNode?): void;
|
|
3335
3335
|
```
|
|
3336
3336
|
|
|
3337
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3337
|
+
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)
|
|
3338
3338
|
|
|
3339
3339
|
Prints a visual representation of the tree to the console.
|
|
3340
3340
|
|
|
@@ -3385,7 +3385,7 @@ Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
|
3385
3385
|
reduce<U>(callbackfn, initialValue): U;
|
|
3386
3386
|
```
|
|
3387
3387
|
|
|
3388
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:171](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3388
|
+
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)
|
|
3389
3389
|
|
|
3390
3390
|
Reduce entries into a single accumulator.
|
|
3391
3391
|
|
|
@@ -3431,59 +3431,13 @@ IBinaryTree.reduce
|
|
|
3431
3431
|
|
|
3432
3432
|
***
|
|
3433
3433
|
|
|
3434
|
-
### refill()
|
|
3435
|
-
|
|
3436
|
-
```ts
|
|
3437
|
-
refill(keysNodesEntriesOrRaws, values?): void;
|
|
3438
|
-
```
|
|
3439
|
-
|
|
3440
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:913](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/binary-tree.ts#L913)
|
|
3441
|
-
|
|
3442
|
-
Clears the tree and refills it with new items.
|
|
3443
|
-
|
|
3444
|
-
#### Parameters
|
|
3445
|
-
|
|
3446
|
-
##### keysNodesEntriesOrRaws
|
|
3447
|
-
|
|
3448
|
-
`Iterable`\<
|
|
3449
|
-
\| `K`
|
|
3450
|
-
\| `R`
|
|
3451
|
-
\| [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>
|
|
3452
|
-
\| \[`K` \| `null` \| `undefined`, `V` \| `undefined`\]
|
|
3453
|
-
\| `null`
|
|
3454
|
-
\| `undefined`\>
|
|
3455
|
-
|
|
3456
|
-
An iterable of items to set.
|
|
3457
|
-
|
|
3458
|
-
##### values?
|
|
3459
|
-
|
|
3460
|
-
`Iterable`\<`V` \| `undefined`, `any`, `any`\>
|
|
3461
|
-
|
|
3462
|
-
An optional parallel iterable of values.
|
|
3463
|
-
|
|
3464
|
-
#### Returns
|
|
3465
|
-
|
|
3466
|
-
`void`
|
|
3467
|
-
|
|
3468
|
-
#### Remarks
|
|
3469
|
-
|
|
3470
|
-
Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
3471
|
-
|
|
3472
|
-
#### Implementation of
|
|
3473
|
-
|
|
3474
|
-
```ts
|
|
3475
|
-
IBinaryTree.refill
|
|
3476
|
-
```
|
|
3477
|
-
|
|
3478
|
-
***
|
|
3479
|
-
|
|
3480
3434
|
### search()
|
|
3481
3435
|
|
|
3482
3436
|
Searches the tree for nodes matching a predicate.
|
|
3483
3437
|
|
|
3484
3438
|
#### Remarks
|
|
3485
3439
|
|
|
3486
|
-
Time O(
|
|
3440
|
+
Time O(N) — full DFS scan; may visit every node. Space O(H) for call/explicit stack (O(N) worst-case). BST subclasses with key search override to O(log N).
|
|
3487
3441
|
|
|
3488
3442
|
#### Template
|
|
3489
3443
|
|
|
@@ -3515,7 +3469,7 @@ Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
|
3515
3469
|
search(keyNodeEntryOrPredicate, onlyOne?): (K | undefined)[];
|
|
3516
3470
|
```
|
|
3517
3471
|
|
|
3518
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3472
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1083](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1083)
|
|
3519
3473
|
|
|
3520
3474
|
Search by predicate
|
|
3521
3475
|
|
|
@@ -3566,7 +3520,7 @@ search<C>(
|
|
|
3566
3520
|
iterationType?): ReturnType<C>[];
|
|
3567
3521
|
```
|
|
3568
3522
|
|
|
3569
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3523
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:1094](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L1094)
|
|
3570
3524
|
|
|
3571
3525
|
Search by predicate
|
|
3572
3526
|
|
|
@@ -3635,7 +3589,7 @@ IBinaryTree.search
|
|
|
3635
3589
|
set(keyNodeOrEntry, value?): boolean;
|
|
3636
3590
|
```
|
|
3637
3591
|
|
|
3638
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3592
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:688](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L688)
|
|
3639
3593
|
|
|
3640
3594
|
Adds or updates a new node to the tree.
|
|
3641
3595
|
|
|
@@ -3667,7 +3621,7 @@ True if the addition was successful, false otherwise.
|
|
|
3667
3621
|
|
|
3668
3622
|
#### Remarks
|
|
3669
3623
|
|
|
3670
|
-
Time O(
|
|
3624
|
+
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).
|
|
3671
3625
|
|
|
3672
3626
|
#### Example
|
|
3673
3627
|
|
|
@@ -3710,7 +3664,7 @@ IBinaryTree.set
|
|
|
3710
3664
|
setMany(keysNodesEntriesOrRaws, values?): boolean[];
|
|
3711
3665
|
```
|
|
3712
3666
|
|
|
3713
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3667
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:844](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L844)
|
|
3714
3668
|
|
|
3715
3669
|
Adds or updates multiple items to the tree.
|
|
3716
3670
|
|
|
@@ -3763,7 +3717,7 @@ Time O(N * M), where N is the number of items to set and M is the size of the tr
|
|
|
3763
3717
|
some(predicate, thisArg?): boolean;
|
|
3764
3718
|
```
|
|
3765
3719
|
|
|
3766
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:83](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3720
|
+
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)
|
|
3767
3721
|
|
|
3768
3722
|
Test whether any entry satisfies the predicate.
|
|
3769
3723
|
|
|
@@ -3809,7 +3763,7 @@ IBinaryTree.some
|
|
|
3809
3763
|
toArray(): [K, V | undefined][];
|
|
3810
3764
|
```
|
|
3811
3765
|
|
|
3812
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:186](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3766
|
+
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)
|
|
3813
3767
|
|
|
3814
3768
|
Converts data structure to `[key, value]` pairs.
|
|
3815
3769
|
|
|
@@ -3835,7 +3789,7 @@ Time O(n), Space O(n)
|
|
|
3835
3789
|
toVisual(startNode?, options?): string;
|
|
3836
3790
|
```
|
|
3837
3791
|
|
|
3838
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3792
|
+
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)
|
|
3839
3793
|
|
|
3840
3794
|
Generates a string representation of the tree for visualization.
|
|
3841
3795
|
|
|
@@ -3878,7 +3832,7 @@ Time O(N), visits every node. Space O(N*H) or O(N^2) in the worst case, as the s
|
|
|
3878
3832
|
values(): IterableIterator<V | undefined>;
|
|
3879
3833
|
```
|
|
3880
3834
|
|
|
3881
|
-
Defined in: [data-structures/base/iterable-entry-base.ts:53](https://github.com/zrwusa/data-structure-typed/blob/
|
|
3835
|
+
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)
|
|
3882
3836
|
|
|
3883
3837
|
Iterate over values only.
|
|
3884
3838
|
|
|
@@ -3913,7 +3867,7 @@ IBinaryTree.values
|
|
|
3913
3867
|
protected readonly _DEFAULT_NODE_CALLBACK: NodeCallback<BinaryTreeNode<K, V> | null | undefined, K | undefined>;
|
|
3914
3868
|
```
|
|
3915
3869
|
|
|
3916
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3870
|
+
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)
|
|
3917
3871
|
|
|
3918
3872
|
(Protected) Default callback function, returns the node's key.
|
|
3919
3873
|
|
|
@@ -3937,7 +3891,7 @@ The node's key or undefined.
|
|
|
3937
3891
|
protected _clearNodes(): void;
|
|
3938
3892
|
```
|
|
3939
3893
|
|
|
3940
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3894
|
+
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)
|
|
3941
3895
|
|
|
3942
3896
|
(Protected) Clears all nodes from the tree.
|
|
3943
3897
|
|
|
@@ -3957,7 +3911,7 @@ Time O(1)
|
|
|
3957
3911
|
protected _clearValues(): void;
|
|
3958
3912
|
```
|
|
3959
3913
|
|
|
3960
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3914
|
+
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)
|
|
3961
3915
|
|
|
3962
3916
|
(Protected) Clears all values from the external store.
|
|
3963
3917
|
|
|
@@ -3977,7 +3931,7 @@ Time O(N)
|
|
|
3977
3931
|
protected _clone(cloned): void;
|
|
3978
3932
|
```
|
|
3979
3933
|
|
|
3980
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3934
|
+
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)
|
|
3981
3935
|
|
|
3982
3936
|
(Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
3983
3937
|
|
|
@@ -4005,7 +3959,7 @@ Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
|
4005
3959
|
protected _createInstance<TK, TV, TR>(options?): this;
|
|
4006
3960
|
```
|
|
4007
3961
|
|
|
4008
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
3962
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3204](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3204)
|
|
4009
3963
|
|
|
4010
3964
|
(Protected) Creates a new, empty instance of the same tree constructor.
|
|
4011
3965
|
|
|
@@ -4049,7 +4003,7 @@ Time O(1)
|
|
|
4049
4003
|
protected _createLike<TK, TV, TR>(iter?, options?): BinaryTree<TK, TV, TR>;
|
|
4050
4004
|
```
|
|
4051
4005
|
|
|
4052
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4006
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3221](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3221)
|
|
4053
4007
|
|
|
4054
4008
|
(Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
|
|
4055
4009
|
|
|
@@ -4099,6 +4053,40 @@ Time O(N) (or as per constructor) due to processing the iterable.
|
|
|
4099
4053
|
|
|
4100
4054
|
***
|
|
4101
4055
|
|
|
4056
|
+
### \_deleteInternal()
|
|
4057
|
+
|
|
4058
|
+
```ts
|
|
4059
|
+
protected _deleteInternal(keyNodeEntryRawOrPredicate): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
4060
|
+
```
|
|
4061
|
+
|
|
4062
|
+
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)
|
|
4063
|
+
|
|
4064
|
+
**`Internal`**
|
|
4065
|
+
|
|
4066
|
+
Deletes a node from the tree (internal, returns balancing metadata).
|
|
4067
|
+
|
|
4068
|
+
#### Parameters
|
|
4069
|
+
|
|
4070
|
+
##### keyNodeEntryRawOrPredicate
|
|
4071
|
+
|
|
4072
|
+
\| `BTNRep`\<`K`, `V`, [`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>
|
|
4073
|
+
\| `NodePredicate`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\> \| `null`\>
|
|
4074
|
+
|
|
4075
|
+
The node to delete.
|
|
4076
|
+
|
|
4077
|
+
#### Returns
|
|
4078
|
+
|
|
4079
|
+
`BinaryTreeDeleteResult`\<[`BinaryTreeNode`](BinaryTreeNode.md)\<`K`, `V`\>\>[]
|
|
4080
|
+
|
|
4081
|
+
An array containing deletion results with balancing metadata.
|
|
4082
|
+
|
|
4083
|
+
#### Remarks
|
|
4084
|
+
|
|
4085
|
+
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).
|
|
4086
|
+
Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
4087
|
+
|
|
4088
|
+
***
|
|
4089
|
+
|
|
4102
4090
|
### \_dfs()
|
|
4103
4091
|
|
|
4104
4092
|
```ts
|
|
@@ -4115,7 +4103,7 @@ protected _dfs<C>(
|
|
|
4115
4103
|
shouldProcessRoot?): ReturnType<C>[];
|
|
4116
4104
|
```
|
|
4117
4105
|
|
|
4118
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4106
|
+
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)
|
|
4119
4107
|
|
|
4120
4108
|
#### Type Parameters
|
|
4121
4109
|
|
|
@@ -4204,7 +4192,7 @@ Array of callback results.
|
|
|
4204
4192
|
protected _displayAux(node, options): NodeDisplayLayout;
|
|
4205
4193
|
```
|
|
4206
4194
|
|
|
4207
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4195
|
+
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)
|
|
4208
4196
|
|
|
4209
4197
|
(Protected) Recursive helper for `toVisual`.
|
|
4210
4198
|
|
|
@@ -4240,7 +4228,7 @@ Time O(N), Space O(N*H) or O(N^2)
|
|
|
4240
4228
|
protected _ensurePredicate(keyNodeEntryOrPredicate): NodePredicate<BinaryTreeNode<K, V>>;
|
|
4241
4229
|
```
|
|
4242
4230
|
|
|
4243
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4231
|
+
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)
|
|
4244
4232
|
|
|
4245
4233
|
(Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
4246
4234
|
|
|
@@ -4275,7 +4263,7 @@ Time O(1)
|
|
|
4275
4263
|
protected _extractKey(keyNodeOrEntry): K | null | undefined;
|
|
4276
4264
|
```
|
|
4277
4265
|
|
|
4278
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4266
|
+
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)
|
|
4279
4267
|
|
|
4280
4268
|
(Protected) Extracts the key from a key, node, or entry.
|
|
4281
4269
|
|
|
@@ -4309,7 +4297,7 @@ Time O(1)
|
|
|
4309
4297
|
protected _getIterator(node?): IterableIterator<[K, V | undefined]>;
|
|
4310
4298
|
```
|
|
4311
4299
|
|
|
4312
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4300
|
+
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)
|
|
4313
4301
|
|
|
4314
4302
|
(Protected) Gets the iterator for the tree (default in-order).
|
|
4315
4303
|
|
|
@@ -4343,7 +4331,7 @@ Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the
|
|
|
4343
4331
|
protected _isDisplayLeaf(node, options): boolean;
|
|
4344
4332
|
```
|
|
4345
4333
|
|
|
4346
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4334
|
+
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)
|
|
4347
4335
|
|
|
4348
4336
|
Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
4349
4337
|
|
|
@@ -4369,7 +4357,7 @@ Check if a node is a display leaf (empty, null, undefined, NIL, or real leaf).
|
|
|
4369
4357
|
protected _isPredicate(p): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
4370
4358
|
```
|
|
4371
4359
|
|
|
4372
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4360
|
+
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)
|
|
4373
4361
|
|
|
4374
4362
|
(Protected) Checks if an item is a predicate function.
|
|
4375
4363
|
|
|
@@ -4399,7 +4387,7 @@ Time O(1)
|
|
|
4399
4387
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value?): [BinaryTreeNode<K, V> | null | undefined, V | undefined];
|
|
4400
4388
|
```
|
|
4401
4389
|
|
|
4402
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4390
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3244](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3244)
|
|
4403
4391
|
|
|
4404
4392
|
(Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
4405
4393
|
|
|
@@ -4439,7 +4427,7 @@ Time O(1)
|
|
|
4439
4427
|
protected _replaceNode(oldNode, newNode): BinaryTreeNode<K, V>;
|
|
4440
4428
|
```
|
|
4441
4429
|
|
|
4442
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4430
|
+
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)
|
|
4443
4431
|
|
|
4444
4432
|
(Protected) Replaces a node in the tree with a new node, maintaining children and parent links.
|
|
4445
4433
|
|
|
@@ -4478,7 +4466,7 @@ protected _resolveDisplayLeaf(
|
|
|
4478
4466
|
emptyDisplayLayout): NodeDisplayLayout;
|
|
4479
4467
|
```
|
|
4480
4468
|
|
|
4481
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4469
|
+
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)
|
|
4482
4470
|
|
|
4483
4471
|
Resolve a display leaf node to its layout.
|
|
4484
4472
|
|
|
@@ -4508,7 +4496,7 @@ Resolve a display leaf node to its layout.
|
|
|
4508
4496
|
protected _setRoot(v): void;
|
|
4509
4497
|
```
|
|
4510
4498
|
|
|
4511
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4499
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3503](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3503)
|
|
4512
4500
|
|
|
4513
4501
|
(Protected) Sets the root node and clears its parent reference.
|
|
4514
4502
|
|
|
@@ -4536,7 +4524,7 @@ Time O(1)
|
|
|
4536
4524
|
protected _setValue(key, value): boolean;
|
|
4537
4525
|
```
|
|
4538
4526
|
|
|
4539
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4527
|
+
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)
|
|
4540
4528
|
|
|
4541
4529
|
(Protected) Sets a value in the external store (Map mode).
|
|
4542
4530
|
|
|
@@ -4572,7 +4560,7 @@ Time O(1) (average for Map.set).
|
|
|
4572
4560
|
protected _snapshotOptions<TK, TV, TR>(): BinaryTreeOptions<TK, TV, TR>;
|
|
4573
4561
|
```
|
|
4574
4562
|
|
|
4575
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4563
|
+
Defined in: [data-structures/binary-tree/binary-tree.ts:3187](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/binary-tree.ts#L3187)
|
|
4576
4564
|
|
|
4577
4565
|
(Protected) Snapshots the current tree's configuration options.
|
|
4578
4566
|
|
|
@@ -4608,7 +4596,7 @@ Time O(1)
|
|
|
4608
4596
|
protected _swapProperties(srcNode, destNode): BinaryTreeNode<K, V> | undefined;
|
|
4609
4597
|
```
|
|
4610
4598
|
|
|
4611
|
-
Defined in: [data-structures/binary-tree/binary-tree.ts:
|
|
4599
|
+
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)
|
|
4612
4600
|
|
|
4613
4601
|
(Protected) Swaps the key/value properties of two nodes.
|
|
4614
4602
|
|