data-structure-typed 1.50.9 → 1.51.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 (45) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +14 -14
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +378 -12
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +1 -1
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js +2 -2
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js +73 -73
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/bst.js +39 -39
  14. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +1 -1
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js +3 -3
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  19. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +2 -2
  20. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  21. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +1 -1
  22. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +1 -1
  23. package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -2
  24. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  25. package/dist/mjs/data-structures/binary-tree/binary-tree.js +73 -73
  26. package/dist/mjs/data-structures/binary-tree/bst.js +39 -39
  27. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +1 -1
  28. package/dist/mjs/data-structures/binary-tree/rb-tree.js +3 -3
  29. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  30. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +2 -2
  31. package/dist/umd/data-structure-typed.js +119 -119
  32. package/dist/umd/data-structure-typed.min.js +2 -2
  33. package/dist/umd/data-structure-typed.min.js.map +1 -1
  34. package/package.json +7 -7
  35. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  36. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  37. package/src/data-structures/binary-tree/binary-tree.ts +71 -71
  38. package/src/data-structures/binary-tree/bst.ts +33 -33
  39. package/src/data-structures/binary-tree/rb-tree.ts +3 -3
  40. package/src/data-structures/binary-tree/tree-multi-map.ts +2 -2
  41. package/test/integration/avl-tree.test.ts +4 -4
  42. package/test/integration/bst.test.ts +7 -7
  43. package/test/integration/index.html +2 -2
  44. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +1 -0
  45. package/test/utils/big-o.ts +12 -0
@@ -187,7 +187,7 @@ export declare class RedBlackTree<K = any, V = any, NODE extends RedBlackTreeNod
187
187
  * deleted is not found.
188
188
  * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
189
189
  * the binary tree based on its identifier. It is an optional parameter and if not provided, the
190
- * `_defaultOneParamCallback` function is used as the default callback. The callback function should
190
+ * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
191
191
  * return the identifier of the node to
192
192
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
193
193
  */
@@ -191,7 +191,7 @@ export class RedBlackTree extends BST {
191
191
  * its default value is taken from the `iterationType` property of the class.
192
192
  * @returns The method is returning a value of type `NODE | null | undefined`.
193
193
  */
194
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
194
+ getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
195
195
  return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? undefined;
196
196
  }
197
197
  /**
@@ -261,11 +261,11 @@ export class RedBlackTree extends BST {
261
261
  * deleted is not found.
262
262
  * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
263
263
  * the binary tree based on its identifier. It is an optional parameter and if not provided, the
264
- * `_defaultOneParamCallback` function is used as the default callback. The callback function should
264
+ * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
265
265
  * return the identifier of the node to
266
266
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
267
267
  */
