min-heap-typed 1.39.1 → 1.39.3

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 (35) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +10 -10
  2. package/dist/data-structures/binary-tree/avl-tree.js +4 -4
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +58 -107
  4. package/dist/data-structures/binary-tree/binary-tree.js +65 -27
  5. package/dist/data-structures/binary-tree/bst.d.ts +22 -22
  6. package/dist/data-structures/binary-tree/bst.js +12 -12
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +3 -3
  8. package/dist/data-structures/binary-tree/tree-multiset.d.ts +14 -14
  9. package/dist/data-structures/binary-tree/tree-multiset.js +7 -7
  10. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  11. package/dist/data-structures/linked-list/doubly-linked-list.js +59 -49
  12. package/dist/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  13. package/dist/data-structures/linked-list/singly-linked-list.js +110 -9
  14. package/dist/data-structures/queue/deque.d.ts +20 -20
  15. package/dist/data-structures/queue/deque.js +22 -22
  16. package/dist/data-structures/queue/queue.d.ts +3 -3
  17. package/dist/data-structures/queue/queue.js +3 -3
  18. package/dist/interfaces/binary-tree.d.ts +4 -4
  19. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  20. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -2
  21. package/dist/types/helpers.d.ts +1 -1
  22. package/package.json +2 -2
  23. package/src/data-structures/binary-tree/avl-tree.ts +10 -10
  24. package/src/data-structures/binary-tree/binary-tree.ts +165 -53
  25. package/src/data-structures/binary-tree/bst.ts +29 -31
  26. package/src/data-structures/binary-tree/rb-tree.ts +5 -5
  27. package/src/data-structures/binary-tree/tree-multiset.ts +14 -14
  28. package/src/data-structures/linked-list/doubly-linked-list.ts +62 -56
  29. package/src/data-structures/linked-list/singly-linked-list.ts +118 -13
  30. package/src/data-structures/queue/deque.ts +22 -22
  31. package/src/data-structures/queue/queue.ts +3 -3
  32. package/src/interfaces/binary-tree.ts +4 -4
  33. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  34. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  35. package/src/types/helpers.ts +1 -1
@@ -6,12 +6,12 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
10
- import { OneParamCallback } from '../../types';
9
+ import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BTNKey } from '../../types';
10
+ import { BTNCallback } from '../../types';
11
11
  import { IBinaryTree } from '../../interfaces';
12
12
  export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
13
13
  height: number;
14
- constructor(key: BinaryTreeNodeKey, val?: V);
14
+ constructor(key: BTNKey, val?: V);
15
15
  }
