graph-typed 1.54.2 → 1.54.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -12
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +2 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +25 -21
- package/dist/data-structures/binary-tree/avl-tree.js +12 -8
- package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
- package/dist/data-structures/binary-tree/binary-tree.js +239 -144
- package/dist/data-structures/binary-tree/bst.d.ts +62 -56
- package/dist/data-structures/binary-tree/bst.js +78 -122
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
- package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/data-structures/binary-tree/tree-counter.js +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +14 -14
- package/dist/data-structures/binary-tree/tree-multi-map.js +4 -4
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/utils/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +25 -15
- package/src/data-structures/binary-tree/avl-tree.ts +35 -29
- package/src/data-structures/binary-tree/binary-tree.ts +469 -252
- package/src/data-structures/binary-tree/bst.ts +141 -143
- package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
- package/src/data-structures/binary-tree/tree-counter.ts +33 -27
- package/src/data-structures/binary-tree/tree-multi-map.ts +25 -17
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/utils/utils.ts +2 -2
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode
|
|
8
|
+
import type { BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparable, Comparator, CP, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNode } from '../../types';
|
|
9
9
|
import { BinaryTree, BinaryTreeNode } from './binary-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { Range } from '../../common';
|
|
12
12
|
export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
13
|
+
parent?: BSTNode<K, V>;
|
|
13
14
|
/**
|
|
14
15
|
* This TypeScript constructor function initializes an instance with a key and an optional value.
|
|
15
16
|
* @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
|
|
@@ -20,13 +21,12 @@ export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
20
21
|
* default to `undefined`.
|
|
21
22
|
*/
|
|
22
23
|
constructor(key: K, value?: V);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
set right(v: OptNodeOrNull<BSTNode<K, V>>);
|
|
24
|
+
_left?: BSTNode<K, V> | null | undefined;
|
|
25
|
+
get left(): BSTNode<K, V> | null | undefined;
|
|
26
|
+
set left(v: BSTNode<K, V> | null | undefined);
|
|
27
|
+
_right?: BSTNode<K, V> | null | undefined;
|
|
28
|
+
get right(): BSTNode<K, V> | null | undefined;
|
|
29
|
+
set right(v: BSTNode<K, V> | null | undefined);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* 1. Node Order: Each node's left child has a lesser value, and the right child has a greater value.
|
|
@@ -62,9 +62,9 @@ export declare class BSTNode<K = any, V = any> extends BinaryTreeNode<K, V> {
|
|
|
62
62
|
* @example
|
|
63
63
|
* // Find elements in a range
|
|
64
64
|
* const bst = new BST<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
65
|
-
* console.log(bst.search(new Range(5, 10))); // [
|
|
66
|
-
* console.log(bst.rangeSearch([4, 12], node => node.key.toString())); // ['
|
|
67
|
-
* console.log(bst.search(new Range(4, 12, true, false))); // [
|
|
65
|
+
* console.log(bst.search(new Range(5, 10))); // [5, 7, 10]
|
|
66
|
+
* console.log(bst.rangeSearch([4, 12], node => node.key.toString())); // ['5', '7', '10', '12']
|
|
67
|
+
* console.log(bst.search(new Range(4, 12, true, false))); // [5, 7, 10]
|
|
68
68
|
* console.log(bst.rangeSearch([15, 20])); // [15, 18]
|
|
69
69
|
* console.log(bst.search(new Range(15, 20, false))); // [18]
|
|
70
70
|
* @example
|
|
@@ -98,12 +98,12 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
98
98
|
* This TypeScript constructor initializes a binary search tree with optional options and adds
|
|
99
99
|
* elements if provided.
|
|
100
100
|
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
|
|
101
|
-
* iterable that can contain elements of type `
|
|
101
|
+
* iterable that can contain elements of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It is used to
|
|
102
102
|
* initialize the binary search tree with keys, nodes, entries, or raw data.
|
|
103
103
|
* @param [options] - The `options` parameter is an optional object that can contain the following
|
|
104
104
|
* properties:
|
|
105
105
|
*/
|
|
106
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<
|
|
106
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
|
|
107
107
|
protected _root?: BSTNode<K, V>;
|
|
108
108
|
get root(): OptNode<BSTNode<K, V>>;
|
|
109
109
|
protected _isReverse: boolean;
|
|
@@ -141,7 +141,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
141
141
|
*
|
|
142
142
|
* The function ensures the existence of a node in a data structure and returns it, or undefined if
|
|
143
143
|
* it doesn't exist.
|
|
144
|
-
* @param {
|
|
144
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
145
145
|
* `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
|
|
146
146
|
* entry, or raw element that needs to be ensured in the tree.
|
|
147
147
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
@@ -150,18 +150,18 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
150
150
|
* @returns The method is returning either the node that was ensured or `undefined` if the node could
|
|
151
151
|
* not be ensured.
|
|
152
152
|
*/
|
|
153
|
-
ensureNode(keyNodeOrEntry:
|
|
153
|
+
ensureNode(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
|
|
154
154
|
/**
|
|
155
155
|
* Time Complexity: O(1)
|
|
156
156
|
* Space Complexity: O(1)
|
|
157
157
|
*
|
|
158
158
|
* The function checks if the input is an instance of the BSTNode class.
|
|
159
|
-
* @param {
|
|
160
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
159
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
160
|
+
* `keyNodeOrEntry` can be of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
161
161
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
162
162
|
* an instance of the `BSTNode` class.
|
|
163
163
|
*/
|
|
164
|
-
isNode(keyNodeOrEntry:
|
|
164
|
+
isNode(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is BSTNode<K, V>;
|
|
165
165
|
/**
|
|
166
166
|
* Time Complexity: O(1)
|
|
167
167
|
* Space Complexity: O(1)
|
|
@@ -179,13 +179,13 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
179
179
|
* Space Complexity: O(log n)
|
|
180
180
|
*
|
|
181
181
|
* The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
|
|
182
|
-
* @param {
|
|
183
|
-
* `keyNodeOrEntry` can accept a value of type `R` or `
|
|
182
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
|
|
183
|
+
* `keyNodeOrEntry` can accept a value of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
|
|
184
184
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
185
185
|
* key in the binary search tree. If provided, it will be stored in the node along with the key.
|
|
186
186
|
* @returns a boolean value.
|
|
187
187
|
*/
|
|
188
|
-
add(keyNodeOrEntry:
|
|
188
|
+
add(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
189
189
|
/**
|
|
190
190
|
* Time Complexity: O(k log n)
|
|
191
191
|
* Space Complexity: O(k + log n)
|
|
@@ -214,7 +214,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
214
214
|
*
|
|
215
215
|
* The function `search` in TypeScript overrides the search behavior in a binary tree structure based
|
|
216
216
|
* on specified criteria.
|
|
217
|
-
* @param {
|
|
217
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
|
|
218
218
|
* `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
|
|
219
219
|
* following types:
|
|
220
220
|
* @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
|
|
@@ -222,9 +222,9 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
222
222
|
* search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
|
|
223
223
|
* @param {C} callback - The `callback` parameter in the `override search` function is a function
|
|
224
224
|
* that will be called on each node that matches the search criteria. It is of type `C`, which
|
|
225
|
-
* extends `NodeCallback<BSTNode<K, V
|
|
225
|
+
* extends `NodeCallback<BSTNode<K, V> | null>`. The callback function should accept a node of type `BSTNode<K, V>` as its
|
|
226
226
|
* argument and
|
|
227
|
-
* @param {
|
|
227
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `override search`
|
|
228
228
|
* method represents the node from which the search operation will begin. It is the starting point
|
|
229
229
|
* for searching within the tree data structure. The method ensures that the `startNode` is a valid
|
|
230
230
|
* node before proceeding with the search operation. If the `
|
|
@@ -236,7 +236,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
236
236
|
* structure based on the provided key, predicate, and other options. The search results are
|
|
237
237
|
* collected in an array and returned as the output of the method.
|
|
238
238
|
*/
|
|
239
|
-
search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate:
|
|
239
|
+
search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
240
240
|
/**
|
|
241
241
|
* Time Complexity: O(log n)
|
|
242
242
|
* Space Complexity: O(k + log n)
|
|
@@ -246,9 +246,9 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
246
246
|
* either a `Range` object or an array of two elements representing the range boundaries.
|
|
247
247
|
* @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
|
|
248
248
|
* function that is used to process each node that is found within the specified range during the
|
|
249
|
-
* search operation. It is of type `NodeCallback<BSTNode<K, V
|
|
249
|
+
* search operation. It is of type `NodeCallback<BSTNode<K, V> | null>`, where `BSTNode<K, V>` is the type of nodes in the
|
|
250
250
|
* data structure.
|
|
251
|
-
* @param {
|
|
251
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `rangeSearch`
|
|
252
252
|
* function represents the node from which the search for nodes within the specified range will
|
|
253
253
|
* begin. It is the starting point for the range search operation.
|
|
254
254
|
* @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
|
|
@@ -258,14 +258,14 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
258
258
|
* @returns The `rangeSearch` function is returning the result of calling the `search` method with
|
|
259
259
|
* the specified parameters.
|
|
260
260
|
*/
|
|
261
|
-
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback?: C, startNode?:
|
|
261
|
+
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
262
262
|
/**
|
|
263
263
|
* Time Complexity: O(log n)
|
|
264
264
|
* Space Complexity: O(log n)
|
|
265
265
|
*
|
|
266
266
|
* This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
|
|
267
|
-
* @param {
|
|
268
|
-
* parameter can be of type `
|
|
267
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
|
|
268
|
+
* parameter can be of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `R`, or `NodePredicate<BSTNode<K, V>>`.
|
|
269
269
|
* @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
|
|
270
270
|
* is used to specify the starting point for searching nodes in the binary search tree. If no
|
|
271
271
|
* specific starting point is provided, the default value is set to `this._root`, which is the root
|
|
@@ -279,28 +279,34 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
279
279
|
* the specified root node (`startNode`) and using the specified iteration type. The method then
|
|
280
280
|
* returns the first node found or `undefined` if no node is found.
|
|
281
281
|
*/
|
|
282
|
-
getNode(keyNodeEntryOrPredicate:
|
|
282
|
+
getNode(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, startNode?: BSTNOptKeyOrNode<K, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
|
|
283
283
|
/**
|
|
284
284
|
* Time complexity: O(n)
|
|
285
285
|
* Space complexity: O(n)
|
|
286
286
|
*
|
|
287
|
-
* The function overrides the
|
|
288
|
-
* the
|
|
287
|
+
* The function `dfs` in TypeScript overrides the base class method with default parameters and
|
|
288
|
+
* returns the result of the super class `dfs` method.
|
|
289
289
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
290
|
-
* during the
|
|
291
|
-
* `
|
|
292
|
-
* @param {DFSOrderPattern} [pattern=IN] - The
|
|
293
|
-
* order in which the Depth-First Search (DFS)
|
|
294
|
-
*
|
|
295
|
-
* @param {
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* following
|
|
301
|
-
* @
|
|
290
|
+
* visited during the Depth-First Search traversal. It is a generic type `C` that extends the
|
|
291
|
+
* `NodeCallback` interface for `BSTNode<K, V>`. The default value for `callback` is `this._
|
|
292
|
+
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `override dfs` method
|
|
293
|
+
* specifies the order in which the Depth-First Search (DFS) traversal should be performed on the
|
|
294
|
+
* Binary Search Tree (BST). The possible values for the `pattern` parameter are:
|
|
295
|
+
* @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `override dfs` method is a
|
|
296
|
+
* boolean flag that indicates whether you want to stop the depth-first search traversal after
|
|
297
|
+
* finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set
|
|
298
|
+
* to `true`, the traversal will stop after finding
|
|
299
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode -
|
|
300
|
+
* The `startNode` parameter in the `override dfs` method can be one of the following types:
|
|
301
|
+
* @param {IterationType} iterationType - The `iterationType` parameter in the `override dfs` method
|
|
302
|
+
* specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
|
|
303
|
+
* Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the
|
|
304
|
+
* traversal. The possible values for `
|
|
305
|
+
* @returns The `override` function is returning the result of calling the `dfs` method from the
|
|
306
|
+
* superclass, with the provided arguments `callback`, `pattern`, `onlyOne`, `startNode`, and
|
|
307
|
+
* `iterationType`. The return type is an array of the return type of the callback function `C`.
|
|
302
308
|
*/
|
|
303
|
-
dfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?:
|
|
309
|
+
dfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
304
310
|
/**
|
|
305
311
|
* Time complexity: O(n)
|
|
306
312
|
* Space complexity: O(n)
|
|
@@ -310,7 +316,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
310
316
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node
|
|
311
317
|
* visited during the breadth-first search. It should take a single argument, which is the current
|
|
312
318
|
* node being visited, and it can return a value of any type.
|
|
313
|
-
* @param {
|
|
319
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
314
320
|
* point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
|
|
315
321
|
* object. If no value is provided, the default value is the root of the tree.
|
|
316
322
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
@@ -318,7 +324,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
318
324
|
* the following values:
|
|
319
325
|
* @returns an array of the return type of the callback function.
|
|
320
326
|
*/
|
|
321
|
-
bfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?:
|
|
327
|
+
bfs<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
322
328
|
/**
|
|
323
329
|
* Time complexity: O(n)
|
|
324
330
|
* Space complexity: O(n)
|
|
@@ -326,9 +332,9 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
326
332
|
* The function overrides the listLevels method from the superclass and returns an array of arrays
|
|
327
333
|
* containing the results of the callback function applied to each level of the tree.
|
|
328
334
|
* @param {C} callback - The `callback` parameter is a generic type `C` that extends
|
|
329
|
-
* `NodeCallback<BSTNode<K, V
|
|
335
|
+
* `NodeCallback<BSTNode<K, V> | null>`. It represents a callback function that will be called for each node in the
|
|
330
336
|
* tree during the iteration process.
|
|
331
|
-
* @param {
|
|
337
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
|
|
332
338
|
* point for listing the levels of the binary tree. It can be either a root node of the tree, a
|
|
333
339
|
* key-value pair representing a node in the tree, or a key representing a node in the tree. If no
|
|
334
340
|
* value is provided, the root of
|
|
@@ -337,7 +343,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
337
343
|
* @returns The method is returning a two-dimensional array of the return type of the callback
|
|
338
344
|
* function.
|
|
339
345
|
*/
|
|
340
|
-
listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?:
|
|
346
|
+
listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[][];
|
|
341
347
|
/**
|
|
342
348
|
* Time complexity: O(n)
|
|
343
349
|
* Space complexity: O(n)
|
|
@@ -350,7 +356,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
350
356
|
* @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
|
|
351
357
|
* traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
|
|
352
358
|
* 0, or 1, where:
|
|
353
|
-
* @param {
|
|
359
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } targetNode - The `targetNode` parameter is the node in
|
|
354
360
|
* the binary tree that you want to start traversing from. It can be specified either by providing
|
|
355
361
|
* the key of the node, the node itself, or an entry containing the key and value of the node. If no
|
|
356
362
|
* `targetNode` is provided,
|
|
@@ -359,7 +365,7 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
359
365
|
* @returns The function `lesserOrGreaterTraverse` returns an array of values of type
|
|
360
366
|
* `ReturnType<C>`, which is the return type of the callback function passed as an argument.
|
|
361
367
|
*/
|
|
362
|
-
lesserOrGreaterTraverse<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, lesserOrGreater?: CP, targetNode?:
|
|
368
|
+
lesserOrGreaterTraverse<C extends NodeCallback<BSTNode<K, V>>>(callback?: C, lesserOrGreater?: CP, targetNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
363
369
|
/**
|
|
364
370
|
* Time complexity: O(n)
|
|
365
371
|
* Space complexity: O(n)
|
|
@@ -420,14 +426,14 @@ export declare class BST<K = any, V = any, R = object, MK = any, MV = any, MR =
|
|
|
420
426
|
* Space Complexity: O(1)
|
|
421
427
|
*
|
|
422
428
|
* The function overrides a method and converts a key, value pair or entry or raw element to a node.
|
|
423
|
-
* @param {
|
|
424
|
-
* type R or
|
|
429
|
+
* @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - A variable that can be of
|
|
430
|
+
* type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . It represents either a key, a node, an entry, or a raw
|
|
425
431
|
* element.
|
|
426
432
|
* @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
|
|
427
433
|
* value associated with a key in a key-value pair.
|
|
428
434
|
* @returns either a BSTNode<K, V> object or undefined.
|
|
429
435
|
*/
|
|
430
|
-
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry:
|
|
436
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): [OptNode<BSTNode<K, V>>, V | undefined];
|
|
431
437
|
/**
|
|
432
438
|
* Time Complexity: O(1)
|
|
433
439
|
* Space Complexity: O(1)
|