heap-typed 1.51.7 → 1.51.9
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/README.md +72 -80
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +103 -74
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +116 -93
- package/dist/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/data-structures/binary-tree/avl-tree.js +90 -71
- package/dist/data-structures/binary-tree/binary-tree.d.ts +318 -233
- package/dist/data-structures/binary-tree/binary-tree.js +492 -392
- package/dist/data-structures/binary-tree/bst.d.ts +204 -251
- package/dist/data-structures/binary-tree/bst.js +256 -358
- package/dist/data-structures/binary-tree/rb-tree.d.ts +74 -85
- package/dist/data-structures/binary-tree/rb-tree.js +111 -119
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +92 -76
- package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/data-structures/graph/abstract-graph.js +10 -15
- package/dist/data-structures/hash/hash-map.d.ts +31 -38
- package/dist/data-structures/hash/hash-map.js +40 -55
- package/dist/data-structures/heap/heap.d.ts +1 -3
- package/dist/data-structures/queue/deque.d.ts +2 -3
- package/dist/data-structures/queue/deque.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +1 -1
- package/dist/data-structures/trie/trie.js +1 -1
- package/dist/interfaces/binary-tree.d.ts +7 -7
- package/dist/types/common.d.ts +2 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -5
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +10 -1
- package/dist/utils/utils.d.ts +2 -1
- package/dist/utils/utils.js +27 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -100
- package/src/data-structures/binary-tree/avl-tree.ts +109 -80
- package/src/data-structures/binary-tree/binary-tree.ts +556 -433
- package/src/data-structures/binary-tree/bst.ts +286 -375
- package/src/data-structures/binary-tree/rb-tree.ts +132 -125
- package/src/data-structures/binary-tree/tree-multi-map.ts +129 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +42 -49
- package/src/data-structures/heap/heap.ts +1 -1
- package/src/data-structures/queue/deque.ts +2 -2
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/trie/trie.ts +2 -2
- package/src/interfaces/binary-tree.ts +11 -9
- package/src/types/common.ts +2 -3
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +4 -3
- package/src/types/data-structures/binary-tree/avl-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +7 -6
- package/src/types/data-structures/binary-tree/bst.ts +6 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +4 -3
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -3
- package/src/types/utils/utils.ts +14 -1
- package/src/utils/utils.ts +20 -1
|
@@ -5,8 +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, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
|
|
9
|
-
import { FamilyPosition, IterationType } from '../../types';
|
|
8
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BinaryTreePrintOptions, BTNCallback, BTNEntry, Comparable, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, KeyOrNodeOrEntry, NodeDisplayLayout } from '../../types';
|
|
10
9
|
import { IBinaryTree } from '../../interfaces';
|
|
11
10
|
import { IterableEntryBase } from '../base';
|
|
12
11
|
/**
|
|
@@ -14,7 +13,7 @@ import { IterableEntryBase } from '../base';
|
|
|
14
13
|
* @template V - The type of data stored in the node.
|
|
15
14
|
* @template NODE - The type of the family relationship in the binary tree.
|
|
16
15
|
*/
|
|
17
|
-
export declare class BinaryTreeNode<K
|
|
16
|
+
export declare class BinaryTreeNode<K extends Comparable, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>> {
|
|
18
17
|
key: K;
|
|
19
18
|
value?: V;
|
|
20
19
|
parent?: NODE;
|
|
@@ -66,24 +65,18 @@ export declare class BinaryTreeNode<K = any, V = any, NODE extends BinaryTreeNod
|
|
|
66
65
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
67
66
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
68
67
|
*/
|
|
69
|
-
export declare class BinaryTree<K
|
|
68
|
+
export declare class BinaryTree<K extends Comparable, V = any, R = BTNEntry<K, V>, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTree<K, V, R, NODE, BinaryTreeNested<K, V, R, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
70
69
|
iterationType: IterationType;
|
|
71
70
|
/**
|
|
72
|
-
* The constructor function initializes a binary tree object with optional
|
|
73
|
-
* @param [
|
|
71
|
+
* The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
|
|
72
|
+
* @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
|
|
74
73
|
* nodes to be added to the binary tree.
|
|
75
74
|
* @param [options] - The `options` parameter is an optional object that can contain additional
|
|
76
75
|
* configuration options for the binary tree. In this case, it is of type
|
|
77
76
|
* `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
|
|
78
77
|
* required.
|
|
79
78
|
*/
|
|
80
|
-
constructor(
|
|
81
|
-
protected _extractor: (key: K) => number;
|
|
82
|
-
/**
|
|
83
|
-
* The function returns the value of the `_extractor` property.
|
|
84
|
-
* @returns The `_extractor` property is being returned.
|
|
85
|
-
*/
|
|
86
|
-
get extractor(): (key: K) => number;
|
|
79
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions<K, V, R>);
|
|
87
80
|
protected _root?: NODE | null;
|
|
88
81
|
/**
|
|
89
82
|
* The function returns the root node, which can be of type NODE, null, or undefined.
|
|
@@ -103,6 +96,12 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
103
96
|
* @returns The method is returning the value of the `_NIL` property.
|
|
104
97
|
*/
|
|
105
98
|
get NIL(): NODE;
|
|
99
|
+
protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
100
|
+
/**
|
|
101
|
+
* The function returns the value of the _toEntryFn property.
|
|
102
|
+
* @returns The function being returned is `this._toEntryFn`.
|
|
103
|
+
*/
|
|
104
|
+
get toEntryFn(): ((rawElement: R) => BTNEntry<K, V>) | undefined;
|
|
106
105
|
/**
|
|
107
106
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
108
107
|
* @param {K} key - The key for the new node.
|
|
@@ -117,16 +116,19 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
117
116
|
* you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
|
|
118
117
|
* @returns a new instance of a binary tree.
|
|
119
118
|
*/
|
|
120
|
-
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
119
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
121
120
|
/**
|
|
122
|
-
* The function `
|
|
123
|
-
*
|
|
121
|
+
* The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
|
|
122
|
+
* into a node object.
|
|
123
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
124
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
124
125
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
125
|
-
* `
|
|
126
|
-
*
|
|
127
|
-
* @returns
|
|
126
|
+
* `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
|
|
127
|
+
* key-value pair. If provided, it will be used to create a node with the specified key and value.
|
|
128
|
+
* @returns The function `keyValueOrEntryOrRawElementToNode` returns either a `NODE` object, `null`,
|
|
129
|
+
* or `undefined`.
|
|
128
130
|
*/
|
|
129
|
-
|
|
131
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | null | undefined;
|
|
130
132
|
/**
|
|
131
133
|
* Time Complexity: O(n)
|
|
132
134
|
* Space Complexity: O(log n)
|
|
@@ -135,49 +137,65 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
135
137
|
* Time Complexity: O(n)
|
|
136
138
|
* Space Complexity: O(log n)
|
|
137
139
|
*
|
|
138
|
-
* The
|
|
139
|
-
*
|
|
140
|
-
* @param {
|
|
141
|
-
* `
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*/
|
|
148
|
-
ensureNode(
|
|
149
|
-
/**
|
|
150
|
-
* The function checks if
|
|
151
|
-
* @param {
|
|
140
|
+
* The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
|
|
141
|
+
* node if it is a key or entry.
|
|
142
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
143
|
+
* `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `KeyOrNodeOrEntry<K, V, NODE>`, or
|
|
144
|
+
* a raw element.
|
|
145
|
+
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
146
|
+
* parameter that specifies the type of iteration to be used when searching for a node. It has a
|
|
147
|
+
* default value of `'ITERATIVE'`.
|
|
148
|
+
* @returns The function `ensureNode` returns either a `NODE` object, `null`, or `undefined`.
|
|
149
|
+
*/
|
|
150
|
+
ensureNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* The function checks if the input is an instance of the BinaryTreeNode class.
|
|
153
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
154
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
155
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
156
|
+
* an instance of the `BinaryTreeNode` class.
|
|
157
|
+
*/
|
|
158
|
+
isNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is NODE;
|
|
159
|
+
/**
|
|
160
|
+
* The function checks if a given node is a valid node in a binary search tree.
|
|
161
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
162
|
+
* `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
152
163
|
* @returns a boolean value.
|
|
153
164
|
*/
|
|
154
|
-
|
|
165
|
+
isRealNode(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE;
|
|
155
166
|
/**
|
|
156
|
-
* The function
|
|
157
|
-
* @param
|
|
158
|
-
*
|
|
167
|
+
* The function checks if a given node is a real node or null.
|
|
168
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
169
|
+
* `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
170
|
+
* @returns a boolean value.
|
|
159
171
|
*/
|
|
160
|
-
|
|
172
|
+
isNodeOrNull(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
|
|
161
173
|
/**
|
|
162
|
-
* The function checks if a given node is
|
|
163
|
-
*
|
|
164
|
-
*
|
|
174
|
+
* The function checks if a given node is equal to the NIL value.
|
|
175
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
|
|
176
|
+
* `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
165
177
|
* @returns a boolean value.
|
|
166
178
|
*/
|
|
167
|
-
|
|
179
|
+
isNIL(node: R | KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
168
180
|
/**
|
|
169
|
-
* The function checks if
|
|
170
|
-
*
|
|
181
|
+
* The function checks if the input is an array with two elements, indicating it is a binary tree
|
|
182
|
+
* node entry.
|
|
183
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
184
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
171
185
|
* @returns a boolean value.
|
|
172
186
|
*/
|
|
173
|
-
|
|
187
|
+
isEntry(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>;
|
|
174
188
|
/**
|
|
175
|
-
* The function checks if a given value is
|
|
176
|
-
* @param
|
|
177
|
-
*
|
|
189
|
+
* The function checks if a given value is a valid key by evaluating its type and value.
|
|
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().
|
|
178
196
|
* @returns a boolean value.
|
|
179
197
|
*/
|
|
180
|
-
|
|
198
|
+
isKey(key: any, isCheckValueOf?: boolean): key is K;
|
|
181
199
|
/**
|
|
182
200
|
* Time Complexity O(n)
|
|
183
201
|
* Space Complexity O(1)
|
|
@@ -186,13 +204,19 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
186
204
|
* Time Complexity O(n)
|
|
187
205
|
* Space Complexity O(1)
|
|
188
206
|
*
|
|
189
|
-
* The `add` function
|
|
190
|
-
*
|
|
191
|
-
* @param
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
* The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
|
|
208
|
+
* and finding the appropriate insertion position.
|
|
209
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
|
|
210
|
+
* `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
|
|
211
|
+
* node, entry, or raw element to be added to the tree. It can also accept a value of type
|
|
212
|
+
* `KeyOrNodeOrEntry<K, V, NODE>
|
|
213
|
+
* @param {V} [value] - The `value` parameter is an optional value that can be associated with the
|
|
214
|
+
* key being added to the tree. It represents the value that will be stored in the tree for the given
|
|
215
|
+
* key.
|
|
216
|
+
* @returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
|
|
217
|
+
* insertion position cannot be found or if there are duplicate keys.
|
|
218
|
+
*/
|
|
219
|
+
add(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
|
|
196
220
|
/**
|
|
197
221
|
* Time Complexity: O(k * n)
|
|
198
222
|
* Space Complexity: O(1)
|
|
@@ -202,13 +226,17 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
202
226
|
* Time Complexity: O(k * n)
|
|
203
227
|
* Space Complexity: O(1)
|
|
204
228
|
*
|
|
205
|
-
* The `addMany` function takes in
|
|
206
|
-
* adds each node with its corresponding value to
|
|
207
|
-
*
|
|
208
|
-
* @param
|
|
209
|
-
*
|
|
210
|
-
|
|
211
|
-
|
|
229
|
+
* The `addMany` function takes in an iterable of keys or nodes or entries or raw elements, and an
|
|
230
|
+
* optional iterable of values, and adds each key or node or entry with its corresponding value to a
|
|
231
|
+
* data structure, returning an array of booleans indicating whether each insertion was successful.
|
|
232
|
+
* @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
|
|
233
|
+
* elements. These elements will be added to the data structure.
|
|
234
|
+
* @param [values] - An optional iterable of values that correspond to the keys or nodes or entries
|
|
235
|
+
* in the `keysOrNodesOrEntriesOrRawElements` parameter.
|
|
236
|
+
* @returns The function `addMany` returns an array of booleans indicating whether each element was
|
|
237
|
+
* successfully added to the data structure.
|
|
238
|
+
*/
|
|
239
|
+
addMany(keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
212
240
|
/**
|
|
213
241
|
* Time Complexity: O(k * n)
|
|
214
242
|
* Space Complexity: O(1)
|
|
@@ -218,24 +246,23 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
218
246
|
* Time Complexity: O(k * n)
|
|
219
247
|
* Space Complexity: O(1)
|
|
220
248
|
*
|
|
221
|
-
* The `refill` function clears the current data and adds new
|
|
222
|
-
* @param
|
|
223
|
-
* KeyOrNodeOrEntry<K, V, NODE
|
|
224
|
-
* @param [values] - The `values` parameter is an optional iterable
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
refill(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): void;
|
|
249
|
+
* The `refill` function clears the current data and adds new data to the collection.
|
|
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 (KeyOrNodeOrEntry<K, V, NODE>).
|
|
252
|
+
* @param [values] - The `values` parameter is an optional iterable of values that will be associated
|
|
253
|
+
* with the keys or nodes being added. If provided, the values will be assigned to the corresponding
|
|
254
|
+
* keys or nodes. If not provided, the values will be set to `undefined`.
|
|
255
|
+
*/
|
|
256
|
+
refill(keysOrNodesOrEntriesOrRawElements: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): void;
|
|
230
257
|
delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
231
258
|
delete<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
232
259
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
233
|
-
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
234
|
-
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
235
|
-
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
236
|
-
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
237
|
-
getNode<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
238
|
-
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
260
|
+
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
261
|
+
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
262
|
+
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
263
|
+
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
264
|
+
getNode<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
265
|
+
getNode<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
239
266
|
/**
|
|
240
267
|
* Time Complexity: O(n)
|
|
241
268
|
* Space Complexity: O(log n)
|
|
@@ -244,23 +271,21 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
244
271
|
* Time Complexity: O(n)
|
|
245
272
|
* Space Complexity: O(log n)
|
|
246
273
|
*
|
|
247
|
-
* The function `getNodeByKey`
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
255
|
-
* found in the binary tree. If no node is found, it returns `undefined`.
|
|
274
|
+
* The function `getNodeByKey` returns a node with a specific key value from a tree structure.
|
|
275
|
+
* @param {K} key - The key parameter is the value that you want to search for in the tree. It is
|
|
276
|
+
* used to find the node with the matching key value.
|
|
277
|
+
* @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
|
|
278
|
+
* parameter that specifies the type of iteration to be used when searching for a node in the tree.
|
|
279
|
+
* It has a default value of `'ITERATIVE'`.
|
|
280
|
+
* @returns a value of type NODE, null, or undefined.
|
|
256
281
|
*/
|
|
257
282
|
getNodeByKey(key: K, iterationType?: IterationType): NODE | null | undefined;
|
|
258
|
-
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
259
|
-
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
260
|
-
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
261
|
-
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
262
|
-
has<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
263
|
-
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
283
|
+
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
284
|
+
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
285
|
+
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
286
|
+
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
287
|
+
has<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
288
|
+
has<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
264
289
|
/**
|
|
265
290
|
* Time Complexity: O(1)
|
|
266
291
|
* Space Complexity: O(1)
|
|
@@ -294,12 +319,13 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
294
319
|
*
|
|
295
320
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
296
321
|
* height of the tree.
|
|
297
|
-
* @param {
|
|
298
|
-
*
|
|
299
|
-
*
|
|
322
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
|
|
323
|
+
* has a default value of `this.root`. It represents the starting point for checking if the tree is
|
|
324
|
+
* perfectly balanced. It can be either a root node (`R`), a key or node or entry
|
|
325
|
+
* (`KeyOrNodeOrEntry<K, V, NODE
|
|
300
326
|
* @returns a boolean value.
|
|
301
327
|
*/
|
|
302
|
-
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
328
|
+
isPerfectlyBalanced(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
303
329
|
/**
|
|
304
330
|
* Time Complexity: O(n)
|
|
305
331
|
* Space Complexity: O(1)
|
|
@@ -308,15 +334,17 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
308
334
|
* Time Complexity: O(n)
|
|
309
335
|
* Space Complexity: O(1)
|
|
310
336
|
*
|
|
311
|
-
* The function `
|
|
312
|
-
* @param {
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
337
|
+
* The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
|
|
338
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
339
|
+
* starting point for checking if a binary search tree (BST) is valid. It can be either a root node
|
|
340
|
+
* of the BST, a key value of a node in the BST, or an entry object containing both the key and value
|
|
341
|
+
* of a node in the BST
|
|
342
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is used to determine the type
|
|
343
|
+
* of iteration to be performed while checking if the binary search tree (BST) is valid. It can have
|
|
344
|
+
* two possible values:
|
|
317
345
|
* @returns a boolean value.
|
|
318
346
|
*/
|
|
319
|
-
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
347
|
+
isBST(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
320
348
|
/**
|
|
321
349
|
* Time Complexity: O(n)
|
|
322
350
|
* Space Complexity: O(1)
|
|
@@ -325,35 +353,35 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
325
353
|
* Time Complexity: O(n)
|
|
326
354
|
* Space Complexity: O(1)
|
|
327
355
|
*
|
|
328
|
-
* The function calculates the depth of a given node in a
|
|
329
|
-
* @param {
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* @param {
|
|
333
|
-
* from which
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
|
|
337
|
-
|
|
356
|
+
* The function calculates the depth of a given node or key in a tree-like data structure.
|
|
357
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
|
|
358
|
+
* (representing a root node), or a `KeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
|
|
359
|
+
* entry).
|
|
360
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
|
|
361
|
+
* represents the starting point from which to calculate the depth. It can be either a reference to a
|
|
362
|
+
* node in the tree or a key-value pair or an entry object. If not provided, the default value is
|
|
363
|
+
* `this.root`, which refers to the root node
|
|
364
|
+
* @returns the depth of a node in a tree structure.
|
|
365
|
+
*/
|
|
366
|
+
getDepth(dist: R | KeyOrNodeOrEntry<K, V, NODE>, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>): number;
|
|
338
367
|
/**
|
|
339
368
|
* Time Complexity: O(n)
|
|
340
369
|
* Space Complexity: O(1)
|
|
341
370
|
*/
|
|
342
371
|
/**
|
|
343
372
|
* Time Complexity: O(n)
|
|
344
|
-
* Space Complexity: O(
|
|
373
|
+
* Space Complexity: O(1)
|
|
345
374
|
*
|
|
346
|
-
* The
|
|
347
|
-
* iterative
|
|
348
|
-
* @param {
|
|
349
|
-
* starting
|
|
350
|
-
*
|
|
351
|
-
* @param iterationType - The `iterationType` parameter
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
* @returns the height of the binary tree.
|
|
375
|
+
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive
|
|
376
|
+
* or iterative approach.
|
|
377
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
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 (`KeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
|
|
380
|
+
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
381
|
+
* iteration used to calculate the height of the tree. It can have two possible values:
|
|
382
|
+
* @returns the maximum height of the binary tree.
|
|
355
383
|
*/
|
|
356
|
-
getHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
384
|
+
getHeight(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
357
385
|
/**
|
|
358
386
|
* Time Complexity: O(n)
|
|
359
387
|
* Space Complexity: O(log n)
|
|
@@ -364,34 +392,35 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
364
392
|
*
|
|
365
393
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
366
394
|
* recursive or iterative approach.
|
|
367
|
-
* @param {
|
|
368
|
-
* starting
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
395
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
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 (`KeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
|
|
398
|
+
* tree.
|
|
399
|
+
* @param {IterationType} iterationType - The `iterationType` parameter determines the type of
|
|
400
|
+
* iteration to be used when calculating the minimum height of the tree. It can have two possible
|
|
401
|
+
* values:
|
|
402
|
+
* @returns The function `getMinHeight` returns a number, which represents the minimum height of the
|
|
403
|
+
* binary tree.
|
|
373
404
|
*/
|
|
374
|
-
getMinHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
405
|
+
getMinHeight(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
375
406
|
/**
|
|
376
407
|
* Time Complexity: O(log n)
|
|
377
408
|
* Space Complexity: O(log n)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
/**
|
|
409
|
+
*/
|
|
410
|
+
/**
|
|
381
411
|
* Time Complexity: O(log n)
|
|
382
412
|
* Space Complexity: O(log n)
|
|
383
413
|
*
|
|
384
|
-
* The function `getPathToRoot` returns an array of nodes from a given node
|
|
385
|
-
*
|
|
386
|
-
* @param {
|
|
387
|
-
*
|
|
388
|
-
* `null`, or `undefined`.
|
|
414
|
+
* The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
|
|
415
|
+
* up to the root node, with an option to reverse the order of the nodes.
|
|
416
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
|
|
417
|
+
* type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
389
418
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
390
419
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
391
|
-
* reversed before returning it. If `isReverse` is set to `false
|
|
392
|
-
* @returns The function `getPathToRoot` returns an array of
|
|
420
|
+
* reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
|
|
421
|
+
* @returns The function `getPathToRoot` returns an array of `NODE` objects.
|
|
393
422
|
*/
|
|
394
|
-
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
423
|
+
getPathToRoot(beginNode: R | KeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
395
424
|
/**
|
|
396
425
|
* Time Complexity: O(log n)
|
|
397
426
|
* Space Complexity: O(1)
|
|
@@ -400,17 +429,16 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
400
429
|
* Time Complexity: O(log n)
|
|
401
430
|
* Space Complexity: O(1)
|
|
402
431
|
*
|
|
403
|
-
* The
|
|
404
|
-
*
|
|
405
|
-
* @param {
|
|
406
|
-
* for finding the leftmost node in a binary tree. It can be either a `
|
|
407
|
-
*
|
|
408
|
-
* @param iterationType - The `iterationType` parameter is used to
|
|
409
|
-
*
|
|
410
|
-
* @returns The function `getLeftMost` returns the leftmost node
|
|
411
|
-
* is no leftmost node, it returns `null` or `undefined` depending on the input.
|
|
432
|
+
* The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
|
|
433
|
+
* iterative traversal.
|
|
434
|
+
* @param {R | KeyOrNodeOrEntry<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 (`KeyOrNodeOrEntry<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.
|
|
412
440
|
*/
|
|
413
|
-
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
441
|
+
getLeftMost(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
414
442
|
/**
|
|
415
443
|
* Time Complexity: O(log n)
|
|
416
444
|
* Space Complexity: O(1)
|
|
@@ -419,18 +447,17 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
419
447
|
* Time Complexity: O(log n)
|
|
420
448
|
* Space Complexity: O(1)
|
|
421
449
|
*
|
|
422
|
-
* The
|
|
450
|
+
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
|
|
423
451
|
* iteratively.
|
|
424
|
-
* @param {
|
|
425
|
-
* starting
|
|
426
|
-
* `
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* @returns The function `getRightMost` returns
|
|
431
|
-
* is no rightmost node, it returns `null` or `undefined`, depending on the input.
|
|
452
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
|
|
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 (`KeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
|
|
455
|
+
* @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
|
|
456
|
+
* of iteration to be performed when finding the rightmost node in a binary tree. It can have two
|
|
457
|
+
* possible values:
|
|
458
|
+
* @returns The function `getRightMost` returns a NODE object, `null`, or `undefined`.
|
|
432
459
|
*/
|
|
433
|
-
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
460
|
+
getRightMost(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
434
461
|
/**
|
|
435
462
|
* Time Complexity: O(log n)
|
|
436
463
|
* Space Complexity: O(1)
|
|
@@ -439,10 +466,10 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
439
466
|
* Time Complexity: O(log n)
|
|
440
467
|
* Space Complexity: O(1)
|
|
441
468
|
*
|
|
442
|
-
* The function returns the predecessor of a given node in a tree.
|
|
443
|
-
* @param {NODE} node - The parameter
|
|
469
|
+
* The function returns the predecessor node of a given node in a binary tree.
|
|
470
|
+
* @param {NODE} node - The parameter "node" is of type "NODE", which represents a node in a binary
|
|
444
471
|
* tree.
|
|
445
|
-
* @returns the predecessor of the given
|
|
472
|
+
* @returns the predecessor node of the given node.
|
|
446
473
|
*/
|
|
447
474
|
getPredecessor(node: NODE): NODE;
|
|
448
475
|
/**
|
|
@@ -455,16 +482,16 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
455
482
|
*
|
|
456
483
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
457
484
|
* @param {K | NODE | null} [x] - The parameter `x` can be of type `K`, `NODE`, or `null`.
|
|
458
|
-
* @returns
|
|
459
|
-
*
|
|
485
|
+
* @returns The function `getSuccessor` returns a `NODE` object if a successor exists, `null` if
|
|
486
|
+
* there is no successor, and `undefined` if the input `x` is not a valid node.
|
|
460
487
|
*/
|
|
461
488
|
getSuccessor(x?: K | NODE | null): NODE | null | undefined;
|
|
462
|
-
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
463
|
-
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
464
|
-
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
465
|
-
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
466
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
467
|
-
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
489
|
+
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
490
|
+
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
491
|
+
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
492
|
+
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
493
|
+
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
494
|
+
listLevels<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[][];
|
|
468
495
|
/**
|
|
469
496
|
* Time complexity: O(n)
|
|
470
497
|
* Space complexity: O(n)
|
|
@@ -476,19 +503,19 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
476
503
|
* The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
|
|
477
504
|
* algorithm.
|
|
478
505
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
479
|
-
* the tree. It takes a single
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
506
|
+
* the tree. It takes a single argument, which is the current node, and can return any value. The
|
|
507
|
+
* return type of the `callback` function is determined by the `ReturnType<C>` type, which represents
|
|
508
|
+
* the return
|
|
509
|
+
* @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
|
|
510
|
+
* to specify the order in which the nodes of a binary tree are traversed. It can take one of the
|
|
483
511
|
* following values:
|
|
484
|
-
* @param {
|
|
485
|
-
* for the traversal. It can be
|
|
486
|
-
* the root of the tree
|
|
487
|
-
* @returns The function `morris` returns an array of values that are the
|
|
488
|
-
*
|
|
489
|
-
* by the return type of the `callback` function.
|
|
512
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
513
|
+
* point for the traversal. It can be either a node object, a key, or an entry object. If no value is
|
|
514
|
+
* provided, the `root` of the tree is used as the starting point.
|
|
515
|
+
* @returns The function `morris` returns an array of values that are the return values of the
|
|
516
|
+
* callback function `callback`.
|
|
490
517
|
*/
|
|
491
|
-
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
|
|
518
|
+
morris<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>): ReturnType<C>[];
|
|
492
519
|
/**
|
|
493
520
|
* Time complexity: O(n)
|
|
494
521
|
* Space complexity: O(n)
|
|
@@ -497,8 +524,7 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
497
524
|
* Time complexity: O(n)
|
|
498
525
|
* Space complexity: O(n)
|
|
499
526
|
*
|
|
500
|
-
* The `clone` function creates a
|
|
501
|
-
* the new tree.
|
|
527
|
+
* The `clone` function creates a deep copy of a tree object.
|
|
502
528
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
503
529
|
*/
|
|
504
530
|
clone(): TREE;
|
|
@@ -510,16 +536,16 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
510
536
|
* Time Complexity: O(n)
|
|
511
537
|
* Space Complexity: O(n)
|
|
512
538
|
*
|
|
513
|
-
* The `filter` function creates a new tree
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* @returns The `filter` method is returning a new tree object that contains the
|
|
522
|
-
*
|
|
539
|
+
* The `filter` function creates a new tree with entries that pass a given predicate function.
|
|
540
|
+
* @param predicate - The `predicate` parameter is a callback function that is used to test each
|
|
541
|
+
* element in the tree. It takes three arguments: `value`, `key`, and `index`. The `value` argument
|
|
542
|
+
* represents the value of the current element being processed, the `key` argument represents the key
|
|
543
|
+
* of the
|
|
544
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
545
|
+
* specify the value of `this` within the `predicate` function. When the `predicate` function is
|
|
546
|
+
* called, `thisArg` will be used as the value of `this` within the function. If `thisArg`
|
|
547
|
+
* @returns The `filter` method is returning a new tree object that contains the entries that pass
|
|
548
|
+
* the given predicate function.
|
|
523
549
|
*/
|
|
524
550
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
|
|
525
551
|
/**
|
|
@@ -530,15 +556,15 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
530
556
|
* Time Complexity: O(n)
|
|
531
557
|
* Space Complexity: O(n)
|
|
532
558
|
*
|
|
533
|
-
* The `map` function creates a new tree by applying a callback function to each
|
|
534
|
-
*
|
|
535
|
-
* @param callback - The callback parameter is a function that will be called for each
|
|
536
|
-
*
|
|
537
|
-
* the
|
|
538
|
-
*
|
|
539
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that
|
|
540
|
-
*
|
|
541
|
-
*
|
|
559
|
+
* The `map` function creates a new tree by applying a callback function to each entry in the current
|
|
560
|
+
* tree.
|
|
561
|
+
* @param callback - The callback parameter is a function that will be called for each entry in the
|
|
562
|
+
* tree. It takes three arguments: value, key, and index. The value argument represents the value of
|
|
563
|
+
* the current entry, the key argument represents the key of the current entry, and the index
|
|
564
|
+
* argument represents the index of the
|
|
565
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
566
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
567
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
542
568
|
* @returns The `map` method is returning a new tree object.
|
|
543
569
|
*/
|
|
544
570
|
map(callback: EntryCallback<K, V | undefined, V>, thisArg?: any): TREE;
|
|
@@ -550,24 +576,40 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
550
576
|
* Time Complexity: O(n)
|
|
551
577
|
* Space Complexity: O(n)
|
|
552
578
|
*
|
|
553
|
-
* The `print` function
|
|
554
|
-
* @param {
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
*
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
|
|
579
|
+
* The `print` function in TypeScript prints the binary tree structure with customizable options.
|
|
580
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
|
|
581
|
+
* point for printing the binary tree. It can be either a node of the binary tree or a key or entry
|
|
582
|
+
* that exists in the binary tree. If no value is provided, the root of the binary tree will be used
|
|
583
|
+
* as the starting point.
|
|
584
|
+
* @param {BinaryTreePrintOptions} [options] - The `options` parameter is an optional object that
|
|
585
|
+
* allows you to customize the printing behavior. It has the following properties:
|
|
586
|
+
* @returns Nothing is being returned. The function has a return type of `void`, which means it does
|
|
587
|
+
* not return any value.
|
|
588
|
+
*/
|
|
589
|
+
print(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): void;
|
|
590
|
+
/**
|
|
591
|
+
* Time Complexity: O(1)
|
|
592
|
+
* Space Complexity: O(1)
|
|
593
|
+
*/
|
|
594
|
+
/**
|
|
595
|
+
* Time Complexity: O(1)
|
|
596
|
+
* Space Complexity: O(1)
|
|
597
|
+
*
|
|
598
|
+
* The function `_getIterator` is a generator function that returns an iterator for the key-value
|
|
599
|
+
* pairs in a binary search tree.
|
|
600
|
+
* @param node - The `node` parameter represents the current node in the binary search tree. It is
|
|
601
|
+
* initially set to the root node of the tree.
|
|
602
|
+
* @returns an IterableIterator<[K, V | undefined]>.
|
|
568
603
|
*/
|
|
569
604
|
protected _getIterator(node?: NODE | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
570
605
|
/**
|
|
606
|
+
* Time Complexity: O(n)
|
|
607
|
+
* Space Complexity: O(n)
|
|
608
|
+
*/
|
|
609
|
+
/**
|
|
610
|
+
* Time Complexity: O(n)
|
|
611
|
+
* Space Complexity: O(n)
|
|
612
|
+
*
|
|
571
613
|
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
|
|
572
614
|
* taking into account various options such as whether to show null, undefined, or NaN nodes.
|
|
573
615
|
* @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
|
|
@@ -584,27 +626,70 @@ export declare class BinaryTree<K = any, V = any, NODE extends BinaryTreeNode<K,
|
|
|
584
626
|
protected _displayAux(node: NODE | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
585
627
|
protected _DEFAULT_CALLBACK: (node: NODE | null | undefined) => K | undefined;
|
|
586
628
|
/**
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
|
|
590
|
-
|
|
629
|
+
* Time Complexity: O(1)
|
|
630
|
+
* Space Complexity: O(1)
|
|
631
|
+
*/
|
|
632
|
+
/**
|
|
633
|
+
* Time Complexity: O(1)
|
|
634
|
+
* Space Complexity: O(1)
|
|
635
|
+
*
|
|
636
|
+
* The function `_swapProperties` swaps the key-value properties between two nodes.
|
|
637
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
|
|
638
|
+
* destination node. It can be either an instance of the class `R`, or an object of type
|
|
639
|
+
* `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
640
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
|
|
641
|
+
* the properties will be swapped with the `srcNode`.
|
|
642
|
+
* @returns either the `destNode` object with its properties swapped with the `srcNode` object's
|
|
643
|
+
* properties, or `undefined` if either `srcNode` or `destNode` is falsy.
|
|
644
|
+
*/
|
|
645
|
+
protected _swapProperties(srcNode: R | KeyOrNodeOrEntry<K, V, NODE>, destNode: R | KeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
|
|
646
|
+
/**
|
|
647
|
+
* Time Complexity: O(1)
|
|
648
|
+
* Space Complexity: O(1)
|
|
591
649
|
*/
|
|
592
|
-
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V, NODE>, destNode: KeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
|
|
593
650
|
/**
|
|
594
|
-
*
|
|
651
|
+
* Time Complexity: O(1)
|
|
652
|
+
* Space Complexity: O(1)
|
|
653
|
+
*
|
|
654
|
+
* The function replaces a node in a binary tree with a new node, updating the parent, left child,
|
|
655
|
+
* right child, and root if necessary.
|
|
595
656
|
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
596
657
|
* tree.
|
|
597
658
|
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
|
|
598
659
|
* tree.
|
|
599
|
-
* @returns
|
|
660
|
+
* @returns the newNode.
|
|
600
661
|
*/
|
|
601
662
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
602
663
|
/**
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
|
|
606
|
-
|
|
664
|
+
* Time Complexity: O(1)
|
|
665
|
+
* Space Complexity: O(1)
|
|
666
|
+
*/
|
|
667
|
+
/**
|
|
668
|
+
* Time Complexity: O(1)
|
|
669
|
+
* Space Complexity: O(1)
|
|
670
|
+
*
|
|
671
|
+
* The function sets the root property of an object to the provided value, and also updates the
|
|
672
|
+
* parent property of the new root.
|
|
673
|
+
* @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`. This
|
|
674
|
+
* means that it can accept a value of type `NODE`, `null`, or `undefined`.
|
|
607
675
|
*/
|
|
608
676
|
protected _setRoot(v: NODE | null | undefined): void;
|
|
677
|
+
/**
|
|
678
|
+
* Time Complexity: O(1)
|
|
679
|
+
* Space Complexity: O(1)
|
|
680
|
+
*/
|
|
681
|
+
/**
|
|
682
|
+
* Time Complexity: O(1)
|
|
683
|
+
* Space Complexity: O(1)
|
|
684
|
+
*
|
|
685
|
+
* The function `_ensureCallback` ensures that a callback function is provided and returns it.
|
|
686
|
+
* @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is of type
|
|
687
|
+
* `ReturnType<C> | null | undefined`. This means it can accept a value that is the return type of
|
|
688
|
+
* the generic type `C`, or it can be `null` or `undefined`.
|
|
689
|
+
* @param {C} callback - The `callback` parameter is a function that takes a `node` as an argument
|
|
690
|
+
* and returns a value. It is of type `C`, which is a generic type that extends the
|
|
691
|
+
* `BTNCallback<NODE>` type.
|
|
692
|
+
* @returns the callback parameter.
|
|
693
|
+
*/
|
|
609
694
|
protected _ensureCallback<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): C;
|
|
610
695
|
}
|