min-heap-typed 1.38.5 → 1.38.7

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.
@@ -7,12 +7,13 @@
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
10
+ import { MapCallback } from '../../types';
10
11
  import { IBinaryTree } from '../../interfaces';
11
- export declare class AVLTreeNode<V = any, FAMILY extends AVLTreeNode<V, FAMILY> = AVLTreeNodeNested<V>> extends BSTNode<V, FAMILY> {
12
+ export declare class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
12
13
  height: number;
13
14
  constructor(key: BinaryTreeNodeKey, val?: V);
14
15
  }
15
- export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IBinaryTree<N> {
16
+ export declare class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode> extends BST<V, N> implements IBinaryTree<V, N> {
16
17
  /**
17
18
  * This is a constructor function for an AVL tree data structure in TypeScript.
18
19
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
@@ -25,11 +26,11 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
25
26
  * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
26
27
  * the new node. It is used to determine the position of the node in the binary search tree.
27
28
  * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
28
- * type `N['val']`, which means it can be any value that is assignable to the `val` property of the
29
+ * type `V`, which means it can be any value that is assignable to the `val` property of the
29
30
  * node type `N`.
30
31
  * @returns a new AVLTreeNode object with the specified key and value.
31
32
  */
32
- createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
33
+ createNode(key: BinaryTreeNodeKey, val?: V): N;
33
34
  /**
34
35
  * The function overrides the add method of a binary tree node and balances the tree after inserting
35
36
  * a new node.
@@ -39,15 +40,20 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
39
40
  * are adding to the binary search tree.
40
41
  * @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
41
42
  */
42
- add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
43
+ add(keyOrNode: BinaryTreeNodeKey | N | null, val?: V): N | null | undefined;
43
44
  /**
44
45
  * The function overrides the delete method of a binary tree and balances the tree after deleting a
45
46
  * node if necessary.
46
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
47
- * (`N`) or a key value (`BinaryTreeNodeKey`).
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
49
+ * searching for. It can be a specific key value or any other property of the node.
50
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
51
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
52
+ * included in the result. The `callback` parameter has a default value of
53
+ * `this._defaultCallbackByKey`
48
54
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
49
55
  */
50
- delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
56
+ delete<C extends MapCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
51
57
  /**
52
58
  * The function swaps the key, value, and height properties between two nodes in a binary tree.
53
59
  * @param {N} srcNode - The `srcNode` parameter represents the source node that needs to be swapped
@@ -31,7 +31,7 @@ class AVLTree extends bst_1.BST {
31
31
  * @param {BinaryTreeNodeKey} 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
- * type `N['val']`, which means it can be any value that is assignable to the `val` property of the
34
+ * type `V`, which means it can be any value that is assignable to the `val` property of the
35
35
  * node type `N`.
36
36
  * @returns a new AVLTreeNode object with the specified key and value.
37
37
  */
@@ -57,12 +57,17 @@ class AVLTree extends bst_1.BST {
57
57
  /**
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
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
61
- * (`N`) or a key value (`BinaryTreeNodeKey`).
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
62
+ * searching for. It can be a specific key value or any other property of the node.
63
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
64
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
65
+ * included in the result. The `callback` parameter has a default value of
66
+ * `this._defaultCallbackByKey`
62
67
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
63
68
  */
64
- delete(nodeOrKey) {
65
- const deletedResults = super.delete(nodeOrKey);
69
+ delete(identifier, callback = this._defaultCallbackByKey) {
70
+ const deletedResults = super.delete(identifier, callback);
66
71
  for (const { needBalanced } of deletedResults) {
67
72
  if (needBalanced) {
68
73
  this._balancePath(needBalanced);
@@ -6,14 +6,14 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { BFSCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, MapCallback } from '../../types';
9
- import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
9
+ import { BinaryTreeDeletedResult, DefaultMapCallback, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
12
12
  * Represents a node in a binary tree.
13
13
  * @template V - The type of data stored in the node.
14
- * @template FAMILY - The type of the family relationship in the binary tree.
14
+ * @template N - The type of the family relationship in the binary tree.
15
15
  */
16
- export declare class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FAMILY> = BinaryTreeNodeNested<V>> {
16
+ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> {
17
17
  /**
18
18
  * The key associated with the node.
19
19
  */
@@ -25,7 +25,7 @@ export declare class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FA
25
25
  /**
26
26
  * The parent node of the current node.
27
27
  */
28
- parent: FAMILY | null | undefined;
28
+ parent: N | null | undefined;
29
29
  /**
30
30
  * Creates a new instance of BinaryTreeNode.
31
31
  * @param {BinaryTreeNodeKey} key - The key associated with the node.
@@ -36,22 +36,22 @@ export declare class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FA
36
36
  /**
37
37
  * Get the left child node.
38
38
  */
39
- get left(): FAMILY | null | undefined;
39
+ get left(): N | null | undefined;
40
40
  /**
41
41
  * Set the left child node.
42
- * @param {FAMILY | null | undefined} v - The left child node.
42
+ * @param {N | null | undefined} v - The left child node.
43
43
  */
44
- set left(v: FAMILY | null | undefined);
44
+ set left(v: N | null | undefined);
45
45
  private _right;
46
46
  /**
47
47
  * Get the right child node.
48
48
  */
49
- get right(): FAMILY | null | undefined;
49
+ get right(): N | null | undefined;
50
50
  /**
51
51
  * Set the right child node.
52
- * @param {FAMILY | null | undefined} v - The right child node.
52
+ * @param {N | null | undefined} v - The right child node.
53
53
  */
54
- set right(v: FAMILY | null | undefined);
54
+ set right(v: N | null | undefined);
55
55
  /**
56
56
  * Get the position of the node within its family.
57
57
  * @returns {FamilyPosition} - The family position of the node.
@@ -62,13 +62,22 @@ export declare class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FA
62
62
  * Represents a binary tree data structure.
63
63
  * @template N - The type of the binary tree's nodes.
64
64
  */
65
- export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> implements IBinaryTree<N> {
66
- private _loopType;
65
+ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode> implements IBinaryTree<V, N> {
67
66
  /**
68
67
  * Creates a new instance of BinaryTree.
69
68
  * @param {BinaryTreeOptions} [options] - The options for the binary tree.
70
69
  */
71
70
  constructor(options?: BinaryTreeOptions);
71
+ private _iterationType;
72
+ /**
73
+ * Get the iteration type used in the binary tree.
74
+ */
75
+ get iterationType(): IterationType;
76
+ /**
77
+ * Set the iteration type for the binary tree.
78
+ * @param {IterationType} v - The new iteration type to set.
79
+ */
80
+ set iterationType(v: IterationType);
72
81
  private _root;
73
82
  /**
74
83
  * Get the root node of the binary tree.
@@ -79,22 +88,13 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
79
88
  * Get the number of nodes in the binary tree.
80
89
  */
81
90
  get size(): number;
82
- /**
83
- * Get the iteration type used in the binary tree.
84
- */
85
- get iterationType(): IterationType;
86
- /**
87
- * Set the iteration type for the binary tree.
88
- * @param {IterationType} v - The new iteration type to set.
89
- */
90
- set iterationType(v: IterationType);
91
91
  /**
92
92
  * Creates a new instance of BinaryTreeNode with the given key and value.
93
93
  * @param {BinaryTreeNodeKey} key - The key for the new node.
94
- * @param {N['val']} val - The value for the new node.
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?: N['val']): N;
97
+ createNode(key: BinaryTreeNodeKey, val?: V): N;
98
98
  /**
99
99
  * Clear the binary tree, removing all nodes.
100
100
  */
@@ -107,57 +107,50 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
107
107
  /**
108
108
  * Add a node with the given key and value to the binary tree.
109
109
  * @param {BinaryTreeNodeKey | N | null} keyOrNode - The key or node to add to the binary tree.
110
- * @param {N['val']} val - The value for the new node (optional).
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?: N['val']): N | null | undefined;
113
+ add(keyOrNode: BinaryTreeNodeKey | 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
117
  * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
118
118
  * objects, or null values.
119
- * @param {N['val'][]} [values] - The `values` parameter is an optional array of values (`N['val'][]`) that corresponds to
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?: N['val'][]): (N | null | undefined)[];
124
+ addMany(keysOrNodes: (BinaryTreeNodeKey | 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
127
  * @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
128
128
  * `BinaryTreeNodeKey` or `N` values.
129
- * @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
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?: N[] | Array<N['val']>): 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
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node (`N`) or
139
- * a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
140
- * binary tree.
141
- * @returns an array of `BinaryTreeDeletedResult<N>` objects.
142
- */
143
- delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
134
+ refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: Array<V>): boolean;
135
+ delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N): BinaryTreeDeletedResult<N>[];
136
+ delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
144
137
  /**
145
138
  * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
146
139
  * specified root node.
147
- * @param {N | BinaryTreeNodeKey | null} distNode - The `distNode` parameter represents the node
140
+ * @param {BinaryTreeNodeKey | N | null} distNode - The `distNode` parameter represents the node
148
141
  * whose depth we want to find in the binary tree. It can be either a node object (`N`), a key value
149
142
  * of the node (`BinaryTreeNodeKey`), or `null`.
150
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter represents the
143
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
151
144
  * starting node from which we want to calculate the depth. It can be either a node object or the key
152
145
  * of a node in the binary tree. If no value is provided for `beginRoot`, it defaults to the root
153
146
  * node of the binary tree.
154
147
  * @returns the depth of the `distNode` relative to the `beginRoot`.
155
148
  */
156
- getDepth(distNode: N | BinaryTreeNodeKey | null, beginRoot?: N | BinaryTreeNodeKey | null): number;
149
+ getDepth(distNode: BinaryTreeNodeKey | N | null, beginRoot?: BinaryTreeNodeKey | N | null): number;
157
150
  /**
158
151
  * The `getHeight` function calculates the maximum height of a binary tree using either recursive or
159
152
  * iterative approach.
160
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter represents the
153
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
161
154
  * starting node from which the height of the binary tree is calculated. It can be either a node
162
155
  * object (`N`), a key value of a node in the tree (`BinaryTreeNodeKey`), or `null` if no starting
163
156
  * node is specified. If `
@@ -166,7 +159,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
166
159
  * possible values:
167
160
  * @returns the height of the binary tree.
168
161
  */
169
- getHeight(beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): number;
162
+ getHeight(beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): number;
170
163
  /**
171
164
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
172
165
  * recursive or iterative approach.
@@ -186,62 +179,21 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
186
179
  * @returns The method is returning a boolean value.
187
180
  */
188
181
  isPerfectlyBalanced(beginRoot?: N | null): boolean;
189
- /**
190
- * The function `getNodes` returns an array of nodes that match a given node property, using either
191
- * recursive or iterative traversal.
192
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a
193
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
194
- * searching for. It can be a specific key value or any other property of the node.
195
- * @param callback - The `callback` parameter is a function that takes a node as input and returns a
196
- * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
197
- * included in the result. The `callback` parameter has a default value of
198
- * `this._defaultCallbackByKey`, which
199
- * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
200
- * first node that matches the nodeProperty. If set to true, the function will return an array with
201
- * only one element (or an empty array if no matching node is found). If set to false (default), the
202
- * function will continue searching for all
203
- * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which the
204
- * traversal of the binary tree will begin. It is optional and defaults to the root of the binary
205
- * tree.
206
- * @param iterationType - The `iterationType` parameter determines the type of iteration used to
207
- * traverse the binary tree. It can have two possible values:
208
- * @returns The function `getNodes` returns an array of nodes (`N[]`).
209
- */
210
- getNodes<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
211
- /**
212
- * The function checks if a binary tree has a node with a given property or key.
213
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
214
- * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
215
- * generic type `N`.
216
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
217
- * matches the desired criteria. It takes a node as input and returns a boolean value indicating
218
- * whether the node matches the criteria or not. The default callback function
219
- * `this._defaultCallbackByKey` is used if no callback function is
220
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
221
- * the node from which the search should begin. By default, it is set to `this.root`, which means the
222
- * search will start from the root node of the binary tree. However, you can provide a different node
223
- * as
224
- * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
225
- * performed when searching for nodes in the binary tree. It can have one of the following values:
226
- * @returns a boolean value.
227
- */
228
- has<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): boolean;
229
- /**
230
- * The function `get` returns the first node in a binary tree that matches the given property or key.
231
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
232
- * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
233
- * type.
234
- * @param callback - The `callback` parameter is a function that is used to determine whether a node
235
- * matches the desired criteria. It takes a node as input and returns a boolean value indicating
236
- * whether the node matches the criteria or not. The default callback function
237
- * (`this._defaultCallbackByKey`) is used if no callback function is
238
- * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
239
- * the root node from which the search should begin.
240
- * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
241
- * performed when searching for a node in the binary tree. It can have one of the following values:
242
- * @returns either the found node (of type N) or null if no node is found.
243
- */
244
- get<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(nodeProperty: BinaryTreeNodeKey | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
182
+ getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N): N[];
183
+ getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): N[];
184
+ getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, onlyOne: boolean): N[];
185
+ getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean): N[];
186
+ getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean, beginRoot: N | null): N[];
187
+ getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, onlyOne: boolean, beginRoot: N | null, iterationType: IterationType): N[];
188
+ has<C extends MapCallback<N>>(identifier: ReturnType<C> | N): boolean;
189
+ has<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): boolean;
190
+ has<C extends MapCallback<N>>(identifier: ReturnType<C> | N, beginRoot: N | null): boolean;
191
+ has<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null): boolean;
192
+ get<C extends MapCallback<N>>(identifier: ReturnType<C> | N): N | null;
193
+ get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): N | null;
194
+ get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, beginRoot: N | null): N | null;
195
+ get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null): N | null;
196
+ get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C, beginRoot: N | null, iterationType: IterationType): N | null;
245
197
  /**
246
198
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
247
199
  * up to the root node, with the option to reverse the order of the nodes.
@@ -256,7 +208,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
256
208
  /**
257
209
  * The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
258
210
  * iterative traversal.
259
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter is the starting point
211
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
260
212
  * for finding the leftmost node in a binary tree. It can be either a node object (`N`), a key value
261
213
  * of a node (`BinaryTreeNodeKey`), or `null` if the tree is empty.
262
214
  * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
@@ -264,7 +216,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
264
216
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in a binary tree. If there is
265
217
  * no leftmost node, it returns `null`.
266
218
  */
