stack-typed 2.0.5 → 2.1.1
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/dist/data-structures/base/iterable-element-base.d.ts +186 -83
- package/dist/data-structures/base/iterable-element-base.js +149 -107
- package/dist/data-structures/base/iterable-entry-base.d.ts +95 -119
- package/dist/data-structures/base/iterable-entry-base.js +59 -116
- package/dist/data-structures/base/linear-base.d.ts +250 -192
- package/dist/data-structures/base/linear-base.js +137 -274
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
- package/dist/data-structures/binary-tree/avl-tree-counter.js +171 -205
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +138 -149
- package/dist/data-structures/binary-tree/avl-tree.js +208 -195
- package/dist/data-structures/binary-tree/binary-tree.d.ts +476 -632
- package/dist/data-structures/binary-tree/binary-tree.js +602 -873
- package/dist/data-structures/binary-tree/bst.d.ts +258 -306
- package/dist/data-structures/binary-tree/bst.js +505 -481
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +107 -179
- package/dist/data-structures/binary-tree/red-black-tree.js +114 -209
- package/dist/data-structures/binary-tree/tree-counter.d.ts +132 -154
- package/dist/data-structures/binary-tree/tree-counter.js +172 -203
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +238 -233
- package/dist/data-structures/graph/abstract-graph.js +267 -237
- package/dist/data-structures/graph/directed-graph.d.ts +108 -224
- package/dist/data-structures/graph/directed-graph.js +146 -233
- package/dist/data-structures/graph/map-graph.d.ts +49 -55
- package/dist/data-structures/graph/map-graph.js +56 -59
- package/dist/data-structures/graph/undirected-graph.d.ts +103 -146
- package/dist/data-structures/graph/undirected-graph.js +129 -149
- package/dist/data-structures/hash/hash-map.d.ts +164 -338
- package/dist/data-structures/hash/hash-map.js +270 -457
- package/dist/data-structures/heap/heap.d.ts +214 -289
- package/dist/data-structures/heap/heap.js +340 -349
- package/dist/data-structures/heap/max-heap.d.ts +11 -47
- package/dist/data-structures/heap/max-heap.js +11 -66
- package/dist/data-structures/heap/min-heap.d.ts +12 -47
- package/dist/data-structures/heap/min-heap.js +11 -66
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
- package/dist/data-structures/linked-list/doubly-linked-list.js +368 -494
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +261 -310
- package/dist/data-structures/linked-list/singly-linked-list.js +447 -466
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -107
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -100
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
- package/dist/data-structures/priority-queue/max-priority-queue.js +11 -78
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
- package/dist/data-structures/priority-queue/min-priority-queue.js +10 -79
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -61
- package/dist/data-structures/priority-queue/priority-queue.js +8 -83
- package/dist/data-structures/queue/deque.d.ts +227 -254
- package/dist/data-structures/queue/deque.js +309 -348
- package/dist/data-structures/queue/queue.d.ts +180 -201
- package/dist/data-structures/queue/queue.js +265 -248
- package/dist/data-structures/stack/stack.d.ts +124 -102
- package/dist/data-structures/stack/stack.js +181 -125
- package/dist/data-structures/trie/trie.d.ts +164 -165
- package/dist/data-structures/trie/trie.js +189 -172
- package/dist/interfaces/binary-tree.d.ts +56 -6
- package/dist/interfaces/graph.d.ts +16 -0
- package/dist/types/data-structures/base/base.d.ts +1 -1
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +2 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +238 -115
- package/src/data-structures/base/iterable-entry-base.ts +96 -120
- package/src/data-structures/base/linear-base.ts +271 -277
- package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
- package/src/data-structures/binary-tree/avl-tree.ts +237 -206
- package/src/data-structures/binary-tree/binary-tree.ts +665 -896
- package/src/data-structures/binary-tree/bst.ts +565 -572
- package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
- package/src/data-structures/binary-tree/tree-counter.ts +195 -219
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
- package/src/data-structures/graph/abstract-graph.ts +339 -264
- package/src/data-structures/graph/directed-graph.ts +146 -236
- package/src/data-structures/graph/map-graph.ts +63 -60
- package/src/data-structures/graph/undirected-graph.ts +129 -152
- package/src/data-structures/hash/hash-map.ts +274 -496
- package/src/data-structures/heap/heap.ts +389 -402
- package/src/data-structures/heap/max-heap.ts +12 -76
- package/src/data-structures/heap/min-heap.ts +13 -76
- package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
- package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
- package/src/data-structures/priority-queue/priority-queue.ts +3 -92
- package/src/data-structures/queue/deque.ts +381 -357
- package/src/data-structures/queue/queue.ts +310 -264
- package/src/data-structures/stack/stack.ts +217 -131
- package/src/data-structures/trie/trie.ts +240 -175
- package/src/interfaces/binary-tree.ts +240 -6
- package/src/interfaces/graph.ts +37 -0
- package/src/types/data-structures/base/base.ts +5 -5
- package/src/types/data-structures/graph/abstract-graph.ts +5 -0
- package/src/types/utils/utils.ts +2 -0
- package/src/utils/utils.ts +9 -14
|
@@ -5,46 +5,119 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BinaryTreePrintOptions, BTNEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodeDisplayLayout, NodePredicate,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeOptions, BinaryTreePrintOptions, BTNEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodeDisplayLayout, NodePredicate, RBTNColor, ToEntryFn } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { IterableEntryBase } from '../base';
|
|
11
11
|
import { Range } from '../../common';
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @template V - The type of
|
|
15
|
-
* @template BinaryTreeNode<K, V> - The type of the family relationship in the binary tree.
|
|
13
|
+
* @template K - The type of the key.
|
|
14
|
+
* @template V - The type of the value.
|
|
16
15
|
*/
|
|
17
16
|
export declare class BinaryTreeNode<K = any, V = any> {
|
|
18
17
|
key: K;
|
|
19
18
|
value?: V;
|
|
20
19
|
parent?: BinaryTreeNode<K, V>;
|
|
21
20
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
* @param
|
|
26
|
-
*
|
|
27
|
-
* default to `undefined`.
|
|
21
|
+
* Creates an instance of BinaryTreeNode.
|
|
22
|
+
* @remarks Time O(1), Space O(1)
|
|
23
|
+
*
|
|
24
|
+
* @param key - The key of the node.
|
|
25
|
+
* @param [value] - The value associated with the key.
|
|
28
26
|
*/
|
|
29
27
|
constructor(key: K, value?: V);
|
|
30
28
|
_left?: BinaryTreeNode<K, V> | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the left child of the node.
|
|
31
|
+
* @remarks Time O(1), Space O(1)
|
|
32
|
+
*
|
|
33
|
+
* @returns The left child.
|
|
34
|
+
*/
|
|
31
35
|
get left(): BinaryTreeNode<K, V> | null | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Sets the left child of the node and updates its parent reference.
|
|
38
|
+
* @remarks Time O(1), Space O(1)
|
|
39
|
+
*
|
|
40
|
+
* @param v - The node to set as the left child.
|
|
41
|
+
*/
|
|
32
42
|
set left(v: BinaryTreeNode<K, V> | null | undefined);
|
|
33
43
|
_right?: BinaryTreeNode<K, V> | null | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the right child of the node.
|
|
46
|
+
* @remarks Time O(1), Space O(1)
|
|
47
|
+
*
|
|
48
|
+
* @returns The right child.
|
|
49
|
+
*/
|
|
34
50
|
get right(): BinaryTreeNode<K, V> | null | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the right child of the node and updates its parent reference.
|
|
53
|
+
* @remarks Time O(1), Space O(1)
|
|
54
|
+
*
|
|
55
|
+
* @param v - The node to set as the right child.
|
|
56
|
+
*/
|
|
35
57
|
set right(v: BinaryTreeNode<K, V> | null | undefined);
|
|
36
58
|
_height: number;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the height of the node (used in self-balancing trees).
|
|
61
|
+
* @remarks Time O(1), Space O(1)
|
|
62
|
+
*
|
|
63
|
+
* @returns The height.
|
|
64
|
+
*/
|
|
37
65
|
get height(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Sets the height of the node.
|
|
68
|
+
* @remarks Time O(1), Space O(1)
|
|
69
|
+
*
|
|
70
|
+
* @param value - The new height.
|
|
71
|
+
*/
|
|
38
72
|
set height(value: number);
|
|
39
73
|
_color: RBTNColor;
|
|
74
|
+
/**
|
|
75
|
+
* Gets the color of the node (used in Red-Black trees).
|
|
76
|
+
* @remarks Time O(1), Space O(1)
|
|
77
|
+
*
|
|
78
|
+
* @returns The node's color.
|
|
79
|
+
*/
|
|
40
80
|
get color(): RBTNColor;
|
|
81
|
+
/**
|
|
82
|
+
* Sets the color of the node.
|
|
83
|
+
* @remarks Time O(1), Space O(1)
|
|
84
|
+
*
|
|
85
|
+
* @param value - The new color.
|
|
86
|
+
*/
|
|
41
87
|
set color(value: RBTNColor);
|
|
42
88
|
_count: number;
|
|
89
|
+
/**
|
|
90
|
+
* Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
|
|
91
|
+
* @remarks Time O(1), Space O(1)
|
|
92
|
+
*
|
|
93
|
+
* @returns The subtree node count.
|
|
94
|
+
*/
|
|
43
95
|
get count(): number;
|
|
96
|
+
/**
|
|
97
|
+
* Sets the count of nodes in the subtree.
|
|
98
|
+
* @remarks Time O(1), Space O(1)
|
|
99
|
+
*
|
|
100
|
+
* @param value - The new count.
|
|
101
|
+
*/
|
|
44
102
|
set count(value: number);
|
|
103
|
+
/**
|
|
104
|
+
* Gets the position of the node relative to its parent.
|
|
105
|
+
* @remarks Time O(1), Space O(1)
|
|
106
|
+
*
|
|
107
|
+
* @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
|
|
108
|
+
*/
|
|
45
109
|
get familyPosition(): FamilyPosition;
|
|
46
110
|
}
|
|
47
111
|
/**
|
|
112
|
+
* A general Binary Tree implementation.
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* This class implements a basic Binary Tree, not a Binary Search Tree.
|
|
116
|
+
* The `add` operation inserts nodes level-by-level (BFS) into the first available slot.
|
|
117
|
+
*
|
|
118
|
+
* @template K - The type of the key.
|
|
119
|
+
* @template V - The type of the value.
|
|
120
|
+
* @template R - The type of the raw data object (if using `toEntryFn`).
|
|
48
121
|
* 1. Two Children Maximum: Each node has at most two children.
|
|
49
122
|
* 2. Left and Right Children: Nodes have distinct left and right children.
|
|
50
123
|
* 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
|
|
@@ -113,536 +186,368 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
113
186
|
*
|
|
114
187
|
* console.log(evaluate(expressionTree.root)); // -27
|
|
115
188
|
*/
|
|
116
|
-
export declare class BinaryTree<K = any, V = any, R =
|
|
189
|
+
export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R> {
|
|
117
190
|
iterationType: IterationType;
|
|
118
191
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @param [options] - The `options` parameter in the constructor is an optional object that can
|
|
125
|
-
* contain the following properties:
|
|
192
|
+
* Creates an instance of BinaryTree.
|
|
193
|
+
* @remarks Time O(N * M), where N is the number of items in `keysNodesEntriesOrRaws` and M is the tree size at insertion time (due to O(M) `add` operation). Space O(N) for storing the nodes.
|
|
194
|
+
*
|
|
195
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
|
|
196
|
+
* @param [options] - Configuration options for the tree.
|
|
126
197
|
*/
|
|
127
198
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BinaryTreeOptions<K, V, R>);
|
|
128
199
|
protected _isMapMode: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Gets whether the tree is in Map mode.
|
|
202
|
+
* @remarks In Map mode (default), values are stored in an external Map, and nodes only hold keys. If false, values are stored directly on the nodes. Time O(1)
|
|
203
|
+
*
|
|
204
|
+
* @returns True if in Map mode, false otherwise.
|
|
205
|
+
*/
|
|
129
206
|
get isMapMode(): boolean;
|
|
130
207
|
protected _isDuplicate: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Gets whether the tree allows duplicate keys.
|
|
210
|
+
* @remarks Time O(1)
|
|
211
|
+
*
|
|
212
|
+
* @returns True if duplicates are allowed, false otherwise.
|
|
213
|
+
*/
|
|
131
214
|
get isDuplicate(): boolean;
|
|
132
215
|
protected _store: Map<K, V | undefined>;
|
|
216
|
+
/**
|
|
217
|
+
* Gets the external value store (used in Map mode).
|
|
218
|
+
* @remarks Time O(1)
|
|
219
|
+
*
|
|
220
|
+
* @returns The map storing key-value pairs.
|
|
221
|
+
*/
|
|
133
222
|
get store(): Map<K, V | undefined>;
|
|
134
223
|
protected _root?: BinaryTreeNode<K, V> | null | undefined;
|
|
224
|
+
/**
|
|
225
|
+
* Gets the root node of the tree.
|
|
226
|
+
* @remarks Time O(1)
|
|
227
|
+
*
|
|
228
|
+
* @returns The root node.
|
|
229
|
+
*/
|
|
135
230
|
get root(): BinaryTreeNode<K, V> | null | undefined;
|
|
136
231
|
protected _size: number;
|
|
232
|
+
/**
|
|
233
|
+
* Gets the number of nodes in the tree.
|
|
234
|
+
* @remarks Time O(1)
|
|
235
|
+
*
|
|
236
|
+
* @returns The size of the tree.
|
|
237
|
+
*/
|
|
137
238
|
get size(): number;
|
|
138
239
|
protected _NIL: BinaryTreeNode<K, V>;
|
|
240
|
+
/**
|
|
241
|
+
* Gets the sentinel NIL node (used in self-balancing trees like Red-Black Tree).
|
|
242
|
+
* @remarks Time O(1)
|
|
243
|
+
*
|
|
244
|
+
* @returns The NIL node.
|
|
245
|
+
*/
|
|
139
246
|
get NIL(): BinaryTreeNode<K, V>;
|
|
140
247
|
protected _toEntryFn?: ToEntryFn<K, V, R>;
|
|
248
|
+
/**
|
|
249
|
+
* Gets the function used to convert raw data objects (R) into [key, value] entries.
|
|
250
|
+
* @remarks Time O(1)
|
|
251
|
+
*
|
|
252
|
+
* @returns The conversion function.
|
|
253
|
+
*/
|
|
141
254
|
get toEntryFn(): ToEntryFn<K, V, R> | undefined;
|
|
142
255
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* The
|
|
147
|
-
* @param
|
|
148
|
-
* @
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* @
|
|
165
|
-
|
|
166
|
-
createTree(options?: BinaryTreeOptions<K, V, R>): BinaryTree<K, V, R, MK, MV, MR>;
|
|
167
|
-
/**
|
|
168
|
-
* Time Complexity: O(n)
|
|
169
|
-
* Space Complexity: O(log n)
|
|
170
|
-
*
|
|
171
|
-
* The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
|
|
172
|
-
* value and returns the corresponding node or null.
|
|
173
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
|
|
174
|
-
* parameter in the `ensureNode` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It
|
|
175
|
-
* is used to determine whether the input is a key, node, entry, or raw data. The
|
|
176
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
|
|
177
|
-
* is used to specify the type of iteration to be performed. It has a default value of
|
|
178
|
-
* `this.iterationType` if not explicitly provided.
|
|
179
|
-
* @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
|
|
180
|
-
* conditions specified in the code snippet.
|
|
256
|
+
* (Protected) Creates a new node.
|
|
257
|
+
* @remarks Time O(1), Space O(1)
|
|
258
|
+
*
|
|
259
|
+
* @param key - The key for the new node.
|
|
260
|
+
* @param [value] - The value for the new node (used if not in Map mode).
|
|
261
|
+
* @returns The newly created node.
|
|
262
|
+
*/
|
|
263
|
+
_createNode(key: K, value?: V): BinaryTreeNode<K, V>;
|
|
264
|
+
/**
|
|
265
|
+
* Creates a new, empty tree of the same type and configuration.
|
|
266
|
+
* @remarks Time O(1) (excluding options cloning), Space O(1)
|
|
267
|
+
*
|
|
268
|
+
* @param [options] - Optional overrides for the new tree's options.
|
|
269
|
+
* @returns A new, empty tree instance.
|
|
270
|
+
*/
|
|
271
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): this;
|
|
272
|
+
/**
|
|
273
|
+
* Ensures the input is a node. If it's a key or entry, it searches for the node.
|
|
274
|
+
* @remarks Time O(1) if a node is passed. O(N) if a key or entry is passed (due to `getNode` performing a full search). Space O(1) if iterative search, O(H) if recursive (where H is height, O(N) worst-case).
|
|
275
|
+
*
|
|
276
|
+
* @param keyNodeOrEntry - The item to resolve to a node.
|
|
277
|
+
* @param [iterationType=this.iterationType] - The traversal method to use if searching.
|
|
278
|
+
* @returns The resolved node, or null/undefined if not found or input is null/undefined.
|
|
181
279
|
*/
|
|
182
280
|
ensureNode(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V> | null | undefined;
|
|
183
281
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
282
|
+
* Checks if the given item is a `BinaryTreeNode` instance.
|
|
283
|
+
* @remarks Time O(1), Space O(1)
|
|
186
284
|
*
|
|
187
|
-
*
|
|
188
|
-
* @
|
|
189
|
-
* `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
|
|
190
|
-
* checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
|
|
191
|
-
* accordingly.
|
|
192
|
-
* @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
|
|
193
|
-
* `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
|
|
194
|
-
* it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
|
|
195
|
-
* is not a node.
|
|
285
|
+
* @param keyNodeOrEntry - The item to check.
|
|
286
|
+
* @returns True if it's a node, false otherwise.
|
|
196
287
|
*/
|
|
197
288
|
isNode(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
198
289
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
290
|
+
* Checks if the given item is a raw data object (R) that needs conversion via `toEntryFn`.
|
|
291
|
+
* @remarks Time O(1), Space O(1)
|
|
201
292
|
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
204
|
-
* @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
|
|
205
|
-
* checking if it is an object. If the parameter is an object, the function will return `true`,
|
|
206
|
-
* indicating that it is of type `R`.
|
|
293
|
+
* @param keyNodeEntryOrRaw - The item to check.
|
|
294
|
+
* @returns True if it's a raw object, false otherwise.
|
|
207
295
|
*/
|
|
208
296
|
isRaw(keyNodeEntryOrRaw: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R): keyNodeEntryOrRaw is R;
|
|
209
297
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
298
|
+
* Checks if the given item is a "real" node (i.e., not null, undefined, or NIL).
|
|
299
|
+
* @remarks Time O(1), Space O(1)
|
|
212
300
|
*
|
|
213
|
-
*
|
|
214
|
-
* @
|
|
215
|
-
* parameter in the `isRealNode` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`.
|
|
216
|
-
* The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
|
|
217
|
-
* @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
|
|
218
|
-
* node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
|
|
219
|
-
* values, it then calls the `isNode` method to further determine if the input is a node. The
|
|
220
|
-
* function will return a boolean value indicating whether the
|
|
301
|
+
* @param keyNodeOrEntry - The item to check.
|
|
302
|
+
* @returns True if it's a real node, false otherwise.
|
|
221
303
|
*/
|
|
222
304
|
isRealNode(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is BinaryTreeNode<K, V>;
|
|
223
305
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
306
|
+
* Checks if the given item is either a "real" node or null.
|
|
307
|
+
* @remarks Time O(1), Space O(1)
|
|
226
308
|
*
|
|
227
|
-
*
|
|
228
|
-
* @
|
|
229
|
-
* `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
|
|
230
|
-
* V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
|
|
231
|
-
* @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
|
|
232
|
-
* `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
|
|
233
|
-
* `null`, and `false` otherwise.
|
|
309
|
+
* @param keyNodeOrEntry - The item to check.
|
|
310
|
+
* @returns True if it's a real node or null, false otherwise.
|
|
234
311
|
*/
|
|
235
312
|
isRealNodeOrNull(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is BinaryTreeNode<K, V> | null;
|
|
236
313
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
314
|
+
* Checks if the given item is the sentinel NIL node.
|
|
315
|
+
* @remarks Time O(1), Space O(1)
|
|
239
316
|
*
|
|
240
|
-
*
|
|
241
|
-
* @
|
|
242
|
-
* BinaryTreeNode<K, V>>
|
|
243
|
-
* @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
|
|
244
|
-
* property of the current object and returning a boolean value based on that comparison.
|
|
317
|
+
* @param keyNodeOrEntry - The item to check.
|
|
318
|
+
* @returns True if it's the NIL node, false otherwise.
|
|
245
319
|
*/
|
|
246
320
|
isNIL(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
247
321
|
/**
|
|
248
|
-
*
|
|
249
|
-
*
|
|
322
|
+
* Checks if the given item is a `Range` object.
|
|
323
|
+
* @remarks Time O(1), Space O(1)
|
|
250
324
|
*
|
|
251
|
-
*
|
|
252
|
-
* @
|
|
253
|
-
* - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
|
|
254
|
-
* of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `NodePredicate<BinaryTreeNode<K, V>>`, or
|
|
255
|
-
* `Range<K>`. The function checks if the `keyNodeEntry
|
|
256
|
-
* @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
|
|
257
|
-
* instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
|
|
258
|
-
* indicating that the parameter is a `Range<K>`. If it is not an instance of `Range`, the function
|
|
259
|
-
* will return `false`.
|
|
325
|
+
* @param keyNodeEntryOrPredicate - The item to check.
|
|
326
|
+
* @returns True if it's a Range, false otherwise.
|
|
260
327
|
*/
|
|
261
328
|
isRange(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>> | Range<K>): keyNodeEntryOrPredicate is Range<K>;
|
|
262
329
|
/**
|
|
263
|
-
*
|
|
264
|
-
*
|
|
330
|
+
* Checks if a node is a leaf (has no real children).
|
|
331
|
+
* @remarks Time O(N) if a key/entry is passed (due to `ensureNode`). O(1) if a node is passed. Space O(1) or O(H) (from `ensureNode`).
|
|
265
332
|
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
269
|
-
* `keyNodeOrEntry` can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It represents a
|
|
270
|
-
* key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
|
|
271
|
-
* provided
|
|
272
|
-
* @returns The function `isLeaf` returns a boolean value indicating whether the input
|
|
273
|
-
* `keyNodeOrEntry` is a leaf node in a binary tree.
|
|
333
|
+
* @param keyNodeOrEntry - The node to check.
|
|
334
|
+
* @returns True if the node is a leaf, false otherwise.
|
|
274
335
|
*/
|
|
275
336
|
isLeaf(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
276
337
|
/**
|
|
277
|
-
*
|
|
278
|
-
*
|
|
338
|
+
* Checks if the given item is a [key, value] entry pair.
|
|
339
|
+
* @remarks Time O(1), Space O(1)
|
|
279
340
|
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
|
|
283
|
-
* parameter in the `isEntry` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or type `R`.
|
|
284
|
-
* The function checks if the provided `keyNodeOrEntry` is of type `BTN
|
|
285
|
-
* @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
|
|
286
|
-
* with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
|
|
287
|
-
* `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
|
|
341
|
+
* @param keyNodeOrEntry - The item to check.
|
|
342
|
+
* @returns True if it's an entry, false otherwise.
|
|
288
343
|
*/
|
|
289
344
|
isEntry(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is BTNEntry<K, V>;
|
|
290
345
|
/**
|
|
291
|
-
*
|
|
292
|
-
*
|
|
346
|
+
* Checks if the given key is valid (comparable or null).
|
|
347
|
+
* @remarks Time O(1), Space O(1)
|
|
293
348
|
*
|
|
294
|
-
*
|
|
295
|
-
* @
|
|
296
|
-
* TypeScript.
|
|
297
|
-
* @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
|
|
298
|
-
* If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
|
|
299
|
-
* `isComparable` function, which is not provided in the code snippet.
|
|
349
|
+
* @param key - The key to validate.
|
|
350
|
+
* @returns True if the key is valid, false otherwise.
|
|
300
351
|
*/
|
|
301
352
|
isValidKey(key: any): key is K;
|
|
302
353
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* @
|
|
309
|
-
* seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
|
|
310
|
-
* parameter in the method can accept different types of values:
|
|
311
|
-
* @param {V} [value] - The `value` parameter in the `add` method represents the value associated
|
|
312
|
-
* with the key that you want to add to the binary tree. When adding a key-value pair to the binary
|
|
313
|
-
* tree, you provide the key and its corresponding value. The `add` method then creates a new node
|
|
314
|
-
* with this
|
|
315
|
-
* @returns The `add` method returns a boolean value. It returns `true` if the insertion of the new
|
|
316
|
-
* node was successful, and `false` if the insertion position could not be found or if a duplicate
|
|
317
|
-
* key was found and the node was replaced instead of inserted.
|
|
354
|
+
* Adds a new node to the tree.
|
|
355
|
+
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
|
|
356
|
+
*
|
|
357
|
+
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
358
|
+
* @param [value] - The value, if providing just a key.
|
|
359
|
+
* @returns True if the addition was successful, false otherwise.
|
|
318
360
|
*/
|
|
319
361
|
add(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
320
362
|
/**
|
|
321
|
-
*
|
|
322
|
-
* Space
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
* each
|
|
327
|
-
* @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
|
|
328
|
-
* mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
|
|
329
|
-
* `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`.
|
|
330
|
-
* @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
|
|
331
|
-
* accepts an iterable of values. These values correspond to the keys or nodes being added in the
|
|
332
|
-
* `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
|
|
333
|
-
* assign them
|
|
334
|
-
* @returns The `addMany` method returns an array of boolean values indicating whether each key,
|
|
335
|
-
* node, entry, or raw value was successfully added to the data structure. Each boolean value
|
|
336
|
-
* corresponds to the success of adding the corresponding key or value in the input iterable.
|
|
363
|
+
* Adds multiple items to the tree.
|
|
364
|
+
* @remarks Time O(N * M), where N is the number of items to add and M is the size of the tree at insertion (due to O(M) `add` operation). Space O(M) (from `add`) + O(N) (for the `inserted` array).
|
|
365
|
+
*
|
|
366
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to add.
|
|
367
|
+
* @param [values] - An optional parallel iterable of values.
|
|
368
|
+
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
337
369
|
*/
|
|
338
370
|
addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
|
|
339
371
|
/**
|
|
340
|
-
*
|
|
341
|
-
*
|
|
372
|
+
* Merges another tree into this one by adding all its nodes.
|
|
373
|
+
* @remarks Time O(N * M), same as `addMany`, where N is the size of `anotherTree` and M is the size of this tree. Space O(M) (from `add`).
|
|
342
374
|
*
|
|
343
|
-
*
|
|
344
|
-
* elements from the other tree.
|
|
345
|
-
* @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
|
|
375
|
+
* @param anotherTree - The tree to merge.
|
|
346
376
|
*/
|
|
347
|
-
merge(anotherTree: BinaryTree<K, V, R
|
|
377
|
+
merge(anotherTree: BinaryTree<K, V, R>): void;
|
|
348
378
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
379
|
+
* Clears the tree and refills it with new items.
|
|
380
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `addMany`) = O(N * M). Space O(M) (from `addMany`).
|
|
351
381
|
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
|
|
355
|
-
* method can accept an iterable containing a mix of `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` objects or `R`
|
|
356
|
-
* objects.
|
|
357
|
-
* @param [values] - The `values` parameter in the `refill` method is an optional parameter that
|
|
358
|
-
* accepts an iterable of values of type `V` or `undefined`.
|
|
382
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to add.
|
|
383
|
+
* @param [values] - An optional parallel iterable of values.
|
|
359
384
|
*/
|
|
360
385
|
refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
|
|
361
386
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
387
|
+
* Deletes a node from the tree.
|
|
388
|
+
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation finds the node, and if it has two children, swaps it with the rightmost node of its left subtree (in-order predecessor) before deleting. Time O(N) in the worst case. O(N) to find the node (`getNode`) and O(H) (which is O(N) worst-case) to find the rightmost node. Space O(1) (if `getNode` is iterative, which it is).
|
|
364
389
|
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry
|
|
368
|
-
* - The `delete` method you provided is used to delete a node from a binary tree based on the key,
|
|
369
|
-
* node, entry or raw data. The method returns an array of
|
|
370
|
-
* `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
|
|
371
|
-
* balancing is needed.
|
|
372
|
-
* @returns The `delete` method returns an array of `BinaryTreeDeleteResult` objects. Each object in
|
|
373
|
-
* the array contains information about the node that was deleted (`deleted`) and the node that may
|
|
374
|
-
* need to be balanced (`needBalanced`).
|
|
390
|
+
* @param keyNodeOrEntry - The node to delete.
|
|
391
|
+
* @returns An array containing deletion results (for compatibility with self-balancing trees).
|
|
375
392
|
*/
|
|
376
393
|
delete(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
377
394
|
/**
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* @param
|
|
384
|
-
*
|
|
385
|
-
* @param [
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
* @param {C} callback - The `callback` parameter in the `search` function is a callback function
|
|
389
|
-
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
390
|
-
* extends `NodeCallback<BinaryTreeNode<K, V> | null>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
|
|
391
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `search` function is
|
|
392
|
-
* used to specify the node from which the search operation should begin. It represents the starting
|
|
393
|
-
* point in the binary tree where the search will be performed. If no specific `startNode` is
|
|
394
|
-
* provided, the search operation will start from the root
|
|
395
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `search` function
|
|
396
|
-
* specifies the type of iteration to be used when searching for nodes in a binary tree. It can have
|
|
397
|
-
* two possible values:
|
|
398
|
-
* @returns The `search` function returns an array of values that match the provided criteria based
|
|
399
|
-
* on the search algorithm implemented within the function.
|
|
395
|
+
* Searches the tree for nodes matching a predicate.
|
|
396
|
+
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Performs a full DFS (pre-order) scan of the tree. Time O(N), as it may visit every node. Space O(H) for the call stack (recursive) or explicit stack (iterative), where H is the tree height (O(N) worst-case).
|
|
397
|
+
*
|
|
398
|
+
* @template C - The type of the callback function.
|
|
399
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
400
|
+
* @param [onlyOne=false] - If true, stops after finding the first match.
|
|
401
|
+
* @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on matching nodes.
|
|
402
|
+
* @param [startNode=this._root] - The node to start the search from.
|
|
403
|
+
* @param [iterationType=this.iterationType] - Whether to use 'RECURSIVE' or 'ITERATIVE' search.
|
|
404
|
+
* @returns An array of results from the callback function for each matching node.
|
|
400
405
|
*/
|
|
401
406
|
search<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, onlyOne?: boolean, callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
407
|
+
/**
|
|
408
|
+
* Gets all nodes matching a predicate.
|
|
409
|
+
* @remarks Time O(N) (via `search`). Space O(H) or O(N) (via `search`).
|
|
410
|
+
*
|
|
411
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
412
|
+
* @param [onlyOne=false] - If true, stops after finding the first match.
|
|
413
|
+
* @param [startNode=this._root] - The node to start the search from.
|
|
414
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
415
|
+
* @returns An array of matching nodes.
|
|
416
|
+
*/
|
|
402
417
|
getNodes(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V>[];
|
|
403
418
|
/**
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* @param
|
|
410
|
-
*
|
|
411
|
-
* node, entry, raw data, or a predicate function.
|
|
412
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
413
|
-
* `getNode` function is used to specify the starting point for searching for a node in a binary
|
|
414
|
-
* tree. If no specific starting point is provided, the default value is set to `this._root`, which
|
|
415
|
-
* is typically the root node of the binary tree.
|
|
416
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `getNode` method is
|
|
417
|
-
* used to specify the type of iteration to be performed when searching for a node. It has a default
|
|
418
|
-
* value of `this.iterationType`, which means it will use the iteration type defined in the current
|
|
419
|
-
* context if no specific value is provided
|
|
420
|
-
* @returns The `getNode` function is returning the first node that matches the specified criteria,
|
|
421
|
-
* or `null` if no matching node is found.
|
|
419
|
+
* Gets the first node matching a predicate.
|
|
420
|
+
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(N) in the worst case (via `search`). Space O(H) or O(N) (via `search`).
|
|
421
|
+
*
|
|
422
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
423
|
+
* @param [startNode=this._root] - The node to start the search from.
|
|
424
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
425
|
+
* @returns The first matching node, or undefined if not found.
|
|
422
426
|
*/
|
|
423
427
|
getNode(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V> | null | undefined;
|
|
424
428
|
/**
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* node
|
|
430
|
-
* @param
|
|
431
|
-
*
|
|
432
|
-
* following types:
|
|
433
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `get`
|
|
434
|
-
* method is used to specify the starting point for searching for a key or node in the binary tree.
|
|
435
|
-
* If no specific starting point is provided, the default starting point is the root of the binary
|
|
436
|
-
* tree (`this._root`).
|
|
437
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `get` method is used
|
|
438
|
-
* to specify the type of iteration to be performed when searching for a key in the binary tree. It
|
|
439
|
-
* is an optional parameter with a default value of `this.iterationType`, which means it will use the
|
|
440
|
-
* iteration type defined in the
|
|
441
|
-
* @returns The `get` method is returning the value associated with the specified key, node, entry,
|
|
442
|
-
* raw data, or predicate in the binary tree map. If the specified key or node is found in the tree,
|
|
443
|
-
* the method returns the corresponding value. If the key or node is not found, it returns
|
|
444
|
-
* `undefined`.
|
|
429
|
+
* Gets the value associated with a key.
|
|
430
|
+
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(1) if in Map mode. O(N) if not in Map mode (uses `getNode`). Space O(1) if in Map mode. O(H) or O(N) otherwise.
|
|
431
|
+
*
|
|
432
|
+
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
433
|
+
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
434
|
+
* @param [iterationType=this.iterationType] - The traversal method (if not in Map mode).
|
|
435
|
+
* @returns The associated value, or undefined.
|
|
445
436
|
*/
|
|
446
437
|
get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
|
|
447
|
-
has(keyNodeEntryOrPredicate?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
448
438
|
/**
|
|
449
|
-
*
|
|
450
|
-
* Space
|
|
439
|
+
* Checks if a node matching the predicate exists in the tree.
|
|
440
|
+
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(N) in the worst case (via `search`). Space O(H) or O(N) (via `search`).
|
|
451
441
|
*
|
|
452
|
-
* The
|
|
442
|
+
* @param [keyNodeEntryOrPredicate] - The key, node, entry, or predicate to check for.
|
|
443
|
+
* @param [startNode] - The node to start the search from.
|
|
444
|
+
* @param [iterationType] - The traversal method.
|
|
445
|
+
* @returns True if a matching node exists, false otherwise.
|
|
446
|
+
*/
|
|
447
|
+
has(keyNodeEntryOrPredicate?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Clears the tree of all nodes and values.
|
|
450
|
+
* @remarks Time O(N) if in Map mode (due to `_store.clear()`), O(1) otherwise. Space O(1)
|
|
453
451
|
*/
|
|
454
452
|
clear(): void;
|
|
455
453
|
/**
|
|
456
|
-
*
|
|
457
|
-
*
|
|
454
|
+
* Checks if the tree is empty.
|
|
455
|
+
* @remarks Time O(1), Space O(1)
|
|
458
456
|
*
|
|
459
|
-
*
|
|
460
|
-
* boolean value.
|
|
461
|
-
* @returns The `isEmpty()` method is returning a boolean value, specifically `true` if the `_size`
|
|
462
|
-
* property is equal to 0, indicating that the data structure is empty, and `false` otherwise.
|
|
457
|
+
* @returns True if the tree has no nodes, false otherwise.
|
|
463
458
|
*/
|
|
464
459
|
isEmpty(): boolean;
|
|
465
460
|
/**
|
|
466
|
-
*
|
|
467
|
-
* Space
|
|
461
|
+
* Checks if the tree is perfectly balanced.
|
|
462
|
+
* @remarks A tree is perfectly balanced if the difference between min and max height is at most 1. Time O(N), as it requires two full traversals (`getMinHeight` and `getHeight`). Space O(H) or O(N) (from height calculation).
|
|
468
463
|
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
472
|
-
* point for checking if the binary tree is perfectly balanced. It represents the root node of the
|
|
473
|
-
* binary tree or a specific node from which the balance check should begin.
|
|
474
|
-
* @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
|
|
475
|
-
* the tree starting from the `startNode` node is perfectly balanced or not. The return value is
|
|
476
|
-
* determined by comparing the minimum height of the tree with the height of the tree. If the minimum
|
|
477
|
-
* height plus 1 is greater than or equal to the height of the tree, then it is considered perfectly
|
|
478
|
-
* balanced and
|
|
464
|
+
* @param [startNode=this._root] - The node to start checking from.
|
|
465
|
+
* @returns True if perfectly balanced, false otherwise.
|
|
479
466
|
*/
|
|
480
467
|
isPerfectlyBalanced(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
481
468
|
/**
|
|
482
|
-
*
|
|
483
|
-
* Space
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* @
|
|
488
|
-
* function represents the starting point for checking whether a binary search tree (BST) is valid.
|
|
489
|
-
* It can be a node in the BST or a reference to the root of the BST. If no specific node is
|
|
490
|
-
* provided, the function will default to
|
|
491
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `isBST` function
|
|
492
|
-
* determines whether the function should use a recursive approach or an iterative approach to check
|
|
493
|
-
* if the binary search tree (BST) is valid.
|
|
494
|
-
* @returns The `isBST` method is returning a boolean value, which indicates whether the binary
|
|
495
|
-
* search tree (BST) represented by the given root node is a valid BST or not. The method checks if
|
|
496
|
-
* the tree satisfies the BST property, where for every node, all nodes in its left subtree have keys
|
|
497
|
-
* less than the node's key, and all nodes in its right subtree have keys greater than the node's
|
|
469
|
+
* Checks if the tree is a valid Binary Search Tree (BST).
|
|
470
|
+
* @remarks Time O(N), as it must visit every node. Space O(H) for the call stack (recursive) or explicit stack (iterative), where H is the tree height (O(N) worst-case).
|
|
471
|
+
*
|
|
472
|
+
* @param [startNode=this._root] - The node to start checking from.
|
|
473
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
474
|
+
* @returns True if it's a valid BST, false otherwise.
|
|
498
475
|
*/
|
|
499
476
|
isBST(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
500
477
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* The
|
|
505
|
-
* @param
|
|
506
|
-
*
|
|
507
|
-
* It is the target node for which you want to calculate the depth from the `startNode` node.
|
|
508
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
509
|
-
* `getDepth` function represents the starting point from which you want to calculate the depth of a
|
|
510
|
-
* given node or entry in a binary tree. If no specific starting point is provided, the default value
|
|
511
|
-
* for `startNode` is set to the root of the binary
|
|
512
|
-
* @returns The `getDepth` method returns the depth of a given node `dist` relative to the
|
|
513
|
-
* `startNode` node in a binary tree. If the `dist` node is not found in the path to the `startNode`
|
|
514
|
-
* node, it returns the depth of the `dist` node from the root of the tree.
|
|
478
|
+
* Gets the depth of a node (distance from `startNode`).
|
|
479
|
+
* @remarks Time O(H), where H is the depth of the `dist` node relative to `startNode`. O(N) worst-case. Space O(1).
|
|
480
|
+
*
|
|
481
|
+
* @param dist - The node to find the depth of.
|
|
482
|
+
* @param [startNode=this._root] - The node to measure depth from (defaults to root).
|
|
483
|
+
* @returns The depth (0 if `dist` is `startNode`).
|
|
515
484
|
*/
|
|
516
485
|
getDepth(dist: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): number;
|
|
517
486
|
/**
|
|
518
|
-
*
|
|
519
|
-
* Space
|
|
520
|
-
*
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
* @
|
|
524
|
-
* point from which the height of the binary tree will be calculated. It can be a node in the binary
|
|
525
|
-
* tree or a reference to the root of the tree. If not provided, it defaults to the root of the
|
|
526
|
-
* binary tree data structure.
|
|
527
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is used to determine the type
|
|
528
|
-
* of iteration to be performed while calculating the height of the binary tree. It can have two
|
|
529
|
-
* possible values:
|
|
530
|
-
* @returns The `getHeight` method returns the height of the binary tree starting from the specified
|
|
531
|
-
* root node. The height is calculated based on the maximum depth of the tree, considering either a
|
|
532
|
-
* recursive approach or an iterative approach depending on the `iterationType` parameter.
|
|
487
|
+
* Gets the maximum height of the tree (longest path from startNode to a leaf).
|
|
488
|
+
* @remarks Time O(N), as it must visit every node. Space O(H) for recursive stack (O(N) worst-case) or O(N) for iterative stack (storing node + depth).
|
|
489
|
+
*
|
|
490
|
+
* @param [startNode=this._root] - The node to start measuring from.
|
|
491
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
492
|
+
* @returns The height ( -1 for an empty tree, 0 for a single-node tree).
|
|
533
493
|
*/
|
|
534
494
|
getHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
|
|
535
495
|
/**
|
|
536
|
-
*
|
|
537
|
-
* Space
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
* @
|
|
542
|
-
* `getMinHeight` function represents the starting node from which the minimum height of the binary
|
|
543
|
-
* tree will be calculated. It is either a node in the binary tree or a reference to the root of the
|
|
544
|
-
* tree. If not provided, the default value is the root
|
|
545
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `getMinHeight` method
|
|
546
|
-
* specifies the type of iteration to use when calculating the minimum height of a binary tree. It
|
|
547
|
-
* can have two possible values:
|
|
548
|
-
* @returns The `getMinHeight` method returns the minimum height of the binary tree starting from the
|
|
549
|
-
* specified root node. The height is calculated based on the shortest path from the root node to a
|
|
550
|
-
* leaf node in the tree. The method uses either a recursive approach or an iterative approach (using
|
|
551
|
-
* a stack) based on the `iterationType` parameter.
|
|
496
|
+
* Gets the minimum height of the tree (shortest path from startNode to a leaf).
|
|
497
|
+
* @remarks Time O(N), as it must visit every node. Space O(H) for recursive stack (O(N) worst-case) or O(N) for iterative (due to `depths` Map).
|
|
498
|
+
*
|
|
499
|
+
* @param [startNode=this._root] - The node to start measuring from.
|
|
500
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
501
|
+
* @returns The minimum height (-1 for empty, 0 for single node).
|
|
552
502
|
*/
|
|
553
503
|
getMinHeight(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): number;
|
|
554
504
|
/**
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
* @param
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* @
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* @param
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* @
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* @
|
|
592
|
-
*
|
|
593
|
-
* `NIL`, it returns the result of the callback function applied to `undefined`. If the `startNode`
|
|
594
|
-
* node is not a real node, it returns the result of the callback
|
|
595
|
-
*/
|
|
596
|
-
getLeftMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
|
|
597
|
-
/**
|
|
598
|
-
* Time Complexity: O(log n)
|
|
599
|
-
* Space Complexity: O(log n)
|
|
600
|
-
*
|
|
601
|
-
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
602
|
-
* or iterative traversal methods.
|
|
603
|
-
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
604
|
-
* of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
|
|
605
|
-
* which means it is a callback function that can accept either an optional binary tree node or null
|
|
606
|
-
* as
|
|
607
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
608
|
-
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
609
|
-
* tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
|
|
610
|
-
* starting point is provided, the function will default
|
|
611
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `getRightMost`
|
|
612
|
-
* function specifies the type of iteration to be used when traversing the binary tree nodes. It can
|
|
613
|
-
* have two possible values:
|
|
614
|
-
* @returns The `getRightMost` function returns the result of the callback function `C`, which is
|
|
615
|
-
* passed as a parameter to the function. The callback function is called with the rightmost node in
|
|
616
|
-
* the binary tree structure, determined based on the specified iteration type ('RECURSIVE' or
|
|
617
|
-
* other).
|
|
618
|
-
*/
|
|
619
|
-
getRightMost<C extends NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
|
|
620
|
-
/**
|
|
621
|
-
* Time Complexity: O(log n)
|
|
622
|
-
* Space Complexity: O(log n)
|
|
623
|
-
*
|
|
624
|
-
* The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
|
|
625
|
-
* binary tree.
|
|
626
|
-
* @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
|
|
627
|
-
* predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
|
|
628
|
-
* while loop condition that might cause an infinite loop.
|
|
629
|
-
* @returns The `getPredecessor` function returns the predecessor node of the input `BinaryTreeNode<K, V>` parameter.
|
|
630
|
-
* If the left child of the input node exists, it traverses to the rightmost node of the left subtree
|
|
631
|
-
* to find the predecessor. If the left child does not exist, it returns the input node itself.
|
|
505
|
+
* Gets the path from a given node up to the root.
|
|
506
|
+
* @remarks Time O(H), where H is the depth of the `beginNode`. O(N) worst-case. Space O(H) for the result array.
|
|
507
|
+
*
|
|
508
|
+
* @template C - The type of the callback function.
|
|
509
|
+
* @param beginNode - The node to start the path from.
|
|
510
|
+
* @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on each node in the path.
|
|
511
|
+
* @param [isReverse=false] - If true, returns the path from root-to-node.
|
|
512
|
+
* @returns An array of callback results.
|
|
513
|
+
*/
|
|
514
|
+
getPathToRoot<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(beginNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, callback?: C, isReverse?: boolean): ReturnType<C>[];
|
|
515
|
+
/**
|
|
516
|
+
* Finds the leftmost node in a subtree (the node with the smallest key in a BST).
|
|
517
|
+
* @remarks Time O(H), where H is the height of the left spine. O(N) worst-case. Space O(H) for recursive/trampoline stack.
|
|
518
|
+
*
|
|
519
|
+
* @template C - The type of the callback function.
|
|
520
|
+
* @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on the leftmost node.
|
|
521
|
+
* @param [startNode=this._root] - The subtree root to search from.
|
|
522
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
523
|
+
* @returns The callback result for the leftmost node.
|
|
524
|
+
*/
|
|
525
|
+
getLeftMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
|
|
526
|
+
/**
|
|
527
|
+
* Finds the rightmost node in a subtree (the node with the largest key in a BST).
|
|
528
|
+
* @remarks Time O(H), where H is the height of the right spine. O(N) worst-case. Space O(H) for recursive/trampoline stack.
|
|
529
|
+
*
|
|
530
|
+
* @template C - The type of the callback function.
|
|
531
|
+
* @param [callback=this._DEFAULT_NODE_CALLBACK] - A function to call on the rightmost node.
|
|
532
|
+
* @param [startNode=this._root] - The subtree root to search from.
|
|
533
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
534
|
+
* @returns The callback result for the rightmost node.
|
|
535
|
+
*/
|
|
536
|
+
getRightMost<C extends NodeCallback<BinaryTreeNode<K, V> | undefined>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>;
|
|
537
|
+
/**
|
|
538
|
+
* Gets the Morris traversal predecessor (rightmost node in the left subtree, or node itself).
|
|
539
|
+
* @remarks This is primarily a helper for Morris traversal. Time O(H), where H is the height of the left subtree. O(N) worst-case. Space O(1).
|
|
540
|
+
*
|
|
541
|
+
* @param node - The node to find the predecessor for.
|
|
542
|
+
* @returns The Morris predecessor.
|
|
632
543
|
*/
|
|
633
544
|
getPredecessor(node: BinaryTreeNode<K, V>): BinaryTreeNode<K, V>;
|
|
634
545
|
/**
|
|
635
|
-
*
|
|
636
|
-
*
|
|
546
|
+
* Gets the in-order successor of a node in a BST.
|
|
547
|
+
* @remarks Time O(H), where H is the tree height. O(N) worst-case. Space O(H) (due to `getLeftMost` stack).
|
|
637
548
|
*
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
* @param {K | BinaryTreeNode<K, V> | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
|
|
641
|
-
* type `K`, `BinaryTreeNode<K, V>`, or `null`.
|
|
642
|
-
* @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
|
|
643
|
-
* a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
|
|
644
|
-
* have a right child, the function traverses up the parent nodes until it finds a node that is not
|
|
645
|
-
* the right child of its parent, and returns that node
|
|
549
|
+
* @param [x] - The node to find the successor of.
|
|
550
|
+
* @returns The successor node, or null/undefined if none exists.
|
|
646
551
|
*/
|
|
647
552
|
getSuccessor(x?: K | BinaryTreeNode<K, V> | null): BinaryTreeNode<K, V> | null | undefined;
|
|
648
553
|
dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
@@ -650,261 +555,200 @@ export declare class BinaryTree<K = any, V = any, R = object, MK = any, MV = any
|
|
|
650
555
|
bfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
651
556
|
bfs<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
652
557
|
/**
|
|
653
|
-
*
|
|
654
|
-
* Space
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* @param
|
|
659
|
-
*
|
|
660
|
-
* @
|
|
661
|
-
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
662
|
-
* tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
|
|
663
|
-
* explicitly provided, the default value
|
|
664
|
-
* @param {IterationType} iterationType - The `iterationType` parameter in the `leaves` method
|
|
665
|
-
* specifies the type of iteration to be performed when collecting the leaves of a binary tree. It
|
|
666
|
-
* can have two possible values:
|
|
667
|
-
* @returns The `leaves` method returns an array of values that are the result of applying the
|
|
668
|
-
* provided callback function to each leaf node in the binary tree.
|
|
558
|
+
* Finds all leaf nodes in the tree.
|
|
559
|
+
* @remarks Time O(N), visits every node. Space O(H) for recursive stack or O(N) for iterative queue.
|
|
560
|
+
*
|
|
561
|
+
* @template C - The type of the callback function.
|
|
562
|
+
* @param [callback=this._DEFAULT_NODE_CALLBACK] - Function to call on each leaf node.
|
|
563
|
+
* @param [startNode=this._root] - The node to start from.
|
|
564
|
+
* @param [iterationType=this.iterationType] - The traversal method.
|
|
565
|
+
* @returns An array of callback results.
|
|
669
566
|
*/
|
|
670
567
|
leaves<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
671
568
|
listLevels<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
672
569
|
listLevels<C extends NodeCallback<BinaryTreeNode<K, V> | null>>(callback?: C, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
673
570
|
morris<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): ReturnType<C>[];
|
|
674
571
|
/**
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
*
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
* tree
|
|
692
|
-
* @
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
* @
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
* @
|
|
700
|
-
*
|
|
701
|
-
*/
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
*
|
|
705
|
-
* Space
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
* @
|
|
710
|
-
* takes the key, value (which can be undefined), and an array containing the mapped key and value as
|
|
711
|
-
* arguments.
|
|
712
|
-
* @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
|
|
713
|
-
* MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
|
|
714
|
-
* tree being created during the mapping process. These options could include things like custom
|
|
715
|
-
* comparators, initial
|
|
716
|
-
* @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
|
|
717
|
-
* of `this` when executing the `callback` function. It allows you to set the context (value of
|
|
718
|
-
* `this`) within the callback function. If `thisArg` is provided, it will be passed
|
|
719
|
-
* @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
|
|
720
|
-
* the result of applying the provided `callback` function to each entry in the original tree.
|
|
721
|
-
*/
|
|
722
|
-
map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BinaryTreeOptions<MK, MV, MR>, thisArg?: any): BinaryTree<MK, MV, MR>;
|
|
723
|
-
/**
|
|
724
|
-
* Time Complexity: O(n)
|
|
725
|
-
* Space Complexity: O(n)
|
|
726
|
-
*
|
|
727
|
-
* The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
|
|
728
|
-
* customizable options for displaying undefined, null, and sentinel nodes.
|
|
729
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
730
|
-
* `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
|
|
731
|
-
* It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
|
|
732
|
-
* the default is set to the root
|
|
733
|
-
* @param {BinaryTreePrintOptions} [options] - The `options` parameter in the `toVisual` method is an
|
|
734
|
-
* object that contains the following properties:
|
|
735
|
-
* @returns The `override toVisual` method returns a string that represents the visual display of the
|
|
736
|
-
* binary tree based on the provided options for showing undefined, null, and Red-Black NIL nodes.
|
|
737
|
-
* The method constructs the visual representation by calling the `_displayAux` method and appending
|
|
738
|
-
* the lines to the output string. The final output string contains the visual representation of the
|
|
739
|
-
* binary tree with the specified options.
|
|
572
|
+
* Clones the tree.
|
|
573
|
+
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `add`, and `add` is O(M)). Space O(N) for the new tree and the BFS queue.
|
|
574
|
+
*
|
|
575
|
+
* @returns A new, cloned instance of the tree.
|
|
576
|
+
*/
|
|
577
|
+
clone(): this;
|
|
578
|
+
/**
|
|
579
|
+
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
580
|
+
* @remarks Time O(N * M), where N is nodes in this tree, and M is size of the new tree during insertion (O(N) iteration + O(M) `add` for each item). Space O(N) for the new tree.
|
|
581
|
+
*
|
|
582
|
+
* @param predicate - A function to test each [key, value] pair.
|
|
583
|
+
* @param [thisArg] - `this` context for the predicate.
|
|
584
|
+
* @returns A new, filtered tree.
|
|
585
|
+
*/
|
|
586
|
+
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
|
|
587
|
+
/**
|
|
588
|
+
* Creates a new tree by mapping each [key, value] pair to a new entry.
|
|
589
|
+
* @remarks Time O(N * M), where N is nodes in this tree, and M is size of the new tree during insertion. Space O(N) for the new tree.
|
|
590
|
+
*
|
|
591
|
+
* @template MK - New key type.
|
|
592
|
+
* @template MV - New value type.
|
|
593
|
+
* @template MR - New raw type.
|
|
594
|
+
* @param cb - A function to map each [key, value] pair.
|
|
595
|
+
* @param [options] - Options for the new tree.
|
|
596
|
+
* @param [thisArg] - `this` context for the callback.
|
|
597
|
+
* @returns A new, mapped tree.
|
|
598
|
+
*/
|
|
599
|
+
map<MK = K, MV = V, MR = any>(cb: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): BinaryTree<MK, MV, MR>;
|
|
600
|
+
/**
|
|
601
|
+
* Generates a string representation of the tree for visualization.
|
|
602
|
+
* @remarks Time O(N), visits every node. Space O(N*H) or O(N^2) in the worst case, as the string width can grow significantly.
|
|
603
|
+
*
|
|
604
|
+
* @param [startNode=this._root] - The node to start printing from.
|
|
605
|
+
* @param [options] - Options to control the output (e.g., show nulls).
|
|
606
|
+
* @returns The string representation of the tree.
|
|
740
607
|
*/
|
|
741
608
|
toVisual(startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, options?: BinaryTreePrintOptions): string;
|
|
742
609
|
/**
|
|
743
|
-
*
|
|
744
|
-
* Space
|
|
610
|
+
* Prints a visual representation of the tree to the console.
|
|
611
|
+
* @remarks Time O(N) (via `toVisual`). Space O(N*H) or O(N^2) (via `toVisual`).
|
|
745
612
|
*
|
|
746
|
-
*
|
|
747
|
-
*
|
|
748
|
-
* @param {BinaryTreePrintOptions} [options] - The `options` parameter is used to specify the
|
|
749
|
-
* printing options for the binary tree. It is an optional parameter that allows you to customize how
|
|
750
|
-
* the binary tree is printed, such as choosing between different traversal orders or formatting
|
|
751
|
-
* options.
|
|
752
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
|
|
753
|
-
* `override print` method is used to specify the starting point for printing the binary tree. It can
|
|
754
|
-
* be either a key, a node, an entry, or the root of the tree. If no specific starting point is
|
|
755
|
-
* provided, the default value is set to
|
|
613
|
+
* @param [options] - Options to control the output.
|
|
614
|
+
* @param [startNode=this._root] - The node to start printing from.
|
|
756
615
|
*/
|
|
757
616
|
print(options?: BinaryTreePrintOptions, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): void;
|
|
758
|
-
protected _clone(cloned: BinaryTree<K, V, R, MK, MV, MR>): void;
|
|
759
|
-
/**
|
|
760
|
-
* Time Complexity: O(1)
|
|
761
|
-
* Space Complexity: O(1)
|
|
762
|
-
*
|
|
763
|
-
* The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
|
|
764
|
-
* or returns null.
|
|
765
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The
|
|
766
|
-
* `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
|
|
767
|
-
* can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. This parameter represents either a key, a
|
|
768
|
-
* node, an entry
|
|
769
|
-
* @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
|
|
770
|
-
* an optional parameter of type `V`. It represents the value associated with the key in the node
|
|
771
|
-
* being created. If a `value` is provided, it will be used when creating the node. If
|
|
772
|
-
* @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
|
|
773
|
-
* (`BinaryTreeNode<K, V> | null | undefined`) based on the input parameters provided. The function checks the type of the
|
|
774
|
-
* input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
|
|
775
|
-
* value.
|
|
776
|
-
*/
|
|
777
|
-
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): [BinaryTreeNode<K, V> | null | undefined, V | undefined];
|
|
778
617
|
protected _dfs<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType, includeNull?: boolean, shouldVisitLeft?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean, shouldVisitRight?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean, shouldVisitRoot?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean, shouldProcessRoot?: (node: BinaryTreeNode<K, V> | null | undefined) => boolean): ReturnType<C>[];
|
|
779
618
|
/**
|
|
780
|
-
*
|
|
781
|
-
* Space
|
|
619
|
+
* (Protected) Gets the iterator for the tree (default in-order).
|
|
620
|
+
* @remarks Time O(N) for full iteration. O(H) to get the first element. Space O(H) for the iterative stack. O(H) for recursive stack.
|
|
782
621
|
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
* @param node - The `node` parameter in the `_getIterator` method represents the current node being
|
|
786
|
-
* processed during iteration. It is initially set to the root node of the data structure (or the
|
|
787
|
-
* node passed as an argument), and then it is traversed through the data structure based on the
|
|
788
|
-
* iteration type specified (`ITER
|
|
789
|
-
* @returns The `_getIterator` method returns an IterableIterator containing key-value pairs of nodes
|
|
790
|
-
* in a binary tree structure. The method uses an iterative approach to traverse the tree based on
|
|
791
|
-
* the `iterationType` property. If the `iterationType` is set to 'ITERATIVE', the method uses a
|
|
792
|
-
* stack to perform an in-order traversal of the tree. If the `iterationType` is not 'ITERATIVE
|
|
622
|
+
* @param [node=this._root] - The node to start iteration from.
|
|
623
|
+
* @returns An iterator for [key, value] pairs.
|
|
793
624
|
*/
|
|
794
625
|
protected _getIterator(node?: BinaryTreeNode<K, V> | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
795
626
|
/**
|
|
796
|
-
*
|
|
797
|
-
*
|
|
627
|
+
* (Protected) Default callback function, returns the node's key.
|
|
628
|
+
* @remarks Time O(1)
|
|
798
629
|
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
* @param node - The `node` parameter in the `_displayAux` function represents a node in a binary
|
|
802
|
-
* tree. It can be either a valid node containing a key or a special type of node like null,
|
|
803
|
-
* undefined, or a Red-Black tree NIL node. The function checks the type of the node and its
|
|
804
|
-
* @param {BinaryTreePrintOptions} options - The `options` parameter in the `_displayAux` function
|
|
805
|
-
* contains the following properties:
|
|
806
|
-
* @returns The `_displayAux` function returns a `NodeDisplayLayout`, which is an array containing
|
|
807
|
-
* information about how to display a node in a binary tree. The `NodeDisplayLayout` consists of four
|
|
808
|
-
* elements:
|
|
630
|
+
* @param node - The node.
|
|
631
|
+
* @returns The node's key or undefined.
|
|
809
632
|
*/
|
|
810
|
-
protected _displayAux(node: BinaryTreeNode<K, V> | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
811
633
|
protected _DEFAULT_NODE_CALLBACK: (node: BinaryTreeNode<K, V> | null | undefined) => K | undefined;
|
|
812
634
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
635
|
+
* (Protected) Snapshots the current tree's configuration options.
|
|
636
|
+
* @remarks Time O(1)
|
|
637
|
+
*
|
|
638
|
+
* @template TK, TV, TR - Generic types for the options.
|
|
639
|
+
* @returns The options object.
|
|
640
|
+
*/
|
|
641
|
+
protected _snapshotOptions<TK = K, TV = V, TR = R>(): BinaryTreeOptions<TK, TV, TR>;
|
|
642
|
+
/**
|
|
643
|
+
* (Protected) Creates a new, empty instance of the same tree constructor.
|
|
644
|
+
* @remarks Time O(1)
|
|
645
|
+
*
|
|
646
|
+
* @template TK, TV, TR - Generic types for the new instance.
|
|
647
|
+
* @param [options] - Options for the new tree.
|
|
648
|
+
* @returns A new, empty tree.
|
|
649
|
+
*/
|
|
650
|
+
protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<BinaryTreeOptions<TK, TV, TR>>): this;
|
|
651
|
+
/**
|
|
652
|
+
* (Protected) Creates a new instance of the same tree constructor, potentially with different generic types.
|
|
653
|
+
* @remarks Time O(N) (or as per constructor) due to processing the iterable.
|
|
654
|
+
*
|
|
655
|
+
* @template TK, TV, TR - Generic types for the new instance.
|
|
656
|
+
* @param [iter=[]] - An iterable to populate the new tree.
|
|
657
|
+
* @param [options] - Options for the new tree.
|
|
658
|
+
* @returns A new tree.
|
|
659
|
+
*/
|
|
660
|
+
protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | BinaryTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BinaryTreeOptions<TK, TV, TR>>): BinaryTree<TK, TV, TR>;
|
|
661
|
+
/**
|
|
662
|
+
* (Protected) Converts a key, node, or entry into a standardized [node, value] tuple.
|
|
663
|
+
* @remarks Time O(1)
|
|
815
664
|
*
|
|
816
|
-
*
|
|
817
|
-
* @param
|
|
818
|
-
*
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
665
|
+
* @param keyNodeOrEntry - The input item.
|
|
666
|
+
* @param [value] - An optional value (used if input is just a key).
|
|
667
|
+
* @returns A tuple of [node, value].
|
|
668
|
+
*/
|
|
669
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): [BinaryTreeNode<K, V> | null | undefined, V | undefined];
|
|
670
|
+
/**
|
|
671
|
+
* (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
|
|
672
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `add` for each node).
|
|
673
|
+
*
|
|
674
|
+
* @param cloned - The new, empty tree instance to populate.
|
|
675
|
+
*/
|
|
676
|
+
protected _clone(cloned: BinaryTree<K, V, R>): void;
|
|
677
|
+
/**
|
|
678
|
+
* (Protected) Recursive helper for `toVisual`.
|
|
679
|
+
* @remarks Time O(N), Space O(N*H) or O(N^2)
|
|
680
|
+
*
|
|
681
|
+
* @param node - The current node.
|
|
682
|
+
* @param options - Print options.
|
|
683
|
+
* @returns Layout information for this subtree.
|
|
684
|
+
*/
|
|
685
|
+
protected _displayAux(node: BinaryTreeNode<K, V> | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
686
|
+
/**
|
|
687
|
+
* (Protected) Swaps the key/value properties of two nodes.
|
|
688
|
+
* @remarks Time O(1)
|
|
689
|
+
*
|
|
690
|
+
* @param srcNode - The source node.
|
|
691
|
+
* @param destNode - The destination node.
|
|
692
|
+
* @returns The `destNode` (now holding `srcNode`'s properties).
|
|
826
693
|
*/
|
|
827
694
|
protected _swapProperties(srcNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, destNode: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeNode<K, V> | undefined;
|
|
828
695
|
/**
|
|
829
|
-
*
|
|
830
|
-
*
|
|
696
|
+
* (Protected) Replaces a node in the tree with a new node, maintaining children and parent links.
|
|
697
|
+
* @remarks Time O(1)
|
|
831
698
|
*
|
|
832
|
-
*
|
|
833
|
-
* @param
|
|
834
|
-
*
|
|
835
|
-
* @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
|
|
836
|
-
* that will replace the `oldNode` in a tree data structure. This function is responsible for
|
|
837
|
-
* updating the parent, left child, right child, and root (if necessary) references when replacing a
|
|
838
|
-
* node in the tree.
|
|
839
|
-
* @returns The method `_replaceNode` is returning the `newNode` that was passed as a parameter after
|
|
840
|
-
* replacing the `oldNode` with it in the binary tree structure.
|
|
699
|
+
* @param oldNode - The node to be replaced.
|
|
700
|
+
* @param newNode - The node to insert.
|
|
701
|
+
* @returns The `newNode`.
|
|
841
702
|
*/
|
|
842
703
|
protected _replaceNode(oldNode: BinaryTreeNode<K, V>, newNode: BinaryTreeNode<K, V>): BinaryTreeNode<K, V>;
|
|
843
704
|
/**
|
|
844
|
-
*
|
|
845
|
-
*
|
|
705
|
+
* (Protected) Sets the root node and clears its parent reference.
|
|
706
|
+
* @remarks Time O(1)
|
|
846
707
|
*
|
|
847
|
-
*
|
|
848
|
-
* of the previous root node.
|
|
849
|
-
* @param v - The parameter `v` in the `_setRoot` method is of type `BinaryTreeNode<K, V> | null | undefined`, which means
|
|
850
|
-
* it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
|
|
708
|
+
* @param v - The node to set as root.
|
|
851
709
|
*/
|
|
852
710
|
protected _setRoot(v: BinaryTreeNode<K, V> | null | undefined): void;
|
|
711
|
+
/**
|
|
712
|
+
* (Protected) Converts a key, node, entry, or predicate into a standardized predicate function.
|
|
713
|
+
* @remarks Time O(1)
|
|
714
|
+
*
|
|
715
|
+
* @param keyNodeEntryOrPredicate - The item to convert.
|
|
716
|
+
* @returns A predicate function.
|
|
717
|
+
*/
|
|
853
718
|
protected _ensurePredicate(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>): NodePredicate<BinaryTreeNode<K, V>>;
|
|
854
719
|
/**
|
|
855
|
-
*
|
|
856
|
-
*
|
|
720
|
+
* (Protected) Checks if an item is a predicate function.
|
|
721
|
+
* @remarks Time O(1)
|
|
857
722
|
*
|
|
858
|
-
*
|
|
859
|
-
* @
|
|
860
|
-
* of value. In this context, the function `_isPredicate` is checking if `p` is a function that
|
|
861
|
-
* satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
|
|
862
|
-
* @returns The function is checking if the input `p` is a function and returning a boolean value
|
|
863
|
-
* based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
|
|
864
|
-
* predicate function for a binary tree node. If `p` is not a function, it will return `false`.
|
|
723
|
+
* @param p - The item to check.
|
|
724
|
+
* @returns True if it's a function.
|
|
865
725
|
*/
|
|
866
726
|
protected _isPredicate(p: any): p is NodePredicate<BinaryTreeNode<K, V>>;
|
|
867
727
|
/**
|
|
868
|
-
*
|
|
869
|
-
*
|
|
728
|
+
* (Protected) Extracts the key from a key, node, or entry.
|
|
729
|
+
* @remarks Time O(1)
|
|
870
730
|
*
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
* @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `_extractKey` method you provided is a
|
|
874
|
-
* TypeScript method that takes in a parameter `keyNodeOrEntry` of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `,
|
|
875
|
-
* where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
|
|
876
|
-
* @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
|
|
877
|
-
* parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
|
|
878
|
-
* the conditions checked in the method.
|
|
731
|
+
* @param keyNodeOrEntry - The item.
|
|
732
|
+
* @returns The extracted key.
|
|
879
733
|
*/
|
|
880
734
|
protected _extractKey(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): K | null | undefined;
|
|
881
735
|
/**
|
|
882
|
-
*
|
|
883
|
-
*
|
|
736
|
+
* (Protected) Sets a value in the external store (Map mode).
|
|
737
|
+
* @remarks Time O(1) (average for Map.set).
|
|
884
738
|
*
|
|
885
|
-
*
|
|
886
|
-
* value
|
|
887
|
-
* @
|
|
888
|
-
* `undefined`.
|
|
889
|
-
* @param {V | undefined} value - The `value` parameter in the `_setValue` method can be of type `V`
|
|
890
|
-
* or `undefined`.
|
|
891
|
-
* @returns The method `_setValue` returns `false` if either the `key` is `null` or `undefined`, or
|
|
892
|
-
* if the `value` is `undefined`. Otherwise, it returns the result of calling the `set` method on the
|
|
893
|
-
* `_store` object with the `key` and `value` arguments.
|
|
739
|
+
* @param key - The key.
|
|
740
|
+
* @param value - The value.
|
|
741
|
+
* @returns True if successful.
|
|
894
742
|
*/
|
|
895
743
|
protected _setValue(key: K | null | undefined, value: V | undefined): false | Map<K, V | undefined>;
|
|
896
744
|
/**
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
* The _clearNodes function sets the root node to undefined and resets the size to 0.
|
|
745
|
+
* (Protected) Clears all nodes from the tree.
|
|
746
|
+
* @remarks Time O(1)
|
|
901
747
|
*/
|
|
902
748
|
protected _clearNodes(): void;
|
|
903
749
|
/**
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
* The _clearValues function clears all values stored in the _store object.
|
|
750
|
+
* (Protected) Clears all values from the external store.
|
|
751
|
+
* @remarks Time O(N)
|
|
908
752
|
*/
|
|
909
753
|
protected _clearValues(): void;
|
|
910
754
|
}
|