min-heap-typed 1.39.0 → 1.39.1

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 (49) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +2 -2
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +86 -32
  3. package/dist/data-structures/binary-tree/binary-tree.js +8 -8
  4. package/dist/data-structures/binary-tree/bst.d.ts +6 -6
  5. package/dist/data-structures/binary-tree/bst.js +2 -2
  6. package/dist/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  7. package/dist/data-structures/graph/abstract-graph.d.ts +1 -1
  8. package/dist/data-structures/graph/abstract-graph.js +1 -1
  9. package/dist/data-structures/graph/map-graph.d.ts +1 -1
  10. package/dist/data-structures/graph/map-graph.js +1 -1
  11. package/dist/data-structures/matrix/matrix2d.d.ts +1 -2
  12. package/dist/data-structures/matrix/matrix2d.js +3 -7
  13. package/dist/data-structures/matrix/vector2d.d.ts +0 -1
  14. package/dist/data-structures/matrix/vector2d.js +0 -1
  15. package/dist/interfaces/binary-tree.d.ts +2 -2
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  17. package/dist/types/helpers.d.ts +1 -4
  18. package/package.json +1 -1
  19. package/src/data-structures/binary-tree/avl-tree.ts +5 -4
  20. package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
  21. package/src/data-structures/binary-tree/binary-tree.ts +37 -93
  22. package/src/data-structures/binary-tree/bst.ts +11 -17
  23. package/src/data-structures/binary-tree/rb-tree.ts +2 -1
  24. package/src/data-structures/binary-tree/tree-multiset.ts +4 -3
  25. package/src/data-structures/graph/abstract-graph.ts +12 -11
  26. package/src/data-structures/graph/directed-graph.ts +2 -1
  27. package/src/data-structures/graph/map-graph.ts +2 -2
  28. package/src/data-structures/graph/undirected-graph.ts +5 -4
  29. package/src/data-structures/hash/hash-map.ts +1 -1
  30. package/src/data-structures/hash/tree-map.ts +1 -2
  31. package/src/data-structures/hash/tree-set.ts +1 -2
  32. package/src/data-structures/heap/heap.ts +2 -2
  33. package/src/data-structures/heap/max-heap.ts +1 -1
  34. package/src/data-structures/heap/min-heap.ts +1 -1
  35. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  36. package/src/data-structures/matrix/matrix.ts +1 -1
  37. package/src/data-structures/matrix/matrix2d.ts +1 -3
  38. package/src/data-structures/matrix/vector2d.ts +1 -4
  39. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
  40. package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
  41. package/src/data-structures/priority-queue/priority-queue.ts +1 -1
  42. package/src/data-structures/queue/deque.ts +4 -5
  43. package/src/data-structures/queue/queue.ts +1 -1
  44. package/src/interfaces/binary-tree.ts +2 -2
  45. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
  46. package/src/types/data-structures/matrix/navigator.ts +1 -1
  47. package/src/types/helpers.ts +1 -7
  48. package/src/types/utils/utils.ts +1 -1
  49. package/src/types/utils/validate-type.ts +2 -2
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey } from '../../types';
10
- import { MapCallback } from '../../types';
10
+ import { OneParamCallback } 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;
@@ -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 MapCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeletedResult<N>[];
56
+ delete<C extends OneParamCallback<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
@@ -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 { BFSCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, MapCallback } from '../../types';
9
- import { BinaryTreeDeletedResult, DefaultMapCallback, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
8
+ import type { OneParamCallback, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions } from '../../types';
9
+ import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  /**
12
12
  * Represents a node in a binary tree.
@@ -132,8 +132,21 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
132
132
  * @returns The method is returning a boolean value.
133
133
  */
134
134
  refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: Array<V>): boolean;
135
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N): BinaryTreeDeletedResult<N>[];
136
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
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>[];
137
150
  /**
138
151
  * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
139
152
  * specified root node.
@@ -179,21 +192,62 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
179
192
  * @returns The method is returning a boolean value.
180
193
  */
