undirected-graph-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.
Files changed (50) hide show
  1. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +104 -66
  2. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +80 -60
  4. package/dist/data-structures/binary-tree/avl-tree.js +78 -59
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +316 -224
  6. package/dist/data-structures/binary-tree/binary-tree.js +471 -361
  7. package/dist/data-structures/binary-tree/bst.d.ts +198 -200
  8. package/dist/data-structures/binary-tree/bst.js +215 -249
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +71 -72
  10. package/dist/data-structures/binary-tree/rb-tree.js +107 -98
  11. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +90 -73
  12. package/dist/data-structures/binary-tree/tree-multi-map.js +105 -93
  13. package/dist/data-structures/graph/abstract-graph.d.ts +10 -15
  14. package/dist/data-structures/graph/abstract-graph.js +10 -15
  15. package/dist/data-structures/hash/hash-map.d.ts +31 -38
  16. package/dist/data-structures/hash/hash-map.js +40 -55
  17. package/dist/data-structures/queue/deque.d.ts +2 -3
  18. package/dist/data-structures/queue/deque.js +2 -3
  19. package/dist/data-structures/trie/trie.d.ts +1 -1
  20. package/dist/data-structures/trie/trie.js +1 -1
  21. package/dist/interfaces/binary-tree.d.ts +6 -6
  22. package/dist/types/common.d.ts +1 -2
  23. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  24. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
  25. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -4
  26. package/dist/types/data-structures/binary-tree/bst.d.ts +4 -4
  27. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +2 -2
  28. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
  29. package/dist/utils/utils.js +3 -5
  30. package/package.json +2 -2
  31. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -92
  32. package/src/data-structures/binary-tree/avl-tree.ts +94 -66
  33. package/src/data-structures/binary-tree/binary-tree.ts +530 -398
  34. package/src/data-structures/binary-tree/bst.ts +251 -270
  35. package/src/data-structures/binary-tree/rb-tree.ts +121 -100
  36. package/src/data-structures/binary-tree/tree-multi-map.ts +125 -99
  37. package/src/data-structures/graph/abstract-graph.ts +10 -10
  38. package/src/data-structures/hash/hash-map.ts +42 -49
  39. package/src/data-structures/queue/deque.ts +2 -2
  40. package/src/data-structures/queue/queue.ts +1 -1
  41. package/src/data-structures/trie/trie.ts +2 -2
  42. package/src/interfaces/binary-tree.ts +8 -7
  43. package/src/types/common.ts +1 -2
  44. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
  45. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  46. package/src/types/data-structures/binary-tree/binary-tree.ts +5 -4
  47. package/src/types/data-structures/binary-tree/bst.ts +4 -4
  48. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  49. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -3
  50. 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 keysOrNodesOrEntries and options.
