data-structure-typed 2.2.7 → 2.2.8

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 (70) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +14 -3
  3. package/README_CN.md +119 -275
  4. package/benchmark/report.html +1 -1
  5. package/benchmark/report.json +20 -324
  6. package/dist/cjs/index.cjs +106 -107
  7. package/dist/cjs/index.cjs.map +1 -1
  8. package/dist/cjs-legacy/index.cjs +106 -107
  9. package/dist/cjs-legacy/index.cjs.map +1 -1
  10. package/dist/esm/index.mjs +106 -107
  11. package/dist/esm/index.mjs.map +1 -1
  12. package/dist/esm-legacy/index.mjs +106 -107
  13. package/dist/esm-legacy/index.mjs.map +1 -1
  14. package/dist/leetcode/avl-tree-counter.mjs +2957 -0
  15. package/dist/leetcode/avl-tree-multi-map.mjs +2889 -0
  16. package/dist/leetcode/avl-tree.mjs +2720 -0
  17. package/dist/leetcode/binary-tree.mjs +1594 -0
  18. package/dist/leetcode/bst.mjs +2398 -0
  19. package/dist/leetcode/deque.mjs +683 -0
  20. package/dist/leetcode/directed-graph.mjs +1733 -0
  21. package/dist/leetcode/doubly-linked-list.mjs +709 -0
  22. package/dist/leetcode/hash-map.mjs +493 -0
  23. package/dist/leetcode/heap.mjs +542 -0
  24. package/dist/leetcode/max-heap.mjs +375 -0
  25. package/dist/leetcode/max-priority-queue.mjs +383 -0
  26. package/dist/leetcode/min-heap.mjs +363 -0
  27. package/dist/leetcode/min-priority-queue.mjs +371 -0
  28. package/dist/leetcode/priority-queue.mjs +363 -0
  29. package/dist/leetcode/queue.mjs +943 -0
  30. package/dist/leetcode/red-black-tree.mjs +2765 -0
  31. package/dist/leetcode/singly-linked-list.mjs +754 -0
  32. package/dist/leetcode/stack.mjs +217 -0
  33. package/dist/leetcode/tree-counter.mjs +3039 -0
  34. package/dist/leetcode/tree-multi-map.mjs +2913 -0
  35. package/dist/leetcode/trie.mjs +413 -0
  36. package/dist/leetcode/undirected-graph.mjs +1650 -0
  37. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
  38. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  39. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
  40. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -23
  41. package/dist/types/data-structures/binary-tree/bst.d.ts +11 -11
  42. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  43. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  44. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
  45. package/dist/umd/data-structure-typed.js +102 -103
  46. package/dist/umd/data-structure-typed.js.map +1 -1
  47. package/dist/umd/data-structure-typed.min.js +2 -2
  48. package/dist/umd/data-structure-typed.min.js.map +1 -1
  49. package/package.json +48 -171
  50. package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
  51. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
  52. package/src/data-structures/binary-tree/avl-tree.ts +15 -15
  53. package/src/data-structures/binary-tree/binary-tree.ts +53 -55
  54. package/src/data-structures/binary-tree/bst.ts +21 -22
  55. package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
  56. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  57. package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
  58. package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +1 -2
  59. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +30 -30
  60. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +46 -46
  61. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +43 -43
  62. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +151 -151
  63. package/test/unit/data-structures/binary-tree/bst.test.ts +99 -99
  64. package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
  65. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +141 -141
  66. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +37 -37
  67. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +145 -145
  68. package/tsup.config.js +50 -21
  69. package/tsup.umd.config.js +29 -0
  70. package/tsup.node.config.js +0 -83