267
- getLeftMost(beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): N | null;
219
+ getLeftMost(beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): N | null;
268
220
  /**
269
221
  * The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
270
222
  * iteratively.
@@ -303,14 +255,14 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
303
255
  * subtree traversal. It takes a single argument, which is the current node being traversed, and
304
256
  * returns a value. The return values from each callback invocation will be collected and returned as
305
257
  * an array.
306
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter is the starting point
258
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
307
259
  * for traversing the subtree. It can be either a node object, a key value of a node, or `null` to
308
260
  * start from the root of the tree.
309
261
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
310
262
  * performed on the binary tree. It can have two possible values:
311
263
  * @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
312
264
  */
313
- subTreeTraverse<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): ReturnType<C>[];
265
+ subTreeTraverse<C extends MapCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
314
266
  /**
315
267
  * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
316
268
  * function on each node according to a specified order pattern.
@@ -326,7 +278,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
326
278
  * iteration used in the depth-first search algorithm. It can have two possible values:
327
279
  * @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
328
280
  */
329
- dfs<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
281
+ dfs<C extends MapCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
330
282
  /**
331
283
  * The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
332
284
  * function on each node.
@@ -334,7 +286,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
334
286
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
335
287
  * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
336
288
  * @param {boolean} [withLevel=false] - The `withLevel` parameter is a boolean flag that determines
337
- * whether or not to include the level of each node in the callback function. If `withLevel` is set
289
+ * whether to include the level of each node in the callback function. If `withLevel` is set
338
290
  * to `true`, the level of each node will be passed as an argument to the callback function. If
339
291
  * `withLevel` is
340
292
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
@@ -365,7 +317,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
365
317
  * `beginRoot` is `null`, an empty array will be returned.
366
318
  * @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
367
319
  */
368
- morris<C extends MapCallback<N> = MapCallback<N, BinaryTreeNodeKey>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
320
+ morris<C extends MapCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
369
321
  /**
370
322
  * Swap the data of two nodes in the binary tree.
371
323
  * @param {N} srcNode - The source node to swap.
@@ -380,7 +332,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
380
332
  * the tree's structure should be restored to its original state to maintain the tree's integrity.
381
333
  * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
382
334
  */
383
- protected _defaultCallbackByKey: (node: N) => number;
335
+ protected _defaultCallbackByKey: DefaultMapCallback<N>;
384
336
  /**
385
337
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
386
338
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to