268
- delete(identifier, callback = this._defaultOneParamCallback) {
268
+ delete(identifier, callback = this._DEFAULT_CALLBACK) {
269
269
  if (identifier === null)
270
270
  return [];
271
271
  const results = [];
@@ -145,7 +145,7 @@ export declare class TreeMultiMap<K = any, V = any, NODE extends TreeMultiMapNod
145
145
  * function. It can also be null or undefined if no node needs to be deleted.
146
146
  * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
147
147
  * input and returns a value of type `ReturnType<C>`. It is used to determine if a node matches the
148
- * identifier for deletion. If no callback is provided, the `_defaultOneParamCallback` function is
148
+ * identifier for deletion. If no callback is provided, the `_DEFAULT_CALLBACK` function is
149
149
  * used
150
150
  * @param [ignoreCount=false] - A boolean value indicating whether to ignore the count of the target
151
151
  * node when performing deletion. If set to true, the count of the target node will not be considered
@@ -197,7 +197,7 @@ export class TreeMultiMap extends RedBlackTree {
197
197
  * function. It can also be null or undefined if no node needs to be deleted.
198
198
  * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
199
199
  * input and returns a value of type `ReturnType<C>`. It is used to determine if a node matches the
200
- * identifier for deletion. If no callback is provided, the `_defaultOneParamCallback` function is
200
+ * identifier for deletion. If no callback is provided, the `_DEFAULT_CALLBACK` function is
201
201
  * used
202
202
  * @param [ignoreCount=false] - A boolean value indicating whether to ignore the count of the target
203
203
  * node when performing deletion. If set to true, the count of the target node will not be considered
@@ -205,7 +205,7 @@ export class TreeMultiMap extends RedBlackTree {
205
205
  * target node will be decremented
206
206
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
207
207
  */
208
- delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
208
+ delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
209
209
  if (identifier === null)
210
210
  return [];
211
211
  const results = [];
@@ -7740,7 +7740,7 @@ var dataStructureTyped = (() => {
7740
7740
  __publicField(this, "_extractor", (key) => typeof key === "number" ? key : Number(key));
7741
7741
  __publicField(this, "_root");
7742
7742
  __publicField(this, "_size");
7743
- __publicField(this, "_defaultOneParamCallback", (node) => node ? node.key : void 0);
7743
+ __publicField(this, "_DEFAULT_CALLBACK", (node) => node ? node.key : void 0);
7744
7744
  if (options) {
7745
7745
  const { iterationType, extractor } = options;
7746
7746
  if (iterationType)
@@ -7844,21 +7844,21 @@ var dataStructureTyped = (() => {
7844
7844
  * itself if it is not a valid node key.
7845
7845
  */
7846
7846
  ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
7847
- let res;
7848
7847
  if (this.isRealNode(keyOrNodeOrEntry)) {
7849
- res = keyOrNodeOrEntry;
7848
+ return keyOrNodeOrEntry;
7850
7849
  } else if (this.isEntry(keyOrNodeOrEntry)) {
7851
7850
  if (keyOrNodeOrEntry[0] === null)
7852
- res = null;
7853
- else if (keyOrNodeOrEntry[0] !== void 0)
7854
- res = this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
7851
+ return null;
7852
+ if (keyOrNodeOrEntry[0] === void 0)
7853
+ return;
7854
+ return this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
7855
7855
  } else {
7856
7856
  if (keyOrNodeOrEntry === null)
7857
- res = null;
7858
- else if (keyOrNodeOrEntry !== void 0)
7859
- res = this.getNodeByKey(keyOrNodeOrEntry, iterationType);
7857
+ return null;
7858
+ if (keyOrNodeOrEntry === void 0)
7859
+ return;
7860
+ return this.getNodeByKey(keyOrNodeOrEntry, iterationType);
7860
7861
  }
7861
- return res;
7862
7862
  }
7863
7863
  /**
7864
7864
  * The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
@@ -8027,14 +8027,14 @@ var dataStructureTyped = (() => {
8027
8027
  * specific node based on its value or object.
8028
8028
  * @param {C} callback - The `callback` parameter is a function that is used to determine the
8029
8029
  * identifier of the node to be deleted. It is optional and has a default value of
8030
- * `this._defaultOneParamCallback`. The `callback` function should return the identifier of the node.
8030
+ * `this._DEFAULT_CALLBACK`. The `callback` function should return the identifier of the node.
8031
8031
  * @returns an array of `BinaryTreeDeleteResult<NODE>`.
8032
8032
  */
8033
- delete(identifier, callback = this._defaultOneParamCallback) {
8033
+ delete(identifier, callback = this._DEFAULT_CALLBACK) {
8034
8034
  const deletedResult = [];
8035
8035
  if (!this.root)
8036
8036
  return deletedResult;
8037
- if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
8037
+ if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
8038
8038
  callback = (node) => node;
8039
8039
  const curr = this.getNode(identifier, callback);
8040
8040
  if (!curr)
@@ -8089,7 +8089,7 @@ var dataStructureTyped = (() => {
8089
8089
  * specific value.
8090
8090
  * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
8091
8091
  * input and returns a value of type `C`. It is used to determine if a node matches the given
8092
- * identifier. If no callback is provided, the `_defaultOneParamCallback` function is used as the
8092
+ * identifier. If no callback is provided, the `_DEFAULT_CALLBACK` function is used as the
8093
8093
  * default
8094
8094
  * @param [onlyOne=false] - A boolean value indicating whether to only return the first node that
8095
8095
  * matches the identifier. If set to true, the function will stop iterating once it finds a matching
@@ -8102,15 +8102,15 @@ var dataStructureTyped = (() => {
8102
8102
  * traverse the binary tree. It can have two possible values:
8103
8103
  * @returns an array of nodes of type `NODE`.
8104
8104
  */
8105
- getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
8106
- if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
8105
+ getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
8106
+ if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
8107
8107
  callback = (node) => node;
8108
8108
  beginRoot = this.ensureNode(beginRoot);
8109
8109
  if (!beginRoot)
8110
8110
  return [];
8111
8111
  const ans = [];
8112
8112
  if (iterationType === "RECURSIVE") {
8113
- const _traverse = (cur) => {
8113
+ const dfs = (cur) => {
8114
8114
  if (callback(cur) === identifier) {
8115
8115
  ans.push(cur);
8116
8116
  if (onlyOne)
@@ -8118,22 +8118,22 @@ var dataStructureTyped = (() => {
8118
8118
  }
8119
8119
  if (!cur.left && !cur.right)
8120
8120
  return;
8121
- cur.left && _traverse(cur.left);
8122
- cur.right && _traverse(cur.right);
8121
+ cur.left && dfs(cur.left);
8122
+ cur.right && dfs(cur.right);
8123
8123
  };
8124
- _traverse(beginRoot);
8124
+ dfs(beginRoot);
8125
8125
  } else {
8126
- const queue = new Queue([beginRoot]);
8127
- while (queue.size > 0) {
8128
- const cur = queue.shift();
8126
+ const stack = [beginRoot];
8127
+ while (stack.length > 0) {
8128
+ const cur = stack.pop();
8129
8129
  if (cur) {
8130
8130
  if (callback(cur) === identifier) {
8131
8131
  ans.push(cur);
8132
8132
  if (onlyOne)
8133
8133
  return ans;
8134
8134
  }
8135
- cur.left && queue.push(cur.left);
8136
- cur.right && queue.push(cur.right);
8135
+ cur.left && stack.push(cur.left);
8136
+ cur.right && stack.push(cur.right);
8137
8137
  }
8138
8138
  }
8139
8139
  }
@@ -8164,9 +8164,9 @@ var dataStructureTyped = (() => {
8164
8164
  * nodes are visited during the search.
8165
8165
  * @returns a value of type `NODE | null | undefined`.
8166
8166
  */
8167
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
8167
+ getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
8168
8168
  var _a;
8169
- if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
8169
+ if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
8170
8170
  callback = (node) => node;
8171
8171
  return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : null;
8172
8172
  }
@@ -8192,26 +8192,26 @@ var dataStructureTyped = (() => {
8192
8192
  if (!this.root)
8193
8193
  return void 0;
8194
8194
  if (iterationType === "RECURSIVE") {
8195
- const _dfs = (cur) => {
8195
+ const dfs = (cur) => {
8196
8196
  if (cur.key === key)
8197
8197
  return cur;
8198
8198
  if (!cur.left && !cur.right)
8199
8199
  return;
8200
8200
  if (cur.left)
8201
- return _dfs(cur.left);
8201
+ return dfs(cur.left);
8202
8202
  if (cur.right)
8203
- return _dfs(cur.right);
8203
+ return dfs(cur.right);
8204
8204
  };
8205
- return _dfs(this.root);
8205
+ return dfs(this.root);
8206
8206
  } else {
8207
- const queue = new Queue([this.root]);
8208
- while (queue.size > 0) {
8209
- const cur = queue.shift();
8207
+ const stack = [this.root];
8208
+ while (stack.length > 0) {
8209
+ const cur = stack.pop();
8210
8210
  if (cur) {
8211
8211
  if (cur.key === key)
8212
8212
  return cur;
8213
- cur.left && queue.push(cur.left);
8214
- cur.right && queue.push(cur.right);
8213
+ cur.left && stack.push(cur.left);
8214
+ cur.right && stack.push(cur.right);
8215
8215
  }
8216
8216
  }
8217
8217
  }
@@ -8242,9 +8242,9 @@ var dataStructureTyped = (() => {
8242
8242
  * @returns The value of the node with the given identifier is being returned. If the node is not
8243
8243
  * found, `undefined` is returned.
8244
8244
  */
8245
- get(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
8245
+ get(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
8246
8246
  var _a, _b;
8247
- if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
8247
+ if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
8248
8248
  callback = (node) => node;
8249
8249
  return (_b = (_a = this.getNode(identifier, callback, beginRoot, iterationType)) == null ? void 0 : _a.value) != null ? _b : void 0;
8250
8250
  }
@@ -8273,8 +8273,8 @@ var dataStructureTyped = (() => {
8273
8273
  * be performed in a pre-order, in-order, or post-order manner.
8274
8274
  * @returns a boolean value.
8275
8275
  */
8276
- has(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
8277
- if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
8276
+ has(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
8277
+ if ((!callback || callback === this._DEFAULT_CALLBACK) && identifier instanceof BinaryTreeNode)
8278
8278
  callback = (node) => node;
8279
8279
  return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
8280
8280
  }
@@ -8569,19 +8569,19 @@ var dataStructureTyped = (() => {
8569
8569
  if (!this.isRealNode(beginRoot))
8570
8570
  return beginRoot;
8571
8571
  if (iterationType === "RECURSIVE") {
8572
- const _traverse = (cur) => {
8572
+ const dfs = (cur) => {
8573
8573
  if (!this.isRealNode(cur.left))
8574
8574
  return cur;
8575
- return _traverse(cur.left);
8575
+ return dfs(cur.left);
8576
8576
  };
8577
- return _traverse(beginRoot);
8577
+ return dfs(beginRoot);
8578
8578
  } else {
8579
- const _traverse = trampoline((cur) => {
8579
+ const dfs = trampoline((cur) => {
8580
8580
  if (!this.isRealNode(cur.left))
8581
8581
  return cur;
8582
- return _traverse.cont(cur.left);
8582
+ return dfs.cont(cur.left);
8583
8583
  });
8584
- return _traverse(beginRoot);
8584
+ return dfs(beginRoot);
8585
8585
  }
8586
8586
  }
8587
8587
  /**
@@ -8610,19 +8610,19 @@ var dataStructureTyped = (() => {
8610
8610
  if (!beginRoot)
8611
8611
  return beginRoot;
8612
8612
  if (iterationType === "RECURSIVE") {
8613
- const _traverse = (cur) => {
8613
+ const dfs = (cur) => {
8614
8614
  if (!this.isRealNode(cur.right))
8615
8615
  return cur;
8616
- return _traverse(cur.right);
8616
+ return dfs(cur.right);
8617
8617
  };
8618
- return _traverse(beginRoot);
8618
+ return dfs(beginRoot);
8619
8619
  } else {
8620
- const _traverse = trampoline((cur) => {
8620
+ const dfs = trampoline((cur) => {
8621
8621
  if (!this.isRealNode(cur.right))
8622
8622
  return cur;
8623
- return _traverse.cont(cur.right);
8623
+ return dfs.cont(cur.right);
8624
8624
  });
8625
- return _traverse(beginRoot);
8625
+ return dfs(beginRoot);
8626
8626
  }
8627
8627
  }
8628
8628
  /**
@@ -8706,62 +8706,62 @@ var dataStructureTyped = (() => {
8706
8706
  * `false`, null or undefined
8707
8707
  * @returns an array of values that are the return values of the callback function.
8708
8708
  */
8709
- dfs(callback = this._defaultOneParamCallback, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8709
+ dfs(callback = this._DEFAULT_CALLBACK, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8710
8710
  beginRoot = this.ensureNode(beginRoot);
8711
8711
  if (!beginRoot)
8712
8712
  return [];
8713
8713
  const ans = [];
8714
8714
  if (iterationType === "RECURSIVE") {
8715
- const _traverse = (node) => {
8715
+ const dfs = (node) => {
8716
8716
  switch (pattern) {
8717
8717
  case "IN":
8718
8718
  if (includeNull) {
8719
8719
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
8720
- _traverse(node.left);
8720
+ dfs(node.left);
8721
8721
  this.isNodeOrNull(node) && ans.push(callback(node));
8722
8722
  if (this.isRealNode(node) && this.isNodeOrNull(node.right))
8723
- _traverse(node.right);
8723
+ dfs(node.right);
8724
8724
  } else {
8725
8725
  if (this.isRealNode(node) && this.isRealNode(node.left))
8726
- _traverse(node.left);
8726
+ dfs(node.left);
8727
8727
  this.isRealNode(node) && ans.push(callback(node));
8728
8728
  if (this.isRealNode(node) && this.isRealNode(node.right))
8729
- _traverse(node.right);
8729
+ dfs(node.right);
8730
8730
  }
8731
8731
  break;
8732
8732
  case "PRE":
8733
8733
  if (includeNull) {
8734
8734
  this.isNodeOrNull(node) && ans.push(callback(node));
8735
8735
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
8736
- _traverse(node.left);
8736
+ dfs(node.left);
8737
8737
  if (this.isRealNode(node) && this.isNodeOrNull(node.right))
8738
- _traverse(node.right);
8738
+ dfs(node.right);
8739
8739
  } else {
8740
8740
  this.isRealNode(node) && ans.push(callback(node));
8741
8741
  if (this.isRealNode(node) && this.isRealNode(node.left))
8742
- _traverse(node.left);
8742
+ dfs(node.left);
8743
8743
  if (this.isRealNode(node) && this.isRealNode(node.right))
8744
- _traverse(node.right);
8744
+ dfs(node.right);
8745
8745
  }
8746
8746
  break;
8747
8747
  case "POST":
8748
8748
  if (includeNull) {
8749
8749
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
8750
- _traverse(node.left);
8750
+ dfs(node.left);
8751
8751
  if (this.isRealNode(node) && this.isNodeOrNull(node.right))
8752
- _traverse(node.right);
8752
+ dfs(node.right);
8753
8753
  this.isNodeOrNull(node) && ans.push(callback(node));
8754
8754
  } else {
8755
8755
  if (this.isRealNode(node) && this.isRealNode(node.left))
8756
- _traverse(node.left);
8756
+ dfs(node.left);
8757
8757
  if (this.isRealNode(node) && this.isRealNode(node.right))
8758
- _traverse(node.right);
8758
+ dfs(node.right);
8759
8759
  this.isRealNode(node) && ans.push(callback(node));
8760
8760
  }
8761
8761
  break;
8762
8762
  }
8763
8763
  };
8764
- _traverse(beginRoot);
8764
+ dfs(beginRoot);
8765
8765
  } else {
8766
8766
  const stack = [{ opt: 0, node: beginRoot }];
8767
8767
  while (stack.length > 0) {
@@ -8830,14 +8830,14 @@ var dataStructureTyped = (() => {
8830
8830
  * @returns an array of values that are the result of invoking the callback function on each node in
8831
8831
  * the breadth-first traversal of a binary tree.
8832
8832
  */
8833
- bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
8833
+ bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
8834
8834
  beginRoot = this.ensureNode(beginRoot);
8835
8835
  if (!beginRoot)
8836
8836
  return [];
8837
8837
  const ans = [];
8838
8838
  if (iterationType === "RECURSIVE") {
8839
8839
  const queue = new Queue([beginRoot]);
8840
- const traverse = (level) => {
8840
+ const dfs = (level) => {
8841
8841
  if (queue.size === 0)
8842
8842
  return;
8843
8843
  const current = queue.shift();
@@ -8853,9 +8853,9 @@ var dataStructureTyped = (() => {
8853
8853
  if (this.isRealNode(current.right))
8854
8854
  queue.push(current.right);
8855
8855
  }
8856
- traverse(level + 1);
8856
+ dfs(level + 1);
8857
8857
  };
8858
- traverse(0);
8858
+ dfs(0);
8859
8859
  } else {
8860
8860
  const queue = new Queue([beginRoot]);
8861
8861
  while (queue.size > 0) {
@@ -8904,7 +8904,7 @@ var dataStructureTyped = (() => {
8904
8904
  * be excluded
8905
8905
  * @returns The function `listLevels` returns a two-dimensional array of type `ReturnType<C>[][]`.
8906
8906
  */
8907
- listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
8907
+ listLevels(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
8908
8908
  beginRoot = this.ensureNode(beginRoot);
8909
8909
  const levelsNodes = [];
8910
8910
  if (!beginRoot)
@@ -8973,7 +8973,7 @@ var dataStructureTyped = (() => {
8973
8973
  * `callback` function on each node in the binary tree. The type of the array nodes is determined
8974
8974
  * by the return type of the `callback` function.
8975
8975
  */
8976
- morris(callback = this._defaultOneParamCallback, pattern = "IN", beginRoot = this.root) {
8976
+ morris(callback = this._DEFAULT_CALLBACK, pattern = "IN", beginRoot = this.root) {
8977
8977
  beginRoot = this.ensureNode(beginRoot);
8978
8978
  if (beginRoot === null)
8979
8979
  return [];
@@ -9487,17 +9487,17 @@ var dataStructureTyped = (() => {
9487
9487
  * @returns either a node object (NODE) or undefined.
9488
9488
  */
9489
9489
  ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
9490
- let res;
9491
9490
  if (this.isRealNode(keyOrNodeOrEntry)) {
9492
- res = keyOrNodeOrEntry;
9491
+ return keyOrNodeOrEntry;
9493
9492
  } else if (this.isEntry(keyOrNodeOrEntry)) {
9494
- if (keyOrNodeOrEntry[0])
9495
- res = this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
9493
+ if (keyOrNodeOrEntry[0] === null || keyOrNodeOrEntry[0] === void 0)
9494
+ return;
9495
+ return this.getNodeByKey(keyOrNodeOrEntry[0], iterationType);
9496
9496
  } else {
9497
- if (keyOrNodeOrEntry)
9498
- res = this.getNodeByKey(keyOrNodeOrEntry, iterationType);
9497
+ if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === void 0)
9498
+ return;
9499
+ return this.getNodeByKey(keyOrNodeOrEntry, iterationType);
9499
9500
  }
9500
- return res;
9501
9501
  }
9502
9502
  /**
9503
9503
  * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
@@ -9672,30 +9672,30 @@ var dataStructureTyped = (() => {
9672
9672
  */
9673
9673
  getNodeByKey(key, iterationType = "ITERATIVE") {
9674
9674
  if (!this.isRealNode(this.root))
9675
- return void 0;
9675
+ return;
9676
9676
  if (iterationType === "RECURSIVE") {
9677
- const _dfs = (cur) => {
9677
+ const dfs = (cur) => {
9678
9678
  if (cur.key === key)
9679
9679
  return cur;
9680
9680
  if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
9681
9681
  return;
9682
- if (this._compare(cur.key, key) === "GT" && this.isRealNode(cur.left))
9683
- return _dfs(cur.left);
9684
- if (this._compare(cur.key, key) === "LT" && this.isRealNode(cur.right))
9685
- return _dfs(cur.right);
9682
+ if (this.isRealNode(cur.left) && this._compare(cur.key, key) === "GT")
9683
+ return dfs(cur.left);
9684
+ if (this.isRealNode(cur.right) && this._compare(cur.key, key) === "LT")
9685
+ return dfs(cur.right);
9686
9686
  };
9687
- return _dfs(this.root);
9687
+ return dfs(this.root);
9688
9688
  } else {
9689
- const queue = new Queue([this.root]);
9690
- while (queue.size > 0) {
9691
- const cur = queue.shift();
9689
+ const stack = [this.root];
9690
+ while (stack.length > 0) {
9691
+ const cur = stack.pop();
9692
9692
  if (this.isRealNode(cur)) {
9693
9693
  if (this._compare(cur.key, key) === "EQ")
9694
9694
  return cur;
9695
- if (this._compare(cur.key, key) === "GT")
9696
- this.isRealNode(cur.left) && queue.push(cur.left);
9697
- if (this._compare(cur.key, key) === "LT")
9698
- this.isRealNode(cur.right) && queue.push(cur.right);
9695
+ if (this.isRealNode(cur.left) && this._compare(cur.key, key) === "GT")
9696
+ stack.push(cur.left);
9697
+ if (this.isRealNode(cur.right) && this._compare(cur.key, key) === "LT")
9698
+ stack.push(cur.right);
9699
9699
  }
9700
9700
  }
9701
9701
  }
@@ -9728,13 +9728,13 @@ var dataStructureTyped = (() => {
9728
9728
  * performed on the binary tree. It can have two possible values:
9729
9729
  * @returns The method returns an array of nodes (`NODE[]`).
9730
9730
  */
9731
- getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
9731
+ getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
9732
9732
  beginRoot = this.ensureNode(beginRoot);
9733
9733
  if (!beginRoot)
9734
9734
  return [];
9735
9735
  const ans = [];
9736
9736
  if (iterationType === "RECURSIVE") {
9737
- const _traverse = (cur) => {
9737
+ const dfs = (cur) => {
9738
9738
  const callbackResult = callback(cur);
9739
9739
  if (callbackResult === identifier) {
9740
9740
  ans.push(cur);
@@ -9743,17 +9743,17 @@ var dataStructureTyped = (() => {
9743
9743
  }
9744
9744
  if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
9745
9745
  return;
9746
- if (callback === this._defaultOneParamCallback) {
9746
+ if (callback === this._DEFAULT_CALLBACK) {
9747
9747
  if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === "GT")
9748
- _traverse(cur.left);
9748
+ dfs(cur.left);
9749
9749
  if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === "LT")
9750
- _traverse(cur.right);
9750
+ dfs(cur.right);
9751
9751
  } else {
9752
- this.isRealNode(cur.left) && _traverse(cur.left);
9753
- this.isRealNode(cur.right) && _traverse(cur.right);
9752
+ this.isRealNode(cur.left) && dfs(cur.left);
9753
+ this.isRealNode(cur.right) && dfs(cur.right);
9754
9754
  }
9755
9755
  };
9756
- _traverse(beginRoot);
9756
+ dfs(beginRoot);
9757
9757
  } else {
9758
9758
  const stack = [beginRoot];
9759
9759
  while (stack.length > 0) {
@@ -9765,7 +9765,7 @@ var dataStructureTyped = (() => {
9765
9765
  if (onlyOne)
9766
9766
  return ans;
9767
9767
  }
9768
- if (callback === this._defaultOneParamCallback) {
9768
+ if (callback === this._DEFAULT_CALLBACK) {
9769
9769
  if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === "LT")
9770
9770
  stack.push(cur.right);
9771
9771
  if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === "GT")
@@ -9802,7 +9802,7 @@ var dataStructureTyped = (() => {
9802
9802
  * following values:
9803
9803
  * @returns The method is returning an array of the return type of the callback function.
9804
9804
  */
9805
- dfs(callback = this._defaultOneParamCallback, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE") {
9805
+ dfs(callback = this._DEFAULT_CALLBACK, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE") {
9806
9806
  return super.dfs(callback, pattern, beginRoot, iterationType, false);
9807
9807
  }
9808
9808
  /**
@@ -9826,7 +9826,7 @@ var dataStructureTyped = (() => {
9826
9826
  * nodes are visited.
9827
9827
  * @returns The method is returning an array of the return type of the callback function.
9828
9828
  */
9829
- bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
9829
+ bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
9830
9830
  return super.bfs(callback, beginRoot, iterationType, false);
9831
9831
  }
9832
9832
  /**
@@ -9851,7 +9851,7 @@ var dataStructureTyped = (() => {
9851
9851
  * @returns The method is returning a two-dimensional array of the return type of the callback
9852
9852
  * function.
9853
9853
  */
9854
- listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
9854
+ listLevels(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
9855
9855
  return super.listLevels(callback, beginRoot, iterationType, false);
9856
9856
  }
9857
9857
  /**
@@ -9911,7 +9911,7 @@ var dataStructureTyped = (() => {
9911
9911
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
9912
9912
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
9913
9913
  */
9914
- lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "LT", targetNode = this.root, iterationType = this.iterationType) {
9914
+ lesserOrGreaterTraverse(callback = this._DEFAULT_CALLBACK, lesserOrGreater = "LT", targetNode = this.root, iterationType = this.iterationType) {
9915
9915
  targetNode = this.ensureNode(targetNode);
9916
9916
  const ans = [];
9917
9917
  if (!targetNode)
@@ -9920,16 +9920,16 @@ var dataStructureTyped = (() => {
9920
9920
  return ans;
9921
9921
  const targetKey = targetNode.key;
9922
9922
  if (iterationType === "RECURSIVE") {
9923
- const _traverse = (cur) => {
9923
+ const dfs = (cur) => {
9924
9924
  const compared = this._compare(cur.key, targetKey);
9925
9925
  if (compared === lesserOrGreater)
9926
9926
  ans.push(callback(cur));
9927
9927
  if (this.isRealNode(cur.left))
9928
- _traverse(cur.left);
9928
+ dfs(cur.left);
9929
9929
  if (this.isRealNode(cur.right))
9930
- _traverse(cur.right);
9930
+ dfs(cur.right);
9931
9931
  };
9932
- _traverse(this.root);
9932
+ dfs(this.root);
9933
9933
  return ans;
9934
9934
  } else {
9935
9935
  const queue = new Queue([this.root]);
@@ -10801,11 +10801,11 @@ var dataStructureTyped = (() => {
10801
10801
  * `callback` function.
10802
10802
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
10803
10803
  * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
10804
- * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
10804
+ * default to the `_DEFAULT_CALLBACK` function. The `callback` function should have a single
10805
10805
  * parameter of type `NODE
10806
10806
  * @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
10807
10807
  */
10808
- delete(identifier, callback = this._defaultOneParamCallback) {
10808
+ delete(identifier, callback = this._DEFAULT_CALLBACK) {
10809
10809
  if (identifier instanceof AVLTreeNode)
10810
10810
  callback = (node) => node;
10811
10811
  const deletedResults = super.delete(identifier, callback);
@@ -11319,7 +11319,7 @@ var dataStructureTyped = (() => {
11319
11319
  * its default value is taken from the `iterationType` property of the class.
11320
11320
  * @returns The method is returning a value of type `NODE | null | undefined`.
11321
11321
  */
11322
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
11322
+ getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
11323
11323
  var _a;
11324
11324
  return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
11325
11325
  }
@@ -11387,11 +11387,11 @@ var dataStructureTyped = (() => {
11387
11387
  * deleted is not found.
11388
11388
  * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
11389
11389
  * the binary tree based on its identifier. It is an optional parameter and if not provided, the
11390
- * `_defaultOneParamCallback` function is used as the default callback. The callback function should
11390
+ * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
11391
11391
  * return the identifier of the node to
11392
11392
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
11393
11393
  */
11394
- delete(identifier, callback = this._defaultOneParamCallback) {
11394
+ delete(identifier, callback = this._DEFAULT_CALLBACK) {
11395
11395
  if (identifier === null)
11396
11396
  return [];
11397
11397
  const results = [];
@@ -11927,7 +11927,7 @@ var dataStructureTyped = (() => {
11927
11927
  * decremented by 1 and
11928
11928
  * @returns an array of `BinaryTreeDeleteResult<NODE>`.
11929
11929
  */
11930
- delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
11930
+ delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
11931
11931
  var _a;
11932
11932
  const deletedResult = [];
11933
11933
  if (!this.root)
@@ -12295,7 +12295,7 @@ var dataStructureTyped = (() => {
12295
12295
  * function. It can also be null or undefined if no node needs to be deleted.
12296
12296
  * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
12297
12297
  * input and returns a value of type `ReturnType<C>`. It is used to determine if a node matches the
12298
- * identifier for deletion. If no callback is provided, the `_defaultOneParamCallback` function is
12298
+ * identifier for deletion. If no callback is provided, the `_DEFAULT_CALLBACK` function is
12299
12299
  * used
12300
12300
  * @param [ignoreCount=false] - A boolean value indicating whether to ignore the count of the target
12301
12301
  * node when performing deletion. If set to true, the count of the target node will not be considered
@@ -12303,7 +12303,7 @@ var dataStructureTyped = (() => {
12303
12303
  * target node will be decremented
12304
12304
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
12305
12305
  */
12306
- delete(identifier, callback = this._defaultOneParamCallback, ignoreCount = false) {
12306
+ delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
12307
12307
  if (identifier === null)
12308
12308
  return [];
12309
12309
  const results = [];