data-structure-typed 2.2.6 → 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 (72) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +47 -1
  3. package/README.md +19 -8
  4. package/README_CN.md +119 -275
  5. package/benchmark/report.html +1 -1
  6. package/benchmark/report.json +20 -324
  7. package/dist/cjs/index.cjs +109 -107
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs-legacy/index.cjs +109 -107
  10. package/dist/cjs-legacy/index.cjs.map +1 -1
  11. package/dist/esm/index.mjs +109 -107
  12. package/dist/esm/index.mjs.map +1 -1
  13. package/dist/esm-legacy/index.mjs +109 -107
  14. package/dist/esm-legacy/index.mjs.map +1 -1
  15. package/dist/leetcode/avl-tree-counter.mjs +2957 -0
  16. package/dist/leetcode/avl-tree-multi-map.mjs +2889 -0
  17. package/dist/leetcode/avl-tree.mjs +2720 -0
  18. package/dist/leetcode/binary-tree.mjs +1594 -0
  19. package/dist/leetcode/bst.mjs +2398 -0
  20. package/dist/leetcode/deque.mjs +683 -0
  21. package/dist/leetcode/directed-graph.mjs +1733 -0
  22. package/dist/leetcode/doubly-linked-list.mjs +709 -0
  23. package/dist/leetcode/hash-map.mjs +493 -0
  24. package/dist/leetcode/heap.mjs +542 -0
  25. package/dist/leetcode/max-heap.mjs +375 -0
  26. package/dist/leetcode/max-priority-queue.mjs +383 -0
  27. package/dist/leetcode/min-heap.mjs +363 -0
  28. package/dist/leetcode/min-priority-queue.mjs +371 -0
  29. package/dist/leetcode/priority-queue.mjs +363 -0
  30. package/dist/leetcode/queue.mjs +943 -0
  31. package/dist/leetcode/red-black-tree.mjs +2765 -0
  32. package/dist/leetcode/singly-linked-list.mjs +754 -0
  33. package/dist/leetcode/stack.mjs +217 -0
  34. package/dist/leetcode/tree-counter.mjs +3039 -0
  35. package/dist/leetcode/tree-multi-map.mjs +2913 -0
  36. package/dist/leetcode/trie.mjs +413 -0
  37. package/dist/leetcode/undirected-graph.mjs +1650 -0
  38. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
  39. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  40. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -23
  42. package/dist/types/data-structures/binary-tree/bst.d.ts +11 -11
  43. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  44. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  45. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
  46. package/dist/umd/data-structure-typed.js +105 -103
  47. package/dist/umd/data-structure-typed.js.map +1 -1
  48. package/dist/umd/data-structure-typed.min.js +2 -2
  49. package/dist/umd/data-structure-typed.min.js.map +1 -1
  50. package/package.json +48 -171
  51. package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
  52. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
  53. package/src/data-structures/binary-tree/avl-tree.ts +15 -15
  54. package/src/data-structures/binary-tree/binary-tree.ts +53 -55
  55. package/src/data-structures/binary-tree/bst.ts +21 -22
  56. package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
  57. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  58. package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
  59. package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +1 -2
  60. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +30 -30
  61. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +46 -46
  62. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +43 -43
  63. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +151 -151
  64. package/test/unit/data-structures/binary-tree/bst.test.ts +99 -99
  65. package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
  66. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +141 -141
  67. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +37 -37
  68. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +145 -145
  69. package/tsup.config.js +50 -21
  70. package/tsup.leetcode.config.js +1 -1
  71. package/tsup.umd.config.js +29 -0
  72. package/tsup.node.config.js +0 -83
@@ -181,6 +181,7 @@ var IterableEntryBase = class {
181
181
  * @remarks Time O(n), Space O(n)
182
182
  */
183
183
  print() {
184
+ console.log(this.toVisual());
184
185
  }
185
186
  };
186
187
 
@@ -403,6 +404,7 @@ var IterableElementBase = class {
403
404
  * Time O(n) due to materialization, Space O(n) for the intermediate representation.
404
405
  */
405
406
  print() {
407
+ console.log(this.toVisual());
406
408
  }
407
409
  };
408
410
 
