min-heap-typed 1.39.2 → 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 (45) 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 +49 -108
  4. package/dist/data-structures/binary-tree/binary-tree.js +27 -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/interfaces/binary-tree.d.ts +4 -4
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -2
  13. package/dist/types/helpers.d.ts +1 -1
  14. package/package.json +1 -1
  15. package/src/data-structures/binary-tree/avl-tree.ts +13 -12
  16. package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
  17. package/src/data-structures/binary-tree/binary-tree.ts +130 -60
  18. package/src/data-structures/binary-tree/bst.ts +31 -32
  19. package/src/data-structures/binary-tree/rb-tree.ts +7 -6
  20. package/src/data-structures/binary-tree/tree-multiset.ts +16 -15
  21. package/src/data-structures/graph/abstract-graph.ts +11 -10
  22. package/src/data-structures/graph/directed-graph.ts +2 -1
  23. package/src/data-structures/graph/undirected-graph.ts +5 -4
  24. package/src/data-structures/hash/hash-map.ts +1 -1
  25. package/src/data-structures/hash/tree-map.ts +1 -2
  26. package/src/data-structures/hash/tree-set.ts +1 -2
  27. package/src/data-structures/heap/heap.ts +2 -2
  28. package/src/data-structures/heap/max-heap.ts +1 -1
  29. package/src/data-structures/heap/min-heap.ts +1 -1
  30. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  31. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  32. package/src/data-structures/matrix/matrix.ts +1 -1
  33. package/src/data-structures/matrix/vector2d.ts +1 -2
  34. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  35. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  36. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  37. package/src/data-structures/queue/deque.ts +4 -5
  38. package/src/data-structures/queue/queue.ts +1 -1
  39. package/src/interfaces/binary-tree.ts +4 -4
  40. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  41. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  42. package/src/types/data-structures/matrix/navigator.ts +1 -1
  43. package/src/types/helpers.ts +1 -1
  44. package/src/types/utils/utils.ts +1 -1
  45. package/src/types/utils/validate-type.ts +2 -2
@@ -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 { BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, OneParamCallback } 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,9 @@ 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.
385
326
  */
386
- morris<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
327
+ morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
387
328
  /**
388
329
  * The above function is an iterator for a binary tree that can be used to traverse the tree in
389
330
  * either an iterative or recursive manner.
@@ -393,7 +334,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
393
334
  * @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
394
335
  * binary tree nodes in a specific order.
395
336
  */
396
- [Symbol.iterator](node?: N | null): Generator<BinaryTreeNodeKey, void, undefined>;
337
+ [Symbol.iterator](node?: N | null): Generator<BTNKey, void, undefined>;
397
338
  /**
398
339
  * Swap the data of two nodes in the binary tree.
399
340
  * @param {N} srcNode - The source node to swap.
@@ -408,7 +349,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
408
349
  * the tree's structure should be restored to its original state to maintain the tree's integrity.
409
350
  * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
410
351
  */
411
- protected _defaultCallbackByKey: OneParamCallback<N, BinaryTreeNodeKey>;
352
+ protected _defaultCallbackByKey: BTNCallback<N, BTNKey>;
412
353
  /**
413
354
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
414
355
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
@@ -19,7 +19,7 @@ const queue_1 = require("../queue");
19
19
  class BinaryTreeNode {
20
20
  /**
21
21
  * Creates a new instance of BinaryTreeNode.
22
- * @param {BinaryTreeNodeKey} key - The key associated with the node.
22
+ * @param {BTNKey} key - The key associated with the node.
23
23
  * @param {V} val - The value stored in the node.
24
24
  */