16
16
  export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>> extends BST<V, N> implements IBinaryTree<V, N> {
17
17
  /**
@@ -23,29 +23,29 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
23
23
  constructor(options?: AVLTreeOptions);
24
24
  /**
25
25
  * The function creates a new AVL tree node with the specified key and value.
26
- * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
26
+ * @param {BTNKey} key - The key parameter is the key value that will be associated with
27
27
  * the new node. It is used to determine the position of the node in the binary search tree.
28
28
  * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
29
29
  * type `V`, which means it can be any value that is assignable to the `val` property of the
30
30
  * node type `N`.
31
31
  * @returns a new AVLTreeNode object with the specified key and value.
32
32
  */
33
- createNode(key: BinaryTreeNodeKey, val?: V): N;
33
+ createNode(key: BTNKey, val?: V): N;
34
34
  /**
35
35
  * The function overrides the add method of a binary tree node and balances the tree after inserting
36
36
  * a new node.
37
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
38
- * `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
37
+ * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
38
+ * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
39
39
  * @param [val] - The `val` parameter is the value that you want to assign to the new node that you
40
40
  * are adding to the binary search tree.
41
41
  * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
42
42
  */
43
- add(keyOrNode: BinaryTreeNodeKey | N | null, val?: V): N | null | undefined;
43
+ add(keyOrNode: BTNKey | N | null, val?: V): N | null | undefined;
44
44
  /**
45
45
  * The function overrides the delete method of a binary tree and balances the tree after deleting a
46
46
  * node if necessary.
47
47
  * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
48
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
48
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
49
49
  * searching for. It can be a specific key value or any other property of the node.
50
50
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
51
51
  * value. This value is compared with the `identifier` parameter to determine if the node should be
@@ -53,7 +53,7 @@ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<
53
53
  * `this._defaultCallbackByKey`
54
54
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
55
55
  */
56
- delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
56
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
57
57
  /**
58
58
  * The function swaps the key, value, and height properties between two nodes in a binary tree.
59
59
  * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
@@ -28,7 +28,7 @@ class AVLTree extends bst_1.BST {
28
28
  }
29
29
  /**
30
30
  * The function creates a new AVL tree node with the specified key and value.
31
- * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
31
+ * @param {BTNKey} key - The key parameter is the key value that will be associated with
32
32
  * the new node. It is used to determine the position of the node in the binary search tree.
33
33
  * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
34
34
  * type `V`, which means it can be any value that is assignable to the `val` property of the
@@ -41,8 +41,8 @@ class AVLTree extends bst_1.BST {
41
41
  /**
42
42
  * The function overrides the add method of a binary tree node and balances the tree after inserting
43
43
  * a new node.
44
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
45
- * `BinaryTreeNodeKey` or a `N` (which represents a node in the binary tree) or `null`.
44
+ * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can accept either a
45
+ * `BTNKey` or a `N` (which represents a node in the binary tree) or `null`.
46
46
  * @param [val] - The `val` parameter is the value that you want to assign to the new node that you
47
47
  * are adding to the binary search tree.
48
48
  * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
@@ -58,7 +58,7 @@ class AVLTree extends bst_1.BST {
58
58
  * The function overrides the delete method of a binary tree and balances the tree after deleting a
59
59
  * node if necessary.
60
60
  * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
61
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
61
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
62
62
  * searching for. It can be a specific key value or any other property of the node.
63
63
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
64
64
  * value. This value is compared with the `identifier` parameter to determine if the node should be
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { OneParamCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
8
+ import type { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey } from '../../types';
9
9
  import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
@@ -17,7 +17,7 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
17
17
  /**
18
18
  * The key associated with the node.
19
19
  */
20
- key: BinaryTreeNodeKey;
20
+ key: BTNKey;
21
21
  /**
22
22
  * The value stored in the node.
23
23
  */
@@ -28,10 +28,10 @@ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = Bi
28
28
  parent: N | null | undefined;
29
29
  /**
30
30
  * Creates a new instance of BinaryTreeNode.
31
- * @param {BinaryTreeNodeKey} key - The key associated with the node.
31
+ * @param {BTNKey} key - The key associated with the node.
32
32
  * @param {V} val - The value stored in the node.
33
33
  */
34
- constructor(key: BinaryTreeNodeKey, val?: V);
34
+ constructor(key: BTNKey, val?: V);
35
35
  private _left;
36
36
  /**
37
37
  * Get the left child node.
@@ -90,11 +90,11 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
90
90
  get size(): number;
91
91
  /**
92
92
  * Creates a new instance of BinaryTreeNode with the given key and value.
93
- * @param {BinaryTreeNodeKey} key - The key for the new node.
93
+ * @param {BTNKey} key - The key for the new node.
94
94
  * @param {V} val - The value for the new node.
95
95
  * @returns {N} - The newly created BinaryTreeNode.
96
96
  */
97
- createNode(key: BinaryTreeNodeKey, val?: V): N;
97
+ createNode(key: BTNKey, val?: V): N;
98
98
  /**
99
99
  * Clear the binary tree, removing all nodes.
100
100
  */
@@ -106,73 +106,61 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
106
106
  isEmpty(): boolean;
107
107
  /**
108
108
  * Add a node with the given key and value to the binary tree.
109
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The key or node to add to the binary tree.
109
+ * @param {BTNKey | N | null} keyOrNode - The key or node to add to the binary tree.
110
110
  * @param {V} val - The value for the new node (optional).
111
111
  * @returns {N | null | undefined} - The inserted node, or null if nothing was inserted, or undefined if the operation failed.
112
112
  */
113
- add(keyOrNode: BinaryTreeNodeKey | N | null, val?: V): N | null | undefined;
113
+ add(keyOrNode: BTNKey | N | null, val?: V): N | null | undefined;
114
114
  /**
115
115
  * The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
116
116
  * values, and adds them to the binary tree.
117
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
117
+ * @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of BTNKey or BinaryTreeNode
118
118
  * objects, or null values.
119
119
  * @param {V[]} [values] - The `values` parameter is an optional array of values (`V[]`) that corresponds to
120
120
  * the nodes or node IDs being added. It is used to set the value of each node being added. If `values` is not provided,
121
121
  * the value of the nodes will be `undefined`.
122
122
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
123
123
  */
124
- addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], values?: V[]): (N | null | undefined)[];
124
+ addMany(keysOrNodes: (BTNKey | null)[] | (N | null)[], values?: V[]): (N | null | undefined)[];
125
125
  /**
126
126
  * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
127
- * @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
128
- * `BinaryTreeNodeKey` or `N` values.
127
+ * @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
128
+ * `BTNKey` or `N` values.
129
129
  * @param {N[] | Array<V>} [data] - The `data` parameter is an optional array of values that will be assigned to
130
130
  * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
131
131
  * array. Each value in the `data` array will be assigned to the
132
132
  * @returns The method is returning a boolean value.
133
133
  */
