data-structure-typed 1.37.3 → 1.37.4

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 (28) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +42 -34
  3. package/dist/data-structures/binary-tree/avl-tree.js +42 -34
  4. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +265 -168
  6. package/dist/data-structures/binary-tree/binary-tree.js +257 -170
  7. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/bst.d.ts +104 -59
  9. package/dist/data-structures/binary-tree/bst.js +105 -60
  10. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  12. package/dist/data-structures/binary-tree/tree-multiset.js +47 -39
  13. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  14. package/lib/data-structures/binary-tree/avl-tree.d.ts +42 -34
  15. package/lib/data-structures/binary-tree/avl-tree.js +42 -34
  16. package/lib/data-structures/binary-tree/binary-tree.d.ts +265 -168
  17. package/lib/data-structures/binary-tree/binary-tree.js +257 -170
  18. package/lib/data-structures/binary-tree/bst.d.ts +104 -59
  19. package/lib/data-structures/binary-tree/bst.js +105 -60
  20. package/lib/data-structures/binary-tree/tree-multiset.d.ts +47 -39
  21. package/lib/data-structures/binary-tree/tree-multiset.js +47 -39
  22. package/package.json +5 -5
  23. package/src/data-structures/binary-tree/avl-tree.ts +42 -34
  24. package/src/data-structures/binary-tree/binary-tree.ts +270 -174
  25. package/src/data-structures/binary-tree/bst.ts +108 -66
  26. package/src/data-structures/binary-tree/tree-multiset.ts +47 -39
  27. package/umd/bundle.min.js +1 -1
  28. package/umd/bundle.min.js.map +1 -1
@@ -25,9 +25,12 @@ export class BSTNode<V = any, FAMILY extends BSTNode<V, FAMILY> = BSTNodeNested<
25
25
  }
26
26
 
