data-structure-typed 1.37.2 → 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 (42) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/dist/data-structures/binary-tree/avl-tree.d.ts +44 -38
  3. package/dist/data-structures/binary-tree/avl-tree.js +46 -40
  4. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +305 -192
  6. package/dist/data-structures/binary-tree/binary-tree.js +304 -201
  7. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  8. package/dist/data-structures/binary-tree/bst.d.ts +111 -64
  9. package/dist/data-structures/binary-tree/bst.js +132 -85
  10. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +49 -41
  12. package/dist/data-structures/binary-tree/tree-multiset.js +49 -41
  13. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  14. package/dist/types/data-structures/binary-tree.d.ts +2 -2
  15. package/dist/types/data-structures/binary-tree.js +6 -6
  16. package/dist/types/data-structures/binary-tree.js.map +1 -1
  17. package/lib/data-structures/binary-tree/avl-tree.d.ts +44 -38
  18. package/lib/data-structures/binary-tree/avl-tree.js +46 -40
  19. package/lib/data-structures/binary-tree/binary-tree.d.ts +305 -192
  20. package/lib/data-structures/binary-tree/binary-tree.js +305 -202
  21. package/lib/data-structures/binary-tree/bst.d.ts +111 -64
  22. package/lib/data-structures/binary-tree/bst.js +133 -86
  23. package/lib/data-structures/binary-tree/tree-multiset.d.ts +49 -41
  24. package/lib/data-structures/binary-tree/tree-multiset.js +50 -42
  25. package/lib/types/data-structures/binary-tree.d.ts +2 -2
  26. package/lib/types/data-structures/binary-tree.js +5 -5
  27. package/package.json +6 -6
  28. package/src/data-structures/binary-tree/avl-tree.ts +46 -40
  29. package/src/data-structures/binary-tree/binary-tree.ts +328 -207
  30. package/src/data-structures/binary-tree/bst.ts +135 -88
  31. package/src/data-structures/binary-tree/tree-multiset.ts +50 -42
  32. package/src/types/data-structures/binary-tree.ts +2 -2
  33. package/test/config.ts +1 -0
  34. package/test/integration/avl-tree.test.ts +7 -8
  35. package/test/integration/bst.test.ts +17 -16
  36. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +50 -0
  37. package/test/unit/data-structures/binary-tree/bst.test.ts +8 -1
  38. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -1
  39. package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
  40. package/test/utils/big-o.ts +2 -1
  41. package/umd/bundle.min.js +1 -1
  42. package/umd/bundle.min.js.map +1 -1
