directed-graph-typed 1.52.0 → 1.52.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/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/data-structures/binary-tree/binary-tree.js +50 -50
- package/dist/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/data-structures/binary-tree/bst.js +15 -15
- package/dist/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/data-structures/graph/directed-graph.js +2 -1
- package/dist/data-structures/queue/deque.d.ts +7 -0
- package/dist/data-structures/queue/deque.js +16 -1
- package/dist/data-structures/queue/queue.d.ts +0 -1
- package/dist/data-structures/queue/queue.js +0 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +1 -22
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +12 -12
- package/src/data-structures/binary-tree/avl-tree.ts +11 -11
- package/src/data-structures/binary-tree/binary-tree.ts +151 -147
- package/src/data-structures/binary-tree/bst.ts +44 -41
- package/src/data-structures/binary-tree/rb-tree.ts +10 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +10 -10
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/queue/deque.ts +15 -1
- package/src/data-structures/queue/queue.ts +0 -1
- package/src/index.ts +2 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/binary-tree/binary-tree.ts +21 -1
- package/src/types/data-structures/binary-tree/bst.ts +7 -0
- package/src/types/data-structures/queue/deque.ts +4 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, BTNKeyOrNodeOrEntry, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeDisplayLayout, OptBTNOrNull } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { IterableEntryBase } from '../base';
|
|
11
11
|
/**
|
|
@@ -32,26 +32,26 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
32
32
|
* @returns The left node of the current node is being returned. It can be either a NODE object,
|
|
33
33
|
* null, or undefined.
|
|
34
34
|
*/
|
|
35
|
-
get left(): NODE
|
|
35
|
+
get left(): OptBTNOrNull<NODE>;
|
|
36
36
|
/**
|
|
37
37
|
* The function sets the left child of a node and updates its parent reference.
|
|
38
|
-
* @param {NODE
|
|
38
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
39
39
|
* `undefined`.
|
|
40
40
|
*/
|
|
41
|
-
set left(v: NODE
|
|
41
|
+
set left(v: OptBTNOrNull<NODE>);
|
|
42
42
|
protected _right?: NODE | null;
|
|
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,
|
|
46
46
|
* `null`, or `undefined`.
|
|
47
47
|
*/
|
|
48
|
-
get right(): NODE
|
|
48
|
+
get right(): OptBTNOrNull<NODE>;
|
|
49
49
|
/**
|
|
50
50
|
* The function sets the right child of a node and updates its parent.
|
|
51
|
-
* @param {NODE
|
|
51
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
|
|
52
52
|
* `undefined`.
|
|
53
53
|
*/
|
|
54
|
-
set right(v: NODE
|
|
54
|
+
set right(v: OptBTNOrNull<NODE>);
|
|
55
55
|
/**
|
|
56
56
|
* Get the position of the node within its family.
|
|
57
57
|
* @returns {FamilyPosition} - The family position of the node.
|
|
@@ -69,21 +69,21 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
69
69
|
iterationType: IterationType;
|
|
70
70
|
/**
|
|
71
71
|
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
|
|
72
|
-
* @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of
|
|
72
|
+
* @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of BTNKeyOrNodeOrEntry objects. These objects represent the
|
|
73
73
|
* nodes to be added to the binary tree.
|
|
74
74
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
75
75
|
* configuration options for the binary tree. In this case, it is of type
|
|
76
76
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
77
77
|
* required.
|
|
78
78
|
*/
|
|
79
|
-
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R |
|
|
80
|
-
protected _root?: NODE
|
|
79
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions<K, V, R>);
|
|
80
|
+
protected _root?: OptBTNOrNull<NODE>;
|
|
81
81
|
/**
|
|
82
82
|
* The function returns the root node, which can be of type NODE, null, or undefined.
|
|
83
83
|
* @returns The method is returning the value of the `_root` property, which can be of type `NODE`,
|
|
84
84
|
* `null`, or `undefined`.
|
|
85
85
|
*/
|
|
86
|
-
get root(): NODE
|
|
86
|
+
get root(): OptBTNOrNull<NODE>;
|
|
87
87
|
protected _size: number;
|
|
88
88
|
/**
|
|
89
89
|
* The function returns the size of an object.
|
|
@@ -120,15 +120,15 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
120
120
|
/**
|
|
121
121
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
|
|
122
122
|
* into a node object.
|
|
123
|
-
* @param {R |
|
|
124
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
123
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
124
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
125
125
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
126
126
|
* `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
|
|
127
127
|
* key-value pair. If provided, it will be used to create a node with the specified key and value.
|
|
128
128
|
* @returns The function `keyValueOrEntryOrRawElementToNode` returns either a `NODE` object, `null`,
|
|
129
129
|
* or `undefined`.
|
|
130
130
|
*/
|
|
131
|
-
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R |
|
|
131
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): OptBTNOrNull<NODE>;
|
|
132
132
|
/**
|
|
133
133
|
* Time Complexity: O(n)
|
|
134
134
|
* Space Complexity: O(log n)
|
|
@@ -139,52 +139,52 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
139
139
|
*
|
|
140
140
|
* The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
|
|
141
141
|
* node if it is a key or entry.
|
|
142
|
-
* @param {R |
|
|
143
|
-
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `
|
|
142
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
143
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
144
144
|
* a raw element.
|
|
145
145
|
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
146
146
|
* parameter that specifies the type of iteration to be used when searching for a node. It has a
|
|
147
147
|
* default value of `'ITERATIVE'`.
|
|
148
148
|
* @returns The function `ensureNode` returns either a `NODE` object, `null`, or `undefined`.
|
|
149
149
|
*/
|
|
150
|
-
ensureNode(keyOrNodeOrEntryOrRawElement: R |
|
|
150
|
+
ensureNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
151
151
|
/**
|
|
152
152
|
* The function checks if the input is an instance of the BinaryTreeNode class.
|
|
153
|
-
* @param {R |
|
|
154
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
153
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
154
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
155
155
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
156
156
|
* an instance of the `BinaryTreeNode` class.
|
|
157
157
|
*/
|
|
158
|
-
isNode(keyOrNodeOrEntryOrRawElement: R |
|
|
158
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
159
159
|
/**
|
|
160
160
|
* The function checks if a given node is a valid node in a binary search tree.
|
|
161
|
-
* @param {R |
|
|
162
|
-
* `
|
|
161
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
162
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
163
163
|
* @returns a boolean value.
|
|
164
164
|
*/
|
|
165
|
-
isRealNode(node: R |
|
|
165
|
+
isRealNode(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE;
|
|
166
166
|
/**
|
|
167
167
|
* The function checks if a given node is a real node or null.
|
|
168
|
-
* @param {R |
|
|
169
|
-
* `
|
|
168
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
169
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
170
170
|
* @returns a boolean value.
|
|
171
171
|
*/
|
|
172
|
-
isNodeOrNull(node: R |
|
|
172
|
+
isNodeOrNull(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
|
|
173
173
|
/**
|
|
174
174
|
* The function checks if a given node is equal to the NIL value.
|
|
175
|
-
* @param {R |
|
|
176
|
-
* `
|
|
175
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
176
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
177
177
|
* @returns a boolean value.
|
|
178
178
|
*/
|
|
179
|
-
isNIL(node: R |
|
|
179
|
+
isNIL(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
180
180
|
/**
|
|
181
181
|
* The function checks if the input is an array with two elements, indicating it is a binary tree
|
|
182
182
|
* node entry.
|
|
183
|
-
* @param {R |
|
|
184
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
183
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
184
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
185
185
|
* @returns a boolean value.
|
|
186
186
|
*/
|
|
187
|
-
isEntry(keyOrNodeOrEntryOrRawElement: R |
|
|
187
|
+
isEntry(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>;
|
|
188
188
|
/**
|
|
189
189
|
* The function checks if a given value is a valid key by evaluating its type and value.
|
|
190
190
|
* @param {any} key - The `key` parameter can be of any type. It is the value that we want to check
|
|
@@ -206,17 +206,17 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
206
206
|
*
|
|
207
207
|
* The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
|
|
208
208
|
* and finding the appropriate insertion position.
|
|
209
|
-
* @param {R |
|
|
209
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
210
210
|
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
|
|
211
211
|
* node, entry, or raw element to be added to the tree. It can also accept a value of type
|
|
212
|
-
* `
|
|
212
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
213
213
|
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
214
214
|
* key being added to the tree. It represents the value that will be stored in the tree for the given
|
|
215
215
|
* key.
|
|
216
216
|
* @returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
217
217
|
* insertion position cannot be found or if there are duplicate keys.
|
|
218
218
|
*/
|
|
219
|
-
add(keyOrNodeOrEntryOrRawElement: R |
|
|
219
|
+
add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
220
220
|
/**
|
|
221
221
|
* Time Complexity: O(k * n)
|
|
222
222
|
* Space Complexity: O(1)
|
|
@@ -236,7 +236,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
236
236
|
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
237
237
|
* successfully added to the data structure.
|
|
238
238
|
*/
|
|
239
|
-
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
239
|
+
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
240
240
|
/**
|
|
241
241
|
* Time Complexity: O(k * n)
|
|
242
242
|
* Space Complexity: O(1)
|
|
@@ -248,21 +248,21 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
248
248
|
*
|
|
249
249
|
* The `refill` function clears the current data and adds new data to the collection.
|
|
250
250
|
* @param keysOrNodesOrEntriesOrRawElements - An iterable collection of keys, nodes, entries, or raw
|
|
251
|
-
* elements. These can be of any type (R) or a specific type (
|
|
251
|
+
* elements. These can be of any type (R) or a specific type (BTNKeyOrNodeOrEntry<K, V, NODE>).
|
|
252
252
|
* @param [values] - The `values` parameter is an optional iterable of values that will be associated
|
|
253
253
|
* with the keys or nodes being added. If provided, the values will be assigned to the corresponding
|
|
254
254
|
* keys or nodes. If not provided, the values will be set to `undefined`.
|
|
255
255
|
*/
|
|
256
|
-
refill(keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
256
|
+
refill(keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): void;
|
|
257
257
|
delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
258
|
-
delete<C extends BTNCallback<NODE, NODE>>(identifier: NODE
|
|
258
|
+
delete<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
259
259
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
260
|
-
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: R |
|
|
261
|
-
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: NODE
|
|
262
|
-
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: R |
|
|
263
|
-
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R |
|
|
264
|
-
getNode<C extends BTNCallback<NODE, NODE>>(identifier: NODE
|
|
265
|
-
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R |
|
|
260
|
+
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
261
|
+
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
262
|
+
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
263
|
+
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
264
|
+
getNode<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
265
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
266
266
|
/**
|
|
267
267
|
* Time Complexity: O(n)
|
|
268
268
|
* Space Complexity: O(log n)
|
|
@@ -279,13 +279,13 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
279
279
|
* It has a default value of `'ITERATIVE'`.
|
|
280
280
|
* @returns a value of type NODE, null, or undefined.
|
|
281
281
|
*/
|
|
282
|
-
getNodeByKey(key: K, iterationType?: IterationType): NODE
|
|
283
|
-
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R |
|
|
284
|
-
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE
|
|
285
|
-
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R |
|
|
286
|
-
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R |
|
|
287
|
-
has<C extends BTNCallback<NODE, NODE>>(identifier: NODE
|
|
288
|
-
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: R |
|
|
282
|
+
getNodeByKey(key: K, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
283
|
+
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
284
|
+
get<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
285
|
+
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
286
|
+
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
287
|
+
has<C extends BTNCallback<NODE, NODE>>(identifier: OptBTNOrNull<NODE>, callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
288
|
+
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
289
289
|
/**
|
|
290
290
|
* Time Complexity: O(1)
|
|
291
291
|
* Space Complexity: O(1)
|
|
@@ -319,13 +319,13 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
319
319
|
*
|
|
320
320
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
321
321
|
* height of the tree.
|
|
322
|
-
* @param {R |
|
|
322
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
|
|
323
323
|
* has a default value of `this.root`. It represents the starting point for checking if the tree is
|
|
324
324
|
* perfectly balanced. It can be either a root node (`R`), a key or node or entry
|
|
325
|
-
* (`
|
|
325
|
+
* (`BTNKeyOrNodeOrEntry<K, V, NODE
|
|
326
326
|
* @returns a boolean value.
|
|
327
327
|
*/
|
|
328
|
-
isPerfectlyBalanced(beginRoot?: R |
|
|
328
|
+
isPerfectlyBalanced(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
329
329
|
/**
|
|
330
330
|
* Time Complexity: O(n)
|
|
331
331
|
* Space Complexity: O(1)
|
|
@@ -335,7 +335,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
335
335
|
* Space Complexity: O(1)
|
|
336
336
|
*
|
|
337
337
|
* The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
|
|
338
|
-
* @param {R |
|
|
338
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
339
339
|
* starting point for checking if a binary search tree (BST) is valid. It can be either a root node
|
|
340
340
|
* of the BST, a key value of a node in the BST, or an entry object containing both the key and value
|
|
341
341
|
* of a node in the BST
|
|
@@ -344,7 +344,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
344
344
|
* two possible values:
|
|
345
345
|
* @returns a boolean value.
|
|
346
346
|
*/
|
|
347
|
-
isBST(beginRoot?: R |
|
|
347
|
+
isBST(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
348
348
|
/**
|
|
349
349
|
* Time Complexity: O(n)
|
|
350
350
|
* Space Complexity: O(1)
|
|
@@ -354,16 +354,16 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
354
354
|
* Space Complexity: O(1)
|
|
355
355
|
*
|
|
356
356
|
* The function calculates the depth of a given node or key in a tree-like data structure.
|
|
357
|
-
* @param {R |
|
|
358
|
-
* (representing a root node), or a `
|
|
357
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
|
|
358
|
+
* (representing a root node), or a `BTNKeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
|
|
359
359
|
* entry).
|
|
360
|
-
* @param {R |
|
|
360
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
|
|
361
361
|
* represents the starting point from which to calculate the depth. It can be either a reference to a
|
|
362
362
|
* node in the tree or a key-value pair or an entry object. If not provided, the default value is
|
|
363
363
|
* `this.root`, which refers to the root node
|
|
364
364
|
* @returns the depth of a node in a tree structure.
|
|
365
365
|
*/
|
|
366
|
-
getDepth(dist: R |
|
|
366
|
+
getDepth(dist: R | BTNKeyOrNodeOrEntry<K, V, NODE>, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): number;
|
|
367
367
|
/**
|
|
368
368
|
* Time Complexity: O(n)
|
|
369
369
|
* Space Complexity: O(1)
|
|
@@ -374,14 +374,14 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
374
374
|
*
|
|
375
375
|
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
376
376
|
* or iterative approach.
|
|
377
|
-
* @param {R |
|
|
377
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
378
378
|
* starting point for calculating the height of a tree. It can be either a root node (`R`), a key or
|
|
379
|
-
* node or entry (`
|
|
379
|
+
* node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
|
|
380
380
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
381
381
|
* iteration used to calculate the height of the tree. It can have two possible values:
|
|
382
382
|
* @returns the maximum height of the binary tree.
|
|
383
383
|
*/
|
|
384
|
-
getHeight(beginRoot?: R |
|
|
384
|
+
getHeight(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
385
385
|
/**
|
|
386
386
|
* Time Complexity: O(n)
|
|
387
387
|
* Space Complexity: O(log n)
|
|
@@ -392,9 +392,9 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
392
392
|
*
|
|
393
393
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
394
394
|
* recursive or iterative approach.
|
|
395
|
-
* @param {R |
|
|
395
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
396
396
|
* starting point for calculating the minimum height of a tree. It can be either a root node (`R`), a
|
|
397
|
-
* key or node or entry (`
|
|
397
|
+
* key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
|
|
398
398
|
* tree.
|
|
399
399
|
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
400
400
|
* iteration to be used when calculating the minimum height of the tree. It can have two possible
|
|
@@ -402,7 +402,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
402
402
|
* @returns The function `getMinHeight` returns a number, which represents the minimum height of the
|
|
403
403
|
* binary tree.
|
|
404
404
|
*/
|
|
405
|
-
getMinHeight(beginRoot?: R |
|
|
405
|
+
getMinHeight(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
406
406
|
/**
|
|
407
407
|
* Time Complexity: O(log n)
|
|
408
408
|
* Space Complexity: O(log n)
|
|
@@ -413,14 +413,14 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
413
413
|
*
|
|
414
414
|
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
415
415
|
* up to the root node, with an option to reverse the order of the nodes.
|
|
416
|
-
* @param {R |
|
|
417
|
-
* type `R` or `
|
|
416
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
|
|
417
|
+
* type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
418
418
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
419
419
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
420
420
|
* reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
|
|
421
421
|
* @returns The function `getPathToRoot` returns an array of `NODE` objects.
|
|
422
422
|
*/
|
|
423
|
-
getPathToRoot(beginNode: R |
|
|
423
|
+
getPathToRoot(beginNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
424
424
|
/**
|
|
425
425
|
* Time Complexity: O(log n)
|
|
426
426
|
* Space Complexity: O(1)
|
|
@@ -431,14 +431,14 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
431
431
|
*
|
|
432
432
|
* The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
|
|
433
433
|
* iterative traversal.
|
|
434
|
-
* @param {R |
|
|
434
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
435
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 (`
|
|
436
|
+
* a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
437
437
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
438
438
|
* of iteration to be performed. It can have two possible values:
|
|
439
439
|
* @returns The function `getLeftMost` returns the leftmost node in a binary tree.
|
|
440
440
|
*/
|
|
441
|
-
getLeftMost(beginRoot?: R |
|
|
441
|
+
getLeftMost(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
442
442
|
/**
|
|
443
443
|
* Time Complexity: O(log n)
|
|
444
444
|
* Space Complexity: O(1)
|
|
@@ -449,15 +449,15 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
449
449
|
*
|
|
450
450
|
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
|
|
451
451
|
* iteratively.
|
|
452
|
-
* @param {R |
|
|
452
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
453
453
|
* starting point for finding the rightmost node in a binary tree. It can be either a root node
|
|
454
|
-
* (`R`), a key or node or entry (`
|
|
454
|
+
* (`R`), a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
455
455
|
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
456
456
|
* of iteration to be performed when finding the rightmost node in a binary tree. It can have two
|
|
457
457
|
* possible values:
|
|
458
458
|
* @returns The function `getRightMost` returns a NODE object, `null`, or `undefined`.
|
|
459
459
|
*/
|
|
460
|
-
getRightMost(beginRoot?: R |
|
|
460
|
+
getRightMost(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): OptBTNOrNull<NODE>;
|
|
461
461
|
/**
|
|
462
462
|
* Time Complexity: O(log n)
|
|
463
463
|
* Space Complexity: O(1)
|
|
@@ -485,13 +485,13 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
485
485
|
* @returns The function `getSuccessor` returns a `NODE` object if a successor exists, `null` if
|
|
486
486
|
* there is no successor, and `undefined` if the input `x` is not a valid node.
|
|
487
487
|
*/
|
|
488
|
-
getSuccessor(x?: K | NODE | null): NODE
|
|
489
|
-
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R |
|
|
490
|
-
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R |
|
|
491
|
-
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R |
|
|
492
|
-
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R |
|
|
493
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R |
|
|
494
|
-
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R |
|
|
488
|
+
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, includeNull?: false): ReturnType<C>[];
|
|
490
|
+
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
491
|
+
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
492
|
+
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
495
|
/**
|
|
496
496
|
* Time complexity: O(n)
|
|
497
497
|
* Space complexity: O(n)
|
|
@@ -509,13 +509,13 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
509
509
|
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
|
|
510
510
|
* to specify the order in which the nodes of a binary tree are traversed. It can take one of the
|
|
511
511
|
* following values:
|
|
512
|
-
* @param {R |
|
|
512
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
513
513
|
* point for the traversal. It can be either a node object, a key, or an entry object. If no value is
|
|
514
514
|
* provided, the `root` of the tree is used as the starting point.
|
|
515
515
|
* @returns The function `morris` returns an array of values that are the return values of the
|
|
516
516
|
* callback function `callback`.
|
|
517
517
|
*/
|
|
518
|
-
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R |
|
|
518
|
+
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
|
|
519
519
|
/**
|
|
520
520
|
* Time complexity: O(n)
|
|
521
521
|
* Space complexity: O(n)
|
|
@@ -577,7 +577,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
577
577
|
* Space Complexity: O(n)
|
|
578
578
|
*
|
|
579
579
|
* The `print` function in TypeScript prints the binary tree structure with customizable options.
|
|
580
|
-
* @param {R |
|
|
580
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
581
581
|
* point for printing the binary tree. It can be either a node of the binary tree or a key or entry
|
|
582
582
|
* that exists in the binary tree. If no value is provided, the root of the binary tree will be used
|
|
583
583
|
* as the starting point.
|
|
@@ -586,7 +586,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
586
586
|
* @returns Nothing is being returned. The function has a return type of `void`, which means it does
|
|
587
587
|
* not return any value.
|
|
588
588
|
*/
|
|
589
|
-
print(beginRoot?: R |
|
|
589
|
+
print(beginRoot?: R | BTNKeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): void;
|
|
590
590
|
/**
|
|
591
591
|
* Time Complexity: O(1)
|
|
592
592
|
* Space Complexity: O(1)
|
|
@@ -601,7 +601,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
601
601
|
* initially set to the root node of the tree.
|
|
602
602
|
* @returns an IterableIterator<[K, V | undefined]>.
|
|
603
603
|
*/
|
|
604
|
-
protected _getIterator(node?: NODE
|
|
604
|
+
protected _getIterator(node?: OptBTNOrNull<NODE>): IterableIterator<[K, V | undefined]>;
|
|
605
605
|
/**
|
|
606
606
|
* Time Complexity: O(n)
|
|
607
607
|
* Space Complexity: O(n)
|
|
@@ -612,7 +612,7 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
612
612
|
*
|
|
613
613
|
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
|
|
614
614
|
* taking into account various options such as whether to show null, undefined, or NaN nodes.
|
|
615
|
-
* @param {NODE
|
|
615
|
+
* @param {OptBTNOrNull<NODE>} node - The `node` parameter represents a node in a binary tree.
|
|
616
616
|
* It can be of type `NODE`, `null`, or `undefined`.
|
|
617
617
|
* @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
|
|
618
618
|
* following properties:
|
|
@@ -623,8 +623,8 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
623
623
|
* 3. `totalHeight`: The total height of the node display.
|
|
624
624
|
* 4. `middleIndex`: The index of the middle character
|
|
625
625
|
*/
|
|
626
|
-
protected _displayAux(node: NODE
|
|
627
|
-
protected _DEFAULT_CALLBACK: (node: NODE
|
|
626
|
+
protected _displayAux(node: OptBTNOrNull<NODE>, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
627
|
+
protected _DEFAULT_CALLBACK: (node: OptBTNOrNull<NODE>) => K | undefined;
|
|
628
628
|
/**
|
|
629
629
|
* Time Complexity: O(1)
|
|
630
630
|
* Space Complexity: O(1)
|
|
@@ -634,15 +634,15 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
634
634
|
* Space Complexity: O(1)
|
|
635
635
|
*
|
|
636
636
|
* The function `_swapProperties` swaps the key-value properties between two nodes.
|
|
637
|
-
* @param {R |
|
|
637
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
|
|
638
638
|
* destination node. It can be either an instance of the class `R`, or an object of type
|
|
639
|
-
* `
|
|
640
|
-
* @param {R |
|
|
639
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
640
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
|
|
641
641
|
* the properties will be swapped with the `srcNode`.
|
|
642
642
|
* @returns either the `destNode` object with its properties swapped with the `srcNode` object's
|
|
643
643
|
* properties, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
644
644
|
*/
|
|
645
|
-
protected _swapProperties(srcNode: R |
|
|
645
|
+
protected _swapProperties(srcNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>, destNode: R | BTNKeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
|
|
646
646
|
/**
|
|
647
647
|
* Time Complexity: O(1)
|
|
648
648
|
* Space Complexity: O(1)
|
|
@@ -670,10 +670,10 @@ export declare class BinaryTree<K = any, V = any, R = BTNEntry<K, V>, NODE exten
|
|
|
670
670
|
*
|
|
671
671
|
* The function sets the root property of an object to the provided value, and also updates the
|
|
672
672
|
* parent property of the new root.
|
|
673
|
-
* @param {NODE
|
|
673
|
+
* @param {OptBTNOrNull<NODE>} v - The parameter `v` is of type `OptBTNOrNull<NODE>`. This
|
|
674
674
|
* means that it can accept a value of type `NODE`, `null`, or `undefined`.
|
|
675
675
|
*/
|
|
676
|
-
protected _setRoot(v: NODE
|
|
676
|
+
protected _setRoot(v: OptBTNOrNull<NODE>): void;
|
|
677
677
|
/**
|
|
678
678
|
* Time Complexity: O(1)
|
|
679
679
|
* Space Complexity: O(1)
|