25
25
  constructor(key, val) {
@@ -130,7 +130,7 @@ class BinaryTree {
130
130
  }
131
131
  /**
132
132
  * Creates a new instance of BinaryTreeNode with the given key and value.
133
- * @param {BinaryTreeNodeKey} key - The key for the new node.
133
+ * @param {BTNKey} key - The key for the new node.
134
134
  * @param {V} val - The value for the new node.
135
135
  * @returns {N} - The newly created BinaryTreeNode.
136
136
  */
@@ -153,7 +153,7 @@ class BinaryTree {
153
153
  }
154
154
  /**
155
155
  * Add a node with the given key and value to the binary tree.
156
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The key or node to add to the binary tree.
156
+ * @param {BTNKey | N | null} keyOrNode - The key or node to add to the binary tree.
157
157
  * @param {V} val - The value for the new node (optional).
158
158
  * @returns {N | null | undefined} - The inserted node, or null if nothing was inserted, or undefined if the operation failed.
159
159
  */
@@ -217,7 +217,7 @@ class BinaryTree {
217
217
  /**
218
218
  * The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
219
219
  * values, and adds them to the binary tree.
220
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
220
+ * @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of BTNKey or BinaryTreeNode
221
221
  * objects, or null values.
222
222
  * @param {V[]} [values] - The `values` parameter is an optional array of values (`V[]`) that corresponds to
223
223
  * the nodes or node IDs being added. It is used to set the value of each node being added. If `values` is not provided,
@@ -239,8 +239,8 @@ class BinaryTree {
239
239
  }
240
240
  /**
241
241
  * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
242
- * @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
243
- * `BinaryTreeNodeKey` or `N` values.
242
+ * @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
243
+ * `BTNKey` or `N` values.
244
244
  * @param {N[] | Array<V>} [data] - The `data` parameter is an optional array of values that will be assigned to
245
245
  * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
246
246
  * array. Each value in the `data` array will be assigned to the
@@ -253,11 +253,11 @@ class BinaryTree {
253
253
  /**
254
254
  * The `delete` function removes a node from a binary search tree and returns the deleted node along
255
255
  * with the parent node that needs to be balanced.
256
- * a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
256
+ * a key (`BTNKey`). If it is a key, the function will find the corresponding node in the
257
257
  * binary tree.
258
258
  * @returns an array of `BinaryTreeDeletedResult<N>` objects.
259
259
  * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
260
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
260
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
261
261
  * searching for. It can be a specific key value or any other property of the node.
262
262
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
263
263
  * value. This value is compared with the `identifier` parameter to determine if the node should be
@@ -312,10 +312,10 @@ class BinaryTree {
312
312
  /**
313
313
  * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
314
314
  * specified root node.
315
- * @param {BinaryTreeNodeKey | N | null} distNode - The `distNode` parameter represents the node
315
+ * @param {BTNKey | N | null} distNode - The `distNode` parameter represents the node
316
316
  * whose depth we want to find in the binary tree. It can be either a node object (`N`), a key value
317
- * of the node (`BinaryTreeNodeKey`), or `null`.
318
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
317
+ * of the node (`BTNKey`), or `null`.
318
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter represents the
319
319
  * starting node from which we want to calculate the depth. It can be either a node object or the key
320
320
  * of a node in the binary tree. If no value is provided for `beginRoot`, it defaults to the root
321
321
  * node of the binary tree.
@@ -339,9 +339,9 @@ class BinaryTree {
339
339
  /**
340
340
  * The `getHeight` function calculates the maximum height of a binary tree using either recursive or
341
341
  * iterative approach.
342
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
342
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter represents the
343
343
  * starting node from which the height of the binary tree is calculated. It can be either a node
344
- * object (`N`), a key value of a node in the tree (`BinaryTreeNodeKey`), or `null` if no starting
344
+ * object (`N`), a key value of a node in the tree (`BTNKey`), or `null` if no starting
345
345
  * node is specified. If `
346
346
  * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
347
347
  * height of the binary tree using a recursive approach or an iterative approach. It can have two
@@ -450,7 +450,7 @@ class BinaryTree {
450
450
  * The function `getNodes` returns an array of nodes that match a given node property, using either
451
451
  * recursive or iterative traversal.
452
452
  * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
453
- * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
453
+ * `BTNKey` or a generic type `N`. It represents the property of the node that we are
454
454
  * searching for. It can be a specific key value or any other property of the node.
455
455
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
456
456
  * value. This value is compared with the `identifier` parameter to determine if the node should be
@@ -506,8 +506,8 @@ class BinaryTree {
506
506
  }
507
507
  /**
508
508
  * The function checks if a binary tree has a node with a given property or key.
509
- * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
510
- * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
509
+ * @param {BTNKey | N} identifier - The `identifier` parameter is the key or value of
510
+ * the node that you want to find in the binary tree. It can be either a `BTNKey` or a
511
511
  * generic type `N`.
512
512
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
513
513
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
@@ -529,8 +529,8 @@ class BinaryTree {
529
529
  }
530
530
  /**
531
531
  * The function `get` returns the first node in a binary tree that matches the given property or key.
532
- * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
533
- * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
532
+ * @param {BTNKey | N} identifier - The `identifier` parameter is the key or value of
533
+ * the node that you want to find in the binary tree. It can be either a `BTNKey` or `N`
534
534
  * type.
535
535
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
536
536
  * matches the desired criteria. It takes a node as input and returns a boolean value indicating
@@ -574,9 +574,9 @@ class BinaryTree {
574
574
  /**
575
575
  * The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
576
576
  * iterative traversal.
577
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
577
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
578
578
  * for finding the leftmost node in a binary tree. It can be either a node object (`N`), a key value
579
- * of a node (`BinaryTreeNodeKey`), or `null` if the tree is empty.
579
+ * of a node (`BTNKey`), or `null` if the tree is empty.
580
580
  * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
581
581
  * be performed when finding the leftmost node in a binary tree. It can have two possible values:
582
582
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in a binary tree. If there is
@@ -698,12 +698,12 @@ class BinaryTree {
698
698
  * subtree traversal. It takes a single argument, which is the current node being traversed, and
699
699
  * returns a value. The return values from each callback invocation will be collected and returned as
700
700
  * an array.
701
- * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
701
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
702
702
  * for traversing the subtree. It can be either a node object, a key value of a node, or `null` to
703
703
  * start from the root of the tree.
704
704
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
705
705
  * performed on the binary tree. It can have two possible values:
706
- * @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
706
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
707
707
  */
708
708
  subTreeTraverse(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
709
709
  if (typeof beginRoot === 'number')
@@ -743,7 +743,7 @@ class BinaryTree {
743
743
  * is `null`, an empty array will be returned.
744
744
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
745
745
  * iteration used in the depth-first search algorithm. It can have two possible values:
746
- * @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
746
+ * @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
747
747
  */
748
748
  dfs(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root, iterationType = types_1.IterationType.ITERATIVE) {
749
749
  if (!beginRoot)
@@ -820,13 +820,13 @@ class BinaryTree {
820
820
  * function on each node.
821
821
  * @param callback - The `callback` parameter is a function that will be called for each node in the
822
822
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
823
- * `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
823
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
824
824
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
825
825
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
826
826
  * will not be performed and an empty array will be returned.
827
827
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
828
828
  * in the breadth-first search (BFS) algorithm. It can have two possible values:
829
- * @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
829
+ * @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
830
830
  */
831
831
  bfs(callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
832
832
  if (!beginRoot)
@@ -934,7 +934,7 @@ class BinaryTree {
934
934
  * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
935
935
  * algorithm and returns an array of values obtained by applying a callback function to each node.
936
936
  * @param callback - The `callback` parameter is a function that will be called on each node in the
937
- * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
937
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
938
938
  * default value for this parameter is `this._defaultCallbackByKey`.
939
939
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
940
940
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
@@ -942,7 +942,7 @@ class BinaryTree {
942
942
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
943
943
  * traversal. It specifies the root node of the tree from which the traversal should begin. If
944
944
  * `beginRoot` is `null`, an empty array will be returned.
945
- * @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
945
+ * @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
946
946
  */
947
947
  morris(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root) {
948
948
  if (beginRoot === null)