@@ -6971,9 +6971,9 @@ var BinaryTreeNode = _BinaryTreeNode;
6971
6971
  var _BinaryTree = class _BinaryTree extends IterableEntryBase {
6972
6972
  /**
6973
6973
  * Creates an instance of BinaryTree.
6974
- * @remarks Time O(N * M), where N is the number of items in `keysNodesEntriesOrRaws` and M is the tree size at insertion time (due to O(M) `add` operation). Space O(N) for storing the nodes.
6974
+ * @remarks Time O(N * M), where N is the number of items in `keysNodesEntriesOrRaws` and M is the tree size at insertion time (due to O(M) `set` operation). Space O(N) for storing the nodes.
6975
6975
  *
6976
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
6976
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
6977
6977
  * @param [options] - Configuration options for the tree.
6978
6978
  */
6979
6979
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -7002,7 +7002,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7002
7002
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
7003
7003
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
7004
7004
  }
7005
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
7005
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
7006
7006
  }
7007
7007
  /**
7008
7008
  * Gets whether the tree is in Map mode.
@@ -7209,10 +7209,20 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7209
7209
  * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
7210
7210
  *
7211
7211
  * @param keyNodeOrEntry - The key, node, or entry to add.
7212
+ * @returns True if the addition was successful, false otherwise.
7213
+ */
7214
+ add(keyNodeOrEntry) {
7215
+ return this.set(keyNodeOrEntry);
7216
+ }
7217
+ /**
7218
+ * Adds or updates a new node to the tree.
7219
+ * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation sets the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
7220
+ *
7221
+ * @param keyNodeOrEntry - The key, node, or entry to set or update.
7212
7222
  * @param [value] - The value, if providing just a key.
7213
7223
  * @returns True if the addition was successful, false otherwise.
7214
7224
  */
