data-structure-typed 1.38.4 → 1.38.6

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 (47) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +9 -3
  3. package/dist/cjs/data-structures/binary-tree/avl-tree.js +9 -4
  4. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +31 -79
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js +50 -59
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/bst.d.ts +7 -7
  9. package/dist/cjs/data-structures/binary-tree/bst.js +13 -13
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +9 -5
  12. package/dist/cjs/data-structures/binary-tree/tree-multiset.js +9 -5
  13. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  14. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +12 -3
  15. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  16. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +17 -4
  17. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +2 -0
  18. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  19. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  20. package/dist/cjs/types/helpers.d.ts +2 -0
  21. package/dist/cjs/types/helpers.js.map +1 -1
  22. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +9 -3
  23. package/dist/mjs/data-structures/binary-tree/avl-tree.js +9 -4
  24. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +31 -79
  25. package/dist/mjs/data-structures/binary-tree/binary-tree.js +50 -59
  26. package/dist/mjs/data-structures/binary-tree/bst.d.ts +7 -7
  27. package/dist/mjs/data-structures/binary-tree/bst.js +13 -13
  28. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +9 -5
  29. package/dist/mjs/data-structures/binary-tree/tree-multiset.js +9 -5
  30. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +12 -3
  31. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +17 -4
  32. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -0
  33. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  34. package/dist/mjs/types/helpers.d.ts +2 -0
  35. package/dist/umd/index.global.js +1 -1
  36. package/dist/umd/index.global.js.map +1 -1
  37. package/package.json +5 -5
  38. package/src/data-structures/binary-tree/avl-tree.ts +13 -4
  39. package/src/data-structures/binary-tree/binary-tree.ts +113 -69
  40. package/src/data-structures/binary-tree/bst.ts +17 -17
  41. package/src/data-structures/binary-tree/rb-tree.ts +2 -2
  42. package/src/data-structures/binary-tree/tree-multiset.ts +14 -6
  43. package/src/data-structures/linked-list/doubly-linked-list.ts +2 -5
  44. package/src/data-structures/linked-list/singly-linked-list.ts +2 -7
  45. package/src/interfaces/binary-tree.ts +2 -2
  46. package/src/types/helpers.ts +4 -0
  47. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +14 -14
@@ -1 +1 @@
1
- {"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,oBAAoB;IAC/B;;;;OAIG;IACH,YAAY,GAAM;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,GAAG,CAAC,KAAQ;QACd,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;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,IAAI,YAAY,EAAE;YAChB,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;YACjC,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;YAC5B,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,EAAE;gBAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;aACrB;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAQ;QACvB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE;YACd,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,EAAE;gBACzB,KAAK,EAAE,CAAC;aACT;YACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE;YACd,MAAM,OAAO,CAAC,GAAG,CAAC;YAClB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;IACH,CAAC;CACF;AA7cD,4CA6cC"}
1
+ {"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,oBAAoB;IAC/B;;;;OAIG;IACH,YAAY,GAAM;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAID,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,C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Y,oBAAoB,EAAE;YACvD,YAAY,GAAG,mBAAmB,CAAC;SACpC;aAAM;YACL,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;SACnD;QAED,IAAI,YAAY,EAAE;YAChB,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC;YACnD,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;YACjC,YAAY,CAAC,IAAI,GAAG,OAAO,CAAC;YAC5B,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,EAAE;gBAC9B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;aACrB;YACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,KAAQ;QACvB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE;YACd,IAAI,OAAO,CAAC,GAAG,KAAK,KAAK,EAAE;gBACzB,KAAK,EAAE,CAAC;aACT;YACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE;YACd,MAAM,OAAO,CAAC,GAAG,CAAC;YAClB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;SACxB;IACH,CAAC;CACF;AAxcD,4CAwcC"}
@@ -1,7 +1,7 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../types';
2
+ import { BinaryTreeDeletedResult, BinaryTreeNodeKey, MapCallback } from '../types';
3
3
  export interface IBinaryTree<N extends BinaryTreeNode<N['val'], N>> {
4
4
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
5
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
6
+ delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
7
7
  }
@@ -1,6 +1,8 @@
1
+ import { BinaryTreeNodeKey } from './data-structures';
1
2
  export type Comparator<T> = (a: T, b: T) => number;
2
3
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
3
4
  export type MapCallback<N, D = any> = (node: N) => D;
5
+ export type DefaultMapCallback<N, D = BinaryTreeNodeKey> = (node: N) => D;
4
6
  export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