134
- refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: Array<V>): boolean;
135
- /**
136
- * The `delete` function removes a node from a binary search tree and returns the deleted node along
137
- * with the parent node that needs to be balanced.
138
- * a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
139
- * binary tree.
140
- * @returns an array of `BinaryTreeDeletedResult<N>` objects.
141
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
142
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
143
- * searching for. It can be a specific key value or any other property of the node.
144
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
145
- * value. This value is compared with the `identifier` parameter to determine if the node should be
146
- * included in the result. The `callback` parameter has a default value of
147
- * `this._defaultCallbackByKey`, which
148
- */
149
- delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C): BinaryTreeDeletedResult<N>[];
134
+ refill(keysOrNodes: (BTNKey | null)[] | (N | null)[], data?: Array<V>): boolean;
135
+ delete<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C): BinaryTreeDeletedResult<N>[];
136
+ delete<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C): BinaryTreeDeletedResult<N>[];
137
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeletedResult<N>[];
150
138
  /**
151
139
  * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
152
140
  * specified root node.
153
- * @param {BinaryTreeNodeKey | N | null} distNode - The `distNode` parameter represents the node
141
+ * @param {BTNKey | N | null} distNode - The `distNode` parameter represents the node
154
142
  * whose depth we want to find in the binary tree. It can be either a node object (`N`), a key value
155
- * of the node (`BinaryTreeNodeKey`), or `null`.
156
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
143
+ * of the node (`BTNKey`), or `null`.
144
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter represents the
157
145
  * starting node from which we want to calculate the depth. It can be either a node object or the key
158
146
  * of a node in the binary tree. If no value is provided for `beginRoot`, it defaults to the root
159
147
  * node of the binary tree.
160
148
  * @returns the depth of the `distNode` relative to the `beginRoot`.
161
149
  */
162
- getDepth(distNode: BinaryTreeNodeKey | N | null, beginRoot?: BinaryTreeNodeKey | N | null): number;
150
+ getDepth(distNode: BTNKey | N | null, beginRoot?: BTNKey | N | null): number;
163
151
  /**
164
152
  * The `getHeight` function calculates the maximum height of a binary tree using either recursive or
165
153
  * iterative approach.
166
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
154
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter represents the
167
155
  * starting node from which the height of the binary tree is calculated. It can be either a node
168
- * object (`N`), a key value of a node in the tree (`BinaryTreeNodeKey`), or `null` if no starting
156
+ * object (`N`), a key value of a node in the tree (`BTNKey`), or `null` if no starting
169
157
  * node is specified. If `
170
158
  * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
171
159
  * height of the binary tree using a recursive approach or an iterative approach. It can have two
172
160
  * possible values:
173
161
  * @returns the height of the binary tree.
174
162
  */
