deque-typed 1.51.8 → 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/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +104 -66
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/data-structures/binary-tree/avl-tree.d.ts +80 -60
- package/dist/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/data-structures/binary-tree/binary-tree.d.ts +316 -224
- package/dist/data-structures/binary-tree/binary-tree.js +471 -361
- package/dist/data-structures/binary-tree/bst.d.ts +198 -200
- package/dist/data-structures/binary-tree/bst.js +215 -249
- package/dist/data-structures/binary-tree/rb-tree.d.ts +71 -72
- package/dist/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +90 -73
- 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/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 +6 -6
- package/dist/types/common.d.ts +1 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
- package/dist/utils/utils.js +3 -5
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -92
- package/src/data-structures/binary-tree/avl-tree.ts +94 -66
- package/src/data-structures/binary-tree/binary-tree.ts +530 -398
- package/src/data-structures/binary-tree/bst.ts +251 -270
- package/src/data-structures/binary-tree/rb-tree.ts +121 -100
- package/src/data-structures/binary-tree/tree-multi-map.ts +125 -99
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +42 -49
- 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 +8 -7
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +5 -4
- package/src/types/data-structures/binary-tree/bst.ts +4 -4
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -3
- package/src/utils/utils.ts +3 -3
|
@@ -65,18 +65,18 @@ export declare class BinaryTreeNode<K extends Comparable, V = any, NODE extends
|
|
|
65
65
|
* 4. Subtrees: Each child of a node forms the root of a subtree.
|
|
66
66
|
* 5. Leaf Nodes: Nodes without children are leaves.
|
|
67
67
|
*/
|
|
68
|
-
export declare class BinaryTree<K extends Comparable, V = any, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNode<K, V, BinaryTreeNodeNested<K, V>>, TREE extends BinaryTree<K, V, NODE, TREE> = BinaryTree<K, V, NODE, BinaryTreeNested<K, V, NODE>>> extends IterableEntryBase<K, V | undefined> implements IBinaryTree<K, V, NODE, TREE> {
|
|
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> {
|
|
69
69
|
iterationType: IterationType;
|
|
70
70
|
/**
|
|
71
|
-
* The constructor function initializes a binary tree object with optional
|
|
72
|
-
* @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
|
|
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(
|
|
79
|
+
constructor(keysOrNodesOrEntriesOrRawElements?: Iterable<R | KeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions<K, V, R>);
|
|
80
80
|
protected _root?: NODE | null;
|
|
81
81
|
/**
|
|
82
82
|
* The function returns the root node, which can be of type NODE, null, or undefined.
|
|
@@ -96,6 +96,12 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
96
96
|
* @returns The method is returning the value of the `_NIL` property.
|
|
97
97
|
*/
|
|
98
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;
|
|
99
105
|
/**
|
|
100
106
|
* Creates a new instance of BinaryTreeNode with the given key and value.
|
|
101
107
|
* @param {K} key - The key for the new node.
|
|
@@ -110,16 +116,19 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
110
116
|
* you can provide only a subset of the properties defined in the `BinaryTreeOptions` interface.
|
|
111
117
|
* @returns a new instance of a binary tree.
|
|
112
118
|
*/
|
|
113
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
119
|
+
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
114
120
|
/**
|
|
115
|
-
* The function `
|
|
116
|
-
*
|
|
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>`.
|
|
117
125
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
118
|
-
* `
|
|
119
|
-
*
|
|
120
|
-
* @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`.
|
|
121
130
|
*/
|
|
122
|
-
|
|
131
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | null | undefined;
|
|
123
132
|
/**
|
|
124
133
|
* Time Complexity: O(n)
|
|
125
134
|
* Space Complexity: O(log n)
|
|
@@ -128,49 +137,65 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
128
137
|
* Time Complexity: O(n)
|
|
129
138
|
* Space Complexity: O(log n)
|
|
130
139
|
*
|
|
131
|
-
* The
|
|
132
|
-
*
|
|
133
|
-
* @param {
|
|
134
|
-
* `
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*/
|
|
141
|
-
ensureNode(
|
|
142
|
-
/**
|
|
143
|
-
* The function checks if
|
|
144
|
-
* @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>`.
|
|
145
163
|
* @returns a boolean value.
|
|
146
164
|
*/
|
|
147
|
-
|
|
165
|
+
isRealNode(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE;
|
|
148
166
|
/**
|
|
149
|
-
* The function
|
|
150
|
-
* @param
|
|
151
|
-
*
|
|
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.
|
|
152
171
|
*/
|
|
153
|
-
|
|
172
|
+
isNodeOrNull(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
|
|
154
173
|
/**
|
|
155
|
-
* The function checks if a given node is
|
|
156
|
-
*
|
|
157
|
-
*
|
|
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>`.
|
|
158
177
|
* @returns a boolean value.
|
|
159
178
|
*/
|
|
160
|
-
|
|
179
|
+
isNIL(node: R | KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
161
180
|
/**
|
|
162
|
-
* The function checks if
|
|
163
|
-
*
|
|
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>`.
|
|
164
185
|
* @returns a boolean value.
|
|
165
186
|
*/
|
|
166
|
-
|
|
187
|
+
isEntry(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>;
|
|
167
188
|
/**
|
|
168
|
-
* The function checks if a given value is
|
|
169
|
-
* @param
|
|
170
|
-
*
|
|
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().
|
|
171
196
|
* @returns a boolean value.
|
|
172
197
|
*/
|
|
173
|
-
|
|
198
|
+
isKey(key: any, isCheckValueOf?: boolean): key is K;
|
|
174
199
|
/**
|
|
175
200
|
* Time Complexity O(n)
|
|
176
201
|
* Space Complexity O(1)
|
|
@@ -179,13 +204,19 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
179
204
|
* Time Complexity O(n)
|
|
180
205
|
* Space Complexity O(1)
|
|
181
206
|
*
|
|
182
|
-
* The `add` function
|
|
183
|
-
*
|
|
184
|
-
* @param
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
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;
|
|
189
220
|
/**
|
|
190
221
|
* Time Complexity: O(k * n)
|
|
191
222
|
* Space Complexity: O(1)
|
|
@@ -195,13 +226,17 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
195
226
|
* Time Complexity: O(k * n)
|
|
196
227
|
* Space Complexity: O(1)
|
|
197
228
|
*
|
|
198
|
-
* The `addMany` function takes in
|
|
199
|
-
* adds each node with its corresponding value to
|
|
200
|
-
*
|
|
201
|
-
* @param
|
|
202
|
-
*
|
|
203
|
-
|
|
204
|
-
|
|
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[];
|
|
205
240
|
/**
|
|
206
241
|
* Time Complexity: O(k * n)
|
|
207
242
|
* Space Complexity: O(1)
|
|
@@ -211,24 +246,23 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
211
246
|
* Time Complexity: O(k * n)
|
|
212
247
|
* Space Complexity: O(1)
|
|
213
248
|
*
|
|
214
|
-
* The `refill` function clears the current data and adds new
|
|
215
|
-
* @param
|
|
216
|
-
* KeyOrNodeOrEntry<K, V, NODE
|
|
217
|
-
* @param [values] - The `values` parameter is an optional iterable
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
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;
|
|
223
257
|
delete<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
224
258
|
delete<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C): BinaryTreeDeleteResult<NODE>[];
|
|
225
259
|
delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeleteResult<NODE>[];
|
|
226
|
-
getNodes<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
227
|
-
getNodes<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
228
|
-
getNodes<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE[];
|
|
229
|
-
getNode<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
230
|
-
getNode<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
231
|
-
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;
|
|
232
266
|
/**
|
|
233
267
|
* Time Complexity: O(n)
|
|
234
268
|
* Space Complexity: O(log n)
|
|
@@ -237,23 +271,21 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
237
271
|
* Time Complexity: O(n)
|
|
238
272
|
* Space Complexity: O(log n)
|
|
239
273
|
*
|
|
240
|
-
* The function `getNodeByKey`
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
|
|
248
|
-
* 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.
|
|
249
281
|
*/
|
|
250
282
|
getNodeByKey(key: K, iterationType?: IterationType): NODE | null | undefined;
|
|
251
|
-
get<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
252
|
-
get<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
253
|
-
get<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): V | undefined;
|
|
254
|
-
has<C extends BTNCallback<NODE, K>>(identifier: K, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
255
|
-
has<C extends BTNCallback<NODE, NODE>>(identifier: NODE | null | undefined, callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
256
|
-
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;
|
|
257
289
|
/**
|
|
258
290
|
* Time Complexity: O(1)
|
|
259
291
|
* Space Complexity: O(1)
|
|
@@ -287,12 +319,13 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
287
319
|
*
|
|
288
320
|
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
|
|
289
321
|
* height of the tree.
|
|
290
|
-
* @param {
|
|
291
|
-
*
|
|
292
|
-
*
|
|
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
|
|
293
326
|
* @returns a boolean value.
|
|
294
327
|
*/
|
|
295
|
-
isPerfectlyBalanced(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
328
|
+
isPerfectlyBalanced(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>): boolean;
|
|
296
329
|
/**
|
|
297
330
|
* Time Complexity: O(n)
|
|
298
331
|
* Space Complexity: O(1)
|
|
@@ -301,15 +334,17 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
301
334
|
* Time Complexity: O(n)
|
|
302
335
|
* Space Complexity: O(1)
|
|
303
336
|
*
|
|
304
|
-
* The function `
|
|
305
|
-
* @param {
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
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:
|
|
310
345
|
* @returns a boolean value.
|
|
311
346
|
*/
|
|
312
|
-
isBST(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
347
|
+
isBST(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): boolean;
|
|
313
348
|
/**
|
|
314
349
|
* Time Complexity: O(n)
|
|
315
350
|
* Space Complexity: O(1)
|
|
@@ -318,35 +353,35 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
318
353
|
* Time Complexity: O(n)
|
|
319
354
|
* Space Complexity: O(1)
|
|
320
355
|
*
|
|
321
|
-
* The function calculates the depth of a given node in a
|
|
322
|
-
* @param {
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @param {
|
|
326
|
-
* from which
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
|
|
330
|
-
|
|
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;
|
|
331
367
|
/**
|
|
332
368
|
* Time Complexity: O(n)
|
|
333
369
|
* Space Complexity: O(1)
|
|
334
370
|
*/
|
|
335
371
|
/**
|
|
336
372
|
* Time Complexity: O(n)
|
|
337
|
-
* Space Complexity: O(
|
|
373
|
+
* Space Complexity: O(1)
|
|
338
374
|
*
|
|
339
|
-
* The
|
|
340
|
-
* iterative
|
|
341
|
-
* @param {
|
|
342
|
-
* starting
|
|
343
|
-
*
|
|
344
|
-
* @param iterationType - The `iterationType` parameter
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
* @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.
|
|
348
383
|
*/
|
|
349
|
-
getHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
384
|
+
getHeight(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
350
385
|
/**
|
|
351
386
|
* Time Complexity: O(n)
|
|
352
387
|
* Space Complexity: O(log n)
|
|
@@ -357,34 +392,35 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
357
392
|
*
|
|
358
393
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a
|
|
359
394
|
* recursive or iterative approach.
|
|
360
|
-
* @param {
|
|
361
|
-
* starting
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
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.
|
|
366
404
|
*/
|
|
367
|
-
getMinHeight(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
405
|
+
getMinHeight(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): number;
|
|
368
406
|
/**
|
|
369
407
|
* Time Complexity: O(log n)
|
|
370
408
|
* Space Complexity: O(log n)
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
/**
|
|
409
|
+
*/
|
|
410
|
+
/**
|
|
374
411
|
* Time Complexity: O(log n)
|
|
375
412
|
* Space Complexity: O(log n)
|
|
376
413
|
*
|
|
377
|
-
* The function `getPathToRoot` returns an array of nodes from a given node
|
|
378
|
-
*
|
|
379
|
-
* @param {
|
|
380
|
-
*
|
|
381
|
-
* `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>`.
|
|
382
418
|
* @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
|
|
383
419
|
* resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
|
|
384
|
-
* reversed before returning it. If `isReverse` is set to `false
|
|
385
|
-
* @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.
|
|
386
422
|
*/
|
|
387
|
-
getPathToRoot(beginNode: KeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
423
|
+
getPathToRoot(beginNode: R | KeyOrNodeOrEntry<K, V, NODE>, isReverse?: boolean): NODE[];
|
|
388
424
|
/**
|
|
389
425
|
* Time Complexity: O(log n)
|
|
390
426
|
* Space Complexity: O(1)
|
|
@@ -393,17 +429,16 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
393
429
|
* Time Complexity: O(log n)
|
|
394
430
|
* Space Complexity: O(1)
|
|
395
431
|
*
|
|
396
|
-
* The
|
|
397
|
-
*
|
|
398
|
-
* @param {
|
|
399
|
-
* for finding the leftmost node in a binary tree. It can be either a `
|
|
400
|
-
*
|
|
401
|
-
* @param iterationType - The `iterationType` parameter is used to
|
|
402
|
-
*
|
|
403
|
-
* @returns The function `getLeftMost` returns the leftmost node
|
|
404
|
-
* 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.
|
|
405
440
|
*/
|
|
406
|
-
getLeftMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
441
|
+
getLeftMost(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
407
442
|
/**
|
|
408
443
|
* Time Complexity: O(log n)
|
|
409
444
|
* Space Complexity: O(1)
|
|
@@ -412,18 +447,17 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
412
447
|
* Time Complexity: O(log n)
|
|
413
448
|
* Space Complexity: O(1)
|
|
414
449
|
*
|
|
415
|
-
* The
|
|
450
|
+
* The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
|
|
416
451
|
* iteratively.
|
|
417
|
-
* @param {
|
|
418
|
-
* starting
|
|
419
|
-
* `
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* @returns The function `getRightMost` returns
|
|
424
|
-
* 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`.
|
|
425
459
|
*/
|
|
426
|
-
getRightMost(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
460
|
+
getRightMost(beginRoot?: R | KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
|
|
427
461
|
/**
|
|
428
462
|
* Time Complexity: O(log n)
|
|
429
463
|
* Space Complexity: O(1)
|
|
@@ -432,10 +466,10 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
432
466
|
* Time Complexity: O(log n)
|
|
433
467
|
* Space Complexity: O(1)
|
|
434
468
|
*
|
|
435
|
-
* The function returns the predecessor of a given node in a tree.
|
|
436
|
-
* @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
|
|
437
471
|
* tree.
|
|
438
|
-
* @returns the predecessor of the given
|
|
472
|
+
* @returns the predecessor node of the given node.
|
|
439
473
|
*/
|
|
440
474
|
getPredecessor(node: NODE): NODE;
|
|
441
475
|
/**
|
|
@@ -448,16 +482,16 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
448
482
|
*
|
|
449
483
|
* The function `getSuccessor` returns the next node in a binary tree given a current node.
|
|
450
484
|
* @param {K | NODE | null} [x] - The parameter `x` can be of type `K`, `NODE`, or `null`.
|
|
451
|
-
* @returns
|
|
452
|
-
*
|
|
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.
|
|
453
487
|
*/
|
|
454
488
|
getSuccessor(x?: K | NODE | null): NODE | null | undefined;
|
|
455
|
-
dfs<C extends BTNCallback<NODE>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
456
|
-
dfs<C extends BTNCallback<NODE | null>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
457
|
-
bfs<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[];
|
|
458
|
-
bfs<C extends BTNCallback<NODE | null>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: true): ReturnType<C>[];
|
|
459
|
-
listLevels<C extends BTNCallback<NODE>>(callback?: C, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType, includeNull?: false): ReturnType<C>[][];
|
|
460
|
-
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>[][];
|
|
461
495
|
/**
|
|
462
496
|
* Time complexity: O(n)
|
|
463
497
|
* Space complexity: O(n)
|
|
@@ -469,19 +503,19 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
469
503
|
* The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
|
|
470
504
|
* algorithm.
|
|
471
505
|
* @param {C} callback - The `callback` parameter is a function that will be called for each node in
|
|
472
|
-
* the tree. It takes a single
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
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
|
|
476
511
|
* following values:
|
|
477
|
-
* @param {
|
|
478
|
-
* for the traversal. It can be
|
|
479
|
-
* the root of the tree
|
|
480
|
-
* @returns The function `morris` returns an array of values that are the
|
|
481
|
-
*
|
|
482
|
-
* 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`.
|
|
483
517
|
*/
|
|
484
|
-
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>[];
|
|
485
519
|
/**
|
|
486
520
|
* Time complexity: O(n)
|
|
487
521
|
* Space complexity: O(n)
|
|
@@ -490,8 +524,7 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
490
524
|
* Time complexity: O(n)
|
|
491
525
|
* Space complexity: O(n)
|
|
492
526
|
*
|
|
493
|
-
* The `clone` function creates a
|
|
494
|
-
* the new tree.
|
|
527
|
+
* The `clone` function creates a deep copy of a tree object.
|
|
495
528
|
* @returns The `clone()` method is returning a cloned instance of the `TREE` object.
|
|
496
529
|
*/
|
|
497
530
|
clone(): TREE;
|
|
@@ -503,16 +536,16 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
503
536
|
* Time Complexity: O(n)
|
|
504
537
|
* Space Complexity: O(n)
|
|
505
538
|
*
|
|
506
|
-
* The `filter` function creates a new tree
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
* @returns The `filter` method is returning a new tree object that contains the
|
|
515
|
-
*
|
|
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.
|
|
516
549
|
*/
|
|
517
550
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: any): TREE;
|
|
518
551
|
/**
|
|
@@ -523,15 +556,15 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
523
556
|
* Time Complexity: O(n)
|
|
524
557
|
* Space Complexity: O(n)
|
|
525
558
|
*
|
|
526
|
-
* The `map` function creates a new tree by applying a callback function to each
|
|
527
|
-
*
|
|
528
|
-
* @param callback - The callback parameter is a function that will be called for each
|
|
529
|
-
*
|
|
530
|
-
* the
|
|
531
|
-
*
|
|
532
|
-
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that
|
|
533
|
-
*
|
|
534
|
-
*
|
|
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
|
|
535
568
|
* @returns The `map` method is returning a new tree object.
|
|
536
569
|
*/
|
|
537
570
|
map(callback: EntryCallback<K, V | undefined, V>, thisArg?: any): TREE;
|
|
@@ -543,24 +576,40 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
543
576
|
* Time Complexity: O(n)
|
|
544
577
|
* Space Complexity: O(n)
|
|
545
578
|
*
|
|
546
|
-
* The `print` function
|
|
547
|
-
* @param {
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
*
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
|
|
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]>.
|
|
561
603
|
*/
|
|
562
604
|
protected _getIterator(node?: NODE | null | undefined): IterableIterator<[K, V | undefined]>;
|
|
563
605
|
/**
|
|
606
|
+
* Time Complexity: O(n)
|
|
607
|
+
* Space Complexity: O(n)
|
|
608
|
+
*/
|
|
609
|
+
/**
|
|
610
|
+
* Time Complexity: O(n)
|
|
611
|
+
* Space Complexity: O(n)
|
|
612
|
+
*
|
|
564
613
|
* The `_displayAux` function is responsible for generating the display layout of a binary tree node,
|
|
565
614
|
* taking into account various options such as whether to show null, undefined, or NaN nodes.
|
|
566
615
|
* @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
|
|
@@ -577,27 +626,70 @@ export declare class BinaryTree<K extends Comparable, V = any, NODE extends Bina
|
|
|
577
626
|
protected _displayAux(node: NODE | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
|
|
578
627
|
protected _DEFAULT_CALLBACK: (node: NODE | null | undefined) => K | undefined;
|
|
579
628
|
/**
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
* @param {NODE} destNode - The destination node to swap.
|
|
583
|
-
* @returns {NODE} - The destination node after the swap.
|
|
629
|
+
* Time Complexity: O(1)
|
|
630
|
+
* Space Complexity: O(1)
|
|
584
631
|
*/
|
|
585
|
-
protected _swapProperties(srcNode: KeyOrNodeOrEntry<K, V, NODE>, destNode: KeyOrNodeOrEntry<K, V, NODE>): NODE | undefined;
|
|
586
632
|
/**
|
|
587
|
-
*
|
|
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)
|
|
649
|
+
*/
|
|
650
|
+
/**
|
|
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.
|
|
588
656
|
* @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
|
|
589
657
|
* tree.
|
|
590
658
|
* @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
|
|
591
659
|
* tree.
|
|
592
|
-
* @returns
|
|
660
|
+
* @returns the newNode.
|
|
593
661
|
*/
|
|
594
662
|
protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
|
|
595
663
|
/**
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
|
|
599
|
-
|
|
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`.
|
|
600
675
|
*/
|
|
601
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
|
+
*/
|
|
602
694
|
protected _ensureCallback<C extends BTNCallback<NODE>>(identifier: ReturnType<C> | null | undefined, callback?: C): C;
|
|
603
695
|
}
|