181
194
  isPerfectlyBalanced(beginRoot?: N | null): boolean;
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;
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;
197
251
  /**
198
252
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
199
253
  * up to the root node, with the option to reverse the order of the nodes.
@@ -238,7 +292,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
238
292
  * possible values:
239
293
  * @returns The function `isSubtreeBST` returns a boolean value.
240
294
  */
241
- isSubtreeBST(beginRoot: N, iterationType?: IterationType): boolean;
295
+ isSubtreeBST(beginRoot: N | null, iterationType?: IterationType): boolean;
242
296
  /**
243
297
  * The function checks if a binary tree is a binary search tree.
244
298
  * @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
@@ -260,9 +314,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
260
314
  * start from the root of the tree.
261
315
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
262
316
  * performed on the binary tree. It can have two possible values:
263
- * @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
317
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
264
318
  */
265
- subTreeTraverse<C extends MapCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
319
+ subTreeTraverse<C extends OneParamCallback<N>>(callback?: C, beginRoot?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
266
320
  /**
267
321
  * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
268
322
  * function on each node according to a specified order pattern.
@@ -276,23 +330,23 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
276
330
  * is `null`, an empty array will be returned.
277
331
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
278
332
  * iteration used in the depth-first search algorithm. It can have two possible values:
279
- * @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
333
+ * @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<N>>` values.
280
334
  */
281
- dfs<C extends MapCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
335
+ dfs<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
282
336
  /**
283
337
  * The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
284
338
  * function on each node.
285
339
  * @param callback - The `callback` parameter is a function that will be called for each node in the
286
340
  * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
287
- * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
341
+ * `ReturnType<OneParamCallback<N>>`. The default value for this parameter is `this._defaultCallbackByKey
288
342
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
289
343
  * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
290
344
  * will not be performed and an empty array will be returned.
291
345
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
292
346
  * in the breadth-first search (BFS) algorithm. It can have two possible values:
293
- * @returns The function `bfs` returns an array of `BFSCallbackReturn<N>[]`.
347
+ * @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<N>>[]`.
294
348
  */
295
- bfs<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
349
+ bfs<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
296
350
  /**
297
351
  * The `listLevels` function takes a binary tree node and a callback function, and returns an array
298
352
  * of arrays representing the levels of the tree.
@@ -308,7 +362,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
308
362
  * level in a binary tree. Each inner array contains the return type of the provided callback
309
363
  * function `C` applied to the nodes at that level.
310
364
  */
311
- listLevels<C extends BFSCallback<N> = BFSCallback<N, BinaryTreeNodeKey>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
365
+ listLevels<C extends OneParamCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
312
366
  /**
313
367
  * The function returns the predecessor node of a given node in a binary tree.
314
368
  * @param {N} node - The parameter "node" represents a node in a binary tree.
@@ -319,7 +373,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
319
373
  * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
320
374
  * algorithm and returns an array of values obtained by applying a callback function to each node.
321
375
  * @param callback - The `callback` parameter is a function that will be called on each node in the
322
- * tree. It takes a node of type `N` as input and returns a value of type `MapCallbackReturn<N>`. The
376
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<N>>`. The
323
377
  * default value for this parameter is `this._defaultCallbackByKey`.
324
378
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
325
379
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
@@ -327,9 +381,9 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
327
381
  * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
328
382
  * traversal. It specifies the root node of the tree from which the traversal should begin. If
329
383
  * `beginRoot` is `null`, an empty array will be returned.
330
- * @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
384
+ * @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
331
385
  */
332
- morris<C extends MapCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
386
+ morris<C extends OneParamCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
333
387
  /**
334
388
  * Swap the data of two nodes in the binary tree.
335
389
  * @param {N} srcNode - The source node to swap.
@@ -344,7 +398,7 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
344
398
  * the tree's structure should be restored to its original state to maintain the tree's integrity.
345
399
  * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
346
400
  */
347
- protected _defaultCallbackByKey: DefaultMapCallback<N>;
401
+ protected _defaultCallbackByKey: OneParamCallback<N, BinaryTreeNodeKey>;
348
402
  /**
349
403
  * The function `_addTo` adds a new node to a binary tree if there is an available position.
350
404
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
@@ -277,8 +277,8 @@ class BinaryTree {
277
277
  let needBalanced = null, orgCurrent = curr;
278
278
  if (!curr.left) {
279
279
  if (!parent) {
280
- if (curr.right !== undefined)
281
- this._setRoot(curr.right);
280
+ // Handle the case when there's only one root node
281
+ this._setRoot(null);
282
282
  }
283
283
  else {
284
284
  const { familyPosition: fp } = curr;
@@ -703,7 +703,7 @@ class BinaryTree {
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 `MapCallbackReturn<N>`.
706
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<OneParamCallback<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 `MapCallbackReturn<N>` values.
746
+ * @returns The function `dfs` returns an array of `ReturnType<OneParamCallback<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
- * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
823
+ * `ReturnType<OneParamCallback<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 `BFSCallbackReturn<N>[]`.
829
+ * @returns The function `bfs` returns an array of `ReturnType<OneParamCallback<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 `MapCallbackReturn<N>`. The
937
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<OneParamCallback<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 `MapCallbackReturn<N>` values.
945
+ * @returns The `morris` function returns an array of `ReturnType<OneParamCallback<N>>` values.
946
946
  */
947
947
  morris(callback = this._defaultCallbackByKey, pattern = 'in', beginRoot = this.root) {
948
948
  if (beginRoot === null)
@@ -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, BSTComparator, BSTNodeNested, BSTOptions, MapCallback } from '../../types';
8
+ import type { BinaryTreeNodeKey, BSTComparator, BSTNodeNested, BSTOptions, OneParamCallback } from '../../types';
9
9
  import { CP, IterationType } from '../../types';
10
10
  import { BinaryTree, BinaryTreeNode } from './binary-tree';
11
11
  import { IBinaryTree } from '../../interfaces';
@@ -59,7 +59,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
59
59
  * callback.
60
60
  * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
61
61
  * property of the binary tree node that you want to search for. It can be either a specific key
62
- * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
62
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
63
63
  * whether a node matches the desired property.
64
64
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
65
65
  * matches the desired property. It takes a node as input and returns a boolean value indicating
@@ -72,7 +72,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
72
72
  * @returns either the first node that matches the given nodeProperty and callback, or null if no
73
73
  * matching node is found.
74
74
  */
75
- get<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
75
+ get<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, beginRoot?: N | null, iterationType?: IterationType): N | null;
76
76
  /**
77
77
  * The function `lastKey` returns the key of the rightmost node if the comparison result is less
78
78
  * than, the key of the leftmost node if the comparison result is greater than, and the key of the
@@ -110,7 +110,7 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
110
110
  * traverse the binary tree. It can have one of the following values:
111
111
  * @returns an array of nodes (N[]).
112
112
  */
