data-structure-typed 1.52.9 → 1.53.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 (65) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +1 -37
  4. package/benchmark/report.json +24 -384
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -47
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +20 -20
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +29 -27
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +186 -144
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +376 -265
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +56 -56
  15. package/dist/cjs/data-structures/binary-tree/bst.js +108 -78
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +42 -36
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
  21. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +59 -49
  22. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  23. package/dist/cjs/data-structures/trie/trie.js +3 -3
  24. package/dist/cjs/interfaces/binary-tree.d.ts +5 -5
  25. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
  26. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  27. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
  28. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -46
  29. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +20 -20
  30. package/dist/mjs/data-structures/binary-tree/avl-tree.js +29 -26
  31. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +186 -144
  32. package/dist/mjs/data-structures/binary-tree/binary-tree.js +376 -264
  33. package/dist/mjs/data-structures/binary-tree/bst.d.ts +56 -56
  34. package/dist/mjs/data-structures/binary-tree/bst.js +108 -76
  35. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
  36. package/dist/mjs/data-structures/binary-tree/rb-tree.js +42 -35
  37. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
  38. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +59 -48
  39. package/dist/mjs/data-structures/trie/trie.js +3 -3
  40. package/dist/mjs/interfaces/binary-tree.d.ts +5 -5
  41. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
  42. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  43. package/dist/umd/data-structure-typed.js +596 -468
  44. package/dist/umd/data-structure-typed.min.js +5 -5
  45. package/dist/umd/data-structure-typed.min.js.map +1 -1
  46. package/package.json +6 -6
  47. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +60 -54
  48. package/src/data-structures/binary-tree/avl-tree.ts +32 -35
  49. package/src/data-structures/binary-tree/binary-tree.ts +440 -360
  50. package/src/data-structures/binary-tree/bst.ts +144 -113
  51. package/src/data-structures/binary-tree/rb-tree.ts +44 -43
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +57 -61
  53. package/src/data-structures/trie/trie.ts +3 -3
  54. package/src/interfaces/binary-tree.ts +6 -6
  55. package/src/types/data-structures/binary-tree/binary-tree.ts +13 -14
  56. package/src/types/data-structures/binary-tree/bst.ts +3 -3
  57. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +2 -2
  58. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -1
  59. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +115 -3
  60. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +109 -4
  61. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +183 -46
  62. package/test/unit/data-structures/binary-tree/bst.test.ts +340 -21
  63. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +19 -0
  64. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +141 -3
  65. package/test/utils/array.ts +15 -12
@@ -6946,27 +6946,36 @@ var dataStructureTyped = (() => {
6946
6946
  /**
6947
6947
  * The constructor initializes a binary tree with optional options and adds keys, nodes, entries, or
6948
6948
  * raw data if provided.
6949
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter in the constructor
6950
- * is an iterable that can contain elements of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. It is
6949
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
6950
+ * is an iterable that can contain elements of type `BTNRep<K, V, NODE>` or `R`. It is
6951
6951
  * initialized with an empty array `[]` by default.
6952
6952
  * @param [options] - The `options` parameter in the constructor is an object that can contain the
6953
6953
  * following properties:
6954
6954
  */
6955
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
6955
+ constructor(keysNodesEntriesOrRaws = [], options) {
6956
6956
  super();
6957
6957
  __publicField(this, "iterationType", "ITERATIVE");
6958
+ __publicField(this, "_isMapMode", true);
6959
+ __publicField(this, "_store", /* @__PURE__ */ new Map());
6958
6960
  __publicField(this, "_root");
6959
6961
  __publicField(this, "_size", 0);
6960
6962
  __publicField(this, "_NIL", new BinaryTreeNode(NaN));
6961
6963
  __publicField(this, "_toEntryFn");
6962
- __publicField(this, "_DEFAULT_BTN_CALLBACK", (node) => node ? node.key : void 0);
6964
+ __publicField(this, "_DEFAULT_NODE_CALLBACK", (node) => node ? node.key : void 0);
6963
6965
  if (options) {
6964
- const { iterationType, toEntryFn } = options;
6966
+ const { iterationType, toEntryFn, isMapMode } = options;
6965
6967
  if (iterationType) this.iterationType = iterationType;
6968
+ if (isMapMode !== void 0) this._isMapMode = isMapMode;
6966
6969
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
6967
6970
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
6968
6971
  }
6969
- if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
6972
+ if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
6973
+ }
6974
+ get isMapMode() {
6975
+ return this._isMapMode;
6976
+ }
6977
+ get store() {
6978
+ return this._store;
6970
6979
  }
6971
6980
  get root() {
6972
6981
  return this._root;
@@ -6990,7 +6999,7 @@ var dataStructureTyped = (() => {
6990
6999
  * as NODE.
6991
7000
  */
6992
7001
  createNode(key, value) {
6993
- return new BinaryTreeNode(key, value);
7002
+ return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
6994
7003
  }
6995
7004
  /**
6996
7005
  * The function creates a binary tree with the specified options.
@@ -7003,41 +7012,46 @@ var dataStructureTyped = (() => {
7003
7012
  createTree(options) {
7004
7013
  return new _BinaryTree([], __spreadValues({
7005
7014
  iterationType: this.iterationType,
7015
+ isMapMode: this._isMapMode,
7006
7016
  toEntryFn: this._toEntryFn
7007
7017
  }, options));
7008
7018
  }
7009
7019
  /**
7010
- * The function `keyValueOrEntryOrRawElementToNode` converts various input types into a node object
7020
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
7011
7021
  * or returns null.
7012
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
7013
- * `keyValueOrEntryOrRawElementToNode` function takes in a parameter `keyOrNodeOrEntryOrRaw`, which
7014
- * can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. This parameter represents either a key, a
7022
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
7023
+ * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
7024
+ * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
7015
7025
  * node, an entry
7016
- * @param {V} [value] - The `value` parameter in the `keyValueOrEntryOrRawElementToNode` function is
7026
+ * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
7017
7027
  * an optional parameter of type `V`. It represents the value associated with the key in the node
7018
7028
  * being created. If a `value` is provided, it will be used when creating the node. If
7019
- * @returns The `keyValueOrEntryOrRawElementToNode` function returns an optional node
7020
- * (`OptBTNOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
7021
- * input parameter (`keyOrNodeOrEntryOrRaw`) and processes it accordingly to return a node or null
7029
+ * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
7030
+ * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
7031
+ * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
7022
7032
  * value.
7023
7033
  */
7024
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value) {
7025
- if (keyOrNodeOrEntryOrRaw === void 0) return;
7026
- if (keyOrNodeOrEntryOrRaw === null) return null;
7027
- if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
7028
- if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
7029
- const [key, entryValue] = keyOrNodeOrEntryOrRaw;
7030
- if (key === void 0) return;
7031
- else if (key === null) return null;
7032
- if (this.isKey(key)) return this.createNode(key, value != null ? value : entryValue);
7034
+ keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
7035
+ if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
7036
+ if (keyNodeEntryOrRaw === null) return [null, void 0];
7037
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
7038
+ if (this.isEntry(keyNodeEntryOrRaw)) {
7039
+ const [key, entryValue] = keyNodeEntryOrRaw;
7040
+ if (key === void 0) return [void 0, void 0];
7041
+ else if (key === null) return [null, void 0];
7042
+ const finalValue = value != null ? value : entryValue;
7043
+ return [this.createNode(key, finalValue), finalValue];
7033
7044
  }
7034
- if (this._toEntryFn) {
7035
- const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
7036
- if (this.isKey(key)) return this.createNode(key, value != null ? value : entryValue);
7037
- else return;
7045
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
7046
+ if (this.isRaw(keyNodeEntryOrRaw)) {
7047
+ if (this._toEntryFn) {
7048
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
7049
+ const finalValue = value != null ? value : entryValue;
7050
+ if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
7051
+ }
7052
+ return [void 0, void 0];
7038
7053
  }
7039
- if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value);
7040
- return;
7054
+ return [void 0, void 0];
7041
7055
  }
7042
7056
  /**
7043
7057
  * Time Complexity: O(n)
@@ -7045,8 +7059,8 @@ var dataStructureTyped = (() => {
7045
7059
  *
7046
7060
  * The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
7047
7061
  * value and returns the corresponding node or null.
7048
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
7049
- * parameter in the `ensureNode` function can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. It
7062
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
7063
+ * parameter in the `ensureNode` function can be of type `BTNRep<K, V, NODE>` or `R`. It
7050
7064
  * is used to determine whether the input is a key, node, entry, or raw data. The
7051
7065
  * @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
7052
7066
  * is used to specify the type of iteration to be performed. It has a default value of
@@ -7054,103 +7068,105 @@ var dataStructureTyped = (() => {
7054
7068
  * @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
7055
7069
  * conditions specified in the code snippet.
7056
7070
  */
7057
- ensureNode(keyOrNodeOrEntryOrRaw, iterationType = this.iterationType) {
7058
- if (keyOrNodeOrEntryOrRaw === null) return null;
7059
- if (keyOrNodeOrEntryOrRaw === void 0) return;
7060
- if (keyOrNodeOrEntryOrRaw === this._NIL) return;
7061
- if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
7062
- if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
7063
- const key = keyOrNodeOrEntryOrRaw[0];
7071
+ ensureNode(keyNodeEntryOrRaw, iterationType = this.iterationType) {
7072
+ if (keyNodeEntryOrRaw === null) return null;
7073
+ if (keyNodeEntryOrRaw === void 0) return;
7074
+ if (keyNodeEntryOrRaw === this._NIL) return;
7075
+ if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
7076
+ if (this.isEntry(keyNodeEntryOrRaw)) {
7077
+ const key = keyNodeEntryOrRaw[0];
7064
7078
  if (key === null) return null;
7065
7079
  if (key === void 0) return;
7066
7080
  return this.getNodeByKey(key, iterationType);
7067
7081
  }
7068
7082
  if (this._toEntryFn) {
7069
- const [key] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
7083
+ const [key] = this._toEntryFn(keyNodeEntryOrRaw);
7070
7084
  if (this.isKey(key)) return this.getNodeByKey(key);
7071
7085
  }
7072
- if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.getNodeByKey(keyOrNodeOrEntryOrRaw, iterationType);
7086
+ if (this.isKey(keyNodeEntryOrRaw)) return this.getNodeByKey(keyNodeEntryOrRaw, iterationType);
7073
7087
  return;
7074
7088
  }
7075
7089
  /**
7076
7090
  * The function isNode checks if the input is an instance of BinaryTreeNode.
7077
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
7078
- * `keyOrNodeOrEntryOrRaw` can be either a key, a node, an entry, or raw data. The function is
7091
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
7092
+ * `keyNodeEntryOrRaw` can be either a key, a node, an entry, or raw data. The function is
7079
7093
  * checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
7080
7094
  * accordingly.
7081
- * @returns The function `isNode` is checking if the input `keyOrNodeOrEntryOrRaw` is an instance of
7095
+ * @returns The function `isNode` is checking if the input `keyNodeEntryOrRaw` is an instance of
7082
7096
  * `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
7083
7097
  * it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
7084
7098
  * is not a node.
7085
7099
  */
7086
- isNode(keyOrNodeOrEntryOrRaw) {
7087
- return keyOrNodeOrEntryOrRaw instanceof BinaryTreeNode;
7100
+ isNode(keyNodeEntryOrRaw) {
7101
+ return keyNodeEntryOrRaw instanceof BinaryTreeNode;
7102
+ }
7103
+ isRaw(keyNodeEntryOrRaw) {
7104
+ return typeof keyNodeEntryOrRaw === "object";
7088
7105
  }
7089
7106
  /**
7090
7107
  * The function `isRealNode` checks if a given input is a valid node in a binary tree.
7091
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
7092
- * parameter in the `isRealNode` function can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`.
7108
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
7109
+ * parameter in the `isRealNode` function can be of type `BTNRep<K, V, NODE>` or `R`.
7093
7110
  * The function checks if the input parameter is a `NODE` type by verifying if it is not equal
7094
- * @returns The function `isRealNode` is checking if the input `keyOrNodeOrEntryOrRaw` is a valid
7111
+ * @returns The function `isRealNode` is checking if the input `keyNodeEntryOrRaw` is a valid
7095
7112
  * node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
7096
7113
  * values, it then calls the `isNode` method to further determine if the input is a node. The
7097
7114
  * function will return a boolean value indicating whether the
7098
7115
  */
7099
- isRealNode(keyOrNodeOrEntryOrRaw) {
7100
- if (keyOrNodeOrEntryOrRaw === this._NIL || keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === void 0)
7101
- return false;
7102
- return this.isNode(keyOrNodeOrEntryOrRaw);
7116
+ isRealNode(keyNodeEntryOrRaw) {
7117
+ if (keyNodeEntryOrRaw === this._NIL || keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === void 0) return false;
7118
+ return this.isNode(keyNodeEntryOrRaw);
7103
7119
  }
7104
7120
  /**
7105
7121
  * The function checks if a given input is a valid node or null.
7106
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
7107
- * `keyOrNodeOrEntryOrRaw` in the `isRealNodeOrNull` function can be of type `BTNKeyOrNodeOrEntry<K,
7122
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
7123
+ * `keyNodeEntryOrRaw` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
7108
7124
  * V, NODE>` or `R`. It is a union type that can either be a key, a node, an entry, or
7109
7125
  * @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
7110
- * `keyOrNodeOrEntryOrRaw` is either `null` or a real node, and returns `true` if it is a node or
7126
+ * `keyNodeEntryOrRaw` is either `null` or a real node, and returns `true` if it is a node or
7111
7127
  * `null`, and `false` otherwise.
7112
7128
  */
7113
- isRealNodeOrNull(keyOrNodeOrEntryOrRaw) {
7114
- return keyOrNodeOrEntryOrRaw === null || this.isRealNode(keyOrNodeOrEntryOrRaw);
7129
+ isRealNodeOrNull(keyNodeEntryOrRaw) {
7130
+ return keyNodeEntryOrRaw === null || this.isRealNode(keyNodeEntryOrRaw);
7115
7131
  }
7116
7132
  /**
7117
7133
  * The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
7118
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - BTNKeyOrNodeOrEntry<K, V,
7134
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V,
7119
7135
  * NODE> | R
7120
- * @returns The function is checking if the `keyOrNodeOrEntryOrRaw` parameter is equal to the `_NIL`
7136
+ * @returns The function is checking if the `keyNodeEntryOrRaw` parameter is equal to the `_NIL`
7121
7137
  * property of the current object and returning a boolean value based on that comparison.
7122
7138
  */
7123
- isNIL(keyOrNodeOrEntryOrRaw) {
7124
- return keyOrNodeOrEntryOrRaw === this._NIL;
7139
+ isNIL(keyNodeEntryOrRaw) {
7140
+ return keyNodeEntryOrRaw === this._NIL;
7125
7141
  }
7126
7142
  /**
7127
7143
  * The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
7128
7144
  * tree.
7129
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
7130
- * `keyOrNodeOrEntryOrRaw` can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. It represents a
7145
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
7146
+ * `keyNodeEntryOrRaw` can be of type `BTNRep<K, V, NODE>` or `R`. It represents a
7131
7147
  * key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
7132
7148
  * provided
7133
7149
  * @returns The function `isLeaf` returns a boolean value indicating whether the input
7134
- * `keyOrNodeOrEntryOrRaw` is a leaf node in a binary tree.
7150
+ * `keyNodeEntryOrRaw` is a leaf node in a binary tree.
7135
7151
  */
7136
- isLeaf(keyOrNodeOrEntryOrRaw) {
7137
- keyOrNodeOrEntryOrRaw = this.ensureNode(keyOrNodeOrEntryOrRaw);
7138
- if (keyOrNodeOrEntryOrRaw === void 0) return false;
7139
- if (keyOrNodeOrEntryOrRaw === null) return true;
7140
- return !this.isRealNode(keyOrNodeOrEntryOrRaw.left) && !this.isRealNode(keyOrNodeOrEntryOrRaw.right);
7152
+ isLeaf(keyNodeEntryOrRaw) {
7153
+ keyNodeEntryOrRaw = this.ensureNode(keyNodeEntryOrRaw);
7154
+ if (keyNodeEntryOrRaw === void 0) return false;
7155
+ if (keyNodeEntryOrRaw === null) return true;
7156
+ return !this.isRealNode(keyNodeEntryOrRaw.left) && !this.isRealNode(keyNodeEntryOrRaw.right);
7141
7157
  }
7142
7158
  /**
7143
7159
  * The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
7144
7160
  * with a length of 2.
7145
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
7146
- * parameter in the `isEntry` function can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or type `R`.
7147
- * The function checks if the provided `keyOrNodeOrEntryOrRaw` is of type `BTN
7148
- * @returns The `isEntry` function is checking if the `keyOrNodeOrEntryOrRaw` parameter is an array
7161
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
7162
+ * parameter in the `isEntry` function can be of type `BTNRep<K, V, NODE>` or type `R`.
7163
+ * The function checks if the provided `keyNodeEntryOrRaw` is of type `BTN
7164
+ * @returns The `isEntry` function is checking if the `keyNodeEntryOrRaw` parameter is an array
7149
7165
  * with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
7150
7166
  * `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
7151
7167
  */
7152
- isEntry(keyOrNodeOrEntryOrRaw) {
7153
- return Array.isArray(keyOrNodeOrEntryOrRaw) && keyOrNodeOrEntryOrRaw.length === 2;
7168
+ isEntry(keyNodeEntryOrRaw) {
7169
+ return Array.isArray(keyNodeEntryOrRaw) && keyNodeEntryOrRaw.length === 2;
7154
7170
  }
7155
7171
  /**
7156
7172
  * Time Complexity O(1)
@@ -7173,8 +7189,8 @@ var dataStructureTyped = (() => {
7173
7189
  *
7174
7190
  * The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
7175
7191
  * and finding the correct insertion position.
7176
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `add` method you provided
7177
- * seems to be for adding a new node to a binary tree structure. The `keyOrNodeOrEntryOrRaw`
7192
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `add` method you provided
7193
+ * seems to be for adding a new node to a binary tree structure. The `keyNodeEntryOrRaw`
7178
7194
  * parameter in the method can accept different types of values:
7179
7195
  * @param {V} [value] - The `value` parameter in the `add` method represents the value associated
7180
7196
  * with the key that you want to add to the binary tree. When adding a key-value pair to the binary
@@ -7184,11 +7200,12 @@ var dataStructureTyped = (() => {
7184
7200
  * node was successful, and `false` if the insertion position could not be found or if a duplicate
7185
7201
  * key was found and the node was replaced instead of inserted.
7186
7202
  */
7187
- add(keyOrNodeOrEntryOrRaw, value) {
7188
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
7203
+ add(keyNodeEntryOrRaw, value) {
7204
+ const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
7189
7205
  if (newNode === void 0) return false;
7190
7206
  if (!this._root) {
7191
7207
  this._setRoot(newNode);
7208
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
7192
7209
  this._size = 1;
7193
7210
  return true;
7194
7211
  }
@@ -7199,6 +7216,7 @@ var dataStructureTyped = (() => {
7199
7216
  if (!cur) continue;
7200
7217
  if (newNode !== null && cur.key === newNode.key) {
7201
7218
  this._replaceNode(cur, newNode);
7219
+ if (this._isMapMode) this._setValue(cur.key, newValue);
7202
7220
  return true;
7203
7221
  }
7204
7222
  if (potentialParent === void 0 && (cur.left === void 0 || cur.right === void 0)) {
@@ -7217,6 +7235,7 @@ var dataStructureTyped = (() => {
7217
7235
  } else if (potentialParent.right === void 0) {
7218
7236
  potentialParent.right = newNode;
7219
7237
  }
7238
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
7220
7239
  this._size++;
7221
7240
  return true;
7222
7241
  }
@@ -7229,24 +7248,24 @@ var dataStructureTyped = (() => {
7229
7248
  * The `addMany` function takes in multiple keys or nodes or entries or raw values along with
7230
7249
  * optional values, and adds them to a data structure while returning an array indicating whether
7231
7250
  * each insertion was successful.
7232
- * @param keysOrNodesOrEntriesOrRaws - `keysOrNodesOrEntriesOrRaws` is an iterable that can contain a
7251
+ * @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
7233
7252
  * mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
7234
- * `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`.
7253
+ * `BTNRep<K, V, NODE>` or `R`.
7235
7254
  * @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
7236
7255
  * accepts an iterable of values. These values correspond to the keys or nodes being added in the
7237
- * `keysOrNodesOrEntriesOrRaws` parameter. If provided, the function will iterate over the values and
7256
+ * `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
7238
7257
  * assign them
7239
7258
  * @returns The `addMany` method returns an array of boolean values indicating whether each key,
7240
7259
  * node, entry, or raw value was successfully added to the data structure. Each boolean value
7241
7260
  * corresponds to the success of adding the corresponding key or value in the input iterable.
7242
7261
  */
7243
- addMany(keysOrNodesOrEntriesOrRaws, values) {
7262
+ addMany(keysNodesEntriesOrRaws, values) {
7244
7263
  const inserted = [];
7245
7264
  let valuesIterator;
7246
7265
  if (values) {
7247
7266
  valuesIterator = values[Symbol.iterator]();
7248
7267
  }
7249
- for (const keyOrNodeOrEntryOrRaw of keysOrNodesOrEntriesOrRaws) {
7268
+ for (const keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
7250
7269
  let value = void 0;
7251
7270
  if (valuesIterator) {
7252
7271
  const valueResult = valuesIterator.next();
@@ -7254,7 +7273,7 @@ var dataStructureTyped = (() => {
7254
7273
  value = valueResult.value;
7255
7274
  }
7256
7275
  }
7257
- inserted.push(this.add(keyOrNodeOrEntryOrRaw, value));
7276
+ inserted.push(this.add(keyNodeEntryOrRaw, value));
7258
7277
  }
7259
7278
  return inserted;
7260
7279
  }
@@ -7264,15 +7283,15 @@ var dataStructureTyped = (() => {
7264
7283
  *
7265
7284
  * The `refill` function clears the existing data structure and then adds new key-value pairs based
7266
7285
  * on the provided input.
7267
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter in the `refill`
7268
- * method can accept an iterable containing a mix of `BTNKeyOrNodeOrEntry<K, V, NODE>` objects or `R`
7286
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
7287
+ * method can accept an iterable containing a mix of `BTNRep<K, V, NODE>` objects or `R`
7269
7288
  * objects.
7270
7289
  * @param [values] - The `values` parameter in the `refill` method is an optional parameter that
7271
7290
  * accepts an iterable of values of type `V` or `undefined`.
7272
7291
  */
7273
- refill(keysOrNodesOrEntriesOrRaws, values) {
7292
+ refill(keysNodesEntriesOrRaws, values) {
7274
7293
  this.clear();
7275
- this.addMany(keysOrNodesOrEntriesOrRaws, values);
7294
+ this.addMany(keysNodesEntriesOrRaws, values);
7276
7295
  }
7277
7296
  /**
7278
7297
  * Time Complexity: O(n)
@@ -7280,7 +7299,7 @@ var dataStructureTyped = (() => {
7280
7299
  *
7281
7300
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
7282
7301
  * the deleted node along with information for tree balancing.
7283
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw
7302
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw
7284
7303
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
7285
7304
  * node, entry or raw data. The method returns an array of
7286
7305
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
@@ -7289,10 +7308,10 @@ var dataStructureTyped = (() => {
7289
7308
  * the array contains information about the node that was deleted (`deleted`) and the node that may
7290
7309
  * need to be balanced (`needBalanced`).
7291
7310
  */
7292
- delete(keyOrNodeOrEntryOrRaw) {
7311
+ delete(keyNodeEntryOrRaw) {
7293
7312
  const deletedResult = [];
7294
7313
  if (!this._root) return deletedResult;
7295
- const curr = this.getNode(keyOrNodeOrEntryOrRaw);
7314
+ const curr = this.getNode(keyNodeEntryOrRaw);
7296
7315
  if (!curr) return deletedResult;
7297
7316
  const parent = curr == null ? void 0 : curr.parent;
7298
7317
  let needBalanced;
@@ -7325,6 +7344,7 @@ var dataStructureTyped = (() => {
7325
7344
  }
7326
7345
  this._size = this._size - 1;
7327
7346
  deletedResult.push({ deleted: orgCurrent, needBalanced });
7347
+ if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
7328
7348
  return deletedResult;
7329
7349
  }
7330
7350
  /**
@@ -7333,12 +7353,12 @@ var dataStructureTyped = (() => {
7333
7353
  *
7334
7354
  * The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
7335
7355
  * or predicate, with options for recursive or iterative traversal.
7336
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
7356
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7337
7357
  * - The `getNodes` function you provided takes several parameters:
7338
7358
  * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
7339
7359
  * determines whether to return only the first node that matches the criteria specified by the
7340
- * `keyOrNodeOrEntryOrRawOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
7341
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7360
+ * `keyNodeEntryRawOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
7361
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7342
7362
  * `getNodes` function is used to specify the starting point for traversing the binary tree. It
7343
7363
  * represents the root node of the binary tree or the node from which the traversal should begin. If
7344
7364
  * not provided, the default value is set to `this._root
@@ -7348,12 +7368,12 @@ var dataStructureTyped = (() => {
7348
7368
  * @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
7349
7369
  * based on the input parameters and the iteration type specified.
7350
7370
  */
7351
- getNodes(keyOrNodeOrEntryOrRawOrPredicate, onlyOne = false, beginRoot = this._root, iterationType = this.iterationType) {
7352
- if (keyOrNodeOrEntryOrRawOrPredicate === void 0) return [];
7353
- if (keyOrNodeOrEntryOrRawOrPredicate === null) return [];
7354
- beginRoot = this.ensureNode(beginRoot);
7355
- if (!beginRoot) return [];
7356
- const callback = this._ensurePredicate(keyOrNodeOrEntryOrRawOrPredicate);
7371
+ getNodes(keyNodeEntryRawOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
7372
+ if (keyNodeEntryRawOrPredicate === void 0) return [];
7373
+ if (keyNodeEntryRawOrPredicate === null) return [];
7374
+ startNode = this.ensureNode(startNode);
7375
+ if (!startNode) return [];
7376
+ const callback = this._ensurePredicate(keyNodeEntryRawOrPredicate);
7357
7377
  const ans = [];
7358
7378
  if (iterationType === "RECURSIVE") {
7359
7379
  const dfs = (cur) => {
@@ -7365,9 +7385,9 @@ var dataStructureTyped = (() => {
7365
7385
  if (this.isRealNode(cur.left)) dfs(cur.left);
7366
7386
  if (this.isRealNode(cur.right)) dfs(cur.right);
7367
7387
  };
7368
- dfs(beginRoot);
7388
+ dfs(startNode);
7369
7389
  } else {
7370
- const stack = [beginRoot];
7390
+ const stack = [startNode];
7371
7391
  while (stack.length > 0) {
7372
7392
  const cur = stack.pop();
7373
7393
  if (this.isRealNode(cur)) {
@@ -7388,10 +7408,10 @@ var dataStructureTyped = (() => {
7388
7408
  *
7389
7409
  * The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
7390
7410
  * predicate.
7391
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
7392
- * - The `keyOrNodeOrEntryOrRawOrPredicate` parameter in the `getNode` function can accept a key,
7411
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7412
+ * - The `keyNodeEntryRawOrPredicate` parameter in the `getNode` function can accept a key,
7393
7413
  * node, entry, raw data, or a predicate function.
7394
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7414
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7395
7415
  * `getNode` function is used to specify the starting point for searching for a node in a binary
7396
7416
  * tree. If no specific starting point is provided, the default value is set to `this._root`, which
7397
7417
  * is typically the root node of the binary tree.
@@ -7402,9 +7422,9 @@ var dataStructureTyped = (() => {
7402
7422
  * @returns The `getNode` function is returning the first node that matches the specified criteria,
7403
7423
  * or `null` if no matching node is found.
7404
7424
  */
7405
- getNode(keyOrNodeOrEntryOrRawOrPredicate, beginRoot = this._root, iterationType = this.iterationType) {
7425
+ getNode(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7406
7426
  var _a;
7407
- return (_a = this.getNodes(keyOrNodeOrEntryOrRawOrPredicate, true, beginRoot, iterationType)[0]) != null ? _a : null;
7427
+ return (_a = this.getNodes(keyNodeEntryRawOrPredicate, true, startNode, iterationType)[0]) != null ? _a : null;
7408
7428
  }
7409
7429
  /**
7410
7430
  * Time Complexity: O(n)
@@ -7417,7 +7437,7 @@ var dataStructureTyped = (() => {
7417
7437
  * specifies how the tree nodes should be traversed when searching for a node with the given key. It
7418
7438
  * is an optional parameter with a default value of `this.iterationType`.
7419
7439
  * @returns The `getNodeByKey` function is returning an optional binary tree node
7420
- * (`OptBTNOrNull<NODE>`).
7440
+ * (`OptNodeOrNull<NODE>`).
7421
7441
  */
7422
7442
  getNodeByKey(key, iterationType = this.iterationType) {
7423
7443
  return this.getNode(key, this._root, iterationType);
@@ -7428,10 +7448,10 @@ var dataStructureTyped = (() => {
7428
7448
  *
7429
7449
  * This function overrides the `get` method to retrieve the value associated with a specified key,
7430
7450
  * node, entry, raw data, or predicate in a data structure.
7431
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
7432
- * - The `keyOrNodeOrEntryOrRawOrPredicate` parameter in the `get` method can accept one of the
7451
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7452
+ * - The `keyNodeEntryRawOrPredicate` parameter in the `get` method can accept one of the
7433
7453
  * following types:
7434
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `get`
7454
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `get`
7435
7455
  * method is used to specify the starting point for searching for a key or node in the binary tree.
7436
7456
  * If no specific starting point is provided, the default starting point is the root of the binary
7437
7457
  * tree (`this._root`).
@@ -7444,9 +7464,14 @@ var dataStructureTyped = (() => {
7444
7464
  * the method returns the corresponding value. If the key or node is not found, it returns
7445
7465
  * `undefined`.
7446
7466
  */
7447
- get(keyOrNodeOrEntryOrRawOrPredicate, beginRoot = this._root, iterationType = this.iterationType) {
7467
+ get(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7448
7468
  var _a;
7449
- return (_a = this.getNode(keyOrNodeOrEntryOrRawOrPredicate, beginRoot, iterationType)) == null ? void 0 : _a.value;
7469
+ if (this._isMapMode) {
7470
+ const key = this._getKey(keyNodeEntryRawOrPredicate);
7471
+ if (key === null || key === void 0) return;
7472
+ return this._store.get(key);
7473
+ }
7474
+ return (_a = this.getNode(keyNodeEntryRawOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
7450
7475
  }
7451
7476
  /**
7452
7477
  * Time Complexity: O(n)
@@ -7454,10 +7479,10 @@ var dataStructureTyped = (() => {
7454
7479
  *
7455
7480
  * The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
7456
7481
  * exists in the data structure.
7457
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrNodeOrEntryOrRawOrPredicate
7458
- * - The `keyOrNodeOrEntryOrRawOrPredicate` parameter in the `override has` method can accept one of
7482
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7483
+ * - The `keyNodeEntryRawOrPredicate` parameter in the `override has` method can accept one of
7459
7484
  * the following types:
7460
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7485
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7461
7486
  * `override` method is used to specify the starting point for the search operation within the data
7462
7487
  * structure. It defaults to `this._root` if not provided explicitly.
7463
7488
  * @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
@@ -7469,8 +7494,8 @@ var dataStructureTyped = (() => {
7469
7494
  * are matching nodes, it returns `true`, indicating that the tree contains the specified element.
7470
7495
  * Otherwise, it returns `false`.
7471
7496
  */
7472
- has(keyOrNodeOrEntryOrRawOrPredicate, beginRoot = this._root, iterationType = this.iterationType) {
7473
- return this.getNodes(keyOrNodeOrEntryOrRawOrPredicate, true, beginRoot, iterationType).length > 0;
7497
+ has(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7498
+ return this.getNodes(keyNodeEntryRawOrPredicate, true, startNode, iterationType).length > 0;
7474
7499
  }
7475
7500
  /**
7476
7501
  * Time Complexity: O(1)
@@ -7479,8 +7504,8 @@ var dataStructureTyped = (() => {
7479
7504
  * The `clear` function resets the root node and size of a data structure to empty.
7480
7505
  */
7481
7506
  clear() {
7482
- this._setRoot(void 0);
7483
- this._size = 0;
7507
+ this._clearNodes();
7508
+ if (this._isMapMode) this._clearValues();
7484
7509
  }
7485
7510
  /**
7486
7511
  * Time Complexity: O(1)
@@ -7500,17 +7525,17 @@ var dataStructureTyped = (() => {
7500
7525
  *
7501
7526
  * The function checks if a binary tree is perfectly balanced by comparing its minimum height with
7502
7527
  * its height.
7503
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
7528
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
7504
7529
  * point for checking if the binary tree is perfectly balanced. It represents the root node of the
7505
7530
  * binary tree or a specific node from which the balance check should begin.
7506
7531
  * @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
7507
- * the tree starting from the `beginRoot` node is perfectly balanced or not. The return value is
7532
+ * the tree starting from the `startNode` node is perfectly balanced or not. The return value is
7508
7533
  * determined by comparing the minimum height of the tree with the height of the tree. If the minimum
7509
7534
  * height plus 1 is greater than or equal to the height of the tree, then it is considered perfectly
7510
7535
  * balanced and
7511
7536
  */
7512
- isPerfectlyBalanced(beginRoot = this._root) {
7513
- return this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot);
7537
+ isPerfectlyBalanced(startNode = this._root) {
7538
+ return this.getMinHeight(startNode) + 1 >= this.getHeight(startNode);
7514
7539
  }
7515
7540
  /**
7516
7541
  * Time Complexity: O(n)
@@ -7518,7 +7543,7 @@ var dataStructureTyped = (() => {
7518
7543
  *
7519
7544
  * The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
7520
7545
  * or iterative methods.
7521
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `isBST`
7546
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `isBST`
7522
7547
  * function represents the starting point for checking whether a binary search tree (BST) is valid.
7523
7548
  * It can be a node in the BST or a reference to the root of the BST. If no specific node is
7524
7549
  * provided, the function will default to
@@ -7530,9 +7555,9 @@ var dataStructureTyped = (() => {
7530
7555
  * the tree satisfies the BST property, where for every node, all nodes in its left subtree have keys
7531
7556
  * less than the node's key, and all nodes in its right subtree have keys greater than the node's
7532
7557
  */
7533
- isBST(beginRoot = this._root, iterationType = this.iterationType) {
7534
- beginRoot = this.ensureNode(beginRoot);
7535
- if (!beginRoot) return true;
7558
+ isBST(startNode = this._root, iterationType = this.iterationType) {
7559
+ startNode = this.ensureNode(startNode);
7560
+ if (!startNode) return true;
7536
7561
  if (iterationType === "RECURSIVE") {
7537
7562
  const dfs = (cur, min, max) => {
7538
7563
  if (!this.isRealNode(cur)) return true;
@@ -7540,14 +7565,14 @@ var dataStructureTyped = (() => {
7540
7565
  if (numKey <= min || numKey >= max) return false;
7541
7566
  return dfs(cur.left, min, numKey) && dfs(cur.right, numKey, max);
7542
7567
  };
7543
- const isStandardBST = dfs(beginRoot, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
7544
- const isInverseBST = dfs(beginRoot, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
7568
+ const isStandardBST = dfs(startNode, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
7569
+ const isInverseBST = dfs(startNode, Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER);
7545
7570
  return isStandardBST || isInverseBST;
7546
7571
  } else {
7547
7572
  const checkBST = (checkMax = false) => {
7548
7573
  const stack = [];
7549
7574
  let prev = checkMax ? Number.MAX_SAFE_INTEGER : Number.MIN_SAFE_INTEGER;
7550
- let curr = beginRoot;
7575
+ let curr = startNode;
7551
7576
  while (this.isRealNode(curr) || stack.length > 0) {
7552
7577
  while (this.isRealNode(curr)) {
7553
7578
  stack.push(curr);
@@ -7570,20 +7595,20 @@ var dataStructureTyped = (() => {
7570
7595
  * Space Complexity: O(1)
7571
7596
  *
7572
7597
  * The `getDepth` function calculates the depth between two nodes in a binary tree.
7573
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} dist - The `dist` parameter in the `getDepth`
7598
+ * @param {BTNRep<K, V, NODE> | R} dist - The `dist` parameter in the `getDepth`
7574
7599
  * function represents the node or entry in a binary tree map, or a reference to a node in the tree.
7575
- * It is the target node for which you want to calculate the depth from the `beginRoot` node.
7576
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7600
+ * It is the target node for which you want to calculate the depth from the `startNode` node.
7601
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7577
7602
  * `getDepth` function represents the starting point from which you want to calculate the depth of a
7578
7603
  * given node or entry in a binary tree. If no specific starting point is provided, the default value
7579
- * for `beginRoot` is set to the root of the binary
7604
+ * for `startNode` is set to the root of the binary
7580
7605
  * @returns The `getDepth` method returns the depth of a given node `dist` relative to the
7581
- * `beginRoot` node in a binary tree. If the `dist` node is not found in the path to the `beginRoot`
7606
+ * `startNode` node in a binary tree. If the `dist` node is not found in the path to the `startNode`
7582
7607
  * node, it returns the depth of the `dist` node from the root of the tree.
7583
7608
  */
7584
- getDepth(dist, beginRoot = this._root) {
7609
+ getDepth(dist, startNode = this._root) {
7585
7610
  let distEnsured = this.ensureNode(dist);
7586
- const beginRootEnsured = this.ensureNode(beginRoot);
7611
+ const beginRootEnsured = this.ensureNode(startNode);
7587
7612
  let depth = 0;
7588
7613
  while (distEnsured == null ? void 0 : distEnsured.parent) {
7589
7614
  if (distEnsured === beginRootEnsured) {
@@ -7600,7 +7625,7 @@ var dataStructureTyped = (() => {
7600
7625
  *
7601
7626
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
7602
7627
  * or iterative approach in TypeScript.
7603
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
7628
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
7604
7629
  * point from which the height of the binary tree will be calculated. It can be a node in the binary
7605
7630
  * tree or a reference to the root of the tree. If not provided, it defaults to the root of the
7606
7631
  * binary tree data structure.
@@ -7611,9 +7636,9 @@ var dataStructureTyped = (() => {
7611
7636
  * root node. The height is calculated based on the maximum depth of the tree, considering either a
7612
7637
  * recursive approach or an iterative approach depending on the `iterationType` parameter.
7613
7638
  */
7614
- getHeight(beginRoot = this._root, iterationType = this.iterationType) {
7615
- beginRoot = this.ensureNode(beginRoot);
7616
- if (!this.isRealNode(beginRoot)) return -1;
7639
+ getHeight(startNode = this._root, iterationType = this.iterationType) {
7640
+ startNode = this.ensureNode(startNode);
7641
+ if (!this.isRealNode(startNode)) return -1;
7617
7642
  if (iterationType === "RECURSIVE") {
7618
7643
  const _getMaxHeight = (cur) => {
7619
7644
  if (!this.isRealNode(cur)) return -1;
@@ -7621,9 +7646,9 @@ var dataStructureTyped = (() => {
7621
7646
  const rightHeight = _getMaxHeight(cur.right);
7622
7647
  return Math.max(leftHeight, rightHeight) + 1;
7623
7648
  };
7624
- return _getMaxHeight(beginRoot);
7649
+ return _getMaxHeight(startNode);
7625
7650
  } else {
7626
- const stack = [{ node: beginRoot, depth: 0 }];
7651
+ const stack = [{ node: startNode, depth: 0 }];
7627
7652
  let maxHeight = 0;
7628
7653
  while (stack.length > 0) {
7629
7654
  const { node, depth } = stack.pop();
@@ -7640,7 +7665,7 @@ var dataStructureTyped = (() => {
7640
7665
  *
7641
7666
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
7642
7667
  * recursive or iterative approach in TypeScript.
7643
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7668
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7644
7669
  * `getMinHeight` function represents the starting node from which the minimum height of the binary
7645
7670
  * tree will be calculated. It is either a node in the binary tree or a reference to the root of the
7646
7671
  * tree. If not provided, the default value is the root
@@ -7652,9 +7677,9 @@ var dataStructureTyped = (() => {
7652
7677
  * leaf node in the tree. The method uses either a recursive approach or an iterative approach (using
7653
7678
  * a stack) based on the `iterationType` parameter.
7654
7679
  */
7655
- getMinHeight(beginRoot = this._root, iterationType = this.iterationType) {
7656
- beginRoot = this.ensureNode(beginRoot);
7657
- if (!beginRoot) return -1;
7680
+ getMinHeight(startNode = this._root, iterationType = this.iterationType) {
7681
+ startNode = this.ensureNode(startNode);
7682
+ if (!startNode) return -1;
7658
7683
  if (iterationType === "RECURSIVE") {
7659
7684
  const _getMinHeight = (cur) => {
7660
7685
  if (!this.isRealNode(cur)) return 0;
@@ -7663,10 +7688,10 @@ var dataStructureTyped = (() => {
7663
7688
  const rightMinHeight = _getMinHeight(cur.right);
7664
7689
  return Math.min(leftMinHeight, rightMinHeight) + 1;
7665
7690
  };
7666
- return _getMinHeight(beginRoot);
7691
+ return _getMinHeight(startNode);
7667
7692
  } else {
7668
7693
  const stack = [];
7669
- let node = beginRoot, last = null;
7694
+ let node = startNode, last = null;
7670
7695
  const depths = /* @__PURE__ */ new Map();
7671
7696
  while (stack.length > 0 || node) {
7672
7697
  if (this.isRealNode(node)) {
@@ -7686,7 +7711,7 @@ var dataStructureTyped = (() => {
7686
7711
  } else node = node.right;
7687
7712
  }
7688
7713
  }
7689
- return depths.get(beginRoot);
7714
+ return depths.get(startNode);
7690
7715
  }
7691
7716
  }
7692
7717
  /**
@@ -7699,7 +7724,7 @@ var dataStructureTyped = (() => {
7699
7724
  * the path to the root. It is expected to be a function that takes a node as an argument and returns
7700
7725
  * a value based on that node. The return type of the callback function is determined by the generic
7701
7726
  * type `C
7702
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginNode - The `beginNode` parameter in the
7727
+ * @param {BTNRep<K, V, NODE> | R} beginNode - The `beginNode` parameter in the
7703
7728
  * `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
7704
7729
  * @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
7705
7730
  * whether the resulting path from the given `beginNode` to the root should be in reverse order or
@@ -7709,7 +7734,7 @@ var dataStructureTyped = (() => {
7709
7734
  * array is either in reverse order or in the original order based on the value of the `isReverse`
7710
7735
  * parameter.
7711
7736
  */
7712
- getPathToRoot(callback = this._DEFAULT_BTN_CALLBACK, beginNode, isReverse = true) {
7737
+ getPathToRoot(callback = this._DEFAULT_NODE_CALLBACK, beginNode, isReverse = true) {
7713
7738
  const result = [];
7714
7739
  let beginNodeEnsured = this.ensureNode(beginNode);
7715
7740
  if (!beginNodeEnsured) return result;
@@ -7728,8 +7753,8 @@ var dataStructureTyped = (() => {
7728
7753
  * tail-recursive iteration.
7729
7754
  * @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
7730
7755
  * node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
7731
- * value of `_DEFAULT_BTN_CALLBACK` if not specified.
7732
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7756
+ * value of `_DEFAULT_NODE_CALLBACK` if not specified.
7757
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7733
7758
  * `getLeftMost` function represents the starting point for finding the leftmost node in a binary
7734
7759
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
7735
7760
  * starting point is provided, the function will default
@@ -7737,26 +7762,26 @@ var dataStructureTyped = (() => {
7737
7762
  * specifies the type of iteration to be used when traversing the binary tree nodes. It can have two
7738
7763
  * possible values:
7739
7764
  * @returns The `getLeftMost` function returns the result of the callback function `C` applied to the
7740
- * leftmost node in the binary tree starting from the `beginRoot` node. If the `beginRoot` node is
7741
- * `NIL`, it returns the result of the callback function applied to `undefined`. If the `beginRoot`
7765
+ * leftmost node in the binary tree starting from the `startNode` node. If the `startNode` node is
7766
+ * `NIL`, it returns the result of the callback function applied to `undefined`. If the `startNode`
7742
7767
  * node is not a real node, it returns the result of the callback
7743
7768
  */
7744
- getLeftMost(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
7745
- if (this.isNIL(beginRoot)) return callback(void 0);
7746
- beginRoot = this.ensureNode(beginRoot);
7747
- if (!this.isRealNode(beginRoot)) return callback(beginRoot);
7769
+ getLeftMost(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
7770
+ if (this.isNIL(startNode)) return callback(void 0);
7771
+ startNode = this.ensureNode(startNode);
7772
+ if (!this.isRealNode(startNode)) return callback(startNode);
7748
7773
  if (iterationType === "RECURSIVE") {
7749
7774
  const dfs = (cur) => {
7750
7775
  if (!this.isRealNode(cur.left)) return cur;
7751
7776
  return dfs(cur.left);
7752
7777
  };
7753
- return callback(dfs(beginRoot));
7778
+ return callback(dfs(startNode));
7754
7779
  } else {
7755
7780
  const dfs = trampoline((cur) => {
7756
7781
  if (!this.isRealNode(cur.left)) return cur;
7757
7782
  return dfs.cont(cur.left);
7758
7783
  });
7759
- return callback(dfs(beginRoot));
7784
+ return callback(dfs(startNode));
7760
7785
  }
7761
7786
  }
7762
7787
  /**
@@ -7766,10 +7791,10 @@ var dataStructureTyped = (() => {
7766
7791
  * The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
7767
7792
  * or iterative traversal methods.
7768
7793
  * @param {C} callback - The `callback` parameter is a function that will be called with the result
7769
- * of finding the rightmost node in a binary tree. It is of type `BTNCallback<OptBTNOrNull<NODE>>`,
7794
+ * of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<NODE>>`,
7770
7795
  * which means it is a callback function that can accept either an optional binary tree node or null
7771
7796
  * as
7772
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
7797
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7773
7798
  * `getRightMost` function represents the starting point for finding the rightmost node in a binary
7774
7799
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
7775
7800
  * starting point is provided, the function will default
@@ -7781,22 +7806,22 @@ var dataStructureTyped = (() => {
7781
7806
  * the binary tree structure, determined based on the specified iteration type ('RECURSIVE' or
7782
7807
  * other).
7783
7808
  */
7784
- getRightMost(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
7785
- if (this.isNIL(beginRoot)) return callback(void 0);
7786
- beginRoot = this.ensureNode(beginRoot);
7787
- if (!beginRoot) return callback(beginRoot);
7809
+ getRightMost(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
7810
+ if (this.isNIL(startNode)) return callback(void 0);
7811
+ startNode = this.ensureNode(startNode);
7812
+ if (!startNode) return callback(startNode);
7788
7813
  if (iterationType === "RECURSIVE") {
7789
7814
  const dfs = (cur) => {
7790
7815
  if (!this.isRealNode(cur.right)) return cur;
7791
7816
  return dfs(cur.right);
7792
7817
  };
7793
- return callback(dfs(beginRoot));
7818
+ return callback(dfs(startNode));
7794
7819
  } else {
7795
7820
  const dfs = trampoline((cur) => {
7796
7821
  if (!this.isRealNode(cur.right)) return cur;
7797
7822
  return dfs.cont(cur.right);
7798
7823
  });
7799
- return callback(dfs(beginRoot));
7824
+ return callback(dfs(startNode));
7800
7825
  }
7801
7826
  }
7802
7827
  /**
@@ -7858,14 +7883,14 @@ var dataStructureTyped = (() => {
7858
7883
  * The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
7859
7884
  * specified parameters.
7860
7885
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends the
7861
- * `BTNCallback` interface with a type parameter of `OptBTNOrNull<NODE>`. It has a default value of
7862
- * `this._DEFAULT_BTN_CALLBACK as C`.
7886
+ * `NodeCallback` interface with a type parameter of `OptNodeOrNull<NODE>`. It has a default value of
7887
+ * `this._DEFAULT_NODE_CALLBACK as C`.
7863
7888
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
7864
7889
  * order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
7865
7890
  * possible values for the `pattern` parameter are:
7866
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `dfs`
7891
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `dfs`
7867
7892
  * method is used to specify the starting point for the Depth-First Search traversal. It can be
7868
- * either a `BTNKeyOrNodeOrEntry` object representing a key, node, or entry in the binary tree map,
7893
+ * either a `BTNRep` object representing a key, node, or entry in the binary tree map,
7869
7894
  * or it can be a
7870
7895
  * @param {IterationType} iterationType - The `iterationType` parameter in the `dfs` method specifies
7871
7896
  * the type of iteration to be performed during the depth-first search traversal. It is used to
@@ -7877,10 +7902,10 @@ var dataStructureTyped = (() => {
7877
7902
  * @returns The `dfs` method is returning an array of the return type specified by the generic type
7878
7903
  * parameter `C`. The return type is determined by the callback function provided to the method.
7879
7904
  */
7880
- dfs(callback = this._DEFAULT_BTN_CALLBACK, pattern = "IN", beginRoot = this._root, iterationType = this.iterationType, includeNull = false) {
7881
- beginRoot = this.ensureNode(beginRoot);
7882
- if (!beginRoot) return [];
7883
- return this._dfs(callback, pattern, beginRoot, iterationType, includeNull);
7905
+ dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType, includeNull = false) {
7906
+ startNode = this.ensureNode(startNode);
7907
+ if (!startNode) return [];
7908
+ return this._dfs(callback, pattern, startNode, iterationType, includeNull);
7884
7909
  }
7885
7910
  /**
7886
7911
  * Time complexity: O(n)
@@ -7890,8 +7915,8 @@ var dataStructureTyped = (() => {
7890
7915
  * tree, executing a specified callback function on each node visited.
7891
7916
  * @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
7892
7917
  * called on each node visited during the breadth-first search traversal. It is a generic type `C`
7893
- * that extends the `BTNCallback` type, which takes a parameter of type `NODE` or `null`.
7894
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `bfs`
7918
+ * that extends the `NodeCallback` type, which takes a parameter of type `NODE` or `null`.
7919
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `bfs`
7895
7920
  * function represents the starting point for the breadth-first search traversal in a binary tree. It
7896
7921
  * can be specified as a key, node, or entry in the binary tree structure. If not provided, the
7897
7922
  * default value is the root node of the binary
@@ -7905,12 +7930,12 @@ var dataStructureTyped = (() => {
7905
7930
  * @returns The `bfs` function returns an array of values that are the result of applying the
7906
7931
  * provided callback function to each node in the binary tree in a breadth-first search manner.
7907
7932
  */
7908
- bfs(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType, includeNull = false) {
7909
- beginRoot = this.ensureNode(beginRoot);
7910
- if (!beginRoot) return [];
7933
+ bfs(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType, includeNull = false) {
7934
+ startNode = this.ensureNode(startNode);
7935
+ if (!startNode) return [];
7911
7936
  const ans = [];
7912
7937
  if (iterationType === "RECURSIVE") {
7913
- const queue = new Queue([beginRoot]);
7938
+ const queue = new Queue([startNode]);
7914
7939
  const dfs = (level) => {
7915
7940
  if (queue.size === 0) return;
7916
7941
  const current = queue.shift();
@@ -7926,7 +7951,7 @@ var dataStructureTyped = (() => {
7926
7951
  };
7927
7952
  dfs(0);
7928
7953
  } else {
7929
- const queue = new Queue([beginRoot]);
7954
+ const queue = new Queue([startNode]);
7930
7955
  while (queue.size > 0) {
7931
7956
  const levelSize = queue.size;
7932
7957
  for (let i = 0; i < levelSize; i++) {
@@ -7952,7 +7977,7 @@ var dataStructureTyped = (() => {
7952
7977
  * structure based on a specified callback and iteration type.
7953
7978
  * @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
7954
7979
  * in the binary tree. It is optional and defaults to a default callback function if not provided.
7955
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `leaves`
7980
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `leaves`
7956
7981
  * method is used to specify the starting point for finding and processing the leaves of a binary
7957
7982
  * tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
7958
7983
  * explicitly provided, the default value
@@ -7962,10 +7987,10 @@ var dataStructureTyped = (() => {
7962
7987
  * @returns The `leaves` method returns an array of values that are the result of applying the
7963
7988
  * provided callback function to each leaf node in the binary tree.
7964
7989
  */
7965
- leaves(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
7966
- beginRoot = this.ensureNode(beginRoot);
7990
+ leaves(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
7991
+ startNode = this.ensureNode(startNode);
7967
7992
  const leaves = [];
7968
- if (!this.isRealNode(beginRoot)) return [];
7993
+ if (!this.isRealNode(startNode)) return [];
7969
7994
  if (iterationType === "RECURSIVE") {
7970
7995
  const dfs = (cur) => {
7971
7996
  if (this.isLeaf(cur)) {
@@ -7975,9 +8000,9 @@ var dataStructureTyped = (() => {
7975
8000
  if (this.isRealNode(cur.left)) dfs(cur.left);
7976
8001
  if (this.isRealNode(cur.right)) dfs(cur.right);
7977
8002
  };
7978
- dfs(beginRoot);
8003
+ dfs(startNode);
7979
8004
  } else {
7980
- const queue = new Queue([beginRoot]);
8005
+ const queue = new Queue([startNode]);
7981
8006
  while (queue.size > 0) {
7982
8007
  const cur = queue.shift();
7983
8008
  if (this.isRealNode(cur)) {
@@ -8000,7 +8025,7 @@ var dataStructureTyped = (() => {
8000
8025
  * @param {C} callback - The `callback` parameter is a function that will be applied to each node in
8001
8026
  * the binary tree during the traversal. It is used to process each node and determine what
8002
8027
  * information to include in the output for each level of the tree.
8003
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
8028
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8004
8029
  * `listLevels` function represents the starting point for traversing the binary tree. It can be
8005
8030
  * either a key, a node, or an entry in the binary tree. If not provided, the default value is the
8006
8031
  * root of the binary tree.
@@ -8015,10 +8040,10 @@ var dataStructureTyped = (() => {
8015
8040
  * level in a binary tree. Each inner array contains the return value of the provided callback
8016
8041
  * function applied to the nodes at that level.
8017
8042
  */
8018
- listLevels(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType, includeNull = false) {
8019
- beginRoot = this.ensureNode(beginRoot);
8043
+ listLevels(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType, includeNull = false) {
8044
+ startNode = this.ensureNode(startNode);
8020
8045
  const levelsNodes = [];
8021
- if (!beginRoot) return levelsNodes;
8046
+ if (!startNode) return levelsNodes;
8022
8047
  if (iterationType === "RECURSIVE") {
8023
8048
  const _recursive = (node, level) => {
8024
8049
  if (!levelsNodes[level]) levelsNodes[level] = [];
@@ -8031,9 +8056,9 @@ var dataStructureTyped = (() => {
8031
8056
  if (node && node.right) _recursive(node.right, level + 1);
8032
8057
  }
8033
8058
  };
8034
- _recursive(beginRoot, 0);
8059
+ _recursive(startNode, 0);
8035
8060
  } else {
8036
- const stack = [[beginRoot, 0]];
8061
+ const stack = [[startNode, 0]];
8037
8062
  while (stack.length > 0) {
8038
8063
  const head = stack.pop();
8039
8064
  const [node, level] = head;
@@ -8058,11 +8083,11 @@ var dataStructureTyped = (() => {
8058
8083
  * Morris Traversal algorithm with different order patterns.
8059
8084
  * @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
8060
8085
  * called on each node in the binary tree during the traversal. It is of type `C`, which extends the
8061
- * `BTNCallback<NODE>` type. The default value for `callback` is `this._DEFAULT
8086
+ * `NodeCallback<NODE>` type. The default value for `callback` is `this._DEFAULT
8062
8087
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
8063
8088
  * the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
8064
8089
  * values for the `pattern` parameter are:
8065
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `morris`
8090
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `morris`
8066
8091
  * function is the starting point for the Morris traversal algorithm. It represents the root node of
8067
8092
  * the binary tree or the node from which the traversal should begin. It can be provided as either a
8068
8093
  * key, a node, an entry, or a reference
@@ -8070,11 +8095,11 @@ var dataStructureTyped = (() => {
8070
8095
  * provided callback function to each node in the binary tree in the specified order pattern (IN,
8071
8096
  * PRE, or POST).
8072
8097
  */
8073
- morris(callback = this._DEFAULT_BTN_CALLBACK, pattern = "IN", beginRoot = this._root) {
8074
- beginRoot = this.ensureNode(beginRoot);
8075
- if (!beginRoot) return [];
8098
+ morris(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root) {
8099
+ startNode = this.ensureNode(startNode);
8100
+ if (!startNode) return [];
8076
8101
  const ans = [];
8077
- let cur = beginRoot;
8102
+ let cur = startNode;
8078
8103
  const _reverseEdge = (node) => {
8079
8104
  let pre = null;
8080
8105
  let next = null;
@@ -8145,7 +8170,7 @@ var dataStructureTyped = (() => {
8145
8170
  }
8146
8171
  cur = cur.right;
8147
8172
  }
8148
- _printEdge(beginRoot);
8173
+ _printEdge(startNode);
8149
8174
  break;
8150
8175
  }
8151
8176
  return ans;
@@ -8166,12 +8191,16 @@ var dataStructureTyped = (() => {
8166
8191
  this.bfs(
8167
8192
  (node) => {
8168
8193
  if (node === null) cloned.add(null);
8169
- else cloned.add([node.key, node.value]);
8194
+ else {
8195
+ if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
8196
+ else cloned.add([node.key, node.value]);
8197
+ }
8170
8198
  },
8171
8199
  this._root,
8172
8200
  this.iterationType,
8173
8201
  true
8174
8202
  );
8203
+ if (this._isMapMode) cloned._store = this._store;
8175
8204
  return cloned;
8176
8205
  }
8177
8206
  /**
@@ -8238,7 +8267,7 @@ var dataStructureTyped = (() => {
8238
8267
  *
8239
8268
  * The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
8240
8269
  * customizable options for displaying undefined, null, and sentinel nodes.
8241
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
8270
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8242
8271
  * `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
8243
8272
  * It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
8244
8273
  * the default is set to the root
@@ -8250,11 +8279,11 @@ var dataStructureTyped = (() => {
8250
8279
  * the lines to the output string. The final output string contains the visual representation of the
8251
8280
  * binary tree with the specified options.
8252
8281
  */
8253
- toVisual(beginRoot = this._root, options) {
8282
+ toVisual(startNode = this._root, options) {
8254
8283
  const opts = __spreadValues({ isShowUndefined: false, isShowNull: true, isShowRedBlackNIL: false }, options);
8255
- beginRoot = this.ensureNode(beginRoot);
8284
+ startNode = this.ensureNode(startNode);
8256
8285
  let output = "";
8257
- if (!beginRoot) return output;
8286
+ if (!startNode) return output;
8258
8287
  if (opts.isShowUndefined) output += `U for undefined
8259
8288
  `;
8260
8289
  if (opts.isShowNull) output += `N for null
@@ -8269,7 +8298,7 @@ var dataStructureTyped = (() => {
8269
8298
  }
8270
8299
  output += paragraph;
8271
8300
  };
8272
- display(beginRoot);
8301
+ display(startNode);
8273
8302
  return output;
8274
8303
  }
8275
8304
  /**
@@ -8282,13 +8311,13 @@ var dataStructureTyped = (() => {
8282
8311
  * printing options for the binary tree. It is an optional parameter that allows you to customize how
8283
8312
  * the binary tree is printed, such as choosing between different traversal orders or formatting
8284
8313
  * options.
8285
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
8314
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8286
8315
  * `override print` method is used to specify the starting point for printing the binary tree. It can
8287
8316
  * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
8288
8317
  * provided, the default value is set to
8289
8318
  */
8290
- print(options, beginRoot = this._root) {
8291
- console.log(this.toVisual(beginRoot, options));
8319
+ print(options, startNode = this._root) {
8320
+ console.log(this.toVisual(startNode, options));
8292
8321
  }
8293
8322
  /**
8294
8323
  * Time complexity: O(n)
@@ -8298,13 +8327,13 @@ var dataStructureTyped = (() => {
8298
8327
  * the specified order pattern and callback function.
8299
8328
  * @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
8300
8329
  * called on each node visited during the depth-first search traversal. It is of type `C`, which
8301
- * extends `BTNCallback<OptBTNOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
8330
+ * extends `NodeCallback<OptNodeOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
8302
8331
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
8303
8332
  * order in which the nodes are visited during the Depth-First Search traversal. It can have one of
8304
8333
  * the following values:
8305
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the `_dfs`
8334
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `_dfs`
8306
8335
  * method is used to specify the starting point for the depth-first search traversal in a binary
8307
- * tree. It can be provided as either a `BTNKeyOrNodeOrEntry` object or a reference to the root node
8336
+ * tree. It can be provided as either a `BTNRep` object or a reference to the root node
8308
8337
  * of the tree. If no specific
8309
8338
  * @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method
8310
8339
  * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
@@ -8332,12 +8361,12 @@ var dataStructureTyped = (() => {
8332
8361
  * @returns The function `_dfs` returns an array of the return type of the callback function provided
8333
8362
  * as input.
8334
8363
  */
8335
- _dfs(callback = this._DEFAULT_BTN_CALLBACK, pattern = "IN", beginRoot = this._root, iterationType = this.iterationType, includeNull = false, shouldVisitLeft = (node) => !!node, shouldVisitRight = (node) => !!node, shouldVisitRoot = (node) => {
8364
+ _dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType, includeNull = false, shouldVisitLeft = (node) => !!node, shouldVisitRight = (node) => !!node, shouldVisitRoot = (node) => {
8336
8365
  if (includeNull) return this.isRealNodeOrNull(node);
8337
8366
  return this.isRealNode(node);
8338
8367
  }, shouldProcessRoot = (node) => this.isRealNodeOrNull(node)) {
8339
- beginRoot = this.ensureNode(beginRoot);
8340
- if (!beginRoot) return [];
8368
+ startNode = this.ensureNode(startNode);
8369
+ if (!startNode) return [];
8341
8370
  const ans = [];
8342
8371
  if (iterationType === "RECURSIVE") {
8343
8372
  const dfs = (node) => {
@@ -8366,9 +8395,9 @@ var dataStructureTyped = (() => {
8366
8395
  break;
8367
8396
  }
8368
8397
  };
8369
- dfs(beginRoot);
8398
+ dfs(startNode);
8370
8399
  } else {
8371
- const stack = [{ opt: 0 /* VISIT */, node: beginRoot }];
8400
+ const stack = [{ opt: 0 /* VISIT */, node: startNode }];
8372
8401
  const pushLeft = (cur) => {
8373
8402
  var _a;
8374
8403
  if (shouldVisitLeft(cur.node)) stack.push({ opt: 0 /* VISIT */, node: (_a = cur.node) == null ? void 0 : _a.left });
@@ -8436,7 +8465,8 @@ var dataStructureTyped = (() => {
8436
8465
  }
8437
8466
  current = stack.pop();
8438
8467
  if (this.isRealNode(current)) {
8439
- yield [current.key, current.value];
8468
+ if (this._isMapMode) yield [current.key, this._store.get(current.key)];
8469
+ else yield [current.key, current.value];
8440
8470
  current = current.right;
8441
8471
  }
8442
8472
  }
@@ -8444,7 +8474,8 @@ var dataStructureTyped = (() => {
8444
8474
  if (node.left && this.isRealNode(node)) {
8445
8475
  yield* __yieldStar(this[Symbol.iterator](node.left));
8446
8476
  }
8447
- yield [node.key, node.value];
8477
+ if (this._isMapMode) yield [node.key, this._store.get(node.key)];
8478
+ else yield [node.key, node.value];
8448
8479
  if (node.right && this.isRealNode(node)) {
8449
8480
  yield* __yieldStar(this[Symbol.iterator](node.right));
8450
8481
  }
@@ -8510,12 +8541,12 @@ var dataStructureTyped = (() => {
8510
8541
  * Space Complexity: O(1)
8511
8542
  *
8512
8543
  * The _swapProperties function swaps key and value properties between two nodes in a binary tree.
8513
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
8514
- * `_swapProperties` method can be either a BTNKeyOrNodeOrEntry object containing key and value
8544
+ * @param {BTNRep<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
8545
+ * `_swapProperties` method can be either a BTNRep object containing key and value
8515
8546
  * properties, or it can be of type R.
8516
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} destNode - The `destNode` parameter in the
8547
+ * @param {BTNRep<K, V, NODE> | R} destNode - The `destNode` parameter in the
8517
8548
  * `_swapProperties` method represents the node or entry where the properties will be swapped with
8518
- * the `srcNode`. It can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>` or `R`. The method ensures that
8549
+ * the `srcNode`. It can be of type `BTNRep<K, V, NODE>` or `R`. The method ensures that
8519
8550
  * both `srcNode
8520
8551
  * @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
8521
8552
  * with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
@@ -8528,9 +8559,9 @@ var dataStructureTyped = (() => {
8528
8559
  const tempNode = this.createNode(key, value);
8529
8560
  if (tempNode) {
8530
8561
  destNode.key = srcNode.key;
8531
- destNode.value = srcNode.value;
8562
+ if (!this._isMapMode) destNode.value = srcNode.value;
8532
8563
  srcNode.key = tempNode.key;
8533
- srcNode.value = tempNode.value;
8564
+ if (!this._isMapMode) srcNode.value = tempNode.value;
8534
8565
  }
8535
8566
  return destNode;
8536
8567
  }
@@ -8572,7 +8603,7 @@ var dataStructureTyped = (() => {
8572
8603
  *
8573
8604
  * The function _setRoot sets the root node of a data structure while updating the parent reference
8574
8605
  * of the previous root node.
8575
- * @param v - The parameter `v` in the `_setRoot` method is of type `OptBTNOrNull<NODE>`, which means
8606
+ * @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<NODE>`, which means
8576
8607
  * it can either be an optional `NODE` type or `null`.
8577
8608
  */
8578
8609
  _setRoot(v) {
@@ -8587,43 +8618,103 @@ var dataStructureTyped = (() => {
8587
8618
  *
8588
8619
  * The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
8589
8620
  * predicate function for a binary tree node.
8590
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} keyOrEntryOrRawOrPredicate - The
8621
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
8591
8622
  * `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
8592
- * parameter `keyOrEntryOrRawOrPredicate` is transformed into a valid predicate function that can be
8623
+ * parameter `keyNodeEntryRawOrPredicate` is transformed into a valid predicate function that can be
8593
8624
  * used for filtering nodes in a binary tree.
8594
- * @returns A BTNPredicate<NODE> function is being returned.
8625
+ * @returns A NodePredicate<NODE> function is being returned.
8595
8626
  */
8596
- _ensurePredicate(keyOrEntryOrRawOrPredicate) {
8597
- if (keyOrEntryOrRawOrPredicate === null || keyOrEntryOrRawOrPredicate === void 0)
8627
+ _ensurePredicate(keyNodeEntryRawOrPredicate) {
8628
+ if (keyNodeEntryRawOrPredicate === null || keyNodeEntryRawOrPredicate === void 0)
8598
8629
  return (node) => node ? false : false;
8599
- if (this._isPredicated(keyOrEntryOrRawOrPredicate)) return keyOrEntryOrRawOrPredicate;
8600
- if (this.isRealNode(keyOrEntryOrRawOrPredicate)) return (node) => node === keyOrEntryOrRawOrPredicate;
8601
- if (this.isEntry(keyOrEntryOrRawOrPredicate)) {
8602
- const [key] = keyOrEntryOrRawOrPredicate;
8630
+ if (this._isPredicate(keyNodeEntryRawOrPredicate)) return keyNodeEntryRawOrPredicate;
8631
+ if (this.isRealNode(keyNodeEntryRawOrPredicate)) return (node) => node === keyNodeEntryRawOrPredicate;
8632
+ if (this.isEntry(keyNodeEntryRawOrPredicate)) {
8633
+ const [key] = keyNodeEntryRawOrPredicate;
8603
8634
  return (node) => node.key === key;
8604
8635
  }
8605
- if (this.isKey(keyOrEntryOrRawOrPredicate)) return (node) => node.key === keyOrEntryOrRawOrPredicate;
8636
+ if (this.isKey(keyNodeEntryRawOrPredicate)) return (node) => node.key === keyNodeEntryRawOrPredicate;
8606
8637
  if (this._toEntryFn) {
8607
- const [key] = this._toEntryFn(keyOrEntryOrRawOrPredicate);
8638
+ const [key] = this._toEntryFn(keyNodeEntryRawOrPredicate);
8608
8639
  return (node) => node.key === key;
8609
8640
  }
8610
- return (node) => node.key === keyOrEntryOrRawOrPredicate;
8641
+ return (node) => node.key === keyNodeEntryRawOrPredicate;
8611
8642
  }
8612
8643
  /**
8613
8644
  * Time Complexity: O(1)
8614
8645
  * Space Complexity: O(1)
8615
8646
  *
8616
- * The function `_isPredicated` checks if a given parameter is a function.
8647
+ * The function `_isPredicate` checks if a given parameter is a function.
8617
8648
  * @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
8618
- * of value. In this context, the function `_isPredicated` is checking if `p` is a function that
8619
- * satisfies the type `BTNPredicate<NODE>`.
8649
+ * of value. In this context, the function `_isPredicate` is checking if `p` is a function that
8650
+ * satisfies the type `NodePredicate<NODE>`.
8620
8651
  * @returns The function is checking if the input `p` is a function and returning a boolean value
8621
8652
  * based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
8622
8653
  * predicate function for a binary tree node. If `p` is not a function, it will return `false`.
8623
8654
  */
8624
- _isPredicated(p) {
8655
+ _isPredicate(p) {
8625
8656
  return typeof p === "function";
8626
8657
  }
8658
+ /**
8659
+ * Time Complexity: O(1)
8660
+ * Space Complexity: O(1)
8661
+ *
8662
+ * The function `_getKey` in TypeScript returns the key from a given input, which can be a node,
8663
+ * entry, raw data, or null/undefined.
8664
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `_getKey` method you provided is a
8665
+ * TypeScript method that takes in a parameter `keyNodeEntryOrRaw` of type `BTNRep<K, V, NODE> | R`,
8666
+ * where `BTNRep` is a generic type with keys `K`, `V`, and `NODE`, and `
8667
+ * @returns The `_getKey` method returns the key value extracted from the `keyNodeEntryOrRaw`
8668
+ * parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
8669
+ * the conditions checked in the method.
8670
+ */
8671
+ _getKey(keyNodeEntryOrRaw) {
8672
+ if (keyNodeEntryOrRaw === null) return null;
8673
+ if (keyNodeEntryOrRaw === void 0) return;
8674
+ if (keyNodeEntryOrRaw === this._NIL) return;
8675
+ if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw.key;
8676
+ if (this.isEntry(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw[0];
8677
+ if (this.isRaw(keyNodeEntryOrRaw)) {
8678
+ if (this._toEntryFn) {
8679
+ const [key] = this._toEntryFn(keyNodeEntryOrRaw);
8680
+ return key;
8681
+ }
8682
+ return;
8683
+ }
8684
+ return keyNodeEntryOrRaw;
8685
+ }
8686
+ /**
8687
+ * Time Complexity: O(1)
8688
+ * Space Complexity: O(1)
8689
+ *
8690
+ * The function `_setValue` sets a value in a store based on a key, handling cases where the key or
8691
+ * value is null or undefined.
8692
+ * @param {K | null | undefined} key - The `key` parameter can be of type `K`, `null`, or
8693
+ * `undefined`.
8694
+ * @param {V | undefined} value - The `value` parameter in the `_setValue` method can be of type `V`
8695
+ * or `undefined`.
8696
+ * @returns The method `_setValue` returns `false` if either the `key` is `null` or `undefined`, or
8697
+ * if the `value` is `undefined`. Otherwise, it returns the result of calling the `set` method on the
8698
+ * `_store` object with the `key` and `value` arguments.
8699
+ */
8700
+ _setValue(key, value) {
8701
+ if (key === null || key === void 0) return false;
8702
+ if (value === void 0) return false;
8703
+ return this._store.set(key, value);
8704
+ }
8705
+ /**
8706
+ * The _clearNodes function sets the root node to undefined and resets the size to 0.
8707
+ */
8708
+ _clearNodes() {
8709
+ this._setRoot(void 0);
8710
+ this._size = 0;
8711
+ }
8712
+ /**
8713
+ * The _clearValues function clears all values stored in the _store object.
8714
+ */
8715
+ _clearValues() {
8716
+ this._store.clear();
8717
+ }
8627
8718
  };
8628
8719
 
8629
8720
  // src/data-structures/binary-tree/bst.ts
@@ -8646,7 +8737,7 @@ var dataStructureTyped = (() => {
8646
8737
  }
8647
8738
  /**
8648
8739
  * The function sets the left child of a node and updates the parent reference of the child.
8649
- * @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
8740
+ * @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be an
8650
8741
  * instance of the `NODE` class or `undefined`.
8651
8742
  */
8652
8743
  set left(v) {
@@ -8665,7 +8756,7 @@ var dataStructureTyped = (() => {
8665
8756
  }
8666
8757
  /**
8667
8758
  * The function sets the right child of a node and updates the parent reference of the child.
8668
- * @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be a
8759
+ * @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be a
8669
8760
  * `NODE` object or `undefined`.
8670
8761
  */
8671
8762
  set right(v) {
@@ -8678,13 +8769,13 @@ var dataStructureTyped = (() => {
8678
8769
  var BST = class _BST extends BinaryTree {
8679
8770
  /**
8680
8771
  * This is the constructor function for a Binary Search Tree class in TypeScript.
8681
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
8772
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
8682
8773
  * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
8683
8774
  * added to the binary search tree during the construction of the object.
8684
8775
  * @param [options] - An optional object that contains additional options for the Binary Search Tree.
8685
8776
  * It can include a comparator function that defines the order of the elements in the tree.
8686
8777
  */
8687
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
8778
+ constructor(keysNodesEntriesOrRaws = [], options) {
8688
8779
  super([], options);
8689
8780
  __publicField(this, "_root");
8690
8781
  __publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
@@ -8702,7 +8793,7 @@ var dataStructureTyped = (() => {
8702
8793
  const { comparator } = options;
8703
8794
  if (comparator) this._comparator = comparator;
8704
8795
  }
8705
- if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
8796
+ if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8706
8797
  }
8707
8798
  /**
8708
8799
  * The function returns the root node of a tree structure.
@@ -8720,7 +8811,7 @@ var dataStructureTyped = (() => {
8720
8811
  * @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
8721
8812
  */
8722
8813
  createNode(key, value) {
8723
- return new BSTNode(key, value);
8814
+ return new BSTNode(key, this._isMapMode ? void 0 : value);
8724
8815
  }
8725
8816
  /**
8726
8817
  * The function creates a new binary search tree with the specified options.
@@ -8732,22 +8823,24 @@ var dataStructureTyped = (() => {
8732
8823
  createTree(options) {
8733
8824
  return new _BST([], __spreadValues({
8734
8825
  iterationType: this.iterationType,
8826
+ isMapMode: this._isMapMode,
8735
8827
  comparator: this._comparator,
8736
8828
  toEntryFn: this._toEntryFn
8737
8829
  }, options));
8738
8830
  }
8739
8831
  /**
8740
8832
  * The function overrides a method and converts a key, value pair or entry or raw element to a node.
8741
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - A variable that can be of
8742
- * type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
8833
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
8834
+ * type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
8743
8835
  * element.
8744
8836
  * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
8745
8837
  * value associated with a key in a key-value pair.
8746
8838
  * @returns either a NODE object or undefined.
8747
8839
  */
8748
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value) {
8749
- var _a;
8750
- return (_a = super.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value)) != null ? _a : void 0;
8840
+ keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
8841
+ const [node, entryValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
8842
+ if (node === null) return [void 0, void 0];
8843
+ return [node, value != null ? value : entryValue];
8751
8844
  }
8752
8845
  /**
8753
8846
  * Time Complexity: O(log n)
@@ -8755,8 +8848,8 @@ var dataStructureTyped = (() => {
8755
8848
  *
8756
8849
  * The function ensures the existence of a node in a data structure and returns it, or undefined if
8757
8850
  * it doesn't exist.
8758
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
8759
- * `keyOrNodeOrEntryOrRaw` can accept a value of type `R`, which represents the key, node,
8851
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
8852
+ * `keyNodeEntryOrRaw` can accept a value of type `R`, which represents the key, node,
8760
8853
  * entry, or raw element that needs to be ensured in the tree.
8761
8854
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
8762
8855
  * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
@@ -8764,19 +8857,19 @@ var dataStructureTyped = (() => {
8764
8857
  * @returns The method is returning either the node that was ensured or `undefined` if the node could
8765
8858
  * not be ensured.
8766
8859
  */
8767
- ensureNode(keyOrNodeOrEntryOrRaw, iterationType = this.iterationType) {
8860
+ ensureNode(keyNodeEntryOrRaw, iterationType = this.iterationType) {
8768
8861
  var _a;
8769
- return (_a = super.ensureNode(keyOrNodeOrEntryOrRaw, iterationType)) != null ? _a : void 0;
8862
+ return (_a = super.ensureNode(keyNodeEntryOrRaw, iterationType)) != null ? _a : void 0;
8770
8863
  }
8771
8864
  /**
8772
8865
  * The function checks if the input is an instance of the BSTNode class.
8773
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
8774
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
8775
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
8866
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
8867
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
8868
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
8776
8869
  * an instance of the `BSTNode` class.
8777
8870
  */
8778
- isNode(keyOrNodeOrEntryOrRaw) {
8779
- return keyOrNodeOrEntryOrRaw instanceof BSTNode;
8871
+ isNode(keyNodeEntryOrRaw) {
8872
+ return keyNodeEntryOrRaw instanceof BSTNode;
8780
8873
  }
8781
8874
  /**
8782
8875
  * The function "override isKey" checks if a key is comparable based on a given comparator.
@@ -8794,17 +8887,18 @@ var dataStructureTyped = (() => {
8794
8887
  * Space Complexity: O(1)
8795
8888
  *
8796
8889
  * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
8797
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
8798
- * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
8890
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
8891
+ * `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
8799
8892
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
8800
8893
  * key in the binary search tree. If provided, it will be stored in the node along with the key.
8801
8894
  * @returns a boolean value.
8802
8895
  */
8803
- add(keyOrNodeOrEntryOrRaw, value) {
8804
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
8896
+ add(keyNodeEntryOrRaw, value) {
8897
+ const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
8805
8898
  if (newNode === void 0) return false;
8806
8899
  if (this._root === void 0) {
8807
8900
  this._setRoot(newNode);
8901
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8808
8902
  this._size++;
8809
8903
  return true;
8810
8904
  }
@@ -8812,10 +8906,12 @@ var dataStructureTyped = (() => {
8812
8906
  while (current !== void 0) {
8813
8907
  if (this.comparator(current.key, newNode.key) === 0) {
8814
8908
  this._replaceNode(current, newNode);
8909
+ if (this._isMapMode) this._setValue(current.key, newValue);
8815
8910
  return true;
8816
8911
  } else if (this.comparator(current.key, newNode.key) > 0) {
8817
8912
  if (current.left === void 0) {
8818
8913
  current.left = newNode;
8914
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8819
8915
  this._size++;
8820
8916
  return true;
8821
8917
  }
@@ -8823,6 +8919,7 @@ var dataStructureTyped = (() => {
8823
8919
  } else {
8824
8920
  if (current.right === void 0) {
8825
8921
  current.right = newNode;
8922
+ if (this._isMapMode) this._setValue(newNode == null ? void 0 : newNode.key, newValue);
8826
8923
  this._size++;
8827
8924
  return true;
8828
8925
  }
@@ -8837,7 +8934,7 @@ var dataStructureTyped = (() => {
8837
8934
  *
8838
8935
  * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
8839
8936
  * an array indicating whether each key or node was successfully inserted.
8840
- * @param keysOrNodesOrEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
8937
+ * @param keysNodesEntriesOrRaws - An iterable containing keys, nodes, entries, or raw
8841
8938
  * elements to be added to the data structure.
8842
8939
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
8843
8940
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
@@ -8852,14 +8949,14 @@ var dataStructureTyped = (() => {
8852
8949
  * @returns The function `addMany` returns an array of booleans indicating whether each element was
8853
8950
  * successfully inserted into the data structure.
8854
8951
  */
8855
- addMany(keysOrNodesOrEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8952
+ addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8856
8953
  const inserted = [];
8857
8954
  let valuesIterator;
8858
8955
  if (values) {
8859
8956
  valuesIterator = values[Symbol.iterator]();
8860
8957
  }
8861
8958
  if (!isBalanceAdd) {
8862
- for (const kve of keysOrNodesOrEntriesOrRaws) {
8959
+ for (const kve of keysNodesEntriesOrRaws) {
8863
8960
  const value = valuesIterator == null ? void 0 : valuesIterator.next().value;
8864
8961
  inserted.push(this.add(kve, value));
8865
8962
  }
@@ -8867,7 +8964,7 @@ var dataStructureTyped = (() => {
8867
8964
  }
8868
8965
  const realBTNExemplars = [];
8869
8966
  let i = 0;
8870
- for (const kve of keysOrNodesOrEntriesOrRaws) {
8967
+ for (const kve of keysNodesEntriesOrRaws) {
8871
8968
  realBTNExemplars.push({ key: kve, value: valuesIterator == null ? void 0 : valuesIterator.next().value, orgIndex: i });
8872
8969
  i++;
8873
8970
  }
@@ -8930,30 +9027,30 @@ var dataStructureTyped = (() => {
8930
9027
  * Space Complexity: O(k + log n)
8931
9028
  *
8932
9029
  * The function `getNodes` in TypeScript overrides the base class method to retrieve nodes based on a
8933
- * given predicate and iteration type.
8934
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
9030
+ * given keyNodeEntryRawOrPredicate and iteration type.
9031
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The `keyNodeEntryRawOrPredicate`
8935
9032
  * parameter in the `getNodes` method is used to filter the nodes that will be returned. It can be a
8936
- * key, a node, an entry, or a custom predicate function that determines whether a node should be
9033
+ * key, a node, an entry, or a custom keyNodeEntryRawOrPredicate function that determines whether a node should be
8937
9034
  * included in the result.
8938
9035
  * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` method is a boolean flag that
8939
- * determines whether to return only the first node that matches the predicate (`true`) or all nodes
8940
- * that match the predicate (`false`). If `onlyOne` is set to `true`, the method will stop iterating
9036
+ * determines whether to return only the first node that matches the keyNodeEntryRawOrPredicate (`true`) or all nodes
9037
+ * that match the keyNodeEntryRawOrPredicate (`false`). If `onlyOne` is set to `true`, the method will stop iterating
8941
9038
  * and
8942
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter in the
9039
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8943
9040
  * `getNodes` method is used to specify the starting point for traversing the tree when searching for
8944
- * nodes that match a given predicate. It represents the root node of the subtree where the search
9041
+ * nodes that match a given keyNodeEntryRawOrPredicate. It represents the root node of the subtree where the search
8945
9042
  * should begin. If not explicitly provided, the default value for `begin
8946
9043
  * @param {IterationType} iterationType - The `iterationType` parameter in the `getNodes` method
8947
9044
  * specifies the type of iteration to be performed when traversing the nodes of a binary tree. It can
8948
9045
  * have two possible values:
8949
- * @returns The `getNodes` method returns an array of nodes that satisfy the given predicate.
8950
- */
8951
- getNodes(predicate, onlyOne = false, beginRoot = this._root, iterationType = this.iterationType) {
8952
- if (predicate === void 0) return [];
8953
- if (predicate === null) return [];
8954
- beginRoot = this.ensureNode(beginRoot);
8955
- if (!beginRoot) return [];
8956
- const callback = this._ensurePredicate(predicate);
9046
+ * @returns The `getNodes` method returns an array of nodes that satisfy the given keyNodeEntryRawOrPredicate.
9047
+ */
9048
+ getNodes(keyNodeEntryRawOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
9049
+ if (keyNodeEntryRawOrPredicate === void 0) return [];
9050
+ if (keyNodeEntryRawOrPredicate === null) return [];
9051
+ startNode = this.ensureNode(startNode);
9052
+ if (!startNode) return [];
9053
+ const callback = this._ensurePredicate(keyNodeEntryRawOrPredicate);
8957
9054
  const ans = [];
8958
9055
  if (iterationType === "RECURSIVE") {
8959
9056
  const dfs = (cur) => {
@@ -8962,26 +9059,32 @@ var dataStructureTyped = (() => {
8962
9059
  if (onlyOne) return;
8963
9060
  }
8964
9061
  if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) return;
8965
- if (this.isKey(predicate)) {
8966
- if (this.isRealNode(cur.left) && this.comparator(cur.key, predicate) > 0) dfs(cur.left);
8967
- if (this.isRealNode(cur.right) && this.comparator(cur.key, predicate) < 0) dfs(cur.right);
9062
+ if (!this._isPredicate(keyNodeEntryRawOrPredicate)) {
9063
+ const benchmarkKey = this._getKey(keyNodeEntryRawOrPredicate);
9064
+ if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this.comparator(cur.key, benchmarkKey) > 0)
9065
+ dfs(cur.left);
9066
+ if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this.comparator(cur.key, benchmarkKey) < 0)
9067
+ dfs(cur.right);
8968
9068
  } else {
8969
9069
  if (this.isRealNode(cur.left)) dfs(cur.left);
8970
9070
  if (this.isRealNode(cur.right)) dfs(cur.right);
8971
9071
  }
8972
9072
  };
8973
- dfs(beginRoot);
9073
+ dfs(startNode);
8974
9074
  } else {
8975
- const stack = [beginRoot];
9075
+ const stack = [startNode];
8976
9076
  while (stack.length > 0) {
8977
9077
  const cur = stack.pop();
8978
9078
  if (callback(cur)) {
8979
9079
  ans.push(cur);
8980
9080
  if (onlyOne) return ans;
8981
9081
  }
8982
- if (this.isKey(predicate)) {
8983
- if (this.isRealNode(cur.right) && this.comparator(cur.key, predicate) < 0) stack.push(cur.right);
8984
- if (this.isRealNode(cur.left) && this.comparator(cur.key, predicate) > 0) stack.push(cur.left);
9082
+ if (!this._isPredicate(keyNodeEntryRawOrPredicate)) {
9083
+ const benchmarkKey = this._getKey(keyNodeEntryRawOrPredicate);
9084
+ if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this.comparator(cur.key, benchmarkKey) < 0)
9085
+ stack.push(cur.right);
9086
+ if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this.comparator(cur.key, benchmarkKey) > 0)
9087
+ stack.push(cur.left);
8985
9088
  } else {
8986
9089
  if (this.isRealNode(cur.right)) stack.push(cur.right);
8987
9090
  if (this.isRealNode(cur.left)) stack.push(cur.left);
@@ -8994,10 +9097,10 @@ var dataStructureTyped = (() => {
8994
9097
  * Time Complexity: O(log n)
8995
9098
  * Space Complexity: O(1)
8996
9099
  *
8997
- * This function retrieves a node based on a given predicate within a binary search tree structure.
8998
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
8999
- * parameter can be of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, `R`, or `BTNPredicate<NODE>`.
9000
- * @param {R | BSTNKeyOrNode<K, NODE>} beginRoot - The `beginRoot` parameter in the `getNode` method
9100
+ * This function retrieves a node based on a given keyNodeEntryRawOrPredicate within a binary search tree structure.
9101
+ * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The `keyNodeEntryRawOrPredicate`
9102
+ * parameter can be of type `BTNRep<K, V, NODE>`, `R`, or `NodePredicate<NODE>`.
9103
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} startNode - The `startNode` parameter in the `getNode` method
9001
9104
  * is used to specify the starting point for searching nodes in the binary search tree. If no
9002
9105
  * specific starting point is provided, the default value is set to `this._root`, which is the root
9003
9106
  * node of the binary search tree.
@@ -9005,14 +9108,14 @@ var dataStructureTyped = (() => {
9005
9108
  * parameter that specifies the type of iteration to be used. It has a default value of
9006
9109
  * `this.iterationType`, which means it will use the iteration type defined in the class instance if
9007
9110
  * no value is provided when calling the method.
9008
- * @returns The `getNode` method is returning an optional binary search tree node (`OptBSTN<NODE>`).
9009
- * It is using the `getNodes` method to find the node based on the provided predicate, beginning at
9010
- * the specified root node (`beginRoot`) and using the specified iteration type. The method then
9111
+ * @returns The `getNode` method is returning an optional binary search tree node (`OptNode<NODE>`).
9112
+ * It is using the `getNodes` method to find the node based on the provided keyNodeEntryRawOrPredicate, beginning at
9113
+ * the specified root node (`startNode`) and using the specified iteration type. The method then
9011
9114
  * returns the first node found or `undefined` if no node is found.
9012
9115
  */
9013
- getNode(predicate, beginRoot = this._root, iterationType = this.iterationType) {
9116
+ getNode(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
9014
9117
  var _a;
9015
- return (_a = this.getNodes(predicate, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
9118
+ return (_a = this.getNodes(keyNodeEntryRawOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
9016
9119
  }
9017
9120
  /**
9018
9121
  * Time Complexity: O(log n)
@@ -9038,11 +9141,11 @@ var dataStructureTyped = (() => {
9038
9141
  * the callback function.
9039
9142
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9040
9143
  * during the depth-first search traversal. It is an optional parameter and defaults to
9041
- * `this._DEFAULT_BTN_CALLBACK`. The type `C` represents the type of the callback function.
9144
+ * `this._DEFAULT_NODE_CALLBACK`. The type `C` represents the type of the callback function.
9042
9145
  * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
9043
9146
  * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
9044
9147
  * take one of the following values:
9045
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
9148
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
9046
9149
  * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
9047
9150
  * node entry. If not specified, the default value is the root of the tree.
9048
9151
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
@@ -9050,8 +9153,8 @@ var dataStructureTyped = (() => {
9050
9153
  * following values:
9051
9154
  * @returns The method is returning an array of the return type of the callback function.
9052
9155
  */
9053
- dfs(callback = this._DEFAULT_BTN_CALLBACK, pattern = "IN", beginRoot = this._root, iterationType = this.iterationType) {
9054
- return super.dfs(callback, pattern, beginRoot, iterationType);
9156
+ dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType) {
9157
+ return super.dfs(callback, pattern, startNode, iterationType);
9055
9158
  }
9056
9159
  /**
9057
9160
  * Time complexity: O(n)
@@ -9062,7 +9165,7 @@ var dataStructureTyped = (() => {
9062
9165
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9063
9166
  * visited during the breadth-first search. It should take a single argument, which is the current
9064
9167
  * node being visited, and it can return a value of any type.
9065
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
9168
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
9066
9169
  * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
9067
9170
  * object. If no value is provided, the default value is the root of the tree.
9068
9171
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -9070,8 +9173,8 @@ var dataStructureTyped = (() => {
9070
9173
  * the following values:
9071
9174
  * @returns an array of the return type of the callback function.
9072
9175
  */
9073
- bfs(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
9074
- return super.bfs(callback, beginRoot, iterationType, false);
9176
+ bfs(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
9177
+ return super.bfs(callback, startNode, iterationType, false);
9075
9178
  }
9076
9179
  /**
9077
9180
  * Time complexity: O(n)
@@ -9080,9 +9183,9 @@ var dataStructureTyped = (() => {
9080
9183
  * The function overrides the listLevels method from the superclass and returns an array of arrays
9081
9184
  * containing the results of the callback function applied to each level of the tree.
9082
9185
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
9083
- * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
9186
+ * `NodeCallback<NODE>`. It represents a callback function that will be called for each node in the
9084
9187
  * tree during the iteration process.
9085
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} beginRoot - The `beginRoot` parameter is the starting
9188
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
9086
9189
  * point for listing the levels of the binary tree. It can be either a root node of the tree, a
9087
9190
  * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
9088
9191
  * value is provided, the root of
@@ -9091,8 +9194,8 @@ var dataStructureTyped = (() => {
9091
9194
  * @returns The method is returning a two-dimensional array of the return type of the callback
9092
9195
  * function.
9093
9196
  */
9094
- listLevels(callback = this._DEFAULT_BTN_CALLBACK, beginRoot = this._root, iterationType = this.iterationType) {
9095
- return super.listLevels(callback, beginRoot, iterationType, false);
9197
+ listLevels(callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
9198
+ return super.listLevels(callback, startNode, iterationType, false);
9096
9199
  }
9097
9200
  /**
9098
9201
  * Time complexity: O(n)
@@ -9106,7 +9209,7 @@ var dataStructureTyped = (() => {
9106
9209
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
9107
9210
  * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
9108
9211
  * 0, or 1, where:
9109
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} targetNode - The `targetNode` parameter is the node in
9212
+ * @param {BTNRep<K, V, NODE> | R} targetNode - The `targetNode` parameter is the node in
9110
9213
  * the binary tree that you want to start traversing from. It can be specified either by providing
9111
9214
  * the key of the node, the node itself, or an entry containing the key and value of the node. If no
9112
9215
  * `targetNode` is provided,
@@ -9115,7 +9218,7 @@ var dataStructureTyped = (() => {
9115
9218
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
9116
9219
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
9117
9220
  */
9118
- lesserOrGreaterTraverse(callback = this._DEFAULT_BTN_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
9221
+ lesserOrGreaterTraverse(callback = this._DEFAULT_NODE_CALLBACK, lesserOrGreater = -1, targetNode = this._root, iterationType = this.iterationType) {
9119
9222
  const targetNodeEnsured = this.ensureNode(targetNode);
9120
9223
  const ans = [];
9121
9224
  if (!this._root) return ans;
@@ -9158,14 +9261,15 @@ var dataStructureTyped = (() => {
9158
9261
  */
9159
9262
  perfectlyBalance(iterationType = this.iterationType) {
9160
9263
  const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
9161
- this.clear();
9264
+ this._clearNodes();
9162
9265
  if (sorted.length < 1) return false;
9163
9266
  if (iterationType === "RECURSIVE") {
9164
9267
  const buildBalanceBST = (l, r) => {
9165
9268
  if (l > r) return;
9166
9269
  const m = l + Math.floor((r - l) / 2);
9167
9270
  const midNode = sorted[m];
9168
- this.add([midNode.key, midNode.value]);
9271
+ if (this._isMapMode) this.add(midNode.key);
9272
+ else this.add([midNode.key, midNode.value]);
9169
9273
  buildBalanceBST(l, m - 1);
9170
9274
  buildBalanceBST(m + 1, r);
9171
9275
  };
@@ -9180,7 +9284,8 @@ var dataStructureTyped = (() => {
9180
9284
  if (l <= r) {
9181
9285
  const m = l + Math.floor((r - l) / 2);
9182
9286
  const midNode = sorted[m];
9183
- this.add([midNode.key, midNode.value]);
9287
+ if (this._isMapMode) this.add(midNode.key);
9288
+ else this.add([midNode.key, midNode.value]);
9184
9289
  stack.push([m + 1, r]);
9185
9290
  stack.push([l, m - 1]);
9186
9291
  }
@@ -9248,7 +9353,7 @@ var dataStructureTyped = (() => {
9248
9353
  /**
9249
9354
  * The function sets the root of a tree-like structure and updates the parent property of the new
9250
9355
  * root.
9251
- * @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
9356
+ * @param {OptNode<NODE>} v - v is a parameter of type NODE or undefined.
9252
9357
  */
9253
9358
  _setRoot(v) {
9254
9359
  if (v) {
@@ -9856,7 +9961,7 @@ var dataStructureTyped = (() => {
9856
9961
  /**
9857
9962
  * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
9858
9963
  * entries, or raw elements.
9859
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
9964
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
9860
9965
  * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
9861
9966
  * be used to initialize the AVLTree.
9862
9967
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
@@ -9864,9 +9969,9 @@ var dataStructureTyped = (() => {
9864
9969
  * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
9865
9970
  * `nodeBuilder` (
9866
9971
  */
9867
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
9972
+ constructor(keysNodesEntriesOrRaws = [], options) {
9868
9973
  super([], options);
9869
- if (keysOrNodesOrEntriesOrRaws) super.addMany(keysOrNodesOrEntriesOrRaws);
9974
+ if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
9870
9975
  }
9871
9976
  /**
9872
9977
  * The function creates a new AVL tree node with the given key and value.
@@ -9878,7 +9983,7 @@ var dataStructureTyped = (() => {
9878
9983
  * type NODE.
9879
9984
  */
9880
9985
  createNode(key, value) {
9881
- return new AVLTreeNode(key, value);
9986
+ return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
9882
9987
  }
9883
9988
  /**
9884
9989
  * The function creates a new AVL tree with the specified options and returns it.
@@ -9890,19 +9995,20 @@ var dataStructureTyped = (() => {
9890
9995
  createTree(options) {
9891
9996
  return new _AVLTree([], __spreadValues({
9892
9997
  iterationType: this.iterationType,
9998
+ isMapMode: this._isMapMode,
9893
9999
  comparator: this._comparator,
9894
10000
  toEntryFn: this._toEntryFn
9895
10001
  }, options));
9896
10002
  }
9897
10003
  /**
9898
10004
  * The function checks if the input is an instance of AVLTreeNode.
9899
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
9900
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
9901
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
10005
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10006
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
10007
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
9902
10008
  * an instance of the `AVLTreeNode` class.
9903
10009
  */
9904
- isNode(keyOrNodeOrEntryOrRaw) {
9905
- return keyOrNodeOrEntryOrRaw instanceof AVLTreeNode;
10010
+ isNode(keyNodeEntryOrRaw) {
10011
+ return keyNodeEntryOrRaw instanceof AVLTreeNode;
9906
10012
  }
9907
10013
  /**
9908
10014
  * Time Complexity: O(log n)
@@ -9910,17 +10016,17 @@ var dataStructureTyped = (() => {
9910
10016
  *
9911
10017
  * The function overrides the add method of a class and inserts a key-value pair into a data
9912
10018
  * structure, then balances the path.
9913
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
9914
- * `keyOrNodeOrEntryOrRaw` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
10019
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10020
+ * `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
9915
10021
  * `RawElement`.
9916
10022
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
9917
10023
  * the key or node being added to the data structure.
9918
10024
  * @returns The method is returning a boolean value.
9919
10025
  */
9920
- add(keyOrNodeOrEntryOrRaw, value) {
9921
- if (keyOrNodeOrEntryOrRaw === null) return false;
9922
- const inserted = super.add(keyOrNodeOrEntryOrRaw, value);
9923
- if (inserted) this._balancePath(keyOrNodeOrEntryOrRaw);
10026
+ add(keyNodeEntryOrRaw, value) {
10027
+ if (keyNodeEntryOrRaw === null) return false;
10028
+ const inserted = super.add(keyNodeEntryOrRaw, value);
10029
+ if (inserted) this._balancePath(keyNodeEntryOrRaw);
9924
10030
  return inserted;
9925
10031
  }
9926
10032
  /**
@@ -9929,15 +10035,15 @@ var dataStructureTyped = (() => {
9929
10035
  *
9930
10036
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
9931
10037
  * balances the tree if necessary.
9932
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
10038
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
9933
10039
  * parameter in the `override delete` method can be one of the following types:
9934
10040
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
9935
10041
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
9936
10042
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
9937
10043
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
9938
10044
  */
9939
- delete(keyOrNodeOrEntryOrRaw) {
9940
- const deletedResults = super.delete(keyOrNodeOrEntryOrRaw);
10045
+ delete(keyNodeEntryOrRaw) {
10046
+ const deletedResults = super.delete(keyNodeEntryOrRaw);
9941
10047
  for (const { needBalanced } of deletedResults) {
9942
10048
  if (needBalanced) {
9943
10049
  this._balancePath(needBalanced);
@@ -9951,10 +10057,10 @@ var dataStructureTyped = (() => {
9951
10057
  *
9952
10058
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
9953
10059
  * binary search tree.
9954
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
10060
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
9955
10061
  * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
9956
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
9957
- * `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
10062
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
10063
+ * `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
9958
10064
  * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
9959
10065
  * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
9960
10066
  */
@@ -9967,10 +10073,10 @@ var dataStructureTyped = (() => {
9967
10073
  if (tempNode) {
9968
10074
  tempNode.height = height;
9969
10075
  destNodeEnsured.key = srcNodeEnsured.key;
9970
- destNodeEnsured.value = srcNodeEnsured.value;
10076
+ if (!this._isMapMode) destNodeEnsured.value = srcNodeEnsured.value;
9971
10077
  destNodeEnsured.height = srcNodeEnsured.height;
9972
10078
  srcNodeEnsured.key = tempNode.key;
9973
- srcNodeEnsured.value = tempNode.value;
10079
+ if (!this._isMapMode) srcNodeEnsured.value = tempNode.value;
9974
10080
  srcNodeEnsured.height = tempNode.height;
9975
10081
  }
9976
10082
  return destNodeEnsured;
@@ -10172,8 +10278,8 @@ var dataStructureTyped = (() => {
10172
10278
  *
10173
10279
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
10174
10280
  * to restore balance in an AVL tree after inserting a node.
10175
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
10176
- * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
10281
+ * @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
10282
+ * `BTNRep<K, V, NODE>`.
10177
10283
  */
10178
10284
  _balancePath(node) {
10179
10285
  node = this.ensureNode(node);
@@ -10259,7 +10365,7 @@ var dataStructureTyped = (() => {
10259
10365
  var RedBlackTree = class _RedBlackTree extends BST {
10260
10366
  /**
10261
10367
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
10262
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
10368
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
10263
10369
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
10264
10370
  * initialize the RBTree with the provided elements.
10265
10371
  * @param [options] - The `options` parameter is an optional object that can be passed to the
@@ -10267,12 +10373,12 @@ var dataStructureTyped = (() => {
10267
10373
  * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
10268
10374
  * depend on the implementation
10269
10375
  */
10270
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
10376
+ constructor(keysNodesEntriesOrRaws = [], options) {
10271
10377
  super([], options);
10272
10378
  __publicField(this, "_root");
10273
10379
  this._root = this.NIL;
10274
- if (keysOrNodesOrEntriesOrRaws) {
10275
- this.addMany(keysOrNodesOrEntriesOrRaws);
10380
+ if (keysNodesEntriesOrRaws) {
10381
+ this.addMany(keysNodesEntriesOrRaws);
10276
10382
  }
10277
10383
  }
10278
10384
  /**
@@ -10297,7 +10403,7 @@ var dataStructureTyped = (() => {
10297
10403
  * returned.
10298
10404
  */
10299
10405
  createNode(key, value, color = "BLACK") {
10300
- return new RedBlackTreeNode(key, value, color);
10406
+ return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
10301
10407
  }
10302
10408
  /**
10303
10409
  * The function creates a new Red-Black Tree with the specified options.
@@ -10308,6 +10414,7 @@ var dataStructureTyped = (() => {
10308
10414
  createTree(options) {
10309
10415
  return new _RedBlackTree([], __spreadValues({
10310
10416
  iterationType: this.iterationType,
10417
+ isMapMode: this._isMapMode,
10311
10418
  comparator: this._comparator,
10312
10419
  toEntryFn: this._toEntryFn
10313
10420
  }, options));
@@ -10317,13 +10424,13 @@ var dataStructureTyped = (() => {
10317
10424
  * Space Complexity: O(1)
10318
10425
  *
10319
10426
  * The function checks if the input is an instance of the RedBlackTreeNode class.
10320
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
10321
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
10322
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
10427
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10428
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
10429
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
10323
10430
  * an instance of the `RedBlackTreeNode` class.
10324
10431
  */
10325
- isNode(keyOrNodeOrEntryOrRaw) {
10326
- return keyOrNodeOrEntryOrRaw instanceof RedBlackTreeNode;
10432
+ isNode(keyNodeEntryOrRaw) {
10433
+ return keyNodeEntryOrRaw instanceof RedBlackTreeNode;
10327
10434
  }
10328
10435
  // /**
10329
10436
  // * Time Complexity: O(1)
@@ -10334,29 +10441,29 @@ var dataStructureTyped = (() => {
10334
10441
  // * Time Complexity: O(1)
10335
10442
  // * Space Complexity: O(1)
10336
10443
  // *
10337
- // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
10444
+ // * The function `keyValueNodeEntryRawToNodeAndValue` takes a key, value, or entry and returns a node if it is
10338
10445
  // * valid, otherwise it returns undefined.
10339
- // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRaw - The key, value, or entry to convert.
10340
- // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRaw` is a key).
10446
+ // * @param {BTNRep<K, V, NODE>} keyNodeEntryOrRaw - The key, value, or entry to convert.
10447
+ // * @param {V} [value] - The value associated with the key (if `keyNodeEntryOrRaw` is a key).
10341
10448
  // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
10342
10449
  // */
10343
- // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): NODE | undefined {
10450
+ // override keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): NODE | undefined {
10344
10451
  //
10345
- // if (keyOrNodeOrEntryOrRaw === null || keyOrNodeOrEntryOrRaw === undefined) return;
10346
- // if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
10452
+ // if (keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === undefined) return;
10453
+ // if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
10347
10454
  //
10348
10455
  // if (this._toEntryFn) {
10349
- // const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw as R);
10350
- // if (this.isKey(key)) return this.createNode(key, entryValue ?? value, 'RED');
10456
+ // const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw as R);
10457
+ // if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'RED');
10351
10458
  // }
10352
10459
  //
10353
- // if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
10354
- // const [key, value] = keyOrNodeOrEntryOrRaw;
10460
+ // if (this.isEntry(keyNodeEntryOrRaw)) {
10461
+ // const [key, value] = keyNodeEntryOrRaw;
10355
10462
  // if (key === undefined || key === null) return;
10356
10463
  // else return this.createNode(key, value, 'RED');
10357
10464
  // }
10358
10465
  //
10359
- // if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, 'RED');
10466
+ // if (this.isKey(keyNodeEntryOrRaw)) return this.createNode(keyNodeEntryOrRaw, value, 'RED');
10360
10467
  //
10361
10468
  // return ;
10362
10469
  // }
@@ -10377,8 +10484,8 @@ var dataStructureTyped = (() => {
10377
10484
  *
10378
10485
  * The function adds a new node to a binary search tree and returns true if the node was successfully
10379
10486
  * added.
10380
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
10381
- * `keyOrNodeOrEntryOrRaw` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
10487
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10488
+ * `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
10382
10489
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
10383
10490
  * the key in the data structure. It represents the value that you want to add or update in the data
10384
10491
  * structure.
@@ -10386,8 +10493,8 @@ var dataStructureTyped = (() => {
10386
10493
  * the method returns true. If the node already exists and its value is updated, the method also
10387
10494
  * returns true. If the node cannot be added or updated, the method returns false.
10388
10495
  */
10389
- add(keyOrNodeOrEntryOrRaw, value) {
10390
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value);
10496
+ add(keyNodeEntryOrRaw, value) {
10497
+ const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
10391
10498
  if (!this.isRealNode(newNode)) return false;
10392
10499
  const insertStatus = this._insert(newNode);
10393
10500
  if (insertStatus === "CREATED") {
@@ -10396,9 +10503,15 @@ var dataStructureTyped = (() => {
10396
10503
  } else {
10397
10504
  return false;
10398
10505
  }
10506
+ if (this._isMapMode) this._setValue(newNode.key, newValue);
10399
10507
  this._size++;
10400
10508
  return true;
10401
- } else return insertStatus === "UPDATED";
10509
+ }
10510
+ if (insertStatus === "UPDATED") {
10511
+ if (this._isMapMode) this._setValue(newNode.key, newValue);
10512
+ return true;
10513
+ }
10514
+ return false;
10402
10515
  }
10403
10516
  /**
10404
10517
  * Time Complexity: O(log n)
@@ -10406,7 +10519,7 @@ var dataStructureTyped = (() => {
10406
10519
  *
10407
10520
  * The function overrides the delete method in a binary tree data structure to remove a node based on
10408
10521
  * a given predicate and maintain the binary search tree properties.
10409
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `keyOrNodeOrEntryOrRaw`
10522
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
10410
10523
  * parameter in the `override delete` method is used to specify the condition or key based on which a
10411
10524
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
10412
10525
  * function that determines which node(s) should be deleted.
@@ -10414,13 +10527,12 @@ var dataStructureTyped = (() => {
10414
10527
  * objects. Each object in the array contains information about the deleted node and whether
10415
10528
  * balancing is needed.
10416
10529
  */
10417
- delete(keyOrNodeOrEntryOrRaw) {
10418
- if (keyOrNodeOrEntryOrRaw === null) return [];
10530
+ delete(keyNodeEntryOrRaw) {
10531
+ if (keyNodeEntryOrRaw === null) return [];
10419
10532
  const results = [];
10420
10533
  let nodeToDelete;
10421
- if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
10422
- else
10423
- nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw) ? keyOrNodeOrEntryOrRaw : this.getNode(keyOrNodeOrEntryOrRaw);
10534
+ if (this._isPredicate(keyNodeEntryOrRaw)) nodeToDelete = this.getNode(keyNodeEntryOrRaw);
10535
+ else nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
10424
10536
  if (!nodeToDelete) {
10425
10537
  return results;
10426
10538
  }
@@ -10456,6 +10568,7 @@ var dataStructureTyped = (() => {
10456
10568
  successor.color = nodeToDelete.color;
10457
10569
  }
10458
10570
  }
10571
+ if (this._isMapMode) this._store.delete(nodeToDelete.key);
10459
10572
  this._size--;
10460
10573
  if (originalColor === "BLACK") {
10461
10574
  this._deleteFixup(replacementNode);
@@ -10769,16 +10882,16 @@ var dataStructureTyped = (() => {
10769
10882
  var AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
10770
10883
  /**
10771
10884
  * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
10772
- * @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
10885
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
10773
10886
  * iterable object that can contain either keys, nodes, entries, or raw elements.
10774
10887
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
10775
10888
  * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
10776
10889
  * `compareValues` functions to define custom comparison logic for keys and values, respectively.
10777
10890
  */
10778
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
10891
+ constructor(keysNodesEntriesOrRaws = [], options) {
10779
10892
  super([], options);
10780
10893
  __publicField(this, "_count", 0);
10781
- if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
10894
+ if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
10782
10895
  }
10783
10896
  /**
10784
10897
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
@@ -10813,7 +10926,7 @@ var dataStructureTyped = (() => {
10813
10926
  * @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
10814
10927
  */
10815
10928
  createNode(key, value, count) {
10816
- return new AVLTreeMultiMapNode(key, value, count);
10929
+ return new AVLTreeMultiMapNode(key, this._isMapMode ? void 0 : value, count);
10817
10930
  }
10818
10931
  /**
10819
10932
  * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
@@ -10825,25 +10938,26 @@ var dataStructureTyped = (() => {
10825
10938
  createTree(options) {
10826
10939
  return new _AVLTreeMultiMap([], __spreadValues({
10827
10940
  iterationType: this.iterationType,
10941
+ isMapMode: this._isMapMode,
10828
10942
  comparator: this._comparator,
10829
10943
  toEntryFn: this._toEntryFn
10830
10944
  }, options));
10831
10945
  }
10832
10946
  /**
10833
10947
  * The function checks if the input is an instance of AVLTreeMultiMapNode.
10834
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
10835
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
10836
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
10948
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10949
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
10950
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
10837
10951
  * an instance of the `AVLTreeMultiMapNode` class.
10838
10952
  */
10839
- isNode(keyOrNodeOrEntryOrRaw) {
10840
- return keyOrNodeOrEntryOrRaw instanceof AVLTreeMultiMapNode;
10953
+ isNode(keyNodeEntryOrRaw) {
10954
+ return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
10841
10955
  }
10842
10956
  /**
10843
- * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
10957
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
10844
10958
  * a node object.
10845
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
10846
- * `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
10959
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
10960
+ * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
10847
10961
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
10848
10962
  * `override` function. It represents the value associated with the key in the data structure. If no
10849
10963
  * value is provided, it will default to `undefined`.
@@ -10851,20 +10965,25 @@ var dataStructureTyped = (() => {
10851
10965
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
10852
10966
  * @returns either a NODE object or undefined.
10853
10967
  */
10854
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
10855
- if (keyOrNodeOrEntryOrRaw === void 0 || keyOrNodeOrEntryOrRaw === null) return;
10856
- if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
10857
- if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
10858
- const [key, entryValue] = keyOrNodeOrEntryOrRaw;
10859
- if (key === void 0 || key === null) return;
10860
- if (this.isKey(key)) return this.createNode(key, value != null ? value : entryValue, count);
10968
+ keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
10969
+ if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
10970
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
10971
+ if (this.isEntry(keyNodeEntryOrRaw)) {
10972
+ const [key, entryValue] = keyNodeEntryOrRaw;
10973
+ if (key === void 0 || key === null) return [void 0, void 0];
10974
+ const finalValue = value != null ? value : entryValue;
10975
+ return [this.createNode(key, finalValue, count), finalValue];
10861
10976
  }
10862
- if (this._toEntryFn) {
10863
- const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
10864
- if (this.isKey(key)) return this.createNode(key, value != null ? value : entryValue, count);
10977
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
10978
+ if (this.isRaw(keyNodeEntryOrRaw)) {
10979
+ if (this._toEntryFn) {
10980
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
10981
+ const finalValue = value != null ? value : entryValue;
10982
+ if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
10983
+ }
10984
+ return [void 0, void 0];
10865
10985
  }
10866
- if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, count);
10867
- return;
10986
+ return [void 0, void 0];
10868
10987
  }
10869
10988
  /**
10870
10989
  * Time Complexity: O(log n)
@@ -10872,9 +10991,9 @@ var dataStructureTyped = (() => {
10872
10991
  *
10873
10992
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
10874
10993
  * and update the count.
10875
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
10876
- * `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
10877
- * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
10994
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
10995
+ * `keyNodeEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
10996
+ * can also accept a value of type `BTNRep<K, V, NODE>`, which represents a key, node,
10878
10997
  * entry, or raw element
10879
10998
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
10880
10999
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -10883,11 +11002,11 @@ var dataStructureTyped = (() => {
10883
11002
  * be added once. However, you can specify a different value for `count` if you want to add
10884
11003
  * @returns a boolean value.
10885
11004
  */
10886
- add(keyOrNodeOrEntryOrRaw, value, count = 1) {
10887
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
11005
+ add(keyNodeEntryOrRaw, value, count = 1) {
11006
+ const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
10888
11007
  if (newNode === void 0) return false;
10889
11008
  const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
10890
- const inserted = super.add(newNode);
11009
+ const inserted = super.add(newNode, newValue);
10891
11010
  if (inserted) {
10892
11011
  this._count += orgNodeCount;
10893
11012
  }
@@ -10899,7 +11018,7 @@ var dataStructureTyped = (() => {
10899
11018
  *
10900
11019
  * The function overrides the delete method in a binary tree data structure, handling deletion of
10901
11020
  * nodes and maintaining balance in the tree.
10902
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
11021
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
10903
11022
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
10904
11023
  * binary tree. It can be a key, node, or entry that determines which
10905
11024
  * node(s) should be deleted.
@@ -10912,11 +11031,11 @@ var dataStructureTyped = (() => {
10912
11031
  * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
10913
11032
  * deleted node and whether balancing is needed in the tree.
10914
11033
  */
10915
- delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) {
11034
+ delete(keyNodeEntryOrRaw, ignoreCount = false) {
10916
11035
  var _a;
10917
11036
  const deletedResult = [];
10918
11037
  if (!this.root) return deletedResult;
10919
- const curr = (_a = this.getNode(keyOrNodeOrEntryOrRaw)) != null ? _a : void 0;
11038
+ const curr = (_a = this.getNode(keyNodeEntryOrRaw)) != null ? _a : void 0;
10920
11039
  if (!curr) return deletedResult;
10921
11040
  const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
10922
11041
  let needBalanced = void 0, orgCurrent = curr;
@@ -10992,7 +11111,8 @@ var dataStructureTyped = (() => {
10992
11111
  if (l > r) return;
10993
11112
  const m = l + Math.floor((r - l) / 2);
10994
11113
  const midNode = sorted[m];
10995
- this.add(midNode.key, midNode.value, midNode.count);
11114
+ if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
11115
+ else this.add(midNode.key, midNode.value, midNode.count);
10996
11116
  buildBalanceBST(l, m - 1);
10997
11117
  buildBalanceBST(m + 1, r);
10998
11118
  };
@@ -11007,7 +11127,8 @@ var dataStructureTyped = (() => {
11007
11127
  if (l <= r) {
11008
11128
  const m = l + Math.floor((r - l) / 2);
11009
11129
  const midNode = sorted[m];
11010
- this.add(midNode.key, midNode.value, midNode.count);
11130
+ if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
11131
+ else this.add(midNode.key, midNode.value, midNode.count);
11011
11132
  stack.push([m + 1, r]);
11012
11133
  stack.push([l, m - 1]);
11013
11134
  }
@@ -11025,7 +11146,9 @@ var dataStructureTyped = (() => {
11025
11146
  */
11026
11147
  clone() {
11027
11148
  const cloned = this.createTree();
11028
- this.bfs((node) => cloned.add(node.key, node.value, node.count));
11149
+ if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
11150
+ else this.bfs((node) => cloned.add(node.key, node.value, node.count));
11151
+ if (this._isMapMode) cloned._store = this._store;
11029
11152
  return cloned;
11030
11153
  }
11031
11154
  /**
@@ -11034,9 +11157,9 @@ var dataStructureTyped = (() => {
11034
11157
  *
11035
11158
  * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
11036
11159
  * in a binary search tree.
11037
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
11160
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
11038
11161
  * that will be swapped with the `destNode`.
11039
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
11162
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
11040
11163
  * node where the properties will be swapped with the source node.
11041
11164
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
11042
11165
  * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
@@ -11050,11 +11173,11 @@ var dataStructureTyped = (() => {
11050
11173
  if (tempNode) {
11051
11174
  tempNode.height = height;
11052
11175
  destNode.key = srcNode.key;
11053
- destNode.value = srcNode.value;
11176
+ if (!this._isMapMode) destNode.value = srcNode.value;
11054
11177
  destNode.count = srcNode.count;
11055
11178
  destNode.height = srcNode.height;
11056
11179
  srcNode.key = tempNode.key;
11057
- srcNode.value = tempNode.value;
11180
+ if (!this._isMapMode) srcNode.value = tempNode.value;
11058
11181
  srcNode.count = tempNode.count;
11059
11182
  srcNode.height = tempNode.height;
11060
11183
  }
@@ -11117,17 +11240,17 @@ var dataStructureTyped = (() => {
11117
11240
  var TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11118
11241
  /**
11119
11242
  * The constructor function initializes a TreeMultiMap object with optional initial data.
11120
- * @param keysOrNodesOrEntriesOrRaws - The parameter `keysOrNodesOrEntriesOrRaws` is an
11243
+ * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
11121
11244
  * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
11122
11245
  * TreeMultiMap with initial data.
11123
11246
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
11124
11247
  * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
11125
11248
  * `compareValues`, which are functions used to compare keys and values respectively.
11126
11249
  */
11127
- constructor(keysOrNodesOrEntriesOrRaws = [], options) {
11250
+ constructor(keysNodesEntriesOrRaws = [], options) {
11128
11251
  super([], options);
11129
11252
  __publicField(this, "_count", 0);
11130
- if (keysOrNodesOrEntriesOrRaws) this.addMany(keysOrNodesOrEntriesOrRaws);
11253
+ if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11131
11254
  }
11132
11255
  // TODO the _count is not accurate after nodes count modified
11133
11256
  /**
@@ -11164,7 +11287,7 @@ var dataStructureTyped = (() => {
11164
11287
  * @returns A new instance of the TreeMultiMapNode class, casted as NODE.
11165
11288
  */
11166
11289
  createNode(key, value, color = "BLACK", count) {
11167
- return new TreeMultiMapNode(key, value, count, color);
11290
+ return new TreeMultiMapNode(key, this._isMapMode ? void 0 : value, count, color);
11168
11291
  }
11169
11292
  /**
11170
11293
  * The function creates a new instance of a TreeMultiMap with the specified options and returns it.
@@ -11177,15 +11300,16 @@ var dataStructureTyped = (() => {
11177
11300
  createTree(options) {
11178
11301
  return new _TreeMultiMap([], __spreadValues({
11179
11302
  iterationType: this.iterationType,
11303
+ isMapMode: this._isMapMode,
11180
11304
  comparator: this._comparator,
11181
11305
  toEntryFn: this._toEntryFn
11182
11306
  }, options));
11183
11307
  }
11184
11308
  /**
11185
- * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
11309
+ * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
11186
11310
  * node based on the input.
11187
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
11188
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11311
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11312
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11189
11313
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
11190
11314
  * associated with the key in the node. It is used when creating a new node or updating the value of
11191
11315
  * an existing node.
@@ -11193,30 +11317,32 @@ var dataStructureTyped = (() => {
11193
11317
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11194
11318
  * @returns either a NODE object or undefined.
11195
11319
  */
11196
- keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
11197
- if (keyOrNodeOrEntryOrRaw === void 0 || keyOrNodeOrEntryOrRaw === null) return;
11198
- if (this.isNode(keyOrNodeOrEntryOrRaw)) return keyOrNodeOrEntryOrRaw;
11199
- if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
11200
- const [key, entryValue] = keyOrNodeOrEntryOrRaw;
11201
- if (key === void 0 || key === null) return;
11202
- if (this.isKey(key)) return this.createNode(key, value != null ? value : entryValue, "BLACK", count);
11320
+ keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11321
+ if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11322
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11323
+ if (this.isEntry(keyNodeEntryOrRaw)) {
11324
+ const [key, entryValue] = keyNodeEntryOrRaw;
11325
+ if (key === void 0 || key === null) return [void 0, void 0];
11326
+ const finalValue = value != null ? value : entryValue;
11327
+ if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11203
11328
  }
11204
11329
  if (this._toEntryFn) {
11205
- const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
11206
- if (this.isKey(key)) return this.createNode(key, value != null ? value : entryValue, "BLACK", count);
11330
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11331
+ const finalValue = value != null ? value : entryValue;
11332
+ if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11207
11333
  }
11208
- if (this.isKey(keyOrNodeOrEntryOrRaw)) return this.createNode(keyOrNodeOrEntryOrRaw, value, "BLACK", count);
11209
- return;
11334
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, "BLACK", count), value];
11335
+ return [void 0, void 0];
11210
11336
  }
11211
11337
  /**
11212
11338
  * The function checks if the input is an instance of the TreeMultiMapNode class.
11213
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
11214
- * `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11215
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
11339
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11340
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11341
+ * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
11216
11342
  * an instance of the `TreeMultiMapNode` class.
11217
11343
  */
11218
- isNode(keyOrNodeOrEntryOrRaw) {
11219
- return keyOrNodeOrEntryOrRaw instanceof TreeMultiMapNode;
11344
+ isNode(keyNodeEntryOrRaw) {
11345
+ return keyNodeEntryOrRaw instanceof TreeMultiMapNode;
11220
11346
  }
11221
11347
  /**
11222
11348
  * Time Complexity: O(log n)
@@ -11224,8 +11350,8 @@ var dataStructureTyped = (() => {
11224
11350
  *
11225
11351
  * The function overrides the add method of a class and adds a new node to a data structure, updating
11226
11352
  * the count and returning a boolean indicating success.
11227
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
11228
- * `keyOrNodeOrEntryOrRaw` parameter can accept one of the following types:
11353
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11354
+ * `keyNodeEntryOrRaw` parameter can accept one of the following types:
11229
11355
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
11230
11356
  * data structure. It is an optional parameter, so it can be omitted if not needed.
11231
11357
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
@@ -11234,10 +11360,10 @@ var dataStructureTyped = (() => {
11234
11360
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
11235
11361
  * was successful, and false otherwise.
11236
11362
  */
11237
- add(keyOrNodeOrEntryOrRaw, value, count = 1) {
11238
- const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
11363
+ add(keyNodeEntryOrRaw, value, count = 1) {
11364
+ const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11239
11365
  const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
11240
- const isSuccessAdded = super.add(newNode);
11366
+ const isSuccessAdded = super.add(newNode, newValue);
11241
11367
  if (isSuccessAdded) {
11242
11368
  this._count += orgCount;
11243
11369
  return true;
@@ -11251,7 +11377,7 @@ var dataStructureTyped = (() => {
11251
11377
  *
11252
11378
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
11253
11379
  * structure, handling cases where nodes have children and maintaining balance in the tree.
11254
- * @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The `predicate`
11380
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
11255
11381
  * parameter in the `delete` method is used to specify the condition or key based on which a node
11256
11382
  * should be deleted from the binary tree. It can be a key, a node, or an entry.
11257
11383
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
@@ -11260,13 +11386,12 @@ var dataStructureTyped = (() => {
11260
11386
  * `ignoreCount` is `false
11261
11387
  * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
11262
11388
  */
11263
- delete(keyOrNodeOrEntryOrRaw, ignoreCount = false) {
11264
- if (keyOrNodeOrEntryOrRaw === null) return [];
11389
+ delete(keyNodeEntryOrRaw, ignoreCount = false) {
11390
+ if (keyNodeEntryOrRaw === null) return [];
11265
11391
  const results = [];
11266
11392
  let nodeToDelete;
11267
- if (this._isPredicated(keyOrNodeOrEntryOrRaw)) nodeToDelete = this.getNode(keyOrNodeOrEntryOrRaw);
11268
- else
11269
- nodeToDelete = this.isRealNode(keyOrNodeOrEntryOrRaw) ? keyOrNodeOrEntryOrRaw : this.getNode(keyOrNodeOrEntryOrRaw);
11393
+ if (this._isPredicate(keyNodeEntryOrRaw)) nodeToDelete = this.getNode(keyNodeEntryOrRaw);
11394
+ else nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
11270
11395
  if (!nodeToDelete) {
11271
11396
  return results;
11272
11397
  }
@@ -11374,7 +11499,8 @@ var dataStructureTyped = (() => {
11374
11499
  if (l > r) return;
11375
11500
  const m = l + Math.floor((r - l) / 2);
11376
11501
  const midNode = sorted[m];
11377
- this.add(midNode.key, midNode.value, midNode.count);
11502
+ if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
11503
+ else this.add(midNode.key, midNode.value, midNode.count);
11378
11504
  buildBalanceBST(l, m - 1);
11379
11505
  buildBalanceBST(m + 1, r);
11380
11506
  };
@@ -11389,7 +11515,8 @@ var dataStructureTyped = (() => {
11389
11515
  if (l <= r) {
11390
11516
  const m = l + Math.floor((r - l) / 2);
11391
11517
  const midNode = sorted[m];
11392
- this.add(midNode.key, midNode.value, midNode.count);
11518
+ if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
11519
+ else this.add(midNode.key, midNode.value, midNode.count);
11393
11520
  stack.push([m + 1, r]);
11394
11521
  stack.push([l, m - 1]);
11395
11522
  }
@@ -11407,7 +11534,8 @@ var dataStructureTyped = (() => {
11407
11534
  */
11408
11535
  clone() {
11409
11536
  const cloned = this.createTree();
11410
- this.bfs((node) => cloned.add(node.key, node.value, node.count));
11537
+ this.bfs((node) => cloned.add(node.key, void 0, node.count));
11538
+ if (this._isMapMode) cloned._store = this._store;
11411
11539
  return cloned;
11412
11540
  }
11413
11541
  /**
@@ -11416,10 +11544,10 @@ var dataStructureTyped = (() => {
11416
11544
  *
11417
11545
  * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
11418
11546
  * in a binary search tree.
11419
- * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
11547
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
11420
11548
  * that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
11421
- * instance of the `BSTNKeyOrNode<K, NODE>` class.
11422
- * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
11549
+ * instance of the `BSTNOptKeyOrNode<K, NODE>` class.
11550
+ * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
11423
11551
  * node where the properties will be swapped with the source node.
11424
11552
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
11425
11553
  * If either `srcNode` or `destNode` is undefined, it returns undefined.
@@ -11433,11 +11561,11 @@ var dataStructureTyped = (() => {
11433
11561
  if (tempNode) {
11434
11562
  tempNode.color = color;
11435
11563
  destNode.key = srcNode.key;
11436
- destNode.value = srcNode.value;
11564
+ if (!this._isMapMode) destNode.value = srcNode.value;
11437
11565
  destNode.count = srcNode.count;
11438
11566
  destNode.color = srcNode.color;
11439
11567
  srcNode.key = tempNode.key;
11440
- srcNode.value = tempNode.value;
11568
+ if (!this._isMapMode) srcNode.value = tempNode.value;
11441
11569
  srcNode.count = tempNode.count;
11442
11570
  srcNode.color = tempNode.color;
11443
11571
  }
@@ -12475,9 +12603,9 @@ var dataStructureTyped = (() => {
12475
12603
  *
12476
12604
  */
12477
12605
  getHeight() {
12478
- const beginRoot = this.root;
12606
+ const startNode = this.root;
12479
12607
  let maxDepth = 0;
12480
- if (beginRoot) {
12608
+ if (startNode) {
12481
12609
  const bfs = (node, level) => {
12482
12610
  if (level > maxDepth) {
12483
12611
  maxDepth = level;
@@ -12489,7 +12617,7 @@ var dataStructureTyped = (() => {
12489
12617
  }
12490
12618
  }
12491
12619
  };
12492
- bfs(beginRoot, 0);
12620
+ bfs(startNode, 0);
12493
12621
  }
12494
12622
  return maxDepth;
12495
12623
  }