5
7
  export declare enum CP {
6
8
  lt = "lt",
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":";;;AAQA,IAAY,EAIX;AAJD,WAAY,EAAE;IACZ,eAAS,CAAA;IACT,eAAS,CAAA;IACT,eAAS,CAAA;AACX,CAAC,EAJW,EAAE,kBAAF,EAAE,QAIb"}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/types/helpers.ts"],"names":[],"mappings":";;;AAYA,IAAY,EAIX;AAJD,WAAY,EAAE;IACZ,eAAS,CAAA;IACT,eAAS,CAAA;IACT,eAAS,CAAA;AACX,CAAC,EAJW,EAAE,kBAAF,EAAE,QAIb"}
@@ -8,6 +8,7 @@
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
+ import { MapCallback } from '../../types';
11
12
  export declare class AVLTreeNode<V = any, FAMILY extends AVLTreeNode<V, FAMILY> = AVLTreeNodeNested<V>> extends BSTNode<V, FAMILY> {
12
13
  height: number;
13
14
  constructor(key: BinaryTreeNodeKey, val?: V);
@@ -43,11 +44,16 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> e
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
@@ -58,12 +58,17 @@ class AVLTree extends bst_1.BST {
58
58
  /**
59
59
  * The function overrides the delete method of a binary tree and balances the tree after deleting a
60
60
  * node if necessary.
61
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
62
- * (`N`) or a key value (`BinaryTreeNodeKey`).
61
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
62
+ * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
63
+ * searching for. It can be a specific key value or any other property of the node.
64
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
65
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
66
+ * included in the result. The `callback` parameter has a default value of
67
+ * `this._defaultCallbackByKey`
63
68
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
64
69
  */
65
- delete(nodeOrKey) {
66
- const deletedResults = super.delete(nodeOrKey);
70
+ delete(identifier, callback = this._defaultCallbackByKey) {
71
+ const deletedResults = super.delete(identifier, callback);
67
72
  for (const { needBalanced } of deletedResults) {
68
73
  if (needBalanced) {
69
74
  this._balancePath(needBalanced);
@@ -6,7 +6,7 @@
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.
@@ -132,32 +132,25 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
132
132
  * @returns The method is returning a boolean value.
133
133
  */
134
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>[];
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
@@ -78,35 +78,16 @@ class BinaryTreeNode {
78
78
  */
79
79
  get familyPosition() {
80
80
  const that = this;
81
- if (that.parent) {
82
- if (that.parent.left === that) {
83
- if (that.left || that.right) {
84
- return types_1.FamilyPosition.ROOT_LEFT;
85
- }
86
- else {
87
- return types_1.FamilyPosition.LEFT;
88
- }
89
- }
90
- else if (that.parent.right === that) {
91
- if (that.left || that.right) {
92
- return types_1.FamilyPosition.ROOT_RIGHT;
93
- }
94
- else {
95
- return types_1.FamilyPosition.RIGHT;
96
- }
97
- }
98
- else {
99
- return types_1.FamilyPosition.MAL_NODE;
100
- }
81
+ if (!this.parent) {
82
+ return this.left || this.right ? types_1.FamilyPosition.ROOT : types_1.FamilyPosition.ISOLATED;
101
83
  }
102
- else {
103
- if (that.left || that.right) {
104
- return types_1.FamilyPosition.ROOT;
105
- }
106
- else {
107
- return types_1.FamilyPosition.ISOLATED;
108
- }
84
+ if (this.parent.left === that) {
85
+ return this.left || this.right ? types_1.FamilyPosition.ROOT_LEFT : types_1.FamilyPosition.LEFT;
109
86
  }
87
+ else if (this.parent.right === that) {
88
+ return this.left || this.right ? types_1.FamilyPosition.ROOT_RIGHT : types_1.FamilyPosition.RIGHT;
89
+ }
90
+ return types_1.FamilyPosition.MAL_NODE;
110
91
  }
111
92
  }
112
93
  exports.BinaryTreeNode = BinaryTreeNode;
@@ -216,7 +197,8 @@ class BinaryTree {
216
197
  else {
217
198
  return;
218
199
  }
219
- const existNode = keyOrNode ? this.get(keyOrNode, this._defaultCallbackByKey) : undefined;
200
+ const key = typeof keyOrNode === 'number' ? keyOrNode : keyOrNode ? keyOrNode.key : undefined;
201
+ const existNode = key !== undefined ? this.get(key, this._defaultCallbackByKey) : undefined;
220
202
  if (this.root) {
221
203
  if (existNode) {
222
204
  existNode.val = val;
@@ -250,21 +232,16 @@ class BinaryTree {
250
232
  */
251
233
  addMany(keysOrNodes, values) {
252
234
  // TODO not sure addMany not be run multi times
253
- const inserted = [];
254
- for (let i = 0; i < keysOrNodes.length; i++) {
255
- const keyOrNode = keysOrNodes[i];
235
+ return keysOrNodes.map((keyOrNode, i) => {
256
236
  if (keyOrNode instanceof BinaryTreeNode) {
257
- inserted.push(this.add(keyOrNode.key, keyOrNode.val));
258
- continue;
237
+ return this.add(keyOrNode.key, keyOrNode.val);
259
238
  }
260
239
  if (keyOrNode === null) {
261
- inserted.push(this.add(null));
262
- continue;
240
+ return this.add(null);
263
241
  }
264
242
  const val = values?.[i];
265
- inserted.push(this.add(keyOrNode, val));
266
- }
267
- return inserted;
243
+ return this.add(keyOrNode, val);
244
+ });
268
245
  }
269
246
  /**
270
247
  * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
@@ -282,16 +259,24 @@ class BinaryTree {
282
259
  /**
283
260
  * The `delete` function removes a node from a binary search tree and returns the deleted node along
284
261
  * with the parent node that needs to be balanced.
285
- * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node (`N`) or
286
262
  * a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
287
263
  * binary tree.
288
264
  * @returns an array of `BinaryTreeDeletedResult<N>` objects.
265
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
266
+ * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
267
+ * searching for. It can be a specific key value or any other property of the node.
268
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
269
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
270
+ * included in the result. The `callback` parameter has a default value of
271
+ * `this._defaultCallbackByKey`, which
289
272
  */
290
- delete(nodeOrKey) {
273
+ delete(identifier, callback = this._defaultCallbackByKey) {
291
274
  const bstDeletedResult = [];
292
275
  if (!this.root)
293
276
  return bstDeletedResult;
294
- const curr = typeof nodeOrKey === 'number' ? this.get(nodeOrKey) : nodeOrKey;
277
+ if (identifier instanceof BinaryTreeNode)
278
+ callback = (node => node);
279
+ const curr = this.get(identifier, callback);
295
280
  if (!curr)
296
281
  return bstDeletedResult;
297
282
  const parent = curr?.parent ? curr.parent : null;
@@ -333,10 +318,10 @@ class BinaryTree {
333
318
  /**
334
319
  * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
335
320
  * specified root node.
336
- * @param {N | BinaryTreeNodeKey | null} distNode - The `distNode` parameter represents the node
321
+ * @param {BinaryTreeNodeKey | N | null} distNode - The `distNode` parameter represents the node
337
322
  * whose depth we want to find in the binary tree. It can be either a node object (`N`), a key value
338
323
  * of the node (`BinaryTreeNodeKey`), or `null`.
339
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter represents the
324
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
340
325
  * starting node from which we want to calculate the depth. It can be either a node object or the key
341
326
  * of a node in the binary tree. If no value is provided for `beginRoot`, it defaults to the root
342
327
  * node of the binary tree.
@@ -360,7 +345,7 @@ class BinaryTree {
360
345
  /**
361
346
  * The `getHeight` function calculates the maximum height of a binary tree using either recursive or
362
347
  * iterative approach.
363
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter represents the
348
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter represents the
364
349
  * starting node from which the height of the binary tree is calculated. It can be either a node
365
350
  * object (`N`), a key value of a node in the tree (`BinaryTreeNodeKey`), or `null` if no starting
366
351
  * node is specified. If `
@@ -469,15 +454,15 @@ class BinaryTree {
469
454
  /**
470
455
  * The function `getNodes` returns an array of nodes that match a given node property, using either
471
456
  * recursive or iterative traversal.
472
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a
457
+ * @param {ReturnType<C>} identifier - The `identifier` parameter is either a
473
458
  * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
474
459
  * searching for. It can be a specific key value or any other property of the node.
475
460
  * @param callback - The `callback` parameter is a function that takes a node as input and returns a
476
- * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
461
+ * value. This value is compared with the `identifier` parameter to determine if the node should be
477
462
  * included in the result. The `callback` parameter has a default value of
478
463
  * `this._defaultCallbackByKey`, which
479
464
  * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
480
- * first node that matches the nodeProperty. If set to true, the function will return an array with
465
+ * first node that matches the identifier. If set to true, the function will return an array with
481
466
  * only one element (or an empty array if no matching node is found). If set to false (default), the
482
467
  * function will continue searching for all
483
468
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which the
@@ -487,13 +472,15 @@ class BinaryTree {
487
472
  * traverse the binary tree. It can have two possible values:
488
473
  * @returns The function `getNodes` returns an array of nodes (`N[]`).
489
474
  */
490
- getNodes(nodeProperty, callback = this._defaultCallbackByKey, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
475
+ getNodes(identifier, callback = this._defaultCallbackByKey, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
491
476
  if (!beginRoot)
492
477
  return [];
478
+ if (identifier instanceof BinaryTreeNode)
479
+ callback = (node => node);
493
480
  const ans = [];
494
481
  if (iterationType === types_1.IterationType.RECURSIVE) {
495
482
  const _traverse = (cur) => {
496
- if (callback(cur) === nodeProperty) {
483
+ if (callback(cur) === identifier) {
497
484
  ans.push(cur);
498
485
  if (onlyOne)
499
486
  return;
@@ -510,7 +497,7 @@ class BinaryTree {
510
497
  while (queue.size > 0) {
511
498
  const cur = queue.shift();
512
499
  if (cur) {
513
- if (callback(cur) === nodeProperty) {
500
+ if (callback(cur) === identifier) {
514
501
  ans.push(cur);
515
502
  if (onlyOne)
516
503
  return ans;
@@ -524,7 +511,7 @@ class BinaryTree {
524
511
  }
525
512
  /**
526
513
  * The function checks if a binary tree has a node with a given property or key.
527
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
514
+ * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
528
515
  * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
529
516
  * generic type `N`.
530
517
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
@@ -539,13 +526,15 @@ class BinaryTree {
539
526
  * performed when searching for nodes in the binary tree. It can have one of the following values:
540
527
  * @returns a boolean value.
541
528
  */
542
- has(nodeProperty, callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
529
+ has(identifier, callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
530
+ if (identifier instanceof BinaryTreeNode)
531
+ callback = (node => node);
543
532
  // TODO may support finding node by value equal
544
- return this.getNodes(nodeProperty, callback, true, beginRoot, iterationType).length > 0;
533
+ return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
545
534
  }
546
535
  /**
547
536
  * The function `get` returns the first node in a binary tree that matches the given property or key.
548
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
537
+ * @param {BinaryTreeNodeKey | N} identifier - The `identifier` parameter is the key or value of
549
538
  * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
550
539
  * type.
551
540
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
@@ -558,9 +547,11 @@ class BinaryTree {
558
547
  * performed when searching for a node in the binary tree. It can have one of the following values:
559
548
  * @returns either the found node (of type N) or null if no node is found.
560
549
  */
561
- get(nodeProperty, callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
550
+ get(identifier, callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
551
+ if (identifier instanceof BinaryTreeNode)
552
+ callback = (node => node);
562
553
  // TODO may support finding node by value equal
563
- return this.getNodes(nodeProperty, callback, true, beginRoot, iterationType)[0] ?? null;
554
+ return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null;
564
555
  }
565
556
  /**
566
557
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
@@ -587,7 +578,7 @@ class BinaryTree {
587
578
  /**
588
579
  * The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
589
580
  * iterative traversal.
590
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter is the starting point
581
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
591
582
  * for finding the leftmost node in a binary tree. It can be either a node object (`N`), a key value
592
583
  * of a node (`BinaryTreeNodeKey`), or `null` if the tree is empty.
593
584
  * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
@@ -711,7 +702,7 @@ class BinaryTree {
711
702
  * subtree traversal. It takes a single argument, which is the current node being traversed, and
712
703
  * returns a value. The return values from each callback invocation will be collected and returned as
713
704
  * an array.
714
- * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter is the starting point
705
+ * @param {BinaryTreeNodeKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
715
706
  * for traversing the subtree. It can be either a node object, a key value of a node, or `null` to
716
707
  * start from the root of the tree.
717
708
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -835,7 +826,7 @@ class BinaryTree {
835
826
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
836
827
  * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
837
828
  * @param {boolean} [withLevel=false] - The `withLevel` parameter is a boolean flag that determines
838
- * whether or not to include the level of each node in the callback function. If `withLevel` is set
829
+ * whether to include the level of each node in the callback function. If `withLevel` is set
839
830
  * to `true`, the level of each node will be passed as an argument to the callback function. If
840
831
  * `withLevel` is
841
832
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first