113
- getNodes<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
113
+ getNodes<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
114
114
  /**
115
115
  * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
116
116
  * nodes that have a key value lesser or greater than a target key value.
@@ -126,9 +126,9 @@ export declare class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNe
126
126
  * (`BinaryTreeNodeKey`), or `null` to
127
127
  * @param iterationType - The `iterationType` parameter determines whether the traversal should be
128
128
  * done recursively or iteratively. It can have two possible values:
129
- * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
129
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
130
130
  */
131
- lesserOrGreaterTraverse<C extends MapCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
131
+ lesserOrGreaterTraverse<C extends OneParamCallback<N>>(callback?: C, lesserOrGreater?: CP, targetNode?: BinaryTreeNodeKey | N | null, iterationType?: IterationType): ReturnType<C>[];
132
132
  /**
133
133
  * Balancing Adjustment:
134
134
  * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
@@ -210,7 +210,7 @@ class BST extends binary_tree_1.BinaryTree {
210
210
  * callback.
211
211
  * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
212
212
  * property of the binary tree node that you want to search for. It can be either a specific key
213
- * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
213
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
214
214
  * whether a node matches the desired property.
215
215
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
216
216
  * matches the desired property. It takes a node as input and returns a boolean value indicating
@@ -343,7 +343,7 @@ class BST extends binary_tree_1.BinaryTree {
343
343
  * (`BinaryTreeNodeKey`), or `null` to
344
344
  * @param iterationType - The `iterationType` parameter determines whether the traversal should be
345
345
  * done recursively or iteratively. It can have two possible values:
346
- * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
346
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
347
347
  */
