min-heap-typed 1.51.7 → 1.51.9

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