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
@@ -6995,9 +6995,9 @@ var BinaryTree = class extends IterableEntryBase {
6995
6995
  iterationType = "ITERATIVE";
6996
6996
  /**
6997
6997
  * Creates an instance of BinaryTree.
6998
- * @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.
6998
+ * @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.
6999
6999
  *
7000
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
7000
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
7001
7001
  * @param [options] - Configuration options for the tree.
7002
7002
  */
7003
7003
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -7010,7 +7010,7 @@ var BinaryTree = class extends IterableEntryBase {
7010
7010
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
7011
7011
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
7012
7012
  }
7013
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
7013
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
7014
7014
  }
7015
7015
  _isMapMode = true;
7016
7016
  /**
@@ -7224,10 +7224,20 @@ var BinaryTree = class extends IterableEntryBase {
7224
7224
  * @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).
7225
7225
  *
7226
7226
  * @param keyNodeOrEntry - The key, node, or entry to add.
7227
+ * @returns True if the addition was successful, false otherwise.
7228
+ */
7229
+ add(keyNodeOrEntry) {
7230
+ return this.set(keyNodeOrEntry);
7231
+ }
7232
+ /**
7233
+ * Adds or updates a new node to the tree.
7234
+ * @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).
7235
+ *
7236
+ * @param keyNodeOrEntry - The key, node, or entry to set or update.
7227
7237
  * @param [value] - The value, if providing just a key.
7228
7238
  * @returns True if the addition was successful, false otherwise.
7229
7239
  */