348
348
  lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
349
349
  if (typeof targetNode === 'number')
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
9
- import { BinaryTreeDeletedResult, IterationType, MapCallback } from '../../types';
9
+ import { BinaryTreeDeletedResult, IterationType, OneParamCallback } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
12
  export declare class TreeMultisetNode<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, N> {
@@ -105,7 +105,7 @@ export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = Tr
105
105
  * decremented by 1 and
106
106
  * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
107
107
  */
108
- delete<C extends MapCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
108
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
109
109
  /**
110
110
  * The clear() function clears the contents of a data structure and sets the count to zero.
111
111
  */
@@ -103,7 +103,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
103
103
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
104
104
  * were removed.
105
105
  */
106
- removeAllVertices(vertices: V[] | VertexKey[]): boolean;
106
+ removeManyVertices(vertices: V[] | VertexKey[]): boolean;
107
107
  /**
108
108
  * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
109
109
  * @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
@@ -133,7 +133,7 @@ class AbstractGraph {
133
133
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
134
134
  * were removed.
135
135
  */
136
- removeAllVertices(vertices) {
136
+ removeManyVertices(vertices) {
137
137
  const removed = [];
138
138
  for (const v of vertices) {
139
139
  removed.push(this.deleteVertex(v));
@@ -62,7 +62,7 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
62
62
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
63
63
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
64
64
  */
65
- createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
65
+ createVertex(key: VertexKey, lat?: number, long?: number, val?: V['val']): V;
66
66
  /**
67
67
  * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
68
68
  * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
@@ -89,7 +89,7 @@ class MapGraph extends directed_graph_1.DirectedGraph {
89
89
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
90
90
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
91
91
  */
92
- createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
92
+ createVertex(key, lat = this.origin[0], long = this.origin[1], val) {
93
93
  return new MapVertex(key, lat, long, val);
94
94
  }
95
95
  /**
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import Vector2D from './vector2d';
8
+ import { Vector2D } from './vector2d';
9
9
  export declare class Matrix2D {
10
10
  private readonly _matrix;
11
11
  /**
@@ -105,4 +105,3 @@ export declare class Matrix2D {
105
105
  */
106
106
  toVector(): Vector2D;
107
107
  }
108
- export default Matrix2D;
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Matrix2D = void 0;
7
4
  /**
@@ -11,7 +8,7 @@ exports.Matrix2D = void 0;
11
8
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
12
9
  * @license MIT License
13
10
  */
14
- const vector2d_1 = __importDefault(require("./vector2d"));
11
+ const vector2d_1 = require("./vector2d");
15
12
  class Matrix2D {
16
13
  /**
17
14
  * The constructor function initializes a Matrix2D object with either a default identity matrix, or a provided matrix
@@ -23,7 +20,7 @@ class Matrix2D {
23
20
  if (typeof value === 'undefined') {
24
21
  this._matrix = Matrix2D.identity;
25
22
  }
26
- else if (value instanceof vector2d_1.default) {
23
+ else if (value instanceof vector2d_1.Vector2D) {
27
24
  this._matrix = Matrix2D.identity;
28
25
  this._matrix[0][0] = value.x;
29
26
  this._matrix[1][0] = value.y;
@@ -196,8 +193,7 @@ class Matrix2D {
196
193
  * the first column of the matrix.
197
194
  */
198
195
  toVector() {
199
- return new vector2d_1.default(this._matrix[0][0], this._matrix[1][0]);
196
+ return new vector2d_1.Vector2D(this._matrix[0][0], this._matrix[1][0]);
200
197
  }
201
198
  }
202
199
  exports.Matrix2D = Matrix2D;
203
- exports.default = Matrix2D;
@@ -198,4 +198,3 @@ export declare class Vector2D {
198
198
  */
199
199
  zero(): void;
200
200
  }
201
- export default Vector2D;
@@ -288,4 +288,3 @@ class Vector2D {
288
288
  }
289
289
  }
290
290
  exports.Vector2D = Vector2D;
291
- exports.default = Vector2D;
@@ -1,7 +1,7 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, MapCallback } from '../types';
2
+ import { BinaryTreeDeletedResult, BinaryTreeNodeKey, BinaryTreeNodeNested, OneParamCallback } from '../types';
3
3
  export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>> {
4
4
  createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
5
5
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
6
- delete<C extends MapCallback<N>>(identifier: ReturnType<C> | N, callback: C): BinaryTreeDeletedResult<N>[];
6
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeletedResult<N>[];
7
7
  }
@@ -19,8 +19,6 @@ export declare enum FamilyPosition {
19
19
  MAL_NODE = "MAL_NODE"
20
20
  }
21
21
  export type BinaryTreeNodeKey = number;
22
- export type BFSCallback<N, D = any> = (node: N, level?: number) => D;
23
- export type BFSCallbackReturn<N> = ReturnType<BFSCallback<N>>;
24
22
  export type BinaryTreeDeletedResult<N> = {
25
23
  deleted: N | null | undefined;
26
24
  needBalanced: N | null;
@@ -1,9 +1,6 @@
1
- import { BinaryTreeNodeKey } from './data-structures';
2
1
  export type Comparator<T> = (a: T, b: T) => number;
3
2
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
- export type MapCallback<N, D = any> = (node: N) => D;
5
- export type DefaultMapCallback<N, D = BinaryTreeNodeKey> = (node: N) => D;
6
- export type MapCallbackReturn<N> = ReturnType<MapCallback<N>>;
3
+ export type OneParamCallback<N, D = any> = (node: N) => D;
7
4
  export declare enum CP {
8
5
  lt = "lt",
9
6
  eq = "eq",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.39.0",
3
+ "version": "1.39.1",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import {BST, BSTNode} from './bst';
9
9
  import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
10
- import {MapCallback} from '../../types';
10
+ import {OneParamCallback} from '../../types';
11
11
  import {IBinaryTree} from '../../interfaces';
12
12
 
13
13
  export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
@@ -21,7 +21,8 @@ export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNeste
21
21
 
22
22
  export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTreeNodeNested<V>>>
23
23
  extends BST<V, N>
24
- implements IBinaryTree<V, N> {
24
+ implements IBinaryTree<V, N>
25
+ {
25
26
  /**
26
27
  * This is a constructor function for an AVL tree data structure in TypeScript.
27
28
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
@@ -73,7 +74,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
73
74
  * `this._defaultCallbackByKey`
74
75
  * @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
75
76
  */
76
- override delete<C extends MapCallback<N>>(
77
+ override delete<C extends OneParamCallback<N>>(
77
78
  identifier: ReturnType<C>,
78
79
  callback: C = this._defaultCallbackByKey as C
79
80
  ): BinaryTreeDeletedResult<N>[] {
@@ -160,7 +161,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
160
161
  // Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
161
162
  switch (
162
163
  this._balanceFactor(A) // second O(1)
163
- ) {
164
+ ) {
164
165
  case -2:
165
166
  if (A && A.left) {
166
167
  if (this._balanceFactor(A.left) <= 0) {
@@ -17,7 +17,7 @@ export class BinaryIndexedTree {
17
17
  * @param - - `frequency`: The default frequency value. It is optional and has a default
18
18
  * value of 0.
19
19
  */
20
- constructor({frequency = 0, max}: { frequency?: number; max: number }) {
20
+ constructor({frequency = 0, max}: {frequency?: number; max: number}) {
21
21
  this._freq = frequency;
22
22
  this._max = max;
23
23
  this._freqMap = {0: 0};