175
- getHeight(beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): number;
163
+ getHeight(beginRoot?: BTNKey | N | null, iterationType?: IterationType): number;
176
164
  /**
177
165
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
178
166
  * recursive or iterative approach.
@@ -192,62 +180,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
192
180
  * @returns The method is returning a boolean value.
193
181
  */
194
182
  isPerfectlyBalanced(beginRoot?: N | null): boolean;
195
- /**
196
- * The function `getNodes` returns an array of nodes that match a given node property, using either
197
- * recursive or iterative traversal.
198
- * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
199
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
200
- * searching for. It can be a specific key value or any other property of the node.
201
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
202
- * value. This value is compared with the `identifier` parameter to determine if the node should be
203
- * included in the result. The `callback` parameter has a default value of
204
- * `this._defaultCallbackByKey`, which
205
- * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
206
- * first node that matches the identifier. If set to true, the function will return an array with
207
- * only one element (or an empty array if no matching node is found). If set to false (default), the
208
- * function will continue searching for all
209
- * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which the
210
- * traversal of the binary tree will begin. It is optional and defaults to the root of the binary
211
- * tree.
212
- * @param iterationType - The `iterationType` parameter determines the type of iteration used to
213
- * traverse the binary tree. It can have two possible values:
214
- * @returns The function `getNodes` returns an array of nodes (`N[]`).
215
- */
216
- getNodes<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
217
- /**
218
- * The function checks if a binary tree has a node with a given property or key.
219
- * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
220
- * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
221
- * generic type `N`.
222
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
223
- * matches the desired criteria. It takes a node as input and returns a boolean value indicating
224
- * whether the node matches the criteria or not. The default callback function
225
- * `this._defaultCallbackByKey` is used if no callback function is
226
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
227
- * the node from which the search should begin. By default, it is set to `this.root`, which means the
228
- * search will start from the root node of the binary tree. However, you can provide a different node
229
- * as
230
- * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
231
- * performed when searching for nodes in the binary tree. It can have one of the following values:
232
- * @returns a boolean value.
233
- */
234
- has<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): boolean;
235
- /**
236
- * The function `get` returns the first node in a binary tree that matches the given property or key.
237
- * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
238
- * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
239
- * type.
240
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
241
- * matches the desired criteria. It takes a node as input and returns a boolean value indicating
242
- * whether the node matches the criteria or not. The default callback function
243
- * (`this._defaultCallbackByKey`) is used if no callback function is
244
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
245
- * the root node from which the search should begin.
246
- * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
247
- * performed when searching for a node in the binary tree. It can have one of the following values:
248
- * @returns either the found node (of type N) or null if no node is found.
249
- */
250
- get<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
183
+ getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
184
+ getNodes<C extends BTNCallback<N, N>>(identifier: N | null, callback: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
185
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
186
+ has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N, iterationType?: IterationType): boolean;
187
+ has<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, beginRoot?: N, iterationType?: IterationType): boolean;
188
+ has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C, beginRoot?: N, iterationType?: IterationType): boolean;
189
+ get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N, iterationType?: IterationType): N | null;
190
+ get<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, beginRoot?: N, iterationType?: IterationType): N | null;
191
+ get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: N, iterationType?: IterationType): N | null;
251
192
  /**
252
193
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
253
194
  * up to the root node, with the option to reverse the order of the nodes.
@@ -262,15 +203,15 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
262
203
  /**
263
204
  * The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
264
205
  * iterative traversal.
265
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
206
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
266
207
  * for finding the leftmost node in a binary tree. It can be either a node object (`N`), a key value
267
- * of a node (`BinaryTreeNodeKey`), or `null` if the tree is empty.
208
+ * of a node (`BTNKey`), or `null` if the tree is empty.
268
209
  * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
269
210
  * be performed when finding the leftmost node in a binary tree. It can have two possible values:
270
211
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in a binary tree. If there is
271
212
  * no leftmost node, it returns `null`.
272
213
  */