27
27
  export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N> implements IBinaryTree<N> {
28
+
28
29
  /**
29
- * The constructor function initializes a binary search tree object with an optional comparator function.
30
- * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
30
+ * The constructor function initializes a binary search tree object with an optional comparator
31
+ * function.
32
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the
33
+ * binary search tree.
31
34
  */
32
35
  constructor(options?: BSTOptions) {
33
36
  super(options);
@@ -41,10 +44,10 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
41
44
 
42
45
  /**
43
46
  * The function creates a new binary search tree node with the given key and value.
44
- * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
45
- * identify each node in the binary tree.
46
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
47
- * that will be stored in the node.
47
+ * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
48
+ * the new node. It is used to determine the position of the node in the binary search tree.
49
+ * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It
50
+ * represents the value associated with the node in a binary search tree.
48
51
  * @returns a new instance of the BSTNode class with the specified key and value.
49
52
  */
50
53
  override createNode(key: BinaryTreeNodeKey, val?: N['val']): N {
@@ -52,13 +55,14 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
52
55
  }
53
56
 
54
57
  /**
55
- * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
56
- * node with the same ID.
57
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
58
- * (which represents a binary tree node) or `null`.
59
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
60
- * being added to the binary search tree.
61
- * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
58
+ * The `add` function in a binary search tree class inserts a new node with a given key and value
59
+ * into the tree.
60
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
61
+ * `BinaryTreeNodeKey` (which can be a number or a string), a `BSTNode` object, or `null`.
62
+ * @param [val] - The `val` parameter is the value to be assigned to the new node being added to the
63
+ * binary search tree.
64
+ * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
65
+ * was not added or if the parameters were invalid, it returns null or undefined.
62
66
  */
63
67
  override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined {
64
68
  // TODO support node as a parameter
@@ -127,22 +131,20 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
127
131
  }
128
132
 
129
133
  /**
130
- * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
131
- * manner.
132
- * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
133
- * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
134
- * to the binary search tree.
134
+ * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
135
+ * maintaining balance.
136
+ * @param {[BinaryTreeNodeKey | N, N['val']][]} arr - The `arr` parameter in the `addMany` function
137
+ * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
138
+ * array of `BinaryTreeNodeKey` or `N` (which represents the node type in the binary search tree) or
139
+ * `null
135
140
  * @param {N['val'][]} data - The values of tree nodes
136
141
  * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
137
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a
138
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
142
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used.
143
+ * It can have two possible values:
144
+ * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values.
139
145
  */
140
- override addMany(
141
- keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[],
142
- data?: N['val'][],
143
- isBalanceAdd = true,
144
- iterationType = this.iterationType
145
- ): (N | null | undefined)[] {
146
+
147
+ override addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][], isBalanceAdd = true, iterationType = this.iterationType): (N | null | undefined)[] {
146
148
  // TODO this addMany function is inefficient, it should be optimized
147
149
  function hasNoNull(arr: (BinaryTreeNodeKey | null)[] | (N | null)[]): arr is BinaryTreeNodeKey[] | N[] {
148
150
  return arr.indexOf(null) === -1;
@@ -211,22 +213,41 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
211
213
  }
212
214
 
213
215
  /**
214
- * The function returns the first node in a binary tree that matches the given property name and value.
215
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
216
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
217
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
218
- * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
219
- * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
216
+ * The function returns the first node in the binary tree that matches the given node property and
217
+ * callback.
218
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is used to specify the
219
+ * property of the binary tree node that you want to search for. It can be either a specific key
220
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
221
+ * whether a node matches the desired property.
222
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
223
+ * matches the desired property. It takes a node as input and returns a boolean value indicating
224
+ * whether the node matches the property or not. If no callback function is provided, the default
225
+ * callback function `_defaultCallbackByKey` is used
226
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
227
+ * the root node from which the search should begin.
228
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
229
+ * be performed when searching for nodes in the binary tree. It can have one of the following values:
230
+ * @returns either the first node that matches the given nodeProperty and callback, or null if no
231
+ * matching node is found.
220
232
  */
221
- override get(nodeProperty: BinaryTreeNodeKey | N, callback: MapCallback<N> = this._defaultCallbackByKey): N | null {
222
- return this.getNodes(nodeProperty, callback, true)[0] ?? null;
233
+ override get(nodeProperty: BinaryTreeNodeKey | N, callback: MapCallback<N> = this._defaultCallbackByKey,beginRoot = this.root, iterationType = this.iterationType): N | null {
234
+ return this.getNodes(nodeProperty, callback, true, beginRoot, iterationType)[0] ?? null;
223
235
  }
224
236
 
225
237
  /**
226
- * lastKey returns the last key in a binary tree. If the binary tree is empty, it returns 0.
227
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to begin
228
- * the search for the last key.
229
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a recursive or iterative approach to search for the last key.
238
+ * The function `lastKey` returns the key of the rightmost node if the comparison result is less
239
+ * than, the key of the leftmost node if the comparison result is greater than, and the key of the
240
+ * rightmost node otherwise.
241
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting point for finding the last
242
+ * key in a binary tree. It represents the root node of the subtree from which the search for the
243
+ * last key should begin. If no specific `beginRoot` is provided, the search will start from the root
244
+ * of the entire binary
245
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
246
+ * be performed when finding the last key. It determines whether the iteration should be performed in
247
+ * pre-order, in-order, or post-order.
248
+ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
249
+ * the key of the leftmost node if the comparison result is greater than, and the key of the
250
+ * rightmost node otherwise. If no node is found, it returns 0.
230
251
  */
231
252
  lastKey(beginRoot: N | null = this.root, iterationType = this.iterationType): BinaryTreeNodeKey {
232
253
  if (this._compare(0, 1) === CP.lt) return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
@@ -235,17 +256,25 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
235
256
  }
236
257
 
237
258
  /**
238
- * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
239
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
240
- * `N` type. It represents the property of the binary tree node that you want to compare with.
241
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
242
- * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
243
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
244
- * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
245
- * is set to `true`, the function will return an array with only one node (if
246
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to
247
- * @param iterationType
248
- * @returns an array of nodes (type N).
259
+ * The function `getNodes` retrieves nodes from a binary tree based on a given node property or key,
260
+ * using either recursive or iterative traversal.
261
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter represents the property
262
+ * of the binary tree node that you want to search for. It can be either a `BinaryTreeNodeKey` or a
263
+ * generic type `N`.
264
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
265
+ * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
266
+ * included in the result. The default value for `callback` is `this._defaultCallbackByKey`, which is
267
+ * a
268
+ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
269
+ * the first node that matches the nodeProperty. If set to true, the function will return an array
270
+ * containing only that node. If set to false (default), the function will continue the traversal and
271
+ * return an array containing all nodes that match the node
272
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the traversal. It
273
+ * specifies the root node of the binary tree from which the traversal should begin. If `beginRoot`
274
+ * is `null`, an empty array will be returned.
275
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
276
+ * traverse the binary tree. It can have one of the following values:
277
+ * @returns an array of nodes (N[]).
249
278
  */
250
279
  override getNodes(
251
280
  nodeProperty: BinaryTreeNodeKey | N,
@@ -305,13 +334,21 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
305
334
  // --- start additional functions
306
335
 
307
336
  /**
308
- * The `lesserOrGreaterTraverse` function adds a delta value to the specified property of all nodes in a binary tree that
309
- * have a greater value than a given node.
310
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
311
- * represents the node in the binary tree to which the delta value will be added.
312
- * @param lesserOrGreater - The `lesserOrGreater` parameter is an optional parameter that specifies whether the delta
313
- * @param targetNode - The `targetNode` parameter is an optional parameter that specifies the node in the binary tree
314
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies whether to use a
337
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
338
+ * nodes that have a key value lesser or greater than a target key value.
339
+ * @param callback - The `callback` parameter is a function that will be called for each node that
340
+ * meets the condition specified by the `lesserOrGreater` parameter. It takes a node as an argument
341
+ * and returns a value.
342
+ * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
343
+ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It can take one
344
+ * of the following values:
345
+ * @param {N | BinaryTreeNodeKey | null} targetNode - The `targetNode` parameter in the
346
+ * `lesserOrGreaterTraverse` function is used to specify the node from which the traversal should
347
+ * start. It can be either a reference to a specific node (`N`), the key of a node
348
+ * (`BinaryTreeNodeKey`), or `null` to
349
+ * @param iterationType - The `iterationType` parameter determines whether the traversal should be
350
+ * done recursively or iteratively. It can have two possible values:
351
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
315
352
  */
316
353
  lesserOrGreaterTraverse(
317
354
  callback: MapCallback<N> = this._defaultCallbackByKey,
@@ -364,9 +401,12 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
364
401
  */
365
402
 
366
403
  /**
367
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
368
- * constructs a balanced binary search tree using either a recursive or iterative approach.
369
- * @returns The function `perfectlyBalance()` returns a boolean value.
404
+ * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
405
+ * ensures the tree is perfectly balanced.
406
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
407
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
408
+ * values:
409
+ * @returns The function `perfectlyBalance` returns a boolean value.
370
410
  */
371
411
  perfectlyBalance(iterationType = this.iterationType): boolean {
372
412
  const sorted = this.dfs(node => node, 'in'),
@@ -406,7 +446,9 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
406
446
  }
407
447
 
408
448
  /**
409
- * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
449
+ * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
450
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
451
+ * to check if the AVL tree is balanced. It can have two possible values:
410
452
  * @returns a boolean value.
411
453
  */
412
454
  isAVLBalanced(iterationType = this.iterationType): boolean {
@@ -456,12 +498,12 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
456
498
  protected _comparator: BSTComparator = (a, b) => a - b;
457
499
 
458
500
  /**
459
- * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
460
- * greater than, less than, or equal to the second ID.
461
- * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
462
- * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
463
- * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
464
- * than), or CP.eq (equal).
501
+ * The function compares two values using a comparator function and returns whether the first value
502
+ * is greater than, less than, or equal to the second value.
503
+ * @param {BinaryTreeNodeKey} a - The parameter "a" is of type BinaryTreeNodeKey.
504
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code represents a BinaryTreeNodeKey.
505
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
506
+ * than), CP.lt (less than), or CP.eq (equal).
465
507
  */
466
508
  protected _compare(a: BinaryTreeNodeKey, b: BinaryTreeNodeKey): CP {
467
509
  const compared = this._comparator(a, b);
@@ -69,11 +69,11 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
69
69
  }
70
70
 
71
71
  /**
72
- * The function swaps the location of two nodes in a tree data structure.
73
- * @param {N} srcNode - The source node that we want to _swap with the destination node.
74
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
75
- * be swapped with.
76
- * @returns the `destNode` after swapping its values with the `srcNode`.
72
+ * The function swaps the values of two nodes in a binary tree.
73
+ * @param {N} srcNode - The source node that needs to be swapped with the destination node.
74
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
75
+ * from `srcNode` will be swapped into.
76
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
77
77
  */
78
78
  protected override _swap(srcNode: N, destNode: N): N {
79
79
  const {key, val, count, height} = destNode;
@@ -96,14 +96,17 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
96
96
  }
97
97
 
98
98
  /**
99
- * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if
100
- * necessary.
101
- * @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which
102
- * represents a `BinaryTreeNode`).
103
- * @param [val] - The `val` parameter represents the value to be added to the binary tree node.
104
- * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
105
- * value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
106
- * @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
99
+ * The `add` function adds a new node to a binary search tree, updating the count if the key already
100
+ * exists, and balancing the tree if necessary.
101
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
102
+ * `BinaryTreeNodeKey` (which represents the key of the node to be added), a `N` (which represents a
103
+ * node to be added), or `null` (which represents a null node).
104
+ * @param [val] - The `val` parameter represents the value associated with the key that is being
105
+ * added to the binary tree.
106
+ * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
107
+ * pair that will be added to the binary tree. It has a default value of 1, which means that if no
108
+ * count is specified, the default count will be 1.
109
+ * @returns The function `add` returns a value of type `N | null | undefined`.
107
110
  */
108
111
  override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count = 1): N | null | undefined {
109
112
  let inserted: N | null | undefined = undefined,
@@ -174,13 +177,12 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
174
177
  }
175
178
 
176
179
  /**
177
- * The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent
178
- * node.
179
- * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
180
- * be either a node object (`N`) or `null`.
181
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
182
- * child.
183
- * @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
180
+ * The function adds a new node to a binary tree if there is an available slot in the parent node.
181
+ * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
182
+ * the tree. It can be either a node object (`N`) or `null`.
183
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
184
+ * be added as a child.
185
+ * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
184
186
  */
185
187
  override _addTo(newNode: N | null, parent: N): N | null | undefined {
186
188
  if (parent) {
@@ -208,13 +210,13 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
208
210
  }
209
211
 
210
212
  /**
211
- * The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
212
- * the inserted nodes.
213
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
214
- * objects, or null values.
215
- * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
216
- * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
217
- * method. If provided, the `data` array should
213
+ * The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
214
+ * inserted nodes.
215
+ * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
216
+ * added to the multiset. Each element can be either a BinaryTreeNodeKey or a TreeMultisetNode.
217
+ * @param {N['val'][]} [data] - The `data` parameter is an optional array of values that correspond
218
+ * to the keys or nodes being added to the multiset. It is used to associate additional data with
219
+ * each key or node.
218
220
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
219
221
  */
220
222
  override addMany(
@@ -242,9 +244,12 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
242
244
  }
243
245
 
244
246
  /**
245
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
246
- * constructs a balanced binary search tree using either a recursive or iterative approach.
247
- * @returns The function `perfectlyBalance()` returns a boolean value.
247
+ * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
248
+ * binary search tree using either a recursive or iterative approach.
249
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
250
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
251
+ * values:
252
+ * @returns a boolean value.
248
253
  */
249
254
  override perfectlyBalance(iterationType = this.iterationType): boolean {
250
255
  const sorted = this.dfs(node => node, 'in'),
@@ -285,13 +290,16 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
285
290
  }
286
291
 
287
292
  /**
288
- * The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
289
- * node that needs to be balanced.
290
- * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
291
- * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
292
- * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
293
- * not be taken into account when removing it. If `ignoreCount` is set to `false
294
- * @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
293
+ * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
294
+ * node along with the parent node that needs to be balanced.
295
+ * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
296
+ * (`N`) or a key value (`BinaryTreeNodeKey`). It represents the node or key that needs to be deleted
297
+ * from the binary tree.
298
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
299
+ * being deleted. If set to true, the count of the node will not be considered and the node will be
300
+ * deleted regardless of its count. If set to false (default), the count of the node will be
301
+ * decremented by 1 and
302
+ * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
295
303
  */
296
304
  override delete(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount = false): BinaryTreeDeletedResult<N>[] {
297
305
  const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
@@ -350,7 +358,7 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
350
358
  }
351
359
 
352
360
  /**
353
- * The clear() function clears the data and sets the count to 0.
361
+ * The clear() function clears the contents of a data structure and sets the count to zero.
354
362
  */
355
363
  clear() {
356
364
  super.clear();
@@ -358,7 +366,7 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
358
366
  }
359
367
 
360
368
  /**
361
- * The function "_setCount" is used to set the value of the "_count" property.
369
+ * The function sets the value of the "_count" property.
362
370
  * @param {number} v - number
363
371
  */
364
372
  protected _setCount(v: number) {