7230
- add(keyNodeOrEntry, value) {
7240
+ set(keyNodeOrEntry, value) {
7231
7241
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
7232
7242
  if (newNode === void 0) return false;
7233
7243
  if (!this._root) {
@@ -7271,25 +7281,25 @@ var BinaryTree = class extends IterableEntryBase {
7271
7281
  return false;
7272
7282
  }
7273
7283
  /**
7274
- * Adds or updates a new node to the tree.
7275
- * @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).
7284
+ * Adds multiple items to the tree.
7285
+ * @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).
7276
7286
  *
7277
- * @param keyNodeOrEntry - The key, node, or entry to add or update.
7278
- * @param [value] - The value, if providing just a key.
7279
- * @returns True if the addition was successful, false otherwise.
7287
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7288
+ * @param [values] - An optional parallel iterable of values.
7289
+ * @returns An array of booleans indicating the success of each individual `set` operation.
7280
7290
  */
7281
- set(keyNodeOrEntry, value) {
7282
- return this.add(keyNodeOrEntry, value);
7291
+ addMany(keysNodesEntriesOrRaws) {
7292
+ return this.setMany(keysNodesEntriesOrRaws);
7283
7293
  }
7284
7294
  /**
7285
- * Adds multiple items to the tree.
7286
- * @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).
7295
+ * Adds or updates multiple items to the tree.
7296
+ * @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).
7287
7297
  *
7288
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7298
+ * @param keysNodesEntriesOrRaws - An iterable of items to set or update.
7289
7299
  * @param [values] - An optional parallel iterable of values.
7290
- * @returns An array of booleans indicating the success of each individual `add` operation.
7300
+ * @returns An array of booleans indicating the success of each individual `set` operation.
7291
7301
  */
7292
- addMany(keysNodesEntriesOrRaws, values) {
7302
+ setMany(keysNodesEntriesOrRaws, values) {
7293
7303
  const inserted = [];
7294
7304
  let valuesIterator;
7295
7305
  if (values) {
@@ -7304,40 +7314,29 @@ var BinaryTree = class extends IterableEntryBase {
7304
7314
  }
7305
7315
  }
7306
7316
  if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
7307
- inserted.push(this.add(keyNodeEntryOrRaw, value));
7317
+ inserted.push(this.set(keyNodeEntryOrRaw, value));
7308
7318
  }
7309
7319
  return inserted;
7310
7320
  }
7311
7321
  /**
7312
- * Adds or updates multiple items to the tree.
7313
- * @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).
7314
- *
7315
- * @param keysNodesEntriesOrRaws - An iterable of items to add or update.
7316
- * @param [values] - An optional parallel iterable of values.
7317
- * @returns An array of booleans indicating the success of each individual `add` operation.
7318
- */
7319
- setMany(keysNodesEntriesOrRaws, values) {
7320
- return this.addMany(keysNodesEntriesOrRaws, values);
7321
- }
7322
- /**
7323
- * Merges another tree into this one by adding all its nodes.
7324
- * @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`).
7322
+ * Merges another tree into this one by seting all its nodes.
7323
+ * @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`).
7325
7324
  *
7326
7325
  * @param anotherTree - The tree to merge.
7327
7326
  */
7328
7327
  merge(anotherTree) {
7329
- this.addMany(anotherTree, []);
7328
+ this.setMany(anotherTree, []);
7330
7329
  }
7331
7330
  /**
7332
7331
  * Clears the tree and refills it with new items.
7333
- * @remarks Time O(N) (for `clear`) + O(N * M) (for `addMany`) = O(N * M). Space O(M) (from `addMany`).
7332
+ * @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
7334
7333
  *
7335
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7334
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7336
7335
  * @param [values] - An optional parallel iterable of values.
7337
7336
  */
7338
7337
  refill(keysNodesEntriesOrRaws, values) {
7339
7338
  this.clear();
7340
- this.addMany(keysNodesEntriesOrRaws, values);
7339
+ this.setMany(keysNodesEntriesOrRaws, values);
7341
7340
  }
7342
7341
  /**
7343
7342
  * Deletes a node from the tree.
@@ -8002,7 +8001,7 @@ var BinaryTree = class extends IterableEntryBase {
8002
8001
  }
8003
8002
  /**
8004
8003
  * Clones the tree.
8005
- * @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.
8004
+ * @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.
8006
8005
  *
8007
8006
  * @returns A new, cloned instance of the tree.
8008
8007
  */
@@ -8013,7 +8012,7 @@ var BinaryTree = class extends IterableEntryBase {
8013
8012
  }
8014
8013
  /**
8015
8014
  * Creates a new tree containing only the entries that satisfy the predicate.
8016
- * @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.
8015
+ * @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.
8017
8016
  *
8018
8017
  * @param predicate - A function to test each [key, value] pair.
8019
8018
  * @param [thisArg] - `this` context for the predicate.
@@ -8022,7 +8021,7 @@ var BinaryTree = class extends IterableEntryBase {
8022
8021
  filter(predicate, thisArg) {
8023
8022
  const out = this._createInstance();
8024
8023
  let i = 0;
8025
- for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
8024
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
8026
8025
  return out;
8027
8026
  }
8028
8027
  /**
@@ -8040,7 +8039,7 @@ var BinaryTree = class extends IterableEntryBase {
8040
8039
  map(cb, options, thisArg) {
8041
8040
  const out = this._createLike([], options);
8042
8041
  let i = 0;
8043
- for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
8042
+ for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
8044
8043
  return out;
8045
8044
  }
8046
8045
  /**
@@ -8292,18 +8291,18 @@ var BinaryTree = class extends IterableEntryBase {
8292
8291
  return [this.createNode(keyNodeOrEntry, value), value];
8293
8292
  }
8294
8293
  /**
8295
- * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
8296
- * @remarks Time O(N * M) (O(N) BFS + O(M) `add` for each node).
8294
+ * (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
8295
+ * @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
8297
8296
  *
8298
8297
  * @param cloned - The new, empty tree instance to populate.
8299
8298
  */
8300
8299
  _clone(cloned) {
8301
8300
  this.bfs(
8302
8301
  (node) => {
8303
- if (node === null) cloned.add(null);
8302
+ if (node === null) cloned.set(null);
8304
8303
  else {
8305
- if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
8306
- else cloned.add([node.key, node.value]);
8304
+ if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
8305
+ else cloned.set([node.key, node.value]);
8307
8306
  }
8308
8307
  },
8309
8308
  this._root,
@@ -8636,7 +8635,7 @@ var BST = class extends BinaryTree {
8636
8635
  * Creates an instance of BST.
8637
8636
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
8638
8637
  *
8639
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
8638
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
8640
8639
  * @param [options] - Configuration options for the BST, including comparator.
8641
8640
  */
8642
8641
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -8650,7 +8649,7 @@ var BST = class extends BinaryTree {
8650
8649
  } else {
8651
8650
  this._comparator = this._createDefaultComparator();
8652
8651
  }
8653
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8652
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
8654
8653
  }
8655
8654
  _root = void 0;
8656
8655
  /**
@@ -8866,11 +8865,11 @@ var BST = class extends BinaryTree {
8866
8865
  * Adds a new node to the BST based on key comparison.
8867
8866
  * @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
8868
8867
  *
8869
- * @param keyNodeOrEntry - The key, node, or entry to add.
8868
+ * @param keyNodeOrEntry - The key, node, or entry to set.
8870
8869
  * @param [value] - The value, if providing just a key.
8871
8870
  * @returns True if the addition was successful, false otherwise.
8872
8871
  */
8873
- add(keyNodeOrEntry, value) {
8872
+ set(keyNodeOrEntry, value) {
8874
8873
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
8875
8874
  if (newNode === void 0) return false;
8876
8875
  if (this._root === void 0) {
@@ -8907,24 +8906,24 @@ var BST = class extends BinaryTree {
8907
8906
  }
8908
8907
  /**
8909
8908
  * Adds multiple items to the tree.
8910
- * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced add).
8909
+ * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
8911
8910
  * If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
8912
8911
  * Space O(N) for sorting and recursion/iteration stack.
8913
8912
  *
8914
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
8913
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
8915
8914
  * @param [values] - An optional parallel iterable of values.
8916
8915
  * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
8917
- * @param [iterationType=this.iterationType] - The traversal method for balanced add (recursive or iterative).
8918
- * @returns An array of booleans indicating the success of each individual `add` operation.
8916
+ * @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
8917
+ * @returns An array of booleans indicating the success of each individual `set` operation.
8919
8918
  */
8920
- addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8919
+ setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8921
8920
  const inserted = [];
8922
8921
  const valuesIterator = values?.[Symbol.iterator]();
8923
8922
  if (!isBalanceAdd) {
8924
8923
  for (let kve of keysNodesEntriesOrRaws) {
8925
8924
  const val = valuesIterator?.next().value;
8926
8925
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
8927
- inserted.push(this.add(kve, val));
8926
+ inserted.push(this.set(kve, val));
8928
8927
  }
8929
8928
  return inserted;
8930
8929
  }
@@ -8952,9 +8951,9 @@ var BST = class extends BinaryTree {
8952
8951
  const { key, value, orgIndex } = arr[mid];
8953
8952
  if (this.isRaw(key)) {
8954
8953
  const entry = this._toEntryFn(key);
8955
- inserted[orgIndex] = this.add(entry);
8954
+ inserted[orgIndex] = this.set(entry);
8956
8955
  } else {
8957
- inserted[orgIndex] = this.add(key, value);
8956
+ inserted[orgIndex] = this.set(key, value);
8958
8957
  }
8959
8958
  _dfs(arr.slice(0, mid));
8960
8959
  _dfs(arr.slice(mid + 1));
@@ -8971,9 +8970,9 @@ var BST = class extends BinaryTree {
8971
8970
  const { key, value, orgIndex } = sorted[m];
8972
8971
  if (this.isRaw(key)) {
8973
8972
  const entry = this._toEntryFn(key);
8974
- inserted[orgIndex] = this.add(entry);
8973
+ inserted[orgIndex] = this.set(entry);
8975
8974
  } else {
8976
- inserted[orgIndex] = this.add(key, value);
8975
+ inserted[orgIndex] = this.set(key, value);
8977
8976
  }
8978
8977
  stack.push([m + 1, r]);
8979
8978
  stack.push([l, m - 1]);
@@ -9248,7 +9247,7 @@ var BST = class extends BinaryTree {
9248
9247
  const out = this._createLike([], options);
9249
9248
  let index = 0;
9250
9249
  for (const [key, value] of this) {
9251
- out.add(callback.call(thisArg, value, key, index++, this));
9250
+ out.set(callback.call(thisArg, value, key, index++, this));
9252
9251
  }
9253
9252
  return out;
9254
9253
  }
@@ -10435,14 +10434,14 @@ var AVLTree = class extends BST {
10435
10434
  }
10436
10435
  /**
10437
10436
  * Creates an instance of AVLTree.
10438
- * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
10437
+ * @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
10439
10438
  *
10440
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
10439
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
10441
10440
  * @param [options] - Configuration options for the AVL tree.
10442
10441
  */
10443
10442
  constructor(keysNodesEntriesOrRaws = [], options) {
10444
10443
  super([], options);
10445
- if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
10444
+ if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
10446
10445
  }
10447
10446
  /**
10448
10447
  * (Protected) Creates a new AVL tree node.
@@ -10466,16 +10465,16 @@ var AVLTree = class extends BST {
10466
10465
  return keyNodeOrEntry instanceof AVLTreeNode;
10467
10466
  }
10468
10467
  /**
10469
- * Adds a new node to the AVL tree and balances the tree path.
10470
- * @remarks Time O(log N) (O(H) for BST add + O(H) for `_balancePath`). Space O(H) for path/recursion.
10468
+ * Sets a new node to the AVL tree and balances the tree path.
10469
+ * @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
10471
10470
  *
10472
- * @param keyNodeOrEntry - The key, node, or entry to add.
10471
+ * @param keyNodeOrEntry - The key, node, or entry to set.
10473
10472
  * @param [value] - The value, if providing just a key.
10474
10473
  * @returns True if the addition was successful, false otherwise.
10475
10474
  */
10476
- add(keyNodeOrEntry, value) {
10475
+ set(keyNodeOrEntry, value) {
10477
10476
  if (keyNodeOrEntry === null) return false;
10478
- const inserted = super.add(keyNodeOrEntry, value);
10477
+ const inserted = super.set(keyNodeOrEntry, value);
10479
10478
  if (inserted) this._balancePath(keyNodeOrEntry);
10480
10479
  return inserted;
10481
10480
  }
@@ -10527,7 +10526,7 @@ var AVLTree = class extends BST {
10527
10526
  }
10528
10527
  /**
10529
10528
  * Creates a new AVLTree by mapping each [key, value] pair.
10530
- * @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.
10529
+ * @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.
10531
10530
  *
10532
10531
  * @template MK - New key type.
10533
10532
  * @template MV - New value type.
@@ -10541,7 +10540,7 @@ var AVLTree = class extends BST {
10541
10540
  const out = this._createLike([], options);
10542
10541
  let index = 0;
10543
10542
  for (const [key, value] of this) {
10544
- out.add(callback.call(thisArg, value, key, index++, this));
10543
+ out.set(callback.call(thisArg, value, key, index++, this));
10545
10544
  }
10546
10545
  return out;
10547
10546
  }
@@ -10967,7 +10966,7 @@ var RedBlackTree = class extends BST {
10967
10966
  super([], options);
10968
10967
  this._root = this.NIL;
10969
10968
  if (keysNodesEntriesOrRaws) {
10970
- this.addMany(keysNodesEntriesOrRaws);
10969
+ this.setMany(keysNodesEntriesOrRaws);
10971
10970
  }
10972
10971
  }
10973
10972
  _root;
@@ -11015,7 +11014,7 @@ var RedBlackTree = class extends BST {
11015
11014
  * @param [value]- See parameter type for details.
11016
11015
  * @returns True if inserted or updated; false if ignored.
11017
11016
  */
11018
- add(keyNodeOrEntry, value) {
11017
+ set(keyNodeOrEntry, value) {
11019
11018
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
11020
11019
  if (!this.isRealNode(newNode)) return false;
11021
11020
  const insertStatus = this._insert(newNode);
@@ -11109,7 +11108,7 @@ var RedBlackTree = class extends BST {
11109
11108
  const out = this._createLike([], options);
11110
11109
  let index = 0;
11111
11110
  for (const [key, value] of this) {
11112
- out.add(callback.call(thisArg, value, key, index++, this));
11111
+ out.set(callback.call(thisArg, value, key, index++, this));
11113
11112
  }
11114
11113
  return out;
11115
11114
  }
@@ -11497,7 +11496,7 @@ var AVLTreeMultiMap = class extends AVLTree {
11497
11496
  constructor(keysNodesEntriesOrRaws = [], options) {
11498
11497
  super([], { ...options, isMapMode: true });
11499
11498
  if (keysNodesEntriesOrRaws) {
11500
- this.addMany(keysNodesEntriesOrRaws);
11499
+ this.setMany(keysNodesEntriesOrRaws);
11501
11500
  }
11502
11501
  }
11503
11502
  createNode(key, value = []) {
@@ -11517,27 +11516,27 @@ var AVLTreeMultiMap = class extends AVLTree {
11517
11516
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11518
11517
  * @remarks Time O(log N + M), Space O(1)
11519
11518
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11520
- * @param [value] - Single value to add when a bare key is provided.
11519
+ * @param [value] - Single value to set when a bare key is provided.
11521
11520
  * @returns True if inserted or appended; false if ignored.
11522
11521
  */
11523
- add(keyNodeOrEntry, value) {
11524
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11522
+ set(keyNodeOrEntry, value) {
11523
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11525
11524
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11526
11525
  if (key === void 0 || key === null) return false;
11527
- const _addToValues = /* @__PURE__ */ __name(() => {
11526
+ const _setToValues = /* @__PURE__ */ __name(() => {
11528
11527
  const existingValues = this.get(key);
11529
11528
  if (existingValues !== void 0 && values !== void 0) {
11530
11529
  for (const value2 of values) existingValues.push(value2);
11531
11530
  return true;
11532
11531
  }
11533
11532
  return false;
11534
- }, "_addToValues");
11535
- const _addByNode = /* @__PURE__ */ __name(() => {
11533
+ }, "_setToValues");
11534
+ const _setByNode = /* @__PURE__ */ __name(() => {
11536
11535
  const existingNode = this.getNode(key);
11537
11536
  if (this.isRealNode(existingNode)) {
11538
11537
  const existingValues = this.get(existingNode);
11539
11538
  if (existingValues === void 0) {
11540
- super.add(key, values);
11539
+ super.set(key, values);
11541
11540
  return true;
11542
11541
  }
11543
11542
  if (values !== void 0) {
@@ -11547,13 +11546,13 @@ var AVLTreeMultiMap = class extends AVLTree {
11547
11546
  return false;
11548
11547
  }
11549
11548
  } else {
11550
- return super.add(key, values);
11549
+ return super.set(key, values);
11551
11550
  }
11552
- }, "_addByNode");
11551
+ }, "_setByNode");
11553
11552
  if (this._isMapMode) {
11554
- return _addByNode() || _addToValues();
11553
+ return _setByNode() || _setToValues();
11555
11554
  }
11556
- return _addToValues() || _addByNode();
11555
+ return _setToValues() || _setByNode();
11557
11556
  }, "_commonAdd");
11558
11557
  if (this.isEntry(keyNodeOrEntry)) {
11559
11558
  const [key, values] = keyNodeOrEntry;
@@ -11621,7 +11620,7 @@ var AVLTreeMultiMap = class extends AVLTree {
11621
11620
  map(callback, options, thisArg) {
11622
11621
  const out = this._createLike([], options);
11623
11622
  let i = 0;
11624
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11623
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
11625
11624
  return out;
11626
11625
  }
11627
11626
  /**
@@ -11804,7 +11803,7 @@ var TreeMultiMap = class extends RedBlackTree {
11804
11803
  constructor(keysNodesEntriesOrRaws = [], options) {
11805
11804
  super([], { ...options });
11806
11805
  if (keysNodesEntriesOrRaws) {
11807
- this.addMany(keysNodesEntriesOrRaws);
11806
+ this.setMany(keysNodesEntriesOrRaws);
11808
11807
  }
11809
11808
  }
11810
11809
  createNode(key, value = []) {
@@ -11824,27 +11823,27 @@ var TreeMultiMap = class extends RedBlackTree {
11824
11823
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11825
11824
  * @remarks Time O(log N + M), Space O(1)
11826
11825
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11827
- * @param [value] - Single value to add when a bare key is provided.
11826
+ * @param [value] - Single value to set when a bare key is provided.
11828
11827
  * @returns True if inserted or appended; false if ignored.
11829
11828
  */
11830
- add(keyNodeOrEntry, value) {
11831
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11829
+ set(keyNodeOrEntry, value) {
11830
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11832
11831
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11833
11832
  if (key === void 0 || key === null) return false;
11834
- const _addToValues = /* @__PURE__ */ __name(() => {
11833
+ const _setToValues = /* @__PURE__ */ __name(() => {
11835
11834
  const existingValues = this.get(key);
11836
11835
  if (existingValues !== void 0 && values !== void 0) {
11837
11836
  for (const value2 of values) existingValues.push(value2);
11838
11837
  return true;
11839
11838
  }
11840
11839
  return false;
11841
- }, "_addToValues");
11842
- const _addByNode = /* @__PURE__ */ __name(() => {
11840
+ }, "_setToValues");
11841
+ const _setByNode = /* @__PURE__ */ __name(() => {
11843
11842
  const existingNode = this.getNode(key);
11844
11843
  if (this.isRealNode(existingNode)) {
11845
11844
  const existingValues = this.get(existingNode);
11846
11845
  if (existingValues === void 0) {
11847
- super.add(key, values);
11846
+ super.set(key, values);
11848
11847
  return true;
11849
11848
  }
11850
11849
  if (values !== void 0) {
@@ -11854,13 +11853,13 @@ var TreeMultiMap = class extends RedBlackTree {
11854
11853
  return false;
11855
11854
  }
11856
11855
  } else {
11857
- return super.add(key, values);
11856
+ return super.set(key, values);
11858
11857
  }
11859
- }, "_addByNode");
11858
+ }, "_setByNode");
11860
11859
  if (this._isMapMode) {
11861
- return _addByNode() || _addToValues();
11860
+ return _setByNode() || _setToValues();
11862
11861
  }
11863
- return _addToValues() || _addByNode();
11862
+ return _setToValues() || _setByNode();
11864
11863
  }, "_commonAdd");
11865
11864
  if (this.isEntry(keyNodeOrEntry)) {
11866
11865
  const [key, values] = keyNodeOrEntry;
@@ -11900,7 +11899,7 @@ var TreeMultiMap = class extends RedBlackTree {
11900
11899
  map(callback, options, thisArg) {
11901
11900
  const out = this._createLike([], options);
11902
11901
  let i = 0;
11903
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11902
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
11904
11903
  return out;
11905
11904
  }
11906
11905
  /**
@@ -12085,7 +12084,7 @@ var TreeCounter = class extends RedBlackTree {
12085
12084
  */
12086
12085
  constructor(keysNodesEntriesOrRaws = [], options) {
12087
12086
  super([], options);
12088
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12087
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12089
12088
  }
12090
12089
  _count = 0;
12091
12090
  /**
@@ -12125,10 +12124,10 @@ var TreeCounter = class extends RedBlackTree {
12125
12124
  * @param [count] - How much to increase the node's count (default 1).
12126
12125
  * @returns True if inserted/updated; false if ignored.
12127
12126
  */
12128
- add(keyNodeOrEntry, value, count = 1) {
12127
+ set(keyNodeOrEntry, value, count = 1) {
12129
12128
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12130
12129
  const orgCount = newNode?.count || 0;
12131
- const isSuccessAdded = super.add(newNode, newValue);
12130
+ const isSuccessAdded = super.set(newNode, newValue);
12132
12131
  if (isSuccessAdded) {
12133
12132
  this._count += orgCount;
12134
12133
  return true;
@@ -12281,7 +12280,7 @@ var TreeCounter = class extends RedBlackTree {
12281
12280
  const out = this._createLike([], options);
12282
12281
  let index = 0;
12283
12282
  for (const [key, value] of this) {
12284
- out.add(callback.call(thisArg, value, key, index++, this));
12283
+ out.set(callback.call(thisArg, value, key, index++, this));
12285
12284
  }
12286
12285
  return out;
12287
12286
  }
@@ -12537,7 +12536,7 @@ var AVLTreeCounter = class extends AVLTree {
12537
12536
  */
12538
12537
  constructor(keysNodesEntriesOrRaws = [], options) {
12539
12538
  super([], options);
12540
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12539
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12541
12540
  }
12542
12541
  _count = 0;
12543
12542
  get count() {
@@ -12572,11 +12571,11 @@ var AVLTreeCounter = class extends AVLTree {
12572
12571
  * @param [count] - How much to increase the node's count (default 1).
12573
12572
  * @returns True if inserted/updated; false if ignored.
12574
12573
  */
12575
- add(keyNodeOrEntry, value, count = 1) {
12574
+ set(keyNodeOrEntry, value, count = 1) {
12576
12575
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12577
12576
  if (newNode === void 0) return false;
12578
12577
  const orgNodeCount = newNode?.count || 0;
12579
- const inserted = super.add(newNode, newValue);
12578
+ const inserted = super.set(newNode, newValue);
12580
12579
  if (inserted) {
12581
12580
  this._count += orgNodeCount;
12582
12581
  }
@@ -12684,9 +12683,9 @@ var AVLTreeCounter = class extends AVLTree {
12684
12683
  clone() {
12685
12684
  const out = this._createInstance();
12686
12685
  if (this._isMapMode) {
12687
- this.bfs((node) => out.add(node.key, void 0, node.count));
12686
+ this.bfs((node) => out.set(node.key, void 0, node.count));
12688
12687
  } else {
12689
- this.bfs((node) => out.add(node.key, node.value, node.count));
12688
+ this.bfs((node) => out.set(node.key, node.value, node.count));
12690
12689
  }
12691
12690
  if (this._isMapMode) out._store = this._store;
12692
12691
  return out;
@@ -12706,7 +12705,7 @@ var AVLTreeCounter = class extends AVLTree {
12706
12705
  const out = this._createLike([], options);
12707
12706
  let index = 0;
12708
12707
  for (const [key, value] of this) {
12709
- out.add(callback.call(thisArg, value, key, index++, this));
12708
+ out.set(callback.call(thisArg, value, key, index++, this));
12710
12709
  }
12711
12710
  return out;
12712
12711
  }