273
- getLeftMost(beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): N | null;
214
+ getLeftMost(beginRoot?: BTNKey | N | null, iterationType?: IterationType): N | null;
274
215
  /**
275
216
  * The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
276
217
  * iteratively.
@@ -309,14 +250,14 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
309
250
  * subtree traversal. It takes a single argument, which is the current node being traversed, and
310
251
  * returns a value. The return values from each callback invocation will be collected and returned as
311
252
  * an array.
312
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
253
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
313
254
  * for traversing the subtree. It can be either a node object, a key value of a node, or `null` to
314
255
  * start from the root of the tree.
315
256
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
316
257
  * performed on the binary tree. It can have two possible values:
317
- * @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
258
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
318
259
  */
319
- subTreeTraverse<C extends OneParamCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
260
+ subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null, iterationType?: IterationType): ReturnType<C>[];
320
261
  /**
321
262
  * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
322
263
  * function on each node according to a specified order pattern.
@@ -330,23 +271,23 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
330
271
  * is `null`, an empty array will be returned.
331
272
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
332
273
  * iteration used in the depth-first search algorithm. It can have two possible values:
333
- * @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
274
+ * @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
334
275
  */
335
- dfs<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
276
+ dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
336
277
  /**
337
278
  * The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
338
279
  * function on each node.
339
280
  * @param callback - The `callback` parameter is a function that will be called for each node in the
340
281
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
341
- * `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
282
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
342
283
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
343
284
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
344
285
  * will not be performed and an empty array will be returned.
345
286
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
346
287
  * in the breadth-first search (BFS) algorithm. It can have two possible values:
347
- * @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
288
+ * @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
348
289
  */
349
- bfs<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
290
+ bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
350
291
  /**
351
292
  * The `listLevels` function takes a binary tree node and a callback function, and returns an array
352
293
  * of arrays representing the levels of the tree.
@@ -362,7 +303,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
362
303
  * level in a binary tree. Each inner array contains the return type of the provided callback
363
304
  * function `C` applied to the nodes at that level.
364
305
  */
365
- listLevels<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
306
+ listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
366
307
  /**
367
308
  * The function returns the predecessor node of a given node in a binary tree.
368
309
  * @param {N} node - The parameter "node" represents a node in a binary tree.
@@ -373,7 +314,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
373
314
  * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
374
315
  * algorithm and returns an array of values obtained by applying a callback function to each node.
375
316
  * @param callback - The `callback` parameter is a function that will be called on each node in the
376
- * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
317
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
377
318
  * default value for this parameter is `this._defaultCallbackByKey`.
378
319
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
379
320
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
@@ -381,9 +322,19 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
381
322
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
382
323
  * traversal. It specifies the root node of the tree from which the traversal should begin. If
383
324
  * `beginRoot` is `null`, an empty array will be returned.
384
- * @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
325
+ * @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
326
+ */
327
+ morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
328
+ /**
329
+ * The above function is an iterator for a binary tree that can be used to traverse the tree in
330
+ * either an iterative or recursive manner.
331
+ * @param node - The `node` parameter represents the current node in the binary tree from which the
332
+ * iteration starts. It is an optional parameter with a default value of `this.root`, which means
333
+ * that if no node is provided, the iteration will start from the root of the binary tree.
334
+ * @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
335
+ * binary tree nodes in a specific order.
385
336
  */
386
- morris<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
337
+ [Symbol.iterator](node?: N | null): Generator<BTNKey, void, undefined>;
387
338
  /**
388
339
  * Swap the data of two nodes in the binary tree.
389
340
  * @param {N} srcNode - The source node to swap.
@@ -398,7 +349,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
398
349
  * the tree's structure should be restored to its original state to maintain the tree's integrity.
399
350
  * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
400
351
  */
401
- protected _defaultCallbackByKey: OneParamCallback<N, BinaryTreeNodeKey>;
352
+ protected _defaultCallbackByKey: BTNCallback<N, BTNKey>;
402
353
  /**
403
354
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
404
355
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to