heap-typed 1.52.4 → 1.52.5
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 +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +27 -111
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +1 -54
- package/dist/data-structures/queue/queue.js +0 -53
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -25,7 +25,7 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
25
25
|
* value associated with the key in the constructor.
|
|
26
26
|
*/
|
|
27
27
|
constructor(key: K, value?: V);
|
|
28
|
-
protected _left?: NODE
|
|
28
|
+
protected _left?: OptBTNOrNull<NODE>;
|
|
29
29
|
/**
|
|
30
30
|
* The function returns the value of the `_left` property, which can be of type `NODE`, `null`, or
|
|
31
31
|
* `undefined`.
|
|
@@ -39,7 +39,7 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
39
39
|
* `undefined`.
|
|
40
40
|
*/
|
|
41
41
|
set left(v: OptBTNOrNull<NODE>);
|
|
42
|
-
protected _right?: NODE
|
|
42
|
+
protected _right?: OptBTNOrNull<NODE>;
|
|
43
43
|
/**
|
|
44
44
|
* The function returns the right node of a binary tree or null if it doesn't exist.
|
|
45
45
|
* @returns The method is returning the value of the `_right` property, which can be a `NODE` object,
|
|
@@ -129,10 +129,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
129
129
|
* or `undefined`.
|
|
130
130
|
*/
|
|
131
131
|
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): OptBTNOrNull<NODE>;
|
|
132
|
-
/**
|
|
133
|
-
* Time Complexity: O(n)
|
|
134
|
-
* Space Complexity: O(log n)
|
|
135
|
-
*/
|
|
136
132
|
/**
|
|
137
133
|
* Time Complexity: O(n)
|
|
138
134
|
* Space Complexity: O(log n)
|
|
@@ -169,7 +165,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
169
165
|
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
170
166
|
* @returns a boolean value.
|
|
171
167
|
*/
|
|
172
|
-
|
|
168
|
+
isRealNodeOrNull(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
|
|
173
169
|
/**
|
|
174
170
|
* The function checks if a given node is equal to the NIL value.
|
|
175
171
|
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
@@ -177,6 +173,16 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
177
173
|
* @returns a boolean value.
|
|
178
174
|
*/
|
|
179
175
|
isNIL(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* The function `isLeaf` determines whether a given node is a leaf node in a binary tree structure.
|
|
178
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter in the `isLeaf` function
|
|
179
|
+
* can be either a regular node (`R`) or a `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
180
|
+
* @returns The `isLeaf` function is checking if the provided node is a leaf node in a binary tree.
|
|
181
|
+
* If the node is `undefined`, it returns `false`. If the node is `null`, it returns `true`.
|
|
182
|
+
* Otherwise, it checks if both the left and right children of the node are not real nodes, and
|
|
183
|
+
* returns `true` if they are not, indicating that the node is a
|
|
184
|
+
*/
|
|
185
|
+
isLeaf(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
180
186
|
/**
|
|
181
187
|
* The function checks if the input is an array with two elements, indicating it is a binary tree
|
|
182
188
|
* node entry.
|
|
@@ -186,20 +192,17 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
186
192
|
*/
|
|
187
193
|
isEntry(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>;
|
|
188
194
|
/**
|
|
189
|
-
*
|
|
190
|
-
* @param {any} key - The `key` parameter can be of any type. It is the value that we want to check
|
|
191
|
-
* if it is a valid key.
|
|
192
|
-
* @param [isCheckValueOf=true] - The `isCheckValueOf` parameter is a boolean flag that determines
|
|
193
|
-
* whether the function should check the valueOf() method of an object when the key is of type
|
|
194
|
-
* 'object'. If `isCheckValueOf` is true, the function will recursively call itself with the value
|
|
195
|
-
* returned by key.valueOf().
|
|
196
|
-
* @returns a boolean value.
|
|
197
|
-
*/
|
|
198
|
-
isKey(key: any, isCheckValueOf?: boolean): key is K;
|
|
199
|
-
/**
|
|
200
|
-
* Time Complexity O(n)
|
|
195
|
+
* Time Complexity O(1)
|
|
201
196
|
* Space Complexity O(1)
|
|
197
|
+
*
|
|
198
|
+
* The function `isKey` checks if a given key is comparable.
|
|
199
|
+
* @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
|
|
200
|
+
* TypeScript.
|
|
201
|
+
* @returns The function `isKey` is checking if the `key` parameter is `null` or if it is comparable.
|
|
202
|
+
* If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
|
|
203
|
+
* `isComparable` function, which is not provided in the code snippet.
|
|
202
204
|
*/
|
|
205
|
+
isKey(key: any): key is K;
|
|
203
206
|
/**
|
|
204
207
|
* Time Complexity O(n)
|
|
205
208
|
* Space Complexity O(1)
|
|
@@ -217,11 +220,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
217
220
|
* insertion position cannot be found or if there are duplicate keys.
|
|
218
221
|
*/
|
|
219
222
|
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
220
|
-
/**
|
|
221
|
-
* Time Complexity: O(k * n)
|
|
222
|
-
* Space Complexity: O(1)
|
|
223
|
-
* Comments: The time complexity for adding a node depends on the depth of the tree. In the best case (when the tree is empty), it's O(1). In the worst case (when the tree is a degenerate tree), it's O(n). The space complexity is constant.
|
|
224
|
-
*/
|
|
225
223
|
/**
|
|
226
224
|
* Time Complexity: O(k * n)
|
|
227
225
|
* Space Complexity: O(1)
|
|
@@ -237,11 +235,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
237
235
|
* successfully added to the data structure.
|
|
238
236
|
*/
|
|
239
237
|
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
240
|
-
/**
|
|
241
|
-
* Time Complexity: O(k * n)
|
|
242
|
-
* Space Complexity: O(1)
|
|
243
|
-
* "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
244
|
-
*/
|
|
245
238
|
/**
|
|
246
239
|
* Time Complexity: O(k * n)
|
|
247
240
|
* Space Complexity: O(1)
|
|
@@ -263,10 +256,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
263
256
|
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
264
257
|
getNode<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
265
258
|
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
266
|
-
/**
|
|
267
|
-
* Time Complexity: O(n)
|
|
268
|
-
* Space Complexity: O(log n)
|
|
269
|
-
*/
|
|
270
259
|
/**
|
|
271
260
|
* Time Complexity: O(n)
|
|
272
261
|
* Space Complexity: O(log n)
|
|
@@ -286,10 +275,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
286
275
|
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
287
276
|
has<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
288
277
|
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
289
|
-
/**
|
|
290
|
-
* Time Complexity: O(1)
|
|
291
|
-
* Space Complexity: O(1)
|
|
292
|
-
*/
|
|
293
278
|
/**
|
|
294
279
|
* Time Complexity: O(1)
|
|
295
280
|
* Space Complexity: O(1)
|
|
@@ -297,10 +282,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
297
282
|
* Clear the binary tree, removing all nodes.
|
|
298
283
|
*/
|
|
299
284
|
clear(): void;
|
|
300
|
-
/**
|
|
301
|
-
* Time Complexity: O(1)
|
|
302
|
-
* Space Complexity: O(1)
|
|
303
|
-
*/
|
|
304
285
|
/**
|
|
305
286
|
* Time Complexity: O(1)
|
|
306
287
|
* Space Complexity: O(1)
|
|
@@ -309,10 +290,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
309
290
|
* @returns {boolean} - True if the binary tree is empty, false otherwise.
|
|
310
291
|
*/
|
|
311
292
|
isEmpty(): boolean;
|
|
312
|
-
/**
|
|
313
|
-
* Time Complexity: O(n)
|
|
314
|
-
* Space Complexity: O(log n)
|
|
315
|
-
*/
|
|
316
293
|
/**
|
|
317
294
|
* Time Complexity: O(n)
|
|
318
295
|
* Space Complexity: O(log n)
|
|
@@ -326,10 +303,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
326
303
|
* @returns a boolean value.
|
|
327
304
|
*/
|
|
328
305
|
isPerfectlyBalanced(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
329
|
-
/**
|
|
330
|
-
* Time Complexity: O(n)
|
|
331
|
-
* Space Complexity: O(1)
|
|
332
|
-
*/
|
|
333
306
|
/**
|
|
334
307
|
* Time Complexity: O(n)
|
|
335
308
|
* Space Complexity: O(1)
|
|
@@ -345,10 +318,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
345
318
|
* @returns a boolean value.
|
|
346
319
|
*/
|
|
347
320
|
isBST(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
348
|
-
/**
|
|
349
|
-
* Time Complexity: O(n)
|
|
350
|
-
* Space Complexity: O(1)
|
|
351
|
-
*/
|
|
352
321
|
/**
|
|
353
322
|
* Time Complexity: O(n)
|
|
354
323
|
* Space Complexity: O(1)
|
|
@@ -364,10 +333,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
364
333
|
* @returns the depth of a node in a tree structure.
|
|
365
334
|
*/
|
|
366
335
|
getDepth(dist: R | BTNKeyOrNodeOrEntry<K, V, NODE>, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): number;
|
|
367
|
-
/**
|
|
368
|
-
* Time Complexity: O(n)
|
|
369
|
-
* Space Complexity: O(1)
|
|
370
|
-
*/
|
|
371
336
|
/**
|
|
372
337
|
* Time Complexity: O(n)
|
|
373
338
|
* Space Complexity: O(1)
|
|
@@ -382,10 +347,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
382
347
|
* @returns the maximum height of the binary tree.
|
|
383
348
|
*/
|
|
384
349
|
getHeight(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
385
|
-
/**
|
|
386
|
-
* Time Complexity: O(n)
|
|
387
|
-
* Space Complexity: O(log n)
|
|
388
|
-
*/
|
|
389
350
|
/**
|
|
390
351
|
* Time Complexity: O(n)
|
|
391
352
|
* Space Complexity: O(log n)
|
|
@@ -403,10 +364,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
403
364
|
* binary tree.
|
|
404
365
|
*/
|
|
405
366
|
getMinHeight(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
406
|
-
/**
|
|
407
|
-
* Time Complexity: O(log n)
|
|
408
|
-
* Space Complexity: O(log n)
|
|
409
|
-
*/
|
|
410
367
|
/**
|
|
411
368
|
* Time Complexity: O(log n)
|
|
412
369
|
* Space Complexity: O(log n)
|
|
@@ -421,47 +378,51 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
421
378
|
* @returns The function `getPathToRoot` returns an array of `NODE` objects.
|
|
422
379
|
*/
|
|
423
380
|
getPathToRoot(beginNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
424
|
-
/**
|
|
425
|
-
* Time Complexity: O(log n)
|
|
426
|
-
* Space Complexity: O(1)
|
|
427
|
-
*/
|
|
428
|
-
/**
|
|
429
|
-
* Time Complexity: O(log n)
|
|
430
|
-
* Space Complexity: O(1)
|
|
431
|
-
*
|
|
432
|
-
* The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
|
|
433
|
-
* iterative traversal.
|
|
434
|
-
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
435
|
-
* starting point for finding the leftmost node in a binary tree. It can be either a root node (`R`),
|
|
436
|
-
* a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
437
|
-
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
438
|
-
* of iteration to be performed. It can have two possible values:
|
|
439
|
-
* @returns The function `getLeftMost` returns the leftmost node in a binary tree.
|
|
440
|
-
*/
|
|
441
|
-
getLeftMost(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
442
|
-
/**
|
|
443
|
-
* Time Complexity: O(log n)
|
|
444
|
-
* Space Complexity: O(1)
|
|
445
|
-
*/
|
|
446
381
|
/**
|
|
447
382
|
* Time Complexity: O(log n)
|
|
448
383
|
* Space Complexity: O(1)
|
|
449
384
|
*
|
|
450
|
-
* The `
|
|
451
|
-
*
|
|
452
|
-
* @param {
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* @param {
|
|
456
|
-
*
|
|
385
|
+
* The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
|
|
386
|
+
* tail-recursive iteration.
|
|
387
|
+
* @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
|
|
388
|
+
* node of a binary tree or null if the tree is empty. It has a default value of `_DEFAULT_CALLBACK`
|
|
389
|
+
* if not provided explicitly.
|
|
390
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter in the
|
|
391
|
+
* `getLeftMost` function represents the starting point for finding the leftmost node in a binary
|
|
392
|
+
* tree. It can be either a reference to the root node of the tree (`R`), or a key, node, or entry in
|
|
393
|
+
* the binary tree structure (`
|
|
394
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `getLeftMost` function
|
|
395
|
+
* specifies the type of iteration to be used when traversing the binary tree nodes. It can have two
|
|
457
396
|
* possible values:
|
|
458
|
-
* @returns The
|
|
397
|
+
* @returns The `getLeftMost` function returns the result of the callback function `C` applied to the
|
|
398
|
+
* leftmost node in the binary tree starting from the `beginRoot` node. If the `beginRoot` is `NIL`,
|
|
399
|
+
* it returns the result of the callback function applied to `undefined`. If the `beginRoot` is not a
|
|
400
|
+
* real node, it returns the result of the callback function applied
|
|
459
401
|
*/
|
|
460
|
-
|
|
402
|
+
getLeftMost<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>;
|
|
461
403
|
/**
|
|
462
404
|
* Time Complexity: O(log n)
|
|
463
405
|
* Space Complexity: O(1)
|
|
464
|
-
|
|
406
|
+
*
|
|
407
|
+
* The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
|
|
408
|
+
* or iterative traversal methods.
|
|
409
|
+
* @param {C} callback - The `callback` parameter is a function that will be called with the result
|
|
410
|
+
* of the operation. It has a generic type `C` which extends `BTNCallback<OptBTNOrNull<NODE>>`. The
|
|
411
|
+
* default value for `callback` is `this._DEFAULT_CALLBACK` if it is not provided.
|
|
412
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter in the
|
|
413
|
+
* `getRightMost` function represents the starting point for finding the rightmost node in a binary
|
|
414
|
+
* tree. It can be either a reference to the root node of the tree (`this.root`) or a specific key,
|
|
415
|
+
* node, or entry in the tree. If
|
|
416
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `getRightMost`
|
|
417
|
+
* function specifies the type of iteration to be used when finding the rightmost node in a binary
|
|
418
|
+
* tree. It can have two possible values:
|
|
419
|
+
* @returns The `getRightMost` function returns the result of the callback function `C` applied to
|
|
420
|
+
* the rightmost node in the binary tree. The rightmost node is found either through a recursive
|
|
421
|
+
* depth-first search (if `iterationType` is 'RECURSIVE') or through an indirect implementation of
|
|
422
|
+
* iteration using tail recursion optimization. The result of the callback function applied to the
|
|
423
|
+
* rightmost node is returned
|
|
424
|
+
*/
|
|
425
|
+
getRightMost<C extends BTNCallback<OptBTNOrNull<NODE>>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>;
|
|
465
426
|
/**
|
|
466
427
|
* Time Complexity: O(log n)
|
|
467
428
|
* Space Complexity: O(1)
|
|
@@ -472,10 +433,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
472
433
|
* @returns the predecessor node of the given node.
|
|
473
434
|
*/
|
|
474
435
|
getPredecessor(node: NODE): NODE;
|
|
475
|
-
/**
|
|
476
|
-
* Time Complexity: O(log n)
|
|
477
|
-
* Space Complexity: O(1)
|
|
478
|
-
*/
|
|
479
436
|
/**
|
|
480
437
|
* Time Complexity: O(log n)
|
|
481
438
|
* Space Complexity: O(1)
|
|
@@ -486,16 +443,32 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
486
443
|
* there is no successor, and `undefined` if the input `x` is not a valid node.
|
|
487
444
|
*/
|
|
488
445
|
getSuccessor(x?: K | NODE | null): OptBTNOrNull<NODE>;
|
|
489
|
-
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType
|
|
490
|
-
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?:
|
|
446
|
+
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
447
|
+
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
|
|
491
448
|
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
492
449
|
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
493
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
494
|
-
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
495
450
|
/**
|
|
496
451
|
* Time complexity: O(n)
|
|
497
452
|
* Space complexity: O(n)
|
|
498
|
-
|
|
453
|
+
*
|
|
454
|
+
* The `leaves` function in TypeScript iterates through a binary tree to find and return the leaf
|
|
455
|
+
* nodes based on a specified callback and iteration type.
|
|
456
|
+
* @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
|
|
457
|
+
* in the binary tree. It is a generic type `C` that extends `BTNCallback<NODE | null>`, where `NODE`
|
|
458
|
+
* represents a node in the binary tree. The default value for `callback` is
|
|
459
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter in the `leaves`
|
|
460
|
+
* method is used to specify the starting point for finding and processing the leaves of a binary
|
|
461
|
+
* tree. It represents the root node of the binary tree or a specific key, node, or entry within the
|
|
462
|
+
* tree from which the search for leaves should begin
|
|
463
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `leaves` method
|
|
464
|
+
* specifies the type of iteration to be performed when collecting the leaves of a binary tree. It
|
|
465
|
+
* can have two possible values:
|
|
466
|
+
* @returns The `leaves` method returns an array of values that are the result of applying the
|
|
467
|
+
* provided callback function to the leaf nodes in the binary tree structure.
|
|
468
|
+
*/
|
|
469
|
+
leaves<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
470
|
+
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
471
|
+
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
499
472
|
/**
|
|
500
473
|
* Time complexity: O(n)
|
|
501
474
|
* Space complexity: O(n)
|
|
@@ -516,10 +489,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
516
489
|
* callback function `callback`.
|
|
517
490
|
*/
|
|
518
491
|
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
|
|
519
|
-
/**
|
|
520
|
-
* Time complexity: O(n)
|
|
521
|
-
* Space complexity: O(n)
|
|
522
|
-
*/
|
|
523
492
|
/**
|
|
524
493
|
* Time complexity: O(n)
|
|
525
494
|
* Space complexity: O(n)
|
|
@@ -528,10 +497,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
528
497
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
529
498
|
*/
|
|
530
499
|
clone(): TREE;
|
|
531
|
-
/**
|
|
532
|
-
* Time Complexity: O(n)
|
|
533
|
-
* Space Complexity: O(n)
|
|
534
|
-
*/
|
|
535
500
|
/**
|
|
536
501
|
* Time Complexity: O(n)
|
|
537
502
|
* Space Complexity: O(n)
|
|
@@ -548,10 +513,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
548
513
|
* the given predicate function.
|
|
549
514
|
*/
|
|
550
515
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
|
|
551
|
-
/**
|
|
552
|
-
* Time Complexity: O(n)
|
|
553
|
-
* Space Complexity: O(n)
|
|
554
|
-
*/
|
|
555
516
|
/**
|
|
556
517
|
* Time Complexity: O(n)
|
|
557
518
|
* Space Complexity: O(n)
|
|
@@ -568,10 +529,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
568
529
|
* @returns The `map` method is returning a new tree object.
|
|
569
530
|
*/
|
|
570
531
|
map(callback: EntryCallback<K, V | undefined, V>, thisArg?: any): TREE;
|
|
571
|
-
/**
|
|
572
|
-
* Time Complexity: O(n)
|
|
573
|
-
* Space Complexity: O(n)
|
|
574
|
-
*/
|
|
575
532
|
/**
|
|
576
533
|
* Time Complexity: O(n)
|
|
577
534
|
* Space Complexity: O(n)
|
|
@@ -586,11 +543,9 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
586
543
|
* @returns Nothing is being returned. The function has a return type of `void`, which means it does
|
|
587
544
|
* not return any value.
|
|
588
545
|
*/
|
|
589
|
-
print(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions):
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
* Space Complexity: O(1)
|
|
593
|
-
*/
|
|
546
|
+
print(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): string;
|
|
547
|
+
protected _dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): ReturnType<C>[];
|
|
548
|
+
protected _dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: boolean): ReturnType<C>[];
|
|
594
549
|
/**
|
|
595
550
|
* Time Complexity: O(1)
|
|
596
551
|
* Space Complexity: O(1)
|
|
@@ -602,10 +557,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
602
557
|
* @returns an IterableIterator<[K, V | undefined]>.
|
|
603
558
|
*/
|
|
604
559
|
protected _getIterator(node?: OptBTNOrNull<NODE>): IterableIterator<[K, V | undefined]>;
|
|
605
|
-
/**
|
|
606
|
-
* Time Complexity: O(n)
|
|
607
|
-
* Space Complexity: O(n)
|
|
608
|
-
*/
|
|
609
560
|
/**
|
|
610
561
|
* Time Complexity: O(n)
|
|
611
562
|
* Space Complexity: O(n)
|
|
@@ -625,10 +576,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
625
576
|
*/
|
|
626
577
|
protected _displayAux(node: OptBTNOrNull<NODE>, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
627
578
|
protected _DEFAULT_CALLBACK: (node: OptBTNOrNull<NODE>) => K | undefined;
|
|
628
|
-
/**
|
|
629
|
-
* Time Complexity: O(1)
|
|
630
|
-
* Space Complexity: O(1)
|
|
631
|
-
*/
|
|
632
579
|
/**
|
|
633
580
|
* Time Complexity: O(1)
|
|
634
581
|
* Space Complexity: O(1)
|
|
@@ -643,10 +590,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
643
590
|
* properties, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
644
591
|
*/
|
|
645
592
|
protected _swapProperties(srcNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, destNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
|
|
646
|
-
/**
|
|
647
|
-
* Time Complexity: O(1)
|
|
648
|
-
* Space Complexity: O(1)
|
|
649
|
-
*/
|
|
650
593
|
/**
|
|
651
594
|
* Time Complexity: O(1)
|
|
652
595
|
* Space Complexity: O(1)
|
|
@@ -660,10 +603,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
660
603
|
* @returns the newNode.
|
|
661
604
|
*/
|
|
662
605
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
663
|
-
/**
|
|
664
|
-
* Time Complexity: O(1)
|
|
665
|
-
* Space Complexity: O(1)
|
|
666
|
-
*/
|
|
667
606
|
/**
|
|
668
607
|
* Time Complexity: O(1)
|
|
669
608
|
* Space Complexity: O(1)
|
|
@@ -674,10 +613,6 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
674
613
|
* means that it can accept a value of type `NODE`, `null`, or `undefined`.
|
|
675
614
|
*/
|
|
676
615
|
protected _setRoot(v: OptBTNOrNull<NODE>): void;
|
|
677
|
-
/**
|
|
678
|
-
* Time Complexity: O(1)
|
|
679
|
-
* Space Complexity: O(1)
|
|
680
|
-
*/
|
|
681
616
|
/**
|
|
682
617
|
* Time Complexity: O(1)
|
|
683
618
|
* Space Complexity: O(1)
|