72
- * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
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(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: BinaryTreeOptions);
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>): TREE;
119
+ createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
114
120
  /**
115
- * The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
116
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
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
- * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If no value
119
- * is provided, it will be `undefined`.
120
- * @returns a value of type NODE (node), or null, or undefined.
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
- keyValueOrEntryToNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | null | undefined;
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 function `ensureNode` returns the node corresponding to the given key if it is a valid node
132
- * key, otherwise it returns the key itself.
133
- * @param {K | NODE | null | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`,
134
- * `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
135
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
136
- * type of iteration to be used when searching for a node by key. It has a default value of
137
- * `'ITERATIVE'`.
138
- * @returns either the node corresponding to the given key if it is a valid node key, or the key
139
- * itself if it is not a valid node key.
140
- */
141
- ensureNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, iterationType?: IterationType): NODE | null | undefined;
142
- /**
143
- * The function checks if a given node is a real node or null.
144
- * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
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
- isNodeOrNull(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
165
+ isRealNode(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE;
148
166
  /**
149
- * The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
150
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
151
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class NODE.
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
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
172
+ isNodeOrNull(node: R | KeyOrNodeOrEntry<K, V, NODE>): node is NODE | null;
154
173
  /**
155
- * The function checks if a given node is a real node by verifying if it is an instance of
156
- * BinaryTreeNode and its key is not NaN.
157
- * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
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
- isRealNode(node: KeyOrNodeOrEntry<K, V, NODE>): node is NODE;
179
+ isNIL(node: R | KeyOrNodeOrEntry<K, V, NODE>): boolean;
161
180
  /**
162
- * The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
163
- * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
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
- isNIL(node: KeyOrNodeOrEntry<K, V, NODE>): boolean;
187
+ isEntry(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntryOrRawElement is BTNEntry<K, V>;
167
188
  /**
168
- * The function checks if a given value is an entry in a binary tree node.
169
- * @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
170
- * two type parameters V and NODE, representing the value and node type respectively.
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
- isEntry(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is BTNEntry<K, V>;
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 adds a new node to a binary tree, either by creating a new node or replacing an
183
- * existing node with the same key.
184
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
185
- * @param {V} [value] - The value to be inserted into the binary tree.
186
- * @returns The function `add` returns either a node (`NODE`), `null`, or `undefined`.
187
- */
188
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
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 a collection of keysOrNodesOrEntries and an optional collection of values, and
199
- * adds each node with its corresponding value to the data structure.
200
- * @param keysOrNodesOrEntries - An iterable collection of KeyOrNodeOrEntry objects.
201
- * @param [values] - An optional iterable of values that will be assigned to each node being added.
202
- * @returns The function `addMany` returns an array of `NODE`, `null`, or `undefined` values.
203
- */
204
- addMany(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
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 key-value pairs to the data structure.
215
- * @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries. These can be of type
216
- * KeyOrNodeOrEntry<K, V, NODE>.
217
- * @param [values] - The `values` parameter is an optional iterable that contains the values to be
218
- * associated with the keys or nodes or entries in the `keysOrNodesOrEntries` parameter. If provided,
219
- * the values will be associated with the corresponding keys or nodes or entries in the
220
- * `keysOrNodesOrEntries` iterable
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` searches for a node in a binary tree by its key, using either
241
- * recursive or iterative iteration.
242
- * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
243
- * It is used to find the node with the matching key value.
244
- * @param iterationType - The `iterationType` parameter is used to determine whether the search for
245
- * the node with the given key should be performed iteratively or recursively. It has two possible
246
- * values:
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 {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
291
- * for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
292
- * value of a binary tree node), `NODE` (a node of a binary tree), `null`, or `undefined`. If
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 `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
305
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the root
306
- * node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
307
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
308
- * type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
309
- * possible values:
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 binary tree.
322
- * @param {K | NODE | null | undefined} dist - The `dist` parameter represents the node in
323
- * the binary tree whose depth we want to find. It can be of type `K`, `NODE`, `null`, or
324
- * `undefined`.
325
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
326
- * from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
327
- * `NODE` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
328
- * @returns the depth of the `dist` relative to the `beginRoot`.
329
- */
330
- getDepth(dist: KeyOrNodeOrEntry<K, V, NODE>, beginRoot?: KeyOrNodeOrEntry<K, V, NODE>): number;
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(log n)
373
+ * Space Complexity: O(1)
338
374
  *
339
- * The function `getHeight` calculates the maximum height of a binary tree using either recursive or
340
- * iterative traversal.
341
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
342
- * starting node of the binary tree from which we want to calculate the height. It can be of type
343
- * `K`, `NODE`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
344
- * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
345
- * height of the tree using a recursive approach or an iterative approach. It can have two possible
346
- * values:
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 {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
361
- * starting node of the binary tree from which we want to calculate the minimum height. It can be of
362
- * type `K`, `NODE`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
363
- * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
364
- * to calculate the minimum height of a binary tree. It can have two possible values:
365
- * @returns The function `getMinHeight` returns the minimum height of a binary tree.
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 to the root of a tree
378
- * structure, with the option to reverse the order of the nodes.
379
- * @param {K | NODE | null | undefined} beginNode - The `beginRoot` parameter represents the
380
- * starting node from which you want to find the path to the root. It can be of type `K`, `NODE`,
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`, the path will be returned as is
385
- * @returns The function `getPathToRoot` returns an array of nodes (`NODE[]`).
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 function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
397
- * iteratively.
398
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
399
- * for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `NODE` (a
400
- * node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
401
- * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
402
- * be performed when finding the leftmost node in a binary tree. It can have two possible values:
403
- * @returns The function `getLeftMost` returns the leftmost node (`NODE`) in the binary tree. If there
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 function `getRightMost` returns the rightmost node in a binary tree, either recursively or
450
+ * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
416
451
  * iteratively.
417
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
418
- * starting node from which we want to find the rightmost node. It can be of type `K`, `NODE`,
419
- * `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
420
- * current object.
421
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
422
- * type of iteration to use when finding the rightmost node. It can have one of two values:
423
- * @returns The function `getRightMost` returns the rightmost node (`NODE`) in a binary tree. If there
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 `node` is of type `RedBlackTreeNode`, which represents a node in a
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 'node'.
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 the successor of the given node or key. The successor is the node that comes immediately
452
- * after the given node in the inorder traversal of the binary tree.
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 parameter of type `NODE` (the type of the nodes in the tree) and returns
473
- * a value of any type.
474
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
475
- * determines the order in which the nodes of a binary tree are traversed. It can have one of the
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 {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
478
- * for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
479
- * the root of the tree. If no value is provided, the default value is the root of the tree.
480
- * @returns The function `morris` returns an array of values that are the result of invoking the
481
- * `callback` function on each node in the binary tree. The type of the array nodes is determined
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 new tree object and copies all the nodes from the original tree to
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 by iterating over the nodes of the current tree and
507
- * adding only the nodes that satisfy the given predicate function.
508
- * @param predicate - The `predicate` parameter is a function that takes three arguments: `value`,
509
- * `key`, and `index`. It should return a boolean value indicating whether the pair should be
510
- * included in the filtered tree or not.
511
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
512
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
513
- * it will be passed as the first argument to the `predicate` function. If `thisArg` is
514
- * @returns The `filter` method is returning a new tree object that contains the key-value pairs that
515
- * pass the given predicate function.
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 key-value pair in
527
- * the original tree.
528
- * @param callback - The callback parameter is a function that will be called for each key-value pair
529
- * in the tree. It takes four arguments: the value of the current pair, the key of the current pair,
530
- * the index of the current pair, and a reference to the tree itself. The callback function should
531
- * return a new
532
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
533
- * specify the value of `this` within the callback function. If you pass a value for `thisArg`, it
534
- * will be used as the `this` value when the callback function is called. If you don't pass a value
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 is used to display a binary tree structure in a visually appealing way.
547
- * @param {K | NODE | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | NODE | null |
548
- * undefined`. It represents the root node of a binary tree. The root node can have one of the
549
- * following types:
550
- * @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
551
- */
552
- print(beginRoot?: KeyOrNodeOrEntry<K, V, NODE>, options?: BinaryTreePrintOptions): void;
553
- /**
554
- * The function `_getIterator` is a protected generator function that returns an iterator for the
555
- * key-value pairs in a binary search tree.
556
- * @param node - The `node` parameter represents the current node in the binary search tree. It is an
557
- * optional parameter with a default value of `this.root`, which means if no node is provided, the
558
- * root node of the tree will be used as the starting point for iteration.
559
- * @returns The function `_getIterator` returns an `IterableIterator` of key-value pairs `[K, V |
560
- * undefined]`.
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
- * Swap the data of two nodes in the binary tree.
581
- * @param {NODE} srcNode - The source node to swap.
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
- * The function replaces an old node with a new node in a binary tree.
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 The method is returning the newNode.
660
+ * @returns the newNode.
593
661
  */
594
662
  protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
595
663
  /**
596
- * The function sets the root property of an object to a given value, and if the value is not null,
597
- * it also sets the parent property of the value to undefined.
598
- * @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`, which means it can either be of
599
- * type `NODE` or `null`.
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
  }