@@ -6993,9 +6995,9 @@ var BinaryTree = class extends IterableEntryBase {
6993
6995
  iterationType = "ITERATIVE";
6994
6996
  /**
6995
6997
  * Creates an instance of BinaryTree.
6996
- * @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.
6997
6999
  *
6998
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
7000
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
6999
7001
  * @param [options] - Configuration options for the tree.
7000
7002
  */
7001
7003
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -7008,7 +7010,7 @@ var BinaryTree = class extends IterableEntryBase {
7008
7010
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
7009
7011
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
7010
7012
  }
7011
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
7013
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
7012
7014
  }
7013
7015
  _isMapMode = true;
7014
7016
  /**
@@ -7222,10 +7224,20 @@ var BinaryTree = class extends IterableEntryBase {
7222
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).
7223
7225
  *
7224
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.
7225
7237
  * @param [value] - The value, if providing just a key.
7226
7238
  * @returns True if the addition was successful, false otherwise.
7227
7239
  */
7228
- add(keyNodeOrEntry, value) {
7240
+ set(keyNodeOrEntry, value) {
7229
7241
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
7230
7242
  if (newNode === void 0) return false;
7231
7243
  if (!this._root) {
@@ -7269,25 +7281,25 @@ var BinaryTree = class extends IterableEntryBase {
7269
7281
  return false;
7270
7282
  }
7271
7283
  /**
7272
- * Adds or updates a new node to the tree.
7273
- * @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).
7274
7286
  *
7275
- * @param keyNodeOrEntry - The key, node, or entry to add or update.
7276
- * @param [value] - The value, if providing just a key.
7277
- * @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.
7278
7290
  */
7279
- set(keyNodeOrEntry, value) {
7280
- return this.add(keyNodeOrEntry, value);
7291
+ addMany(keysNodesEntriesOrRaws) {
7292
+ return this.setMany(keysNodesEntriesOrRaws);
7281
7293
  }
7282
7294
  /**
7283
- * Adds multiple items to the tree.
7284
- * @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).
7285
7297
  *
7286
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7298
+ * @param keysNodesEntriesOrRaws - An iterable of items to set or update.
7287
7299
  * @param [values] - An optional parallel iterable of values.
7288
- * @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.
7289
7301
  */
7290
- addMany(keysNodesEntriesOrRaws, values) {
7302
+ setMany(keysNodesEntriesOrRaws, values) {
7291
7303
  const inserted = [];
7292
7304
  let valuesIterator;
7293
7305
  if (values) {
@@ -7302,40 +7314,29 @@ var BinaryTree = class extends IterableEntryBase {
7302
7314
  }
7303
7315
  }
7304
7316
  if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
7305
- inserted.push(this.add(keyNodeEntryOrRaw, value));
7317
+ inserted.push(this.set(keyNodeEntryOrRaw, value));
7306
7318
  }
7307
7319
  return inserted;
7308
7320
  }
7309
7321
  /**
7310
- * Adds or updates multiple items to the tree.
7311
- * @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).
7312
- *
7313
- * @param keysNodesEntriesOrRaws - An iterable of items to add or update.
7314
- * @param [values] - An optional parallel iterable of values.
7315
- * @returns An array of booleans indicating the success of each individual `add` operation.
7316
- */
7317
- setMany(keysNodesEntriesOrRaws, values) {
7318
- return this.addMany(keysNodesEntriesOrRaws, values);
7319
- }
7320
- /**
7321
- * Merges another tree into this one by adding all its nodes.
7322
- * @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`).
7323
7324
  *
7324
7325
  * @param anotherTree - The tree to merge.
7325
7326
  */
7326
7327
  merge(anotherTree) {
7327
- this.addMany(anotherTree, []);
7328
+ this.setMany(anotherTree, []);
7328
7329
  }
7329
7330
  /**
7330
7331
  * Clears the tree and refills it with new items.
7331
- * @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`).
7332
7333
  *
7333
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7334
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7334
7335
  * @param [values] - An optional parallel iterable of values.
7335
7336
  */
7336
7337
  refill(keysNodesEntriesOrRaws, values) {
7337
7338
  this.clear();
7338
- this.addMany(keysNodesEntriesOrRaws, values);
7339
+ this.setMany(keysNodesEntriesOrRaws, values);
7339
7340
  }
7340
7341
  /**
7341
7342
  * Deletes a node from the tree.
@@ -8000,7 +8001,7 @@ var BinaryTree = class extends IterableEntryBase {
8000
8001
  }
8001
8002
  /**
8002
8003
  * Clones the tree.
8003
- * @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.
8004
8005
  *
8005
8006
  * @returns A new, cloned instance of the tree.
8006
8007
  */
@@ -8011,7 +8012,7 @@ var BinaryTree = class extends IterableEntryBase {
8011
8012
  }
8012
8013
  /**
8013
8014
  * Creates a new tree containing only the entries that satisfy the predicate.
8014
- * @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.
8015
8016
  *
8016
8017
  * @param predicate - A function to test each [key, value] pair.
8017
8018
  * @param [thisArg] - `this` context for the predicate.
@@ -8020,7 +8021,7 @@ var BinaryTree = class extends IterableEntryBase {
8020
8021
  filter(predicate, thisArg) {
8021
8022
  const out = this._createInstance();
8022
8023
  let i = 0;
8023
- 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]);
8024
8025
  return out;
8025
8026
  }
8026
8027
  /**
@@ -8038,7 +8039,7 @@ var BinaryTree = class extends IterableEntryBase {
8038
8039
  map(cb, options, thisArg) {
8039
8040
  const out = this._createLike([], options);
8040
8041
  let i = 0;
8041
- 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));
8042
8043
  return out;
8043
8044
  }
8044
8045
  /**
@@ -8079,6 +8080,7 @@ var BinaryTree = class extends IterableEntryBase {
8079
8080
  * @param [startNode=this._root] - The node to start printing from.
8080
8081
  */
8081
8082
  print(options, startNode = this._root) {
8083
+ console.log(this.toVisual(startNode, options));
8082
8084
  }
8083
8085
  /**
8084
8086
  * (Protected) Core DFS implementation.
@@ -8289,18 +8291,18 @@ var BinaryTree = class extends IterableEntryBase {
8289
8291
  return [this.createNode(keyNodeOrEntry, value), value];
8290
8292
  }
8291
8293
  /**
8292
- * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
8293
- * @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).
8294
8296
  *
8295
8297
  * @param cloned - The new, empty tree instance to populate.
8296
8298
  */
8297
8299
  _clone(cloned) {
8298
8300
  this.bfs(
8299
8301
  (node) => {
8300
- if (node === null) cloned.add(null);
8302
+ if (node === null) cloned.set(null);
8301
8303
  else {
8302
- if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
8303
- 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]);
8304
8306
  }
8305
8307
  },
8306
8308
  this._root,
@@ -8633,7 +8635,7 @@ var BST = class extends BinaryTree {
8633
8635
  * Creates an instance of BST.
8634
8636
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
8635
8637
  *
8636
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
8638
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
8637
8639
  * @param [options] - Configuration options for the BST, including comparator.
8638
8640
  */
8639
8641
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -8647,7 +8649,7 @@ var BST = class extends BinaryTree {
8647
8649
  } else {
8648
8650
  this._comparator = this._createDefaultComparator();
8649
8651
  }
8650
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8652
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
8651
8653
  }
8652
8654
  _root = void 0;
8653
8655
  /**
@@ -8863,11 +8865,11 @@ var BST = class extends BinaryTree {
8863
8865
  * Adds a new node to the BST based on key comparison.
8864
8866
  * @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
8865
8867
  *
8866
- * @param keyNodeOrEntry - The key, node, or entry to add.
8868
+ * @param keyNodeOrEntry - The key, node, or entry to set.
8867
8869
  * @param [value] - The value, if providing just a key.
8868
8870
  * @returns True if the addition was successful, false otherwise.
8869
8871
  */
8870
- add(keyNodeOrEntry, value) {
8872
+ set(keyNodeOrEntry, value) {
8871
8873
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
8872
8874
  if (newNode === void 0) return false;
8873
8875
  if (this._root === void 0) {
@@ -8904,24 +8906,24 @@ var BST = class extends BinaryTree {
8904
8906
  }
8905
8907
  /**
8906
8908
  * Adds multiple items to the tree.
8907
- * @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).
8908
8910
  * If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
8909
8911
  * Space O(N) for sorting and recursion/iteration stack.
8910
8912
  *
8911
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
8913
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
8912
8914
  * @param [values] - An optional parallel iterable of values.
8913
8915
  * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
8914
- * @param [iterationType=this.iterationType] - The traversal method for balanced add (recursive or iterative).
8915
- * @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.
8916
8918
  */
8917
- addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8919
+ setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8918
8920
  const inserted = [];
8919
8921
  const valuesIterator = values?.[Symbol.iterator]();
8920
8922
  if (!isBalanceAdd) {
8921
8923
  for (let kve of keysNodesEntriesOrRaws) {
8922
8924
  const val = valuesIterator?.next().value;
8923
8925
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
8924
- inserted.push(this.add(kve, val));
8926
+ inserted.push(this.set(kve, val));
8925
8927
  }
8926
8928
  return inserted;
8927
8929
  }
@@ -8949,9 +8951,9 @@ var BST = class extends BinaryTree {
8949
8951
  const { key, value, orgIndex } = arr[mid];
8950
8952
  if (this.isRaw(key)) {
8951
8953
  const entry = this._toEntryFn(key);
8952
- inserted[orgIndex] = this.add(entry);
8954
+ inserted[orgIndex] = this.set(entry);
8953
8955
  } else {
8954
- inserted[orgIndex] = this.add(key, value);
8956
+ inserted[orgIndex] = this.set(key, value);
8955
8957
  }
8956
8958
  _dfs(arr.slice(0, mid));
8957
8959
  _dfs(arr.slice(mid + 1));
@@ -8968,9 +8970,9 @@ var BST = class extends BinaryTree {
8968
8970
  const { key, value, orgIndex } = sorted[m];
8969
8971
  if (this.isRaw(key)) {
8970
8972
  const entry = this._toEntryFn(key);
8971
- inserted[orgIndex] = this.add(entry);
8973
+ inserted[orgIndex] = this.set(entry);
8972
8974
  } else {
8973
- inserted[orgIndex] = this.add(key, value);
8975
+ inserted[orgIndex] = this.set(key, value);
8974
8976
  }
8975
8977
  stack.push([m + 1, r]);
8976
8978
  stack.push([l, m - 1]);
@@ -9245,7 +9247,7 @@ var BST = class extends BinaryTree {
9245
9247
  const out = this._createLike([], options);
9246
9248
  let index = 0;
9247
9249
  for (const [key, value] of this) {
9248
- out.add(callback.call(thisArg, value, key, index++, this));
9250
+ out.set(callback.call(thisArg, value, key, index++, this));
9249
9251
  }
9250
9252
  return out;
9251
9253
  }
@@ -10432,14 +10434,14 @@ var AVLTree = class extends BST {
10432
10434
  }
10433
10435
  /**
10434
10436
  * Creates an instance of AVLTree.
10435
- * @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).
10436
10438
  *
10437
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
10439
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
10438
10440
  * @param [options] - Configuration options for the AVL tree.
10439
10441
  */
10440
10442
  constructor(keysNodesEntriesOrRaws = [], options) {
10441
10443
  super([], options);
10442
- if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
10444
+ if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
10443
10445
  }
10444
10446
  /**
10445
10447
  * (Protected) Creates a new AVL tree node.
@@ -10463,16 +10465,16 @@ var AVLTree = class extends BST {
10463
10465
  return keyNodeOrEntry instanceof AVLTreeNode;
10464
10466
  }
10465
10467
  /**
10466
- * Adds a new node to the AVL tree and balances the tree path.
10467
- * @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.
10468
10470
  *
10469
- * @param keyNodeOrEntry - The key, node, or entry to add.
10471
+ * @param keyNodeOrEntry - The key, node, or entry to set.
10470
10472
  * @param [value] - The value, if providing just a key.
10471
10473
  * @returns True if the addition was successful, false otherwise.
10472
10474
  */
10473
- add(keyNodeOrEntry, value) {
10475
+ set(keyNodeOrEntry, value) {
10474
10476
  if (keyNodeOrEntry === null) return false;
10475
- const inserted = super.add(keyNodeOrEntry, value);
10477
+ const inserted = super.set(keyNodeOrEntry, value);
10476
10478
  if (inserted) this._balancePath(keyNodeOrEntry);
10477
10479
  return inserted;
10478
10480
  }
@@ -10524,7 +10526,7 @@ var AVLTree = class extends BST {
10524
10526
  }
10525
10527
  /**
10526
10528
  * Creates a new AVLTree by mapping each [key, value] pair.
10527
- * @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.
10528
10530
  *
10529
10531
  * @template MK - New key type.
10530
10532
  * @template MV - New value type.
@@ -10538,7 +10540,7 @@ var AVLTree = class extends BST {
10538
10540
  const out = this._createLike([], options);
10539
10541
  let index = 0;
10540
10542
  for (const [key, value] of this) {
10541
- out.add(callback.call(thisArg, value, key, index++, this));
10543
+ out.set(callback.call(thisArg, value, key, index++, this));
10542
10544
  }
10543
10545
  return out;
10544
10546
  }
@@ -10964,7 +10966,7 @@ var RedBlackTree = class extends BST {
10964
10966
  super([], options);
10965
10967
  this._root = this.NIL;
10966
10968
  if (keysNodesEntriesOrRaws) {
10967
- this.addMany(keysNodesEntriesOrRaws);
10969
+ this.setMany(keysNodesEntriesOrRaws);
10968
10970
  }
10969
10971
  }
10970
10972
  _root;
@@ -11012,7 +11014,7 @@ var RedBlackTree = class extends BST {
11012
11014
  * @param [value]- See parameter type for details.
11013
11015
  * @returns True if inserted or updated; false if ignored.
11014
11016
  */
11015
- add(keyNodeOrEntry, value) {
11017
+ set(keyNodeOrEntry, value) {
11016
11018
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
11017
11019
  if (!this.isRealNode(newNode)) return false;
11018
11020
  const insertStatus = this._insert(newNode);
@@ -11106,7 +11108,7 @@ var RedBlackTree = class extends BST {
11106
11108
  const out = this._createLike([], options);
11107
11109
  let index = 0;
11108
11110
  for (const [key, value] of this) {
11109
- out.add(callback.call(thisArg, value, key, index++, this));
11111
+ out.set(callback.call(thisArg, value, key, index++, this));
11110
11112
  }
11111
11113
  return out;
11112
11114
  }
@@ -11494,7 +11496,7 @@ var AVLTreeMultiMap = class extends AVLTree {
11494
11496
  constructor(keysNodesEntriesOrRaws = [], options) {
11495
11497
  super([], { ...options, isMapMode: true });
11496
11498
  if (keysNodesEntriesOrRaws) {
11497
- this.addMany(keysNodesEntriesOrRaws);
11499
+ this.setMany(keysNodesEntriesOrRaws);
11498
11500
  }
11499
11501
  }
11500
11502
  createNode(key, value = []) {
@@ -11514,27 +11516,27 @@ var AVLTreeMultiMap = class extends AVLTree {
11514
11516
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11515
11517
  * @remarks Time O(log N + M), Space O(1)
11516
11518
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11517
- * @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.
11518
11520
  * @returns True if inserted or appended; false if ignored.
11519
11521
  */
11520
- add(keyNodeOrEntry, value) {
11521
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11522
+ set(keyNodeOrEntry, value) {
11523
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11522
11524
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11523
11525
  if (key === void 0 || key === null) return false;
11524
- const _addToValues = /* @__PURE__ */ __name(() => {
11526
+ const _setToValues = /* @__PURE__ */ __name(() => {
11525
11527
  const existingValues = this.get(key);
11526
11528
  if (existingValues !== void 0 && values !== void 0) {
11527
11529
  for (const value2 of values) existingValues.push(value2);
11528
11530
  return true;
11529
11531
  }
11530
11532
  return false;
11531
- }, "_addToValues");
11532
- const _addByNode = /* @__PURE__ */ __name(() => {
11533
+ }, "_setToValues");
11534
+ const _setByNode = /* @__PURE__ */ __name(() => {
11533
11535
  const existingNode = this.getNode(key);
11534
11536
  if (this.isRealNode(existingNode)) {
11535
11537
  const existingValues = this.get(existingNode);
11536
11538
  if (existingValues === void 0) {
11537
- super.add(key, values);
11539
+ super.set(key, values);
11538
11540
  return true;
11539
11541
  }
11540
11542
  if (values !== void 0) {
@@ -11544,13 +11546,13 @@ var AVLTreeMultiMap = class extends AVLTree {
11544
11546
  return false;
11545
11547
  }
11546
11548
  } else {
11547
- return super.add(key, values);
11549
+ return super.set(key, values);
11548
11550
  }
11549
- }, "_addByNode");
11551
+ }, "_setByNode");
11550
11552
  if (this._isMapMode) {
11551
- return _addByNode() || _addToValues();
11553
+ return _setByNode() || _setToValues();
11552
11554
  }
11553
- return _addToValues() || _addByNode();
11555
+ return _setToValues() || _setByNode();
11554
11556
  }, "_commonAdd");
11555
11557
  if (this.isEntry(keyNodeOrEntry)) {
11556
11558
  const [key, values] = keyNodeOrEntry;
@@ -11618,7 +11620,7 @@ var AVLTreeMultiMap = class extends AVLTree {
11618
11620
  map(callback, options, thisArg) {
11619
11621
  const out = this._createLike([], options);
11620
11622
  let i = 0;
11621
- 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));
11622
11624
  return out;
11623
11625
  }
11624
11626
  /**
@@ -11801,7 +11803,7 @@ var TreeMultiMap = class extends RedBlackTree {
11801
11803
  constructor(keysNodesEntriesOrRaws = [], options) {
11802
11804
  super([], { ...options });
11803
11805
  if (keysNodesEntriesOrRaws) {
11804
- this.addMany(keysNodesEntriesOrRaws);
11806
+ this.setMany(keysNodesEntriesOrRaws);
11805
11807
  }
11806
11808
  }
11807
11809
  createNode(key, value = []) {
@@ -11821,27 +11823,27 @@ var TreeMultiMap = class extends RedBlackTree {
11821
11823
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11822
11824
  * @remarks Time O(log N + M), Space O(1)
11823
11825
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11824
- * @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.
11825
11827
  * @returns True if inserted or appended; false if ignored.
11826
11828
  */
11827
- add(keyNodeOrEntry, value) {
11828
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11829
+ set(keyNodeOrEntry, value) {
11830
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11829
11831
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11830
11832
  if (key === void 0 || key === null) return false;
11831
- const _addToValues = /* @__PURE__ */ __name(() => {
11833
+ const _setToValues = /* @__PURE__ */ __name(() => {
11832
11834
  const existingValues = this.get(key);
11833
11835
  if (existingValues !== void 0 && values !== void 0) {
11834
11836
  for (const value2 of values) existingValues.push(value2);
11835
11837
  return true;
11836
11838
  }
11837
11839
  return false;
11838
- }, "_addToValues");
11839
- const _addByNode = /* @__PURE__ */ __name(() => {
11840
+ }, "_setToValues");
11841
+ const _setByNode = /* @__PURE__ */ __name(() => {
11840
11842
  const existingNode = this.getNode(key);
11841
11843
  if (this.isRealNode(existingNode)) {
11842
11844
  const existingValues = this.get(existingNode);
11843
11845
  if (existingValues === void 0) {
11844
- super.add(key, values);
11846
+ super.set(key, values);
11845
11847
  return true;
11846
11848
  }
11847
11849
  if (values !== void 0) {
@@ -11851,13 +11853,13 @@ var TreeMultiMap = class extends RedBlackTree {
11851
11853
  return false;
11852
11854
  }
11853
11855
  } else {
11854
- return super.add(key, values);
11856
+ return super.set(key, values);
11855
11857
  }
11856
- }, "_addByNode");
11858
+ }, "_setByNode");
11857
11859
  if (this._isMapMode) {
11858
- return _addByNode() || _addToValues();
11860
+ return _setByNode() || _setToValues();
11859
11861
  }
11860
- return _addToValues() || _addByNode();
11862
+ return _setToValues() || _setByNode();
11861
11863
  }, "_commonAdd");
11862
11864
  if (this.isEntry(keyNodeOrEntry)) {
11863
11865
  const [key, values] = keyNodeOrEntry;
@@ -11897,7 +11899,7 @@ var TreeMultiMap = class extends RedBlackTree {
11897
11899
  map(callback, options, thisArg) {
11898
11900
  const out = this._createLike([], options);
11899
11901
  let i = 0;
11900
- 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));
11901
11903
  return out;
11902
11904
  }
11903
11905
  /**
@@ -12082,7 +12084,7 @@ var TreeCounter = class extends RedBlackTree {
12082
12084
  */
12083
12085
  constructor(keysNodesEntriesOrRaws = [], options) {
12084
12086
  super([], options);
12085
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12087
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12086
12088
  }
12087
12089
  _count = 0;
12088
12090
  /**
@@ -12122,10 +12124,10 @@ var TreeCounter = class extends RedBlackTree {
12122
12124
  * @param [count] - How much to increase the node's count (default 1).
12123
12125
  * @returns True if inserted/updated; false if ignored.
12124
12126
  */
12125
- add(keyNodeOrEntry, value, count = 1) {
12127
+ set(keyNodeOrEntry, value, count = 1) {
12126
12128
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12127
12129
  const orgCount = newNode?.count || 0;
12128
- const isSuccessAdded = super.add(newNode, newValue);
12130
+ const isSuccessAdded = super.set(newNode, newValue);
12129
12131
  if (isSuccessAdded) {
12130
12132
  this._count += orgCount;
12131
12133
  return true;
@@ -12278,7 +12280,7 @@ var TreeCounter = class extends RedBlackTree {
12278
12280
  const out = this._createLike([], options);
12279
12281
  let index = 0;
12280
12282
  for (const [key, value] of this) {
12281
- out.add(callback.call(thisArg, value, key, index++, this));
12283
+ out.set(callback.call(thisArg, value, key, index++, this));
12282
12284
  }
12283
12285
  return out;
12284
12286
  }
@@ -12534,7 +12536,7 @@ var AVLTreeCounter = class extends AVLTree {
12534
12536
  */
12535
12537
  constructor(keysNodesEntriesOrRaws = [], options) {
12536
12538
  super([], options);
12537
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12539
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12538
12540
  }
12539
12541
  _count = 0;
12540
12542
  get count() {
@@ -12569,11 +12571,11 @@ var AVLTreeCounter = class extends AVLTree {
12569
12571
  * @param [count] - How much to increase the node's count (default 1).
12570
12572
  * @returns True if inserted/updated; false if ignored.
12571
12573
  */
12572
- add(keyNodeOrEntry, value, count = 1) {
12574
+ set(keyNodeOrEntry, value, count = 1) {
12573
12575
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12574
12576
  if (newNode === void 0) return false;
12575
12577
  const orgNodeCount = newNode?.count || 0;
12576
- const inserted = super.add(newNode, newValue);
12578
+ const inserted = super.set(newNode, newValue);
12577
12579
  if (inserted) {
12578
12580
  this._count += orgNodeCount;
12579
12581
  }
@@ -12681,9 +12683,9 @@ var AVLTreeCounter = class extends AVLTree {
12681
12683
  clone() {
12682
12684
  const out = this._createInstance();
12683
12685
  if (this._isMapMode) {
12684
- this.bfs((node) => out.add(node.key, void 0, node.count));
12686
+ this.bfs((node) => out.set(node.key, void 0, node.count));
12685
12687
  } else {
12686
- this.bfs((node) => out.add(node.key, node.value, node.count));
12688
+ this.bfs((node) => out.set(node.key, node.value, node.count));
12687
12689
  }
12688
12690
  if (this._isMapMode) out._store = this._store;
12689
12691
  return out;
@@ -12703,7 +12705,7 @@ var AVLTreeCounter = class extends AVLTree {
12703
12705
  const out = this._createLike([], options);
12704
12706
  let index = 0;
12705
12707
  for (const [key, value] of this) {
12706
- out.add(callback.call(thisArg, value, key, index++, this));
12708
+ out.set(callback.call(thisArg, value, key, index++, this));
12707
12709
  }
12708
12710
  return out;
12709
12711
  }