@@ -12,8 +12,10 @@ class BSTNode extends binary_tree_1.BinaryTreeNode {
12
12
  exports.BSTNode = BSTNode;
13
13
  class BST extends binary_tree_1.BinaryTree {
14
14
  /**
15
- * The constructor function initializes a binary search tree object with an optional comparator function.
16
- * @param {BSTOptions} [options] - An optional object that contains configuration options for the binary search tree.
15
+ * The constructor function initializes a binary search tree object with an optional comparator
16
+ * function.
17
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the
18
+ * binary search tree.
17
19
  */
18
20
  constructor(options) {
19
21
  super(options);
@@ -27,23 +29,24 @@ class BST extends binary_tree_1.BinaryTree {
27
29
  }
28
30
  /**
29
31
  * The function creates a new binary search tree node with the given key and value.
30
- * @param {BinaryTreeNodeKey} key - The `key` parameter is the identifier for the binary tree node. It is used to uniquely
31
- * identify each node in the binary tree.
32
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
33
- * that will be stored in the node.
32
+ * @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
33
+ * the new node. It is used to determine the position of the node in the binary search tree.
34
+ * @param [val] - The parameter `val` is an optional value that can be assigned to the node. It
35
+ * represents the value associated with the node in a binary search tree.
34
36
  * @returns a new instance of the BSTNode class with the specified key and value.
35
37
  */
36
38
  createNode(key, val) {
37
39
  return new BSTNode(key, val);
38
40
  }
39
41
  /**
40
- * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing
41
- * node with the same ID.
42
- * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N`
43
- * (which represents a binary tree node) or `null`.
44
- * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node
45
- * being added to the binary search tree.
46
- * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`.
42
+ * The `add` function in a binary search tree class inserts a new node with a given key and value
43
+ * into the tree.
44
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
45
+ * `BinaryTreeNodeKey` (which can be a number or a string), a `BSTNode` object, or `null`.
46
+ * @param [val] - The `val` parameter is the value to be assigned to the new node being added to the
47
+ * binary search tree.
48
+ * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
49
+ * was not added or if the parameters were invalid, it returns null or undefined.
47
50
  */
48
51
  add(keyOrNode, val) {
49
52
  // TODO support node as a parameter
@@ -121,16 +124,19 @@ class BST extends binary_tree_1.BinaryTree {
121
124
  return inserted;
122
125
  }
123
126
  /**
124
- * The `addMany` function overrides the base class method to add multiple nodes to a binary search tree in a balanced
125
- * manner.
126
- * @param {[BinaryTreeNodeKey | N , N['val']][]} keysOrNodes - The `keysOrNodes` parameter in the `addMany` function is an array of
127
- * `BinaryTreeNodeKey` or `N` (node) objects, or `null` values. It represents the nodes or node IDs that need to be added
128
- * to the binary search tree.
127
+ * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
128
+ * maintaining balance.
129
+ * @param {[BinaryTreeNodeKey | N, N['val']][]} arr - The `arr` parameter in the `addMany` function
130
+ * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
131
+ * array of `BinaryTreeNodeKey` or `N` (which represents the node type in the binary search tree) or
132
+ * `null
129
133
  * @param {N['val'][]} data - The values of tree nodes
130
134
  * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
131
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
135
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used.
136
+ * It can have two possible values:
137
+ * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values.
132
138
  */
133
- addMany(keysOrNodes, data, isBalanceAdd = true) {
139
+ addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.iterationType) {
134
140
  // TODO this addMany function is inefficient, it should be optimized
135
141
  function hasNoNull(arr) {
136
142
  return arr.indexOf(null) === -1;
@@ -191,7 +197,7 @@ class BST extends binary_tree_1.BinaryTree {
191
197
  }
192
198
  }
193
199
  };
194
- if (this.loopType === types_1.LoopType.RECURSIVE) {
200
+ if (iterationType === types_1.IterationType.RECURSIVE) {
195
201
  recursive(sortedKeysOrNodes, sortedData);
196
202
  }
197
203
  else {
@@ -200,50 +206,77 @@ class BST extends binary_tree_1.BinaryTree {
200
206
  return inserted;
201
207
  }
202
208
  /**
203
- * The function returns the first node in a binary tree that matches the given property name and value.
204
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or a
205
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
206
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
207
- * specifies the property name to use for searching the binary tree nodes. If not provided, it defaults to `'key'`.
208
- * @returns The method is returning either a BinaryTreeNodeKey or N (generic type) or null.
209
+ * The function returns the first node in the binary tree that matches the given node property and
210
+ * callback.
211
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is used to specify the
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
214
+ * whether a node matches the desired property.
215
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
216
+ * matches the desired property. It takes a node as input and returns a boolean value indicating
217
+ * whether the node matches the property or not. If no callback function is provided, the default
218
+ * callback function `_defaultCallbackByKey` is used
219
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
220
+ * the root node from which the search should begin.
221
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
222
+ * be performed when searching for nodes in the binary tree. It can have one of the following values:
223
+ * @returns either the first node that matches the given nodeProperty and callback, or null if no
224
+ * matching node is found.
209
225
  */
210
- get(nodeProperty, callback = this._defaultCallbackByKey) {
226
+ get(nodeProperty, callback = this._defaultCallbackByKey, beginRoot = this.root, iterationType = this.iterationType) {
211
227
  var _a;
212
- return (_a = this.getNodes(nodeProperty, callback, true)[0]) !== null && _a !== void 0 ? _a : null;
228
+ return (_a = this.getNodes(nodeProperty, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : null;
213
229
  }
214
230
  /**
215
- * The function returns the key of the rightmost node if the comparison between two values is less than, the key of the
216
- * leftmost node if the comparison is greater than, and the key of the rightmost node otherwise.
217
- * @returns The method `lastKey()` returns the key of the rightmost node in the binary tree if the comparison between
218
- * the values at index 0 and 1 is less than, otherwise it returns the key of the leftmost node. If the comparison is
219
- * equal, it returns the key of the rightmost node. If there are no nodes in the tree, it returns 0.
231
+ * The function `lastKey` returns the key of the rightmost node if the comparison result is less
232
+ * than, the key of the leftmost node if the comparison result is greater than, and the key of the
233
+ * rightmost node otherwise.
234
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting point for finding the last
235
+ * key in a binary tree. It represents the root node of the subtree from which the search for the
236
+ * last key should begin. If no specific `beginRoot` is provided, the search will start from the root
237
+ * of the entire binary
238
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
239
+ * be performed when finding the last key. It determines whether the iteration should be performed in
240
+ * pre-order, in-order, or post-order.
241
+ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
242
+ * the key of the leftmost node if the comparison result is greater than, and the key of the
243
+ * rightmost node otherwise. If no node is found, it returns 0.
220
244
  */
221
- lastKey() {
245
+ lastKey(beginRoot = this.root, iterationType = this.iterationType) {
222
246
  var _a, _b, _c, _d, _e, _f;
223
247
  if (this._compare(0, 1) === types_1.CP.lt)
224
- return (_b = (_a = this.getRightMost()) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : 0;
248
+ return (_b = (_a = this.getRightMost(beginRoot, iterationType)) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : 0;
225
249
  else if (this._compare(0, 1) === types_1.CP.gt)
226
- return (_d = (_c = this.getLeftMost()) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : 0;
250
+ return (_d = (_c = this.getLeftMost(beginRoot, iterationType)) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : 0;
227
251
  else
228
- return (_f = (_e = this.getRightMost()) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
252
+ return (_f = (_e = this.getRightMost(beginRoot, iterationType)) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
229
253
  }
230
254
  /**
231
- * The function `getNodes` returns an array of nodes in a binary tree that match a given property value.
232
- * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeKey` or an
233
- * `N` type. It represents the property of the binary tree node that you want to compare with.
234
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
235
- * specifies the property name to use for comparison. If not provided, it defaults to `'key'`.
236
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
237
- * return only one node that matches the given `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne`
238
- * is set to `true`, the function will return an array with only one node (if
239
- * @param beginRoot - The `beginRoot` parameter is an optional parameter that specifies the root node from which to
240
- * @returns an array of nodes (type N).
255
+ * The function `getNodes` retrieves nodes from a binary tree based on a given node property or key,
256
+ * using either recursive or iterative traversal.
257
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter represents the property
258
+ * of the binary tree node that you want to search for. It can be either a `BinaryTreeNodeKey` or a
259
+ * generic type `N`.
260
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
261
+ * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
262
+ * included in the result. The default value for `callback` is `this._defaultCallbackByKey`, which is
263
+ * a
264
+ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
265
+ * the first node that matches the nodeProperty. If set to true, the function will return an array
266
+ * containing only that node. If set to false (default), the function will continue the traversal and
267
+ * return an array containing all nodes that match the node
268
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the traversal. It
269
+ * specifies the root node of the binary tree from which the traversal should begin. If `beginRoot`
270
+ * is `null`, an empty array will be returned.
271
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
272
+ * traverse the binary tree. It can have one of the following values:
273
+ * @returns an array of nodes (N[]).
241
274
  */
242
- getNodes(nodeProperty, callback = this._defaultCallbackByKey, onlyOne = false, beginRoot = this.root) {
275
+ getNodes(nodeProperty, callback = this._defaultCallbackByKey, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
243
276
  if (!beginRoot)
244
277
  return [];
245
278
  const ans = [];
246
- if (this.loopType === types_1.LoopType.RECURSIVE) {
279
+ if (iterationType === types_1.IterationType.RECURSIVE) {
247
280
  const _traverse = (cur) => {
248
281
  const callbackResult = callback(cur);
249
282
  if (callbackResult === nodeProperty) {
@@ -296,48 +329,57 @@ class BST extends binary_tree_1.BinaryTree {
296
329
  }
297
330
  // --- start additional functions
298
331
  /**
299
- * The `lesserOrGreaterTraverse` function adds a delta value to the specified property of all nodes in a binary tree that
300
- * have a greater value than a given node.
301
- * @param callback - The `callback` parameter is a function that takes a node as a parameter and returns a value.
302
- * @param {N | BinaryTreeNodeKey | null} node - The `node` parameter can be either of type `N` (a generic type), `BinaryTreeNodeKey`, or `null`. It
303
- * represents the node in the binary tree to which the delta value will be added.
304
- * @param lesserOrGreater - The `lesserOrGreater` parameter is an optional parameter that specifies whether the delta
332
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
333
+ * nodes that have a key value lesser or greater than a target key value.
334
+ * @param callback - The `callback` parameter is a function that will be called for each node that
335
+ * meets the condition specified by the `lesserOrGreater` parameter. It takes a node as an argument
336
+ * and returns a value.
337
+ * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
338
+ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It can take one
339
+ * of the following values:
340
+ * @param {N | BinaryTreeNodeKey | null} targetNode - The `targetNode` parameter in the
341
+ * `lesserOrGreaterTraverse` function is used to specify the node from which the traversal should
342
+ * start. It can be either a reference to a specific node (`N`), the key of a node
343
+ * (`BinaryTreeNodeKey`), or `null` to
344
+ * @param iterationType - The `iterationType` parameter determines whether the traversal should be
345
+ * done recursively or iteratively. It can have two possible values:
346
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
305
347
  */
306
- lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = types_1.CP.lt, node) {
307
- if (typeof node === 'number')
308
- node = this.get(node);
348
+ lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
349
+ if (typeof targetNode === 'number')
350
+ targetNode = this.get(targetNode);
309
351
  const ans = [];
310
- if (!node)
311
- return [];
312
- const key = node.key;
352
+ if (!targetNode)
353
+ return ans;
354
+ const targetKey = targetNode.key;
313
355
  if (!this.root)
314
- return false;
315
- if (this.loopType === types_1.LoopType.RECURSIVE) {
356
+ return ans;
357
+ if (iterationType === types_1.IterationType.RECURSIVE) {
316
358
  const _traverse = (cur) => {
317
- const compared = this._compare(cur.key, key);
359
+ const compared = this._compare(cur.key, targetKey);
318
360
  if (compared === lesserOrGreater)
319
361
  ans.push(callback(cur));
320
362
  if (!cur.left && !cur.right)
321
363
  return;
322
- if (cur.left && this._compare(cur.left.key, key) === lesserOrGreater)
364
+ if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater)
323
365
  _traverse(cur.left);
324
- if (cur.right && this._compare(cur.right.key, key) === lesserOrGreater)
366
+ if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater)
325
367
  _traverse(cur.right);
326
368
  };
327
369
  _traverse(this.root);
328
- return true;
370
+ return ans;
329
371
  }
330
372
  else {
331
373
  const queue = new queue_1.Queue([this.root]);
332
374
  while (queue.size > 0) {
333
375
  const cur = queue.shift();
334
376
  if (cur) {
335
- const compared = this._compare(cur.key, key);
377
+ const compared = this._compare(cur.key, targetKey);
336
378
  if (compared === lesserOrGreater)
337
379
  ans.push(callback(cur));
338
- if (cur.left && this._compare(cur.left.key, key) === lesserOrGreater)
380
+ if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater)
339
381
  queue.push(cur.left);
340
- if (cur.right && this._compare(cur.right.key, key) === lesserOrGreater)
382
+ if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater)
341
383
  queue.push(cur.right);
342
384
  }
343
385
  }
@@ -354,16 +396,19 @@ class BST extends binary_tree_1.BinaryTree {
354
396
  * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
355
397
  */
356
398
  /**
357
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
358
- * constructs a balanced binary search tree using either a recursive or iterative approach.
359
- * @returns The function `perfectlyBalance()` returns a boolean value.
399
+ * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
400
+ * ensures the tree is perfectly balanced.
401
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
402
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
403
+ * values:
404
+ * @returns The function `perfectlyBalance` returns a boolean value.
360
405
  */
361
- perfectlyBalance() {
406
+ perfectlyBalance(iterationType = this.iterationType) {
362
407
  const sorted = this.dfs(node => node, 'in'), n = sorted.length;
363
408
  this.clear();
364
409
  if (sorted.length < 1)
365
410
  return false;
366
- if (this.loopType === types_1.LoopType.RECURSIVE) {
411
+ if (iterationType === types_1.IterationType.RECURSIVE) {
367
412
  const buildBalanceBST = (l, r) => {
368
413
  if (l > r)
369
414
  return;
@@ -395,15 +440,17 @@ class BST extends binary_tree_1.BinaryTree {
395
440
  }
396
441
  }
397
442
  /**
398
- * The function `isAVLBalanced` checks if a binary tree is balanced according to the AVL tree property.
443
+ * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
444
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
445
+ * to check if the AVL tree is balanced. It can have two possible values:
399
446
  * @returns a boolean value.
400
447
  */
401
- isAVLBalanced() {
448
+ isAVLBalanced(iterationType = this.iterationType) {
402
449
  var _a, _b;
403
450
  if (!this.root)
404
451
  return true;
405
452
  let balanced = true;
406
- if (this.loopType === types_1.LoopType.RECURSIVE) {
453
+ if (iterationType === types_1.IterationType.RECURSIVE) {
407
454
  const _height = (cur) => {
408
455
  if (!cur)
409
456
  return 0;
@@ -445,12 +492,12 @@ class BST extends binary_tree_1.BinaryTree {
445
492
  return balanced;
446
493
  }
447
494
  /**
448
- * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is
449
- * greater than, less than, or equal to the second ID.
450
- * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node.
451
- * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey.
452
- * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less
453
- * than), or CP.eq (equal).
495
+ * The function compares two values using a comparator function and returns whether the first value
496
+ * is greater than, less than, or equal to the second value.
497
+ * @param {BinaryTreeNodeKey} a - The parameter "a" is of type BinaryTreeNodeKey.
498
+ * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code represents a BinaryTreeNodeKey.
499
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
500
+ * than), CP.lt (less than), or CP.eq (equal).
454
501
  */
455
502
  _compare(a, b) {
456
503
  const compared = this._comparator(a, b);
@@ -1 +1 @@
1
- {"version":3,"file":"bst.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/bst.ts"],"names":[],"mappings":";;;AAeA,uCAAyC;AACzC,+CAAyD;AAEzD,oCAA+B;AAE/B,MAAa,OAAuE,SAAQ,4BAAyB;IACnH,YAAY,GAAsB,EAAE,GAAO;QACzC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,CAAC;CACF;AAJD,0BAIC;AAED,MAAa,GAA8C,SAAQ,wBAAa;IAC9E;;;OAGG;IACH,YAAY,OAAoB;QAC9B,KAAK,CAAC,OAAO,CAAC,CAAC;QAkaP,gBAAW,GAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAjarD,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,MAAM,EAAC,UAAU,EAAC,GAAG,OAAO,CAAC;YAC7B,IAAI,UAAU,KAAK,SAAS,EAAE;gBAC5B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;aAC/B;SACF;IACH,CAAC;IAED;;;;;;;OAOG;IACM,UAAU,CAAC,GAAsB,EAAE,GAAc;QACxD,OAAO,IAAI,OAAO,CAAc,GAAG,EAAE,GAAG,CAAM,CAAC;IACjD,CAAC;IAED;;;;;;;;OAQG;IACM,GAAG,CAAC,SAAuC,EAAE,GAAc;QAClE,mCAAmC;QACnC,IAAI,QAAQ,GAAa,IAAI,CAAC;QAC9B,IAAI,OAAO,GAAa,IAAI,CAAC;QAC7B,IAAI,SAAS,YAAY,OAAO,EAAE;YAChC,OAAO,GAAG,SAAS,CAAC;SACrB;aAAM,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;YACxC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;SAC3C;aAAM,IAAI,SAAS,KAAK,IAAI,EAAE;YAC7B,OAAO,GAAG,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AAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,UAAE,CAAC,EAAE,CAAC;aAC1B,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,UAAE,CAAC,EAAE,CAAC;;YAC/B,OAAO,UAAE,CAAC,EAAE,CAAC;IACpB,CAAC;CAGF;AAzeD,kBAyeC"}
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
9
- import { BinaryTreeDeletedResult } from '../../types';
9
+ import { BinaryTreeDeletedResult, IterationType } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
12
  export declare class TreeMultisetNode<V = any, FAMILY extends TreeMultisetNode<V, FAMILY> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, FAMILY> {
@@ -47,67 +47,75 @@ export declare class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = Tree
47
47
  */
48
48
  createNode(key: BinaryTreeNodeKey, val?: N['val'], count?: number): N;
49
49
  /**
50
- * The function swaps the location of two nodes in a tree data structure.
51
- * @param {N} srcNode - The source node that we want to _swap with the destination node.
52
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
53
- * be swapped with.
54
- * @returns the `destNode` after swapping its values with the `srcNode`.
50
+ * The function swaps the values of two nodes in a binary tree.
51
+ * @param {N} srcNode - The source node that needs to be swapped with the destination node.
52
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values
53
+ * from `srcNode` will be swapped into.
54
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
55
55
  */
56
56
  protected _swap(srcNode: N, destNode: N): N;
57
57
  /**
58
- * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if
59
- * necessary.
60
- * @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which
61
- * represents a `BinaryTreeNode`).
62
- * @param [val] - The `val` parameter represents the value to be added to the binary tree node.
63
- * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
64
- * value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
65
- * @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
58
+ * The `add` function adds a new node to a binary search tree, updating the count if the key already
59
+ * exists, and balancing the tree if necessary.
60
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
61
+ * `BinaryTreeNodeKey` (which represents the key of the node to be added), a `N` (which represents a
62
+ * node to be added), or `null` (which represents a null node).
63
+ * @param [val] - The `val` parameter represents the value associated with the key that is being
64
+ * added to the binary tree.
65
+ * @param [count=1] - The `count` parameter represents the number of occurrences of the key/value
66
+ * pair that will be added to the binary tree. It has a default value of 1, which means that if no
67
+ * count is specified, the default count will be 1.
68
+ * @returns The function `add` returns a value of type `N | null | undefined`.
66
69
  */
67
70
  add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count?: number): N | null | undefined;
68
71
  /**
69
- * 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
70
- * node.
71
- * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
72
- * be either a node object (`N`) or `null`.
73
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
74
- * child.
75
- * @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
72
+ * The function adds a new node to a binary tree if there is an available slot in the parent node.
73
+ * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to
74
+ * the tree. It can be either a node object (`N`) or `null`.
75
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
76
+ * be added as a child.
77
+ * @returns The method `_addTo` returns either the `parent.left`, `parent.right`, or `undefined`.
76
78
  */
77
79
  _addTo(newNode: N | null, parent: N): N | null | undefined;
78
80
  /**
79
- * The `addMany` function takes an array of node IDs or nodes and adds them to the tree multiset, returning an array of
80
- * the inserted nodes.
81
- * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
82
- * objects, or null values.
83
- * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to
84
- * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()`
85
- * method. If provided, the `data` array should
81
+ * The `addMany` function adds multiple keys or nodes to a TreeMultiset and returns an array of the
82
+ * inserted nodes.
83
+ * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of keys or nodes to be
84
+ * added to the multiset. Each element can be either a BinaryTreeNodeKey or a TreeMultisetNode.
85
+ * @param {N['val'][]} [data] - The `data` parameter is an optional array of values that correspond
86
+ * to the keys or nodes being added to the multiset. It is used to associate additional data with
87
+ * each key or node.
86
88
  * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
87
89
  */
88
90
  addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N['val'][]): (N | null | undefined)[];
89
91
  /**
90
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
91
- * constructs a balanced binary search tree using either a recursive or iterative approach.
92
- * @returns The function `perfectlyBalance()` returns a boolean value.
92
+ * The `perfectlyBalance` function in TypeScript takes a sorted array of nodes and builds a balanced
93
+ * binary search tree using either a recursive or iterative approach.
94
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
95
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
96
+ * values:
97
+ * @returns a boolean value.
93
98
  */
94
- perfectlyBalance(): boolean;
99
+ perfectlyBalance(iterationType?: IterationType): boolean;
95
100
  /**
96
- * The `delete` function removes a node from a binary search tree and returns the deleted node along with the parent
97
- * node that needs to be balanced.
98
- * @param {N | BinaryTreeNodeKey | null} nodeOrKey - The `nodeOrKey` parameter can be one of the following:
99
- * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
100
- * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
101
- * not be taken into account when removing it. If `ignoreCount` is set to `false
102
- * @returns The function `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
101
+ * The `delete` function in a binary search tree deletes a node from the tree and returns the deleted
102
+ * node along with the parent node that needs to be balanced.
103
+ * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node object
104
+ * (`N`) or a key value (`BinaryTreeNodeKey`). It represents the node or key that needs to be deleted
105
+ * from the binary tree.
106
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
107
+ * being deleted. If set to true, the count of the node will not be considered and the node will be
108
+ * deleted regardless of its count. If set to false (default), the count of the node will be
109
+ * decremented by 1 and
110
+ * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
103
111
  */
104
112
  delete(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
105
113
  /**
106
- * The clear() function clears the data and sets the count to 0.
114
+ * The clear() function clears the contents of a data structure and sets the count to zero.
107
115
  */
108
116
  clear(): void;
109
117
  /**
110
- * The function "_setCount" is used to set the value of the "_count" property.
118
+ * The function sets the value of the "_count" property.
111
119
  * @param {number} v - number
112
120
  */
113
121
  protected _setCount(v: number): void;