data-structure-typed 1.37.0 → 1.37.2

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 (41) hide show
  1. package/dist/data-structures/binary-tree/binary-tree.d.ts +36 -200
  2. package/dist/data-structures/binary-tree/binary-tree.js +79 -231
  3. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  4. package/dist/data-structures/binary-tree/bst.d.ts +9 -8
  5. package/dist/data-structures/binary-tree/bst.js +37 -25
  6. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  7. package/dist/data-structures/binary-tree/tree-multiset.d.ts +1 -35
  8. package/dist/data-structures/binary-tree/tree-multiset.js +1 -79
  9. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  10. package/dist/data-structures/heap/heap.d.ts +1 -1
  11. package/dist/data-structures/heap/heap.js +1 -1
  12. package/dist/types/data-structures/binary-tree.d.ts +2 -0
  13. package/dist/types/data-structures/index.d.ts +2 -0
  14. package/lib/data-structures/binary-tree/binary-tree.d.ts +36 -200
  15. package/lib/data-structures/binary-tree/binary-tree.js +79 -231
  16. package/lib/data-structures/binary-tree/bst.d.ts +9 -8
  17. package/lib/data-structures/binary-tree/bst.js +37 -25
  18. package/lib/data-structures/binary-tree/tree-multiset.d.ts +1 -35
  19. package/lib/data-structures/binary-tree/tree-multiset.js +1 -79
  20. package/lib/data-structures/heap/heap.d.ts +1 -1
  21. package/lib/data-structures/heap/heap.js +1 -1
  22. package/lib/types/data-structures/binary-tree.d.ts +2 -0
  23. package/lib/types/data-structures/index.d.ts +2 -0
  24. package/package.json +5 -5
  25. package/src/data-structures/binary-tree/binary-tree.ts +95 -445
  26. package/src/data-structures/binary-tree/bst.ts +43 -29
  27. package/src/data-structures/binary-tree/tree-multiset.ts +2 -84
  28. package/src/data-structures/heap/heap.ts +1 -1
  29. package/src/types/data-structures/binary-tree.ts +4 -0
  30. package/src/types/data-structures/index.ts +3 -0
  31. package/test/integration/avl-tree.test.ts +19 -16
  32. package/test/integration/bst.test.ts +37 -33
  33. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +12 -9
  34. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
  35. package/test/unit/data-structures/binary-tree/bst.test.ts +52 -22
  36. package/test/unit/data-structures/binary-tree/overall.test.ts +2 -1
  37. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +5 -5
  38. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +16 -21
  39. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  40. package/umd/bundle.min.js +1 -1
  41. package/umd/bundle.min.js.map +1 -1
@@ -5,8 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeNodeProperties, BinaryTreeOptions } from '../../types';
9
- import { BinaryTreeDeletedResult, BinaryTreeNodePropertyName, DFSOrderPattern, FamilyPosition, LoopType, NodeOrPropertyName } from '../../types';
8
+ import type { BFSCallback, BFSCallbackReturn, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, MapCallback, MapCallbackReturn } from '../../types';
9
+ import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, LoopType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FAMILY> = BinaryTreeNodeNested<V>> {
12
12
  /**
@@ -56,9 +56,6 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
56
56
  private _loopType;
57
57
  get loopType(): LoopType;
58
58
  set loopType(v: LoopType);
59
- visitedKey: BinaryTreeNodeKey[];
60
- visitedVal: N['val'][];
61
- visitedNode: N[];
62
59
  /**
63
60
  * The `_swap` function swaps the location of two nodes in a binary tree.
64
61
  * @param {N} srcNode - The source node that you want to _swap with the destination node.
@@ -134,6 +131,7 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
134
131
  * @returns the height of the binary tree.
135
132
  */
136
133
  getHeight(beginRoot?: N | BinaryTreeNodeKey | null): number;
134
+ protected _defaultCallbackByKey: MapCallback<N>;
137
135
  /**
138
136
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
139
137
  * approach.
@@ -153,88 +151,72 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
153
151
  isPerfectlyBalanced(beginRoot?: N | null): boolean;
154
152
  /**
155
153
  * The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
154
+ * @param callback
156
155
  * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
157
156
  * generic type `N`. It represents the property of the binary tree node that you want to search for.
158
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
159
157
  * specifies the property name to use when searching for nodes. If not provided, it defaults to 'key'.
160
158
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
161
159
  * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
162
160
  * function will stop traversing the tree and return the first matching node. If `only
161
+ * @param beginRoot
163
162
  * @returns an array of nodes (type N).
164
163
  */
165
- getNodes(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
164
+ getNodes(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>, onlyOne?: boolean, beginRoot?: N | null): N[];
166
165
  /**
167
166
  * The function checks if a binary tree node has a specific property.
167
+ * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
168
168
  * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
169
169
  * It represents the property of the binary tree node that you want to check.
170
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
171
170
  * specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'key'.
172
171
  * @returns a boolean value.
173
172
  */
174
- has(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): boolean;
173
+ has(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>): boolean;
175
174
  /**
176
175
  * The function returns the first node that matches the given property name and value, or null if no matching node is
177
176
  * found.
177
+ * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
178
178
  * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or `N`.
179
179
  * It represents the property of the binary tree node that you want to search for.
180
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
181
180
  * specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
182
181
  * default value is set to `'key'`.
183
182
  * @returns either the value of the specified property of the node, or the node itself if no property name is provided.
184
183
  * If no matching node is found, it returns null.
185
184
  */
186
- get(nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName): N | null;
185
+ get(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>): N | null;
187
186
  /**
188
187
  * The function `getPathToRoot` returns an array of nodes representing the path from a given node to the root node, with
189
188
  * an option to reverse the order of the nodes.
190
- * @param {N} node - The `node` parameter represents a node in a tree structure. It is of type `N`, which could be any
191
189
  * type that represents a node in your specific implementation.
190
+ * @param beginRoot - The `beginRoot` parameter is of type `N` and represents the starting node from which you want to
192
191
  * @param {boolean} [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the resulting
193
192
  * path should be reversed or not. If `isReverse` is set to `true`, the path will be reversed before returning it. If
194
193
  * `isReverse` is set to `false` or not provided, the path will
195
194
  * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
196
195
  */
197
- getPathToRoot(node: N, isReverse?: boolean): N[];
198
- /**
199
- * The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if
200
- * no node is specified.
201
- * generic type representing a node in a binary tree, `BinaryTreeNodeKey` (a type representing the ID of a binary tree
202
- * node), or `null`.
203
- * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
204
- * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the traversal
205
- * from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
206
- * node is found (
207
- */
208
- getLeftMost(): N | null;
196
+ getPathToRoot(beginRoot: N, isReverse?: boolean): N[];
209
197
  /**
210
198
  * The function `getLeftMost` returns the leftmost node in a binary tree, starting from a specified node or the root if
211
199
  * no node is specified.
212
- * @param {N | BinaryTreeNodeKey | null} [node] - The `beginRoot` parameter is optional and can be of type `N` (a
200
+ * @param {N | BinaryTreeNodeKey | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
213
201
  * generic type representing a node in a binary tree), `BinaryTreeNodeKey` (a type representing the ID of a binary tree
214
- * node).
202
+ * node), or `null`.
215
203
  * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
216
204
  * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the traversal
217
205
  * from the root of the binary tree. The function returns the leftmost node found during the traversal. If no leftmost
218
206
  * node is found (
219
207
  */
220
- getLeftMost(node: N): N;
221
- /**
222
- * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
223
- * recursion optimization.
224
- * @returns The `getRightMost` function returns the rightmost node in a binary tree. It returns the
225
- * rightmost node starting from the root of the binary tree.
226
- */
227
- getRightMost(): N | null;
208
+ getLeftMost(beginRoot?: N | BinaryTreeNodeKey | null): N | null;
228
209
  /**
229
210
  * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using tail
230
211
  * recursion optimization.
231
212
  * @param {N | null} [beginRoot] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
232
213
  * starting node from which we want to find the rightmost node. If no node is provided, the function will default to
233
214
  * using the root node of the data structure.
234
- * @returns The `getRightMost` function returns the rightmost node in a binary tree. It returns the rightmost node
235
- * starting from that node.
215
+ * @returns The `getRightMost` function returns the rightmost node in a binary tree. If the `node` parameter is provided,
216
+ * it returns the rightmost node starting from that node. If the `node` parameter is not provided, it returns the
217
+ * rightmost node starting from the root of the binary tree.
236
218
  */
237
- getRightMost(beginRoot: N): N;
219
+ getRightMost(beginRoot?: N | null): N | null;
238
220
  /**
239
221
  * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
240
222
  * @param {N | null} subTreeRoot - The `node` parameter represents the root node of a binary search tree (BST).
@@ -247,111 +229,31 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
247
229
  */
248
230
  isBST(): boolean;
249
231
  /**
250
- * The function calculates the size of a subtree by traversing it either recursively or iteratively.
251
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
252
- * binary tree.
253
- * @returns the size of the subtree rooted at `subTreeRoot`.
254
- */
255
- getSubTreeSize(subTreeRoot: N | null | undefined): number;
256
- /**
257
- * The function `subTreeForeach` adds a delta value to a specified property of each node in a subtree.
232
+ * The function `subTreeTraverse` adds a delta value to a specified property of each node in a subtree.
258
233
  * @param {N | BinaryTreeNodeKey | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
259
234
  * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
260
235
  * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
261
236
  * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'key'.
262
237
  * @returns a boolean value.
263
238
  */
264
- subTreeForeach(subTreeRoot: N | BinaryTreeNodeKey | null, callback: (node: N) => any): boolean;
265
- /**
266
- * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on their 'key' property.
267
- * @returns An array of binary tree node IDs.
268
- */
269
- bfs(): BinaryTreeNodeKey[];
270
- /**
271
- * Performs a breadth-first search (bfs) on a binary tree, accumulating properties of each node based on the specified property name.
272
- * @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
273
- * @returns An array of values corresponding to the specified property.
274
- */
275
- bfs(nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
276
- /**
277
- * Performs a breadth-first search (bfs) on a binary tree, accumulating the 'val' property of each node.
278
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
279
- * @returns An array of 'val' properties from each node.
280
- */
281
- bfs(nodeOrPropertyName: 'val'): N['val'][];
282
- /**
283
- * Performs a breadth-first search (bfs) on a binary tree, accumulating nodes themselves.
284
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
285
- * @returns An array of binary tree nodes.
286
- */
287
- bfs(nodeOrPropertyName: 'node'): N[];
288
- /**
289
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
290
- * @returns An array of binary tree node IDs.
291
- */
292
- dfs(): BinaryTreeNodeKey[];
293
- /**
294
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
295
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
296
- * @returns An array of values corresponding to the specified property.
297
- */
298
- dfs(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
299
- /**
300
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
301
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
302
- * @param {string} nodeOrPropertyName - The name of the property to accumulate.
303
- * @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
304
- * @returns An array of values corresponding to the specified property.
305
- */
306
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'key', loopType?: LoopType): BinaryTreeNodeKey[];
239
+ subTreeTraverse(callback?: MapCallback<N>, subTreeRoot?: N | BinaryTreeNodeKey | null): MapCallbackReturn<N>[];
307
240
  /**
308
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates the 'val' property of each node.
241
+ * The dfs function performs a depth-first search traversal on a binary tree and returns the accumulated properties of
242
+ * each node based on the specified pattern and property name.
243
+ * @param callback
244
+ * @param beginRoot - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It represents the
309
245
  * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
310
- * @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
311
246
  * @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
312
- * @returns An array of 'val' properties from each node.
313
- */
314
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'val', loopType?: LoopType): N[];
315
- /**
316
- * Performs a depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
317
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
318
- * @param {'node'} nodeOrPropertyName - The name of the property to accumulate.
319
- * @param loopType - The type of loop to use for the depth-first search traversal. The default value is `LoopType.ITERATIVE`.
320
- * @returns An array of binary tree nodes.
321
- */
322
- dfs(pattern: DFSOrderPattern, nodeOrPropertyName: 'node', loopType?: LoopType): N[];
323
- /**
324
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
325
- * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
326
- */
327
- listLevels(): BinaryTreeNodeKey[][];
328
- /**
329
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
330
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
331
- * @returns A 2D array of AbstractBinaryTreeNodeProperty<N> objects.
332
- */
333
- listLevels(node: N | null): BinaryTreeNodeKey[][];
334
- /**
335
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
336
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
337
- * @param {'key} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
338
- * @returns A 2D array of values corresponding to the specified property.
339
- */
340
- listLevels(node: N | null, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[][];
341
- /**
342
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
343
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
344
- * @param {'val'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
345
- * @returns A 2D array of 'val' properties from each node.
247
+ * @returns an instance of the BinaryTreeNodeProperties class, which contains the accumulated properties of the binary tree nodes based on the specified pattern and node or property name.
346
248
  */
347
- listLevels(node: N | null, nodeOrPropertyName: 'val'): N['val'][][];
249
+ dfs(callback?: MapCallback<N>, pattern?: DFSOrderPattern, beginRoot?: N | null, loopType?: LoopType): MapCallbackReturn<N>[];
348
250
  /**
349
- * Collects nodes from a binary tree by a specified property and organizes them into levels.
350
- * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance.
351
- * @param {'node'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
352
- * @returns A 2D array of binary tree nodes.
251
+ * The `listLevels` function collects nodes from a binary tree by a specified property and organizes them into levels.
252
+ * @param {N | null} node - The `node` parameter is a BinaryTreeNode object or null. It represents the root node of a binary tree. If it is null, the function will use the root node of the current binary tree instance.
253
+ * @param callback - The `callback` parameter is a function that takes a node and a level as parameters and returns a value.
254
+ * @param withLevel - The `withLevel` parameter is a boolean flag that determines whether to include the level of each node in the result. If `withLevel` is set to `true`, the function will include the level of each node in the result. If `withLevel` is set to `false` or not provided, the function will not include the level of each node in the result.
353
255
  */
354
- listLevels(node: N | null, nodeOrPropertyName: 'node'): N[][];
256
+ bfs(callback?: BFSCallback<N>, withLevel?: boolean, node?: N | null): BFSCallbackReturn<N>[];
355
257
  /**
356
258
  * The function returns the predecessor of a given node in a binary tree.
357
259
  * @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
@@ -363,37 +265,12 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
363
265
  * Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
364
266
  */
365
267
  /**
366
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
367
- * @returns An array of binary tree node IDs.
368
- */
369
- morris(): BinaryTreeNodeKey[];
370
- /**
371
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
372
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
373
- * @param {'key'} nodeOrPropertyName - The name of the property to accumulate.
374
- * @returns An array of values corresponding to the specified property.
375
- */
376
- morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
377
- /**
378
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
268
+ * The `morris` function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm.
379
269
  * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
380
- * @returns An array of values corresponding to the specified property.
270
+ * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
271
+ * @returns An array of BinaryTreeNodeProperties<N> objects.
381
272
  */
382
- morris(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
383
- /**
384
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.
385
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
386
- * @param {'val'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
387
- * @returns An array of 'val' properties from each node.
388
- */
389
- morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
390
- /**
391
- * Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates nodes themselves.
392
- * @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
393
- * @param {'node'} nodeOrPropertyName - The property of the BinaryTreeNode object to collect at each level.
394
- * @returns An array of binary tree nodes.
395
- */
396
- morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
273
+ morris(callback?: MapCallback<N>, pattern?: DFSOrderPattern): MapCallbackReturn<N>[];
397
274
  /**
398
275
  * The function adds a new node to a binary tree if there is an available position.
399
276
  * @param {N | null} newNode - The `newNode` parameter is of type `N | null`, which means it can either be a node of
@@ -416,45 +293,4 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
416
293
  * @param {number} v - number
417
294
  */
418
295
  protected _setSize(v: number): void;
419
- /**
420
- * The function `_clearResults` resets the values of several arrays used for tracking visited nodes and their
421
- * properties.
422
- */
423
- protected _clearResults(): void;
424
- /**
425
- * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
426
- * a result array.
427
- * @param {N} cur - The current node being processed.
428
- * @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
429
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeKey` or a `N`
430
- * type. It represents the property value that we are comparing against in the switch statement.
431
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
432
- * specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'key'`
433
- * or `'val'`. If it is not provided or is not equal to `'key'` or `'val'`, the
434
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
435
- * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
436
- * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
437
- * @returns a boolean value indicating whether only one matching node should be pushed into the result array.
438
- */
439
- protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeKey | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
440
- /**
441
- * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
442
- * @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
443
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
444
- * can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
445
- * specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
446
- */
447
- protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
448
- /**
449
- * The time complexity of Morris traversal is O(n), it may slower than others
450
- * The space complexity Morris traversal is O(1) because no using stack
451
- */
452
- /**
453
- * The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
454
- * name.
455
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
456
- * can accept either a `NodeOrPropertyName` type or be undefined.
457
- * @returns The method `_getResultByPropertyName` returns an instance of `BinaryTreeNodeProperties<N>`.
458
- */
459
- protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): BinaryTreeNodeProperties<N>;
460
296
  }