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
@@ -6973,9 +6973,9 @@ var BinaryTreeNode = _BinaryTreeNode;
6973
6973
  var _BinaryTree = class _BinaryTree extends IterableEntryBase {
6974
6974
  /**
6975
6975
  * Creates an instance of BinaryTree.
6976
- * @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.
6976
+ * @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.
6977
6977
  *
6978
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
6978
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
6979
6979
  * @param [options] - Configuration options for the tree.
6980
6980
  */
6981
6981
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -7004,7 +7004,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7004
7004
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
7005
7005
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
7006
7006
  }
7007
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
7007
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
7008
7008
  }
7009
7009
  /**
7010
7010
  * Gets whether the tree is in Map mode.
@@ -7211,10 +7211,20 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7211
7211
  * @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).
7212
7212
  *
7213
7213
  * @param keyNodeOrEntry - The key, node, or entry to add.
7214
+ * @returns True if the addition was successful, false otherwise.
7215
+ */
7216
+ add(keyNodeOrEntry) {
7217
+ return this.set(keyNodeOrEntry);
7218
+ }
7219
+ /**
7220
+ * Adds or updates a new node to the tree.
7221
+ * @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).
7222
+ *
7223
+ * @param keyNodeOrEntry - The key, node, or entry to set or update.
7214
7224
  * @param [value] - The value, if providing just a key.
7215
7225
  * @returns True if the addition was successful, false otherwise.
7216
7226
  */
7217
- add(keyNodeOrEntry, value) {
7227
+ set(keyNodeOrEntry, value) {
7218
7228
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
7219
7229
  if (newNode === void 0) return false;
7220
7230
  if (!this._root) {
@@ -7258,25 +7268,25 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7258
7268
  return false;
7259
7269
  }
7260
7270
  /**
7261
- * Adds or updates a new node to the tree.
7262
- * @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).
7271
+ * Adds multiple items to the tree.
7272
+ * @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).
7263
7273
  *
7264
- * @param keyNodeOrEntry - The key, node, or entry to add or update.
7265
- * @param [value] - The value, if providing just a key.
7266
- * @returns True if the addition was successful, false otherwise.
7274
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7275
+ * @param [values] - An optional parallel iterable of values.
7276
+ * @returns An array of booleans indicating the success of each individual `set` operation.
7267
7277
  */
7268
- set(keyNodeOrEntry, value) {
7269
- return this.add(keyNodeOrEntry, value);
7278
+ addMany(keysNodesEntriesOrRaws) {
7279
+ return this.setMany(keysNodesEntriesOrRaws);
7270
7280
  }
7271
7281
  /**
7272
- * Adds multiple items to the tree.
7273
- * @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).
7282
+ * Adds or updates multiple items to the tree.
7283
+ * @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
7284
  *
7275
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7285
+ * @param keysNodesEntriesOrRaws - An iterable of items to set or update.
7276
7286
  * @param [values] - An optional parallel iterable of values.
7277
- * @returns An array of booleans indicating the success of each individual `add` operation.
7287
+ * @returns An array of booleans indicating the success of each individual `set` operation.
7278
7288
  */
7279
- addMany(keysNodesEntriesOrRaws, values) {
7289
+ setMany(keysNodesEntriesOrRaws, values) {
7280
7290
  const inserted = [];
7281
7291
  let valuesIterator;
7282
7292
  if (values) {
@@ -7291,40 +7301,29 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7291
7301
  }
7292
7302
  }
7293
7303
  if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
7294
- inserted.push(this.add(keyNodeEntryOrRaw, value));
7304
+ inserted.push(this.set(keyNodeEntryOrRaw, value));
7295
7305
  }
7296
7306
  return inserted;
7297
7307
  }
7298
7308
  /**
7299
- * Adds or updates multiple items to the tree.
7300
- * @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).
7301
- *
7302
- * @param keysNodesEntriesOrRaws - An iterable of items to add or update.
7303
- * @param [values] - An optional parallel iterable of values.
7304
- * @returns An array of booleans indicating the success of each individual `add` operation.
7305
- */
7306
- setMany(keysNodesEntriesOrRaws, values) {
7307
- return this.addMany(keysNodesEntriesOrRaws, values);
7308
- }
7309
- /**
7310
- * Merges another tree into this one by adding all its nodes.
7311
- * @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`).
7309
+ * Merges another tree into this one by seting all its nodes.
7310
+ * @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`).
7312
7311
  *
7313
7312
  * @param anotherTree - The tree to merge.
7314
7313
  */
7315
7314
  merge(anotherTree) {
7316
- this.addMany(anotherTree, []);
7315
+ this.setMany(anotherTree, []);
7317
7316
  }
7318
7317
  /**
7319
7318
  * Clears the tree and refills it with new items.
7320
- * @remarks Time O(N) (for `clear`) + O(N * M) (for `addMany`) = O(N * M). Space O(M) (from `addMany`).
7319
+ * @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
7321
7320
  *
7322
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
7321
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
7323
7322
  * @param [values] - An optional parallel iterable of values.
7324
7323
  */
7325
7324
  refill(keysNodesEntriesOrRaws, values) {
7326
7325
  this.clear();
7327
- this.addMany(keysNodesEntriesOrRaws, values);
7326
+ this.setMany(keysNodesEntriesOrRaws, values);
7328
7327
  }
7329
7328
  /**
7330
7329
  * Deletes a node from the tree.
@@ -7990,7 +7989,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
7990
7989
  }
7991
7990
  /**
7992
7991
  * Clones the tree.
7993
- * @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.
7992
+ * @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.
7994
7993
  *
7995
7994
  * @returns A new, cloned instance of the tree.
7996
7995
  */
@@ -8001,7 +8000,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8001
8000
  }
8002
8001
  /**
8003
8002
  * Creates a new tree containing only the entries that satisfy the predicate.
8004
- * @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.
8003
+ * @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.
8005
8004
  *
8006
8005
  * @param predicate - A function to test each [key, value] pair.
8007
8006
  * @param [thisArg] - `this` context for the predicate.
@@ -8010,7 +8009,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8010
8009
  filter(predicate, thisArg) {
8011
8010
  const out = this._createInstance();
8012
8011
  let i = 0;
8013
- for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
8012
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
8014
8013
  return out;
8015
8014
  }
8016
8015
  /**
@@ -8028,7 +8027,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8028
8027
  map(cb, options, thisArg) {
8029
8028
  const out = this._createLike([], options);
8030
8029
  let i = 0;
8031
- for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
8030
+ for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
8032
8031
  return out;
8033
8032
  }
8034
8033
  /**
@@ -8274,18 +8273,18 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
8274
8273
  return [this.createNode(keyNodeOrEntry, value), value];
8275
8274
  }
8276
8275
  /**
8277
- * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
8278
- * @remarks Time O(N * M) (O(N) BFS + O(M) `add` for each node).
8276
+ * (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
8277
+ * @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
8279
8278
  *
8280
8279
  * @param cloned - The new, empty tree instance to populate.
8281
8280
  */
8282
8281
  _clone(cloned) {
8283
8282
  this.bfs(
8284
8283
  (node) => {
8285
- if (node === null) cloned.add(null);
8284
+ if (node === null) cloned.set(null);
8286
8285
  else {
8287
- if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
8288
- else cloned.add([node.key, node.value]);
8286
+ if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
8287
+ else cloned.set([node.key, node.value]);
8289
8288
  }
8290
8289
  },
8291
8290
  this._root,
@@ -8616,7 +8615,7 @@ var _BST = class _BST extends BinaryTree {
8616
8615
  * Creates an instance of BST.
8617
8616
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
8618
8617
  *
8619
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
8618
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
8620
8619
  * @param [options] - Configuration options for the BST, including comparator.
8621
8620
  */
8622
8621
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -8637,7 +8636,7 @@ var _BST = class _BST extends BinaryTree {
8637
8636
  } else {
8638
8637
  this._comparator = this._createDefaultComparator();
8639
8638
  }
8640
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
8639
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
8641
8640
  }
8642
8641
  /**
8643
8642
  * Gets the root node of the tree.
@@ -8848,11 +8847,11 @@ var _BST = class _BST extends BinaryTree {
8848
8847
  * Adds a new node to the BST based on key comparison.
8849
8848
  * @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
8850
8849
  *
8851
- * @param keyNodeOrEntry - The key, node, or entry to add.
8850
+ * @param keyNodeOrEntry - The key, node, or entry to set.
8852
8851
  * @param [value] - The value, if providing just a key.
8853
8852
  * @returns True if the addition was successful, false otherwise.
8854
8853
  */
8855
- add(keyNodeOrEntry, value) {
8854
+ set(keyNodeOrEntry, value) {
8856
8855
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
8857
8856
  if (newNode === void 0) return false;
8858
8857
  if (this._root === void 0) {
@@ -8889,24 +8888,24 @@ var _BST = class _BST extends BinaryTree {
8889
8888
  }
8890
8889
  /**
8891
8890
  * Adds multiple items to the tree.
8892
- * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced add).
8891
+ * @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
8893
8892
  * If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
8894
8893
  * Space O(N) for sorting and recursion/iteration stack.
8895
8894
  *
8896
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
8895
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
8897
8896
  * @param [values] - An optional parallel iterable of values.
8898
8897
  * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
8899
- * @param [iterationType=this.iterationType] - The traversal method for balanced add (recursive or iterative).
8900
- * @returns An array of booleans indicating the success of each individual `add` operation.
8898
+ * @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
8899
+ * @returns An array of booleans indicating the success of each individual `set` operation.
8901
8900
  */
8902
- addMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8901
+ setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
8903
8902
  const inserted = [];
8904
8903
  const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
8905
8904
  if (!isBalanceAdd) {
8906
8905
  for (let kve of keysNodesEntriesOrRaws) {
8907
8906
  const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
8908
8907
  if (this.isRaw(kve)) kve = this._toEntryFn(kve);
8909
- inserted.push(this.add(kve, val));
8908
+ inserted.push(this.set(kve, val));
8910
8909
  }
8911
8910
  return inserted;
8912
8911
  }
@@ -8934,9 +8933,9 @@ var _BST = class _BST extends BinaryTree {
8934
8933
  const { key, value, orgIndex } = arr[mid];
8935
8934
  if (this.isRaw(key)) {
8936
8935
  const entry = this._toEntryFn(key);
8937
- inserted[orgIndex] = this.add(entry);
8936
+ inserted[orgIndex] = this.set(entry);
8938
8937
  } else {
8939
- inserted[orgIndex] = this.add(key, value);
8938
+ inserted[orgIndex] = this.set(key, value);
8940
8939
  }
8941
8940
  _dfs(arr.slice(0, mid));
8942
8941
  _dfs(arr.slice(mid + 1));
@@ -8953,9 +8952,9 @@ var _BST = class _BST extends BinaryTree {
8953
8952
  const { key, value, orgIndex } = sorted[m];
8954
8953
  if (this.isRaw(key)) {
8955
8954
  const entry = this._toEntryFn(key);
8956
- inserted[orgIndex] = this.add(entry);
8955
+ inserted[orgIndex] = this.set(entry);
8957
8956
  } else {
8958
- inserted[orgIndex] = this.add(key, value);
8957
+ inserted[orgIndex] = this.set(key, value);
8959
8958
  }
8960
8959
  stack.push([m + 1, r]);
8961
8960
  stack.push([l, m - 1]);
@@ -9230,7 +9229,7 @@ var _BST = class _BST extends BinaryTree {
9230
9229
  const out = this._createLike([], options);
9231
9230
  let index = 0;
9232
9231
  for (const [key, value] of this) {
9233
- out.add(callback.call(thisArg, value, key, index++, this));
9232
+ out.set(callback.call(thisArg, value, key, index++, this));
9234
9233
  }
9235
9234
  return out;
9236
9235
  }
@@ -10416,14 +10415,14 @@ var AVLTreeNode = _AVLTreeNode;
10416
10415
  var _AVLTree = class _AVLTree extends BST {
10417
10416
  /**
10418
10417
  * Creates an instance of AVLTree.
10419
- * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
10418
+ * @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
10420
10419
  *
10421
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
10420
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
10422
10421
  * @param [options] - Configuration options for the AVL tree.
10423
10422
  */
10424
10423
  constructor(keysNodesEntriesOrRaws = [], options) {
10425
10424
  super([], options);
10426
- if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
10425
+ if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
10427
10426
  }
10428
10427
  /**
10429
10428
  * (Protected) Creates a new AVL tree node.
@@ -10447,16 +10446,16 @@ var _AVLTree = class _AVLTree extends BST {
10447
10446
  return keyNodeOrEntry instanceof AVLTreeNode;
10448
10447
  }
10449
10448
  /**
10450
- * Adds a new node to the AVL tree and balances the tree path.
10451
- * @remarks Time O(log N) (O(H) for BST add + O(H) for `_balancePath`). Space O(H) for path/recursion.
10449
+ * Sets a new node to the AVL tree and balances the tree path.
10450
+ * @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
10452
10451
  *
10453
- * @param keyNodeOrEntry - The key, node, or entry to add.
10452
+ * @param keyNodeOrEntry - The key, node, or entry to set.
10454
10453
  * @param [value] - The value, if providing just a key.
10455
10454
  * @returns True if the addition was successful, false otherwise.
10456
10455
  */
10457
- add(keyNodeOrEntry, value) {
10456
+ set(keyNodeOrEntry, value) {
10458
10457
  if (keyNodeOrEntry === null) return false;
10459
- const inserted = super.add(keyNodeOrEntry, value);
10458
+ const inserted = super.set(keyNodeOrEntry, value);
10460
10459
  if (inserted) this._balancePath(keyNodeOrEntry);
10461
10460
  return inserted;
10462
10461
  }
@@ -10508,7 +10507,7 @@ var _AVLTree = class _AVLTree extends BST {
10508
10507
  }
10509
10508
  /**
10510
10509
  * Creates a new AVLTree by mapping each [key, value] pair.
10511
- * @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.
10510
+ * @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.
10512
10511
  *
10513
10512
  * @template MK - New key type.
10514
10513
  * @template MV - New value type.
@@ -10522,7 +10521,7 @@ var _AVLTree = class _AVLTree extends BST {
10522
10521
  const out = this._createLike([], options);
10523
10522
  let index = 0;
10524
10523
  for (const [key, value] of this) {
10525
- out.add(callback.call(thisArg, value, key, index++, this));
10524
+ out.set(callback.call(thisArg, value, key, index++, this));
10526
10525
  }
10527
10526
  return out;
10528
10527
  }
@@ -10947,7 +10946,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10947
10946
  __publicField(this, "_root");
10948
10947
  this._root = this.NIL;
10949
10948
  if (keysNodesEntriesOrRaws) {
10950
- this.addMany(keysNodesEntriesOrRaws);
10949
+ this.setMany(keysNodesEntriesOrRaws);
10951
10950
  }
10952
10951
  }
10953
10952
  /**
@@ -10994,7 +10993,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
10994
10993
  * @param [value]- See parameter type for details.
10995
10994
  * @returns True if inserted or updated; false if ignored.
10996
10995
  */
10997
- add(keyNodeOrEntry, value) {
10996
+ set(keyNodeOrEntry, value) {
10998
10997
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
10999
10998
  if (!this.isRealNode(newNode)) return false;
11000
10999
  const insertStatus = this._insert(newNode);
@@ -11088,7 +11087,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
11088
11087
  const out = this._createLike([], options);
11089
11088
  let index = 0;
11090
11089
  for (const [key, value] of this) {
11091
- out.add(callback.call(thisArg, value, key, index++, this));
11090
+ out.set(callback.call(thisArg, value, key, index++, this));
11092
11091
  }
11093
11092
  return out;
11094
11093
  }
@@ -11477,7 +11476,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11477
11476
  constructor(keysNodesEntriesOrRaws = [], options) {
11478
11477
  super([], { ...options, isMapMode: true });
11479
11478
  if (keysNodesEntriesOrRaws) {
11480
- this.addMany(keysNodesEntriesOrRaws);
11479
+ this.setMany(keysNodesEntriesOrRaws);
11481
11480
  }
11482
11481
  }
11483
11482
  createNode(key, value = []) {
@@ -11497,27 +11496,27 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11497
11496
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11498
11497
  * @remarks Time O(log N + M), Space O(1)
11499
11498
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11500
- * @param [value] - Single value to add when a bare key is provided.
11499
+ * @param [value] - Single value to set when a bare key is provided.
11501
11500
  * @returns True if inserted or appended; false if ignored.
11502
11501
  */
11503
- add(keyNodeOrEntry, value) {
11504
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11502
+ set(keyNodeOrEntry, value) {
11503
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11505
11504
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11506
11505
  if (key === void 0 || key === null) return false;
11507
- const _addToValues = /* @__PURE__ */ __name(() => {
11506
+ const _setToValues = /* @__PURE__ */ __name(() => {
11508
11507
  const existingValues = this.get(key);
11509
11508
  if (existingValues !== void 0 && values !== void 0) {
11510
11509
  for (const value2 of values) existingValues.push(value2);
11511
11510
  return true;
11512
11511
  }
11513
11512
  return false;
11514
- }, "_addToValues");
11515
- const _addByNode = /* @__PURE__ */ __name(() => {
11513
+ }, "_setToValues");
11514
+ const _setByNode = /* @__PURE__ */ __name(() => {
11516
11515
  const existingNode = this.getNode(key);
11517
11516
  if (this.isRealNode(existingNode)) {
11518
11517
  const existingValues = this.get(existingNode);
11519
11518
  if (existingValues === void 0) {
11520
- super.add(key, values);
11519
+ super.set(key, values);
11521
11520
  return true;
11522
11521
  }
11523
11522
  if (values !== void 0) {
@@ -11527,13 +11526,13 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11527
11526
  return false;
11528
11527
  }
11529
11528
  } else {
11530
- return super.add(key, values);
11529
+ return super.set(key, values);
11531
11530
  }
11532
- }, "_addByNode");
11531
+ }, "_setByNode");
11533
11532
  if (this._isMapMode) {
11534
- return _addByNode() || _addToValues();
11533
+ return _setByNode() || _setToValues();
11535
11534
  }
11536
- return _addToValues() || _addByNode();
11535
+ return _setToValues() || _setByNode();
11537
11536
  }, "_commonAdd");
11538
11537
  if (this.isEntry(keyNodeOrEntry)) {
11539
11538
  const [key, values] = keyNodeOrEntry;
@@ -11601,7 +11600,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11601
11600
  map(callback, options, thisArg) {
11602
11601
  const out = this._createLike([], options);
11603
11602
  let i = 0;
11604
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11603
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
11605
11604
  return out;
11606
11605
  }
11607
11606
  /**
@@ -11784,7 +11783,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11784
11783
  constructor(keysNodesEntriesOrRaws = [], options) {
11785
11784
  super([], { ...options });
11786
11785
  if (keysNodesEntriesOrRaws) {
11787
- this.addMany(keysNodesEntriesOrRaws);
11786
+ this.setMany(keysNodesEntriesOrRaws);
11788
11787
  }
11789
11788
  }
11790
11789
  createNode(key, value = []) {
@@ -11804,27 +11803,27 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11804
11803
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
11805
11804
  * @remarks Time O(log N + M), Space O(1)
11806
11805
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
11807
- * @param [value] - Single value to add when a bare key is provided.
11806
+ * @param [value] - Single value to set when a bare key is provided.
11808
11807
  * @returns True if inserted or appended; false if ignored.
11809
11808
  */
11810
- add(keyNodeOrEntry, value) {
11811
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11809
+ set(keyNodeOrEntry, value) {
11810
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
11812
11811
  const _commonAdd = /* @__PURE__ */ __name((key, values) => {
11813
11812
  if (key === void 0 || key === null) return false;
11814
- const _addToValues = /* @__PURE__ */ __name(() => {
11813
+ const _setToValues = /* @__PURE__ */ __name(() => {
11815
11814
  const existingValues = this.get(key);
11816
11815
  if (existingValues !== void 0 && values !== void 0) {
11817
11816
  for (const value2 of values) existingValues.push(value2);
11818
11817
  return true;
11819
11818
  }
11820
11819
  return false;
11821
- }, "_addToValues");
11822
- const _addByNode = /* @__PURE__ */ __name(() => {
11820
+ }, "_setToValues");
11821
+ const _setByNode = /* @__PURE__ */ __name(() => {
11823
11822
  const existingNode = this.getNode(key);
11824
11823
  if (this.isRealNode(existingNode)) {
11825
11824
  const existingValues = this.get(existingNode);
11826
11825
  if (existingValues === void 0) {
11827
- super.add(key, values);
11826
+ super.set(key, values);
11828
11827
  return true;
11829
11828
  }
11830
11829
  if (values !== void 0) {
@@ -11834,13 +11833,13 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11834
11833
  return false;
11835
11834
  }
11836
11835
  } else {
11837
- return super.add(key, values);
11836
+ return super.set(key, values);
11838
11837
  }
11839
- }, "_addByNode");
11838
+ }, "_setByNode");
11840
11839
  if (this._isMapMode) {
11841
- return _addByNode() || _addToValues();
11840
+ return _setByNode() || _setToValues();
11842
11841
  }
11843
- return _addToValues() || _addByNode();
11842
+ return _setToValues() || _setByNode();
11844
11843
  }, "_commonAdd");
11845
11844
  if (this.isEntry(keyNodeOrEntry)) {
11846
11845
  const [key, values] = keyNodeOrEntry;
@@ -11880,7 +11879,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11880
11879
  map(callback, options, thisArg) {
11881
11880
  const out = this._createLike([], options);
11882
11881
  let i = 0;
11883
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
11882
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
11884
11883
  return out;
11885
11884
  }
11886
11885
  /**
@@ -12066,7 +12065,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
12066
12065
  constructor(keysNodesEntriesOrRaws = [], options) {
12067
12066
  super([], options);
12068
12067
  __publicField(this, "_count", 0);
12069
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12068
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12070
12069
  }
12071
12070
  /**
12072
12071
  * Get the total aggregate count across all nodes.
@@ -12105,10 +12104,10 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
12105
12104
  * @param [count] - How much to increase the node's count (default 1).
12106
12105
  * @returns True if inserted/updated; false if ignored.
12107
12106
  */
12108
- add(keyNodeOrEntry, value, count = 1) {
12107
+ set(keyNodeOrEntry, value, count = 1) {
12109
12108
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12110
12109
  const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
12111
- const isSuccessAdded = super.add(newNode, newValue);
12110
+ const isSuccessAdded = super.set(newNode, newValue);
12112
12111
  if (isSuccessAdded) {
12113
12112
  this._count += orgCount;
12114
12113
  return true;
@@ -12261,7 +12260,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
12261
12260
  const out = this._createLike([], options);
12262
12261
  let index = 0;
12263
12262
  for (const [key, value] of this) {
12264
- out.add(callback.call(thisArg, value, key, index++, this));
12263
+ out.set(callback.call(thisArg, value, key, index++, this));
12265
12264
  }
12266
12265
  return out;
12267
12266
  }
@@ -12516,7 +12515,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12516
12515
  constructor(keysNodesEntriesOrRaws = [], options) {
12517
12516
  super([], options);
12518
12517
  __publicField(this, "_count", 0);
12519
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12518
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
12520
12519
  }
12521
12520
  get count() {
12522
12521
  return this._count;
@@ -12550,11 +12549,11 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12550
12549
  * @param [count] - How much to increase the node's count (default 1).
12551
12550
  * @returns True if inserted/updated; false if ignored.
12552
12551
  */
12553
- add(keyNodeOrEntry, value, count = 1) {
12552
+ set(keyNodeOrEntry, value, count = 1) {
12554
12553
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12555
12554
  if (newNode === void 0) return false;
12556
12555
  const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
12557
- const inserted = super.add(newNode, newValue);
12556
+ const inserted = super.set(newNode, newValue);
12558
12557
  if (inserted) {
12559
12558
  this._count += orgNodeCount;
12560
12559
  }
@@ -12663,9 +12662,9 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12663
12662
  clone() {
12664
12663
  const out = this._createInstance();
12665
12664
  if (this._isMapMode) {
12666
- this.bfs((node) => out.add(node.key, void 0, node.count));
12665
+ this.bfs((node) => out.set(node.key, void 0, node.count));
12667
12666
  } else {
12668
- this.bfs((node) => out.add(node.key, node.value, node.count));
12667
+ this.bfs((node) => out.set(node.key, node.value, node.count));
12669
12668
  }
12670
12669
  if (this._isMapMode) out._store = this._store;
12671
12670
  return out;
@@ -12685,7 +12684,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
12685
12684
  const out = this._createLike([], options);
12686
12685
  let index = 0;
12687
12686
  for (const [key, value] of this) {
12688
- out.add(callback.call(thisArg, value, key, index++, this));
12687
+ out.set(callback.call(thisArg, value, key, index++, this));
12689
12688
  }
12690
12689
  return out;
12691
12690
  }