7215
- add(keyNodeOrEntry, value) {
7225
+ set(keyNodeOrEntry, value) {
7216
7226
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
7217
7227
  if (newNode === void 0) return false;
7218
7228
  if (!this._root) {
@@ -7256,25 +7266,25 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7256
7266
  return false;
7257
7267
  }
7258
7268
  /**
7259
- * Adds or updates a new node to the tree.
7260
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
7269
+ * Adds multiple items to the tree.
7270
+ * @remarks Time O(N * M), where N is the number of items to set and M is the size of the tree at insertion (due to O(M) `set` operation). Space O(M) (from `set`) + O(N) (for the `inserted` array).
7261
7271
  *
7262
- * @param keyNodeOrEntry - The key, node, or entry to add or update.
7263
- * @param [value] - The value, if providing just a key.
7264
- * @returns True if the addition was successful, false otherwise.
7272
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7273
+ * @param [values] - An optional parallel iterable of values.
7274
+ * @returns An array of booleans indicating the success of each individual `set` operation.
7265
7275
  */
7266
- set(keyNodeOrEntry, value) {
7267
- return this.add(keyNodeOrEntry, value);
7276
+ addMany(keysNodesEntriesOrRaws) {
7277
+ return this.setMany(keysNodesEntriesOrRaws);
7268
7278
  }
7269
7279
  /**
7270
- * Adds multiple items to the tree.
7271
- * @remarks Time O(N * M), where N is the number of items to add and M is the size of the tree at insertion (due to O(M) `add` operation). Space O(M) (from `add`) + O(N) (for the `inserted` array).
7280
+ * Adds or updates multiple items to the tree.
7281
+ * @remarks Time O(N * M), where N is the number of items to set and M is the size of the tree at insertion (due to O(M) `set` operation). Space O(M) (from `set`) + O(N) (for the `inserted` array).
7272
7282
  *
7273
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7283
+ * @param keysNodesEntriesOrRaws - An iterable of items to set or update.
7274
7284
  * @param [values] - An optional parallel iterable of values.
7275
- * @returns An array of booleans indicating the success of each individual `add` operation.
7285
+ * @returns An array of booleans indicating the success of each individual `set` operation.
7276
7286
  */
7277
- addMany(keysNodesEntriesOrRaws, values) {
7287
+ setMany(keysNodesEntriesOrRaws, values) {
7278
7288
  const inserted = [];
7279
7289
  let valuesIterator;
7280
7290
  if (values) {
@@ -7289,40 +7299,29 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7289
7299
  }
7290
7300
  }
7291
7301
  if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
7292
- inserted.push(this.add(keyNodeEntryOrRaw, value));
7302
+ inserted.push(this.set(keyNodeEntryOrRaw, value));
7293
7303
  }
7294
7304
  return inserted;
7295
7305
  }
7296
7306
  /**
7297
- * Adds or updates multiple items to the tree.
7298
- * @remarks Time O(N * M), where N is the number of items to add and M is the size of the tree at insertion (due to O(M) `add` operation). Space O(M) (from `add`) + O(N) (for the `inserted` array).
7299
- *
7300
- * @param keysNodesEntriesOrRaws - An iterable of items to add or update.
7301
- * @param [values] - An optional parallel iterable of values.
7302
- * @returns An array of booleans indicating the success of each individual `add` operation.
7303
- */
7304
- setMany(keysNodesEntriesOrRaws, values) {
7305
- return this.addMany(keysNodesEntriesOrRaws, values);
7306
- }
7307
- /**
7308
- * Merges another tree into this one by adding all its nodes.
7309
- * @remarks Time O(N * M), same as `addMany`, where N is the size of `anotherTree` and M is the size of this tree. Space O(M) (from `add`).
7307
+ * Merges another tree into this one by seting all its nodes.
7308
+ * @remarks Time O(N * M), same as `setMany`, where N is the size of `anotherTree` and M is the size of this tree. Space O(M) (from `set`).
7310
7309
  *
7311
7310
  * @param anotherTree - The tree to merge.
7312
7311
  */
7313
7312
  merge(anotherTree) {
7314
- this.addMany(anotherTree, []);
7313
+ this.setMany(anotherTree, []);
7315
7314
  }
7316
7315
  /**
7317
7316
  * Clears the tree and refills it with new items.
7318
- * @remarks Time O(N) (for `clear`) + O(N * M) (for `addMany`) = O(N * M). Space O(M) (from `addMany`).
7317
+ * @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
7319
7318
  *
7320
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7319
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7321
7320
  * @param [values] - An optional parallel iterable of values.
7322
7321
  */
7323
7322
  refill(keysNodesEntriesOrRaws, values) {
7324
7323
  this.clear();
7325
- this.addMany(keysNodesEntriesOrRaws, values);
7324
+ this.setMany(keysNodesEntriesOrRaws, values);
7326
7325
  }
7327
7326
  /**
7328
7327
  * Deletes a node from the tree.
@@ -7988,7 +7987,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7988
7987
  }
7989
7988
  /**
7990
7989
  * Clones the tree.
7991
- * @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `add`, and `add` is O(M)). Space O(N) for the new tree and the BFS queue.
7990
+ * @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `set`, and `set` is O(M)). Space O(N) for the new tree and the BFS queue.
7992
7991
  *
7993
7992
  * @returns A new, cloned instance of the tree.
7994
7993
  */
@@ -7999,7 +7998,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7999
7998
  }
8000
7999
  /**
8001
8000
  * Creates a new tree containing only the entries that satisfy the predicate.
8002
- * @remarks Time O(N * M), where N is nodes in this tree, and M is size of the new tree during insertion (O(N) iteration + O(M) `add` for each item). Space O(N) for the new tree.
8001
+ * @remarks Time O(N * M), where N is nodes in this tree, and M is size of the new tree during insertion (O(N) iteration + O(M) `set` for each item). Space O(N) for the new tree.
8003
8002
  *
8004
8003
  * @param predicate - A function to test each [key, value] pair.
8005
8004
  * @param [thisArg] - `this` context for the predicate.
@@ -8008,7 +8007,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8008
8007
  filter(predicate, thisArg) {
8009
8008
  const out = this._createInstance();
8010
8009
  let i = 0;
8011
- for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
8010
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
8012
8011
  return out;
8013
8012
  }
8014
8013
  /**
@@ -8026,7 +8025,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8026
8025
  map(cb, options, thisArg) {
8027
8026
  const out = this._createLike([], options);
8028
8027
  let i = 0;
8029
- for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
8028
+ for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
8030
8029
  return out;
8031
8030
  }
8032
8031
  /**
@@ -8272,18 +8271,18 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8272
8271
  return [this.createNode(keyNodeOrEntry, value), value];
8273
8272
  }
8274
8273
  /**
8275
- * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
8276
- * @remarks Time O(N * M) (O(N) BFS + O(M) `add` for each node).
8274
+ * (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
8275
+ * @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
8277
8276
  *
8278
8277
  * @param cloned - The new, empty tree instance to populate.
8279
8278
  */
8280
8279
  _clone(cloned) {
8281
8280
  this.bfs(
8282
8281
  (node) => {
8283
- if (node === null) cloned.add(null);
8282
+ if (node === null) cloned.set(null);
8284
8283
  else {
8285
- if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
8286
- else cloned.add([node.key, node.value]);
8284
+ if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
8285
+ else cloned.set([node.key, node.value]);
8287
8286
  }
8288
8287
  },
8289
8288
  this._root,
@@ -8614,7 +8613,7 @@ var _BST = class _BST extends BinaryTree {
8614
8613
  * Creates an instance of BST.
8615
8614
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
8616
8615
  *
8617
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
8616
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
8618
8617
  * @param [options] - Configuration options for the BST, including comparator.
8619
8618
  */
8620
8619
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -8635,7 +8634,7 @@ var _BST = class _BST extends BinaryTree {
8635
8634
  } else {
8636
8635
  this._comparator = this._createDefaultComparator();
8637
8636
  }
8638
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8637
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
8639
8638
  }
8640
8639
  /**
8641
8640
  * Gets the root node of the tree.
@@ -8846,11 +8845,11 @@ var _BST = class _BST extends BinaryTree {
8846
8845
  * Adds a new node to the BST based on key comparison.
8847
8846
  * @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
8848
8847
  *
8849
- * @param keyNodeOrEntry - The key, node, or entry to add.
8848
+ * @param keyNodeOrEntry - The key, node, or entry to set.
8850
8849
  * @param [value] - The value, if providing just a key.
8851
8850
  * @returns True if the addition was successful, false otherwise.
8852
8851
  */
8853
- add(keyNodeOrEntry, value) {
8852
+ set(keyNodeOrEntry, value) {
8854
8853
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
8855
8854
  if (newNode === void 0) return false;
8856
8855
  if (this._root === void 0) {
@@ -8887,24 +8886,24 @@ var _BST = class _BST extends BinaryTree {
8887
8886
  }
8888
8887
  /**
8889
8888
  * Adds multiple items to the tree.
8890
- * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced add).
8889
+ * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
8891
8890
  * If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
8892
8891
  * Space O(N) for sorting and recursion/iteration stack.
8893
8892
  *
8894
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
8893
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
8895
8894
  * @param [values] - An optional parallel iterable of values.
8896
8895
  * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
8897
- * @param [iterationType=this.iterationType] - The traversal method for balanced add (recursive or iterative).
8898
- * @returns An array of booleans indicating the success of each individual `add` operation.
8896
+ * @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
8897
+ * @returns An array of booleans indicating the success of each individual `set` operation.
8899
8898
  */
8900
- addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8899
+ setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8901
8900
  const inserted = [];
8902
8901
  const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
8903
8902
  if (!isBalanceAdd) {
8904
8903
  for (let kve of keysNodesEntriesOrRaws) {
8905
8904
  const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
8906
8905
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
8907
- inserted.push(this.add(kve, val));
8906
+ inserted.push(this.set(kve, val));
8908
8907
  }
8909
8908
  return inserted;
8910
8909
  }
@@ -8932,9 +8931,9 @@ var _BST = class _BST extends BinaryTree {
8932
8931
  const { key, value, orgIndex } = arr[mid];
8933
8932
  if (this.isRaw(key)) {
8934
8933
  const entry = this._toEntryFn(key);
8935
- inserted[orgIndex] = this.add(entry);
8934
+ inserted[orgIndex] = this.set(entry);
8936
8935
  } else {
8937
- inserted[orgIndex] = this.add(key, value);
8936
+ inserted[orgIndex] = this.set(key, value);
8938
8937
  }
8939
8938
  _dfs(arr.slice(0, mid));
8940
8939
  _dfs(arr.slice(mid + 1));
@@ -8951,9 +8950,9 @@ var _BST = class _BST extends BinaryTree {
8951
8950
  const { key, value, orgIndex } = sorted[m];
8952
8951
  if (this.isRaw(key)) {
8953
8952
  const entry = this._toEntryFn(key);
8954
- inserted[orgIndex] = this.add(entry);
8953
+ inserted[orgIndex] = this.set(entry);
8955
8954
  } else {
8956
- inserted[orgIndex] = this.add(key, value);
8955
+ inserted[orgIndex] = this.set(key, value);
8957
8956
  }
8958
8957
  stack.push([m + 1, r]);
8959
8958
  stack.push([l, m - 1]);
@@ -9228,7 +9227,7 @@ var _BST = class _BST extends BinaryTree {
9228
9227
  const out = this._createLike([], options);
9229
9228
  let index = 0;
9230
9229
  for (const [key, value] of this) {
9231
- out.add(callback.call(thisArg, value, key, index++, this));
9230
+ out.set(callback.call(thisArg, value, key, index++, this));
9232
9231
  }
9233
9232
  return out;
9234
9233
  }
@@ -10414,14 +10413,14 @@ var AVLTreeNode = _AVLTreeNode;
10414
10413
  var _AVLTree = class _AVLTree extends BST {
10415
10414
  /**
10416
10415
  * Creates an instance of AVLTree.
10417
- * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
10416
+ * @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
10418
10417
  *
10419
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
10418
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
10420
10419
  * @param [options] - Configuration options for the AVL tree.
10421
10420
  */
10422
10421
  constructor(keysNodesEntriesOrRaws = [], options) {
10423
10422
  super([], options);
10424
- if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
10423
+ if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
10425
10424
  }
10426
10425
  /**
10427
10426
  * (Protected) Creates a new AVL tree node.
@@ -10445,16 +10444,16 @@ var _AVLTree = class _AVLTree extends BST {
10445
10444
  return keyNodeOrEntry instanceof AVLTreeNode;
10446
10445
  }
10447
10446
  /**
10448
- * Adds a new node to the AVL tree and balances the tree path.
10449
- * @remarks Time O(log N) (O(H) for BST add + O(H) for `_balancePath`). Space O(H) for path/recursion.
10447
+ * Sets a new node to the AVL tree and balances the tree path.
10448
+ * @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
10450
10449
  *
10451
- * @param keyNodeOrEntry - The key, node, or entry to add.
10450
+ * @param keyNodeOrEntry - The key, node, or entry to set.
10452
10451
  * @param [value] - The value, if providing just a key.
10453
10452
  * @returns True if the addition was successful, false otherwise.
10454
10453
  */
10455
- add(keyNodeOrEntry, value) {
10454
+ set(keyNodeOrEntry, value) {
10456
10455
  if (keyNodeOrEntry === null) return false;
10457
- const inserted = super.add(keyNodeOrEntry, value);
10456
+ const inserted = super.set(keyNodeOrEntry, value);
10458
10457
  if (inserted) this._balancePath(keyNodeOrEntry);
10459
10458
  return inserted;
10460
10459
  }
@@ -10506,7 +10505,7 @@ var _AVLTree = class _AVLTree extends BST {
10506
10505
  }
10507
10506
  /**
10508
10507
  * Creates a new AVLTree by mapping each [key, value] pair.
10509
- * @remarks Time O(N log N) (O(N) iteration + O(log M) `add` for each item into the new tree). Space O(N) for the new tree.
10508
+ * @remarks Time O(N log N) (O(N) iteration + O(log M) `set` for each item into the new tree). Space O(N) for the new tree.
10510
10509
  *
10511
10510
  * @template MK - New key type.
10512
10511
  * @template MV - New value type.
@@ -10520,7 +10519,7 @@ var _AVLTree = class _AVLTree extends BST {
10520
10519
  const out = this._createLike([], options);
10521
10520
  let index = 0;
10522
10521
  for (const [key, value] of this) {
10523
- out.add(callback.call(thisArg, value, key, index++, this));
10522
+ out.set(callback.call(thisArg, value, key, index++, this));
10524
10523
  }
10525
10524
  return out;
10526
10525
  }
@@ -10945,7 +10944,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10945
10944
  __publicField(this, "_root");
10946
10945
  this._root = this.NIL;
10947
10946
  if (keysNodesEntriesOrRaws) {
10948
- this.addMany(keysNodesEntriesOrRaws);
10947
+ this.setMany(keysNodesEntriesOrRaws);
10949
10948
  }
10950
10949
  }
10951
10950
  /**
@@ -10992,7 +10991,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10992
10991
  * @param [value]- See parameter type for details.
10993
10992
  * @returns True if inserted or updated; false if ignored.
10994
10993
  */
10995
- add(keyNodeOrEntry, value) {
10994
+ set(keyNodeOrEntry, value) {
10996
10995
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
10997
10996
  if (!this.isRealNode(newNode)) return false;
10998
10997
  const insertStatus = this._insert(newNode);
@@ -11086,7 +11085,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
11086
11085
  const out = this._createLike([], options);
11087
11086
  let index = 0;
11088
11087
  for (const [key, value] of this) {
11089
- out.add(callback.call(thisArg, value, key, index++, this));
11088
+ out.set(callback.call(thisArg, value, key, index++, this));
11090
11089
  }
11091
11090
  return out;
11092
11091
  }
@@ -11475,7 +11474,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11475
11474
  constructor(keysNodesEntriesOrRaws = [], options) {
11476
11475
  super([], { ...options, isMapMode: true });
11477
11476
  if (keysNodesEntriesOrRaws) {
11478
- this.addMany(keysNodesEntriesOrRaws);
11477
+ this.setMany(keysNodesEntriesOrRaws);
11479
11478
  }
11480
11479
  }
11481
11480
  createNode(key, value = []) {
@@ -11495,27 +11494,27 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11495
11494
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11496
11495
  * @remarks Time O(log N + M), Space O(1)
11497
11496
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11498
- * @param [value] - Single value to add when a bare key is provided.
11497
+ * @param [value] - Single value to set when a bare key is provided.
11499
11498
  * @returns True if inserted or appended; false if ignored.
11500
11499
  */
11501
- add(keyNodeOrEntry, value) {
11502
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11500
+ set(keyNodeOrEntry, value) {
11501
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11503
11502
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11504
11503
  if (key === void 0 || key === null) return false;
11505
- const _addToValues = /* @__PURE__ */ __name(() => {
11504
+ const _setToValues = /* @__PURE__ */ __name(() => {
11506
11505
  const existingValues = this.get(key);
11507
11506
  if (existingValues !== void 0 && values !== void 0) {
11508
11507
  for (const value2 of values) existingValues.push(value2);
11509
11508
  return true;
11510
11509
  }
11511
11510
  return false;
11512
- }, "_addToValues");
11513
- const _addByNode = /* @__PURE__ */ __name(() => {
11511
+ }, "_setToValues");
11512
+ const _setByNode = /* @__PURE__ */ __name(() => {
11514
11513
  const existingNode = this.getNode(key);
11515
11514
  if (this.isRealNode(existingNode)) {
11516
11515
  const existingValues = this.get(existingNode);
11517
11516
  if (existingValues === void 0) {
11518
- super.add(key, values);
11517
+ super.set(key, values);
11519
11518
  return true;
11520
11519
  }
11521
11520
  if (values !== void 0) {
@@ -11525,13 +11524,13 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11525
11524
  return false;
11526
11525
  }
11527
11526
  } else {
11528
- return super.add(key, values);
11527
+ return super.set(key, values);
11529
11528
  }
11530
- }, "_addByNode");
11529
+ }, "_setByNode");
11531
11530
  if (this._isMapMode) {
11532
- return _addByNode() || _addToValues();
11531
+ return _setByNode() || _setToValues();
11533
11532
  }
11534
- return _addToValues() || _addByNode();
11533
+ return _setToValues() || _setByNode();
11535
11534
  }, "_commonAdd");
11536
11535
  if (this.isEntry(keyNodeOrEntry)) {
11537
11536
  const [key, values] = keyNodeOrEntry;
@@ -11599,7 +11598,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11599
11598
  map(callback, options, thisArg) {
11600
11599
  const out = this._createLike([], options);
11601
11600
  let i = 0;
11602
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11601
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
11603
11602
  return out;
11604
11603
  }
11605
11604
  /**
@@ -11782,7 +11781,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11782
11781
  constructor(keysNodesEntriesOrRaws = [], options) {
11783
11782
  super([], { ...options });
11784
11783
  if (keysNodesEntriesOrRaws) {
11785
- this.addMany(keysNodesEntriesOrRaws);
11784
+ this.setMany(keysNodesEntriesOrRaws);
11786
11785
  }
11787
11786
  }
11788
11787
  createNode(key, value = []) {
@@ -11802,27 +11801,27 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11802
11801
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11803
11802
  * @remarks Time O(log N + M), Space O(1)
11804
11803
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11805
- * @param [value] - Single value to add when a bare key is provided.
11804
+ * @param [value] - Single value to set when a bare key is provided.
11806
11805
  * @returns True if inserted or appended; false if ignored.
11807
11806
  */
11808
- add(keyNodeOrEntry, value) {
11809
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11807
+ set(keyNodeOrEntry, value) {
11808
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11810
11809
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11811
11810
  if (key === void 0 || key === null) return false;
11812
- const _addToValues = /* @__PURE__ */ __name(() => {
11811
+ const _setToValues = /* @__PURE__ */ __name(() => {
11813
11812
  const existingValues = this.get(key);
11814
11813
  if (existingValues !== void 0 && values !== void 0) {
11815
11814
  for (const value2 of values) existingValues.push(value2);
11816
11815
  return true;
11817
11816
  }
11818
11817
  return false;
11819
- }, "_addToValues");
11820
- const _addByNode = /* @__PURE__ */ __name(() => {
11818
+ }, "_setToValues");
11819
+ const _setByNode = /* @__PURE__ */ __name(() => {
11821
11820
  const existingNode = this.getNode(key);
11822
11821
  if (this.isRealNode(existingNode)) {
11823
11822
  const existingValues = this.get(existingNode);
11824
11823
  if (existingValues === void 0) {
11825
- super.add(key, values);
11824
+ super.set(key, values);
11826
11825
  return true;
11827
11826
  }
11828
11827
  if (values !== void 0) {
@@ -11832,13 +11831,13 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11832
11831
  return false;
11833
11832
  }
11834
11833
  } else {
11835
- return super.add(key, values);
11834
+ return super.set(key, values);
11836
11835
  }
11837
- }, "_addByNode");
11836
+ }, "_setByNode");
11838
11837
  if (this._isMapMode) {
11839
- return _addByNode() || _addToValues();
11838
+ return _setByNode() || _setToValues();
11840
11839
  }
11841
- return _addToValues() || _addByNode();
11840
+ return _setToValues() || _setByNode();
11842
11841
  }, "_commonAdd");
11843
11842
  if (this.isEntry(keyNodeOrEntry)) {
11844
11843
  const [key, values] = keyNodeOrEntry;
@@ -11878,7 +11877,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11878
11877
  map(callback, options, thisArg) {
11879
11878
  const out = this._createLike([], options);
11880
11879
  let i = 0;
11881
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11880
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
11882
11881
  return out;
11883
11882
  }
11884
11883
  /**
@@ -12064,7 +12063,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
12064
12063
  constructor(keysNodesEntriesOrRaws = [], options) {
12065
12064
  super([], options);
12066
12065
  __publicField(this, "_count", 0);
12067
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12066
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12068
12067
  }
12069
12068
  /**
12070
12069
  * Get the total aggregate count across all nodes.
@@ -12103,10 +12102,10 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
12103
12102
  * @param [count] - How much to increase the node's count (default 1).
12104
12103
  * @returns True if inserted/updated; false if ignored.
12105
12104
  */
12106
- add(keyNodeOrEntry, value, count = 1) {
12105
+ set(keyNodeOrEntry, value, count = 1) {
12107
12106
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12108
12107
  const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
12109
- const isSuccessAdded = super.add(newNode, newValue);
12108
+ const isSuccessAdded = super.set(newNode, newValue);
12110
12109
  if (isSuccessAdded) {
12111
12110
  this._count += orgCount;
12112
12111
  return true;
@@ -12259,7 +12258,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
12259
12258
  const out = this._createLike([], options);
12260
12259
  let index = 0;
12261
12260
  for (const [key, value] of this) {
12262
- out.add(callback.call(thisArg, value, key, index++, this));
12261
+ out.set(callback.call(thisArg, value, key, index++, this));
12263
12262
  }
12264
12263
  return out;
12265
12264
  }
@@ -12514,7 +12513,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12514
12513
  constructor(keysNodesEntriesOrRaws = [], options) {
12515
12514
  super([], options);
12516
12515
  __publicField(this, "_count", 0);
12517
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12516
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12518
12517
  }
12519
12518
  get count() {
12520
12519
  return this._count;
@@ -12548,11 +12547,11 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12548
12547
  * @param [count] - How much to increase the node's count (default 1).
12549
12548
  * @returns True if inserted/updated; false if ignored.
12550
12549
  */
12551
- add(keyNodeOrEntry, value, count = 1) {
12550
+ set(keyNodeOrEntry, value, count = 1) {
12552
12551
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12553
12552
  if (newNode === void 0) return false;
12554
12553
  const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
12555
- const inserted = super.add(newNode, newValue);
12554
+ const inserted = super.set(newNode, newValue);
12556
12555
  if (inserted) {
12557
12556
  this._count += orgNodeCount;
12558
12557
  }
@@ -12661,9 +12660,9 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12661
12660
  clone() {
12662
12661
  const out = this._createInstance();
12663
12662
  if (this._isMapMode) {
12664
- this.bfs((node) => out.add(node.key, void 0, node.count));
12663
+ this.bfs((node) => out.set(node.key, void 0, node.count));
12665
12664
  } else {
12666
- this.bfs((node) => out.add(node.key, node.value, node.count));
12665
+ this.bfs((node) => out.set(node.key, node.value, node.count));
12667
12666
  }
12668
12667
  if (this._isMapMode) out._store = this._store;
12669
12668
  return out;
@@ -12683,7 +12682,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12683
12682
  const out = this._createLike([], options);
12684
12683
  let index = 0;
12685
12684
  for (const [key, value] of this) {
12686
- out.add(callback.call(thisArg, value, key, index++, this));
12685
+ out.set(callback.call(thisArg, value, key, index++, this));
12687
12686
  }
12688
12687
  return out;
12689
12688
  }