binary-tree-typed 2.2.7 → 2.3.0

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 (30) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/index.cjs +41 -43
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +41 -43
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +41 -43
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +41 -43
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
  11. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  12. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -24
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +11 -11
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  16. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  17. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
  18. package/dist/umd/binary-tree-typed.js +41 -43
  19. package/dist/umd/binary-tree-typed.js.map +1 -1
  20. package/dist/umd/binary-tree-typed.min.js +2 -2
  21. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  22. package/package.json +2 -2
  23. package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
  24. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
  25. package/src/data-structures/binary-tree/avl-tree.ts +15 -15
  26. package/src/data-structures/binary-tree/binary-tree.ts +52 -55
  27. package/src/data-structures/binary-tree/bst.ts +21 -22
  28. package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
  29. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  30. package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
@@ -1188,9 +1188,9 @@ var BinaryTreeNode = _BinaryTreeNode;
1188
1188
  var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1189
1189
  /**
1190
1190
  * Creates an instance of BinaryTree.
1191
- * @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.
1191
+ * @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.
1192
1192
  *
1193
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
1193
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
1194
1194
  * @param [options] - Configuration options for the tree.
1195
1195
  */
1196
1196
  constructor(keysNodesEntriesOrRaws = [], options) {
@@ -1219,7 +1219,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1219
1219
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
1220
1220
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
1221
1221
  }
1222
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
1222
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
1223
1223
  }
1224
1224
  /**
1225
1225
  * Gets whether the tree is in Map mode.
@@ -1426,10 +1426,20 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1426
1426
  * @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).
1427
1427
  *
1428
1428
  * @param keyNodeOrEntry - The key, node, or entry to add.
1429
+ * @returns True if the addition was successful, false otherwise.
1430
+ */
1431
+ add(keyNodeOrEntry) {
1432
+ return this.set(keyNodeOrEntry);
1433
+ }
1434
+ /**
1435
+ * Adds or updates a new node to the tree.
1436
+ * @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).
1437
+ *
1438
+ * @param keyNodeOrEntry - The key, node, or entry to set or update.
1429
1439
  * @param [value] - The value, if providing just a key.
1430
1440
  * @returns True if the addition was successful, false otherwise.
1431
1441
  */
1432
- add(keyNodeOrEntry, value) {
1442
+ set(keyNodeOrEntry, value) {
1433
1443
  const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
1434
1444
  if (newNode === void 0) return false;
1435
1445
  if (!this._root) {
@@ -1473,25 +1483,24 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1473
1483
  return false;
1474
1484
  }
1475
1485
  /**
1476
- * Adds or updates a new node to the tree.
1477
- * @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).
1486
+ * Adds multiple items to the tree.
1487
+ * @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).
1478
1488
  *
1479
- * @param keyNodeOrEntry - The key, node, or entry to add or update.
1480
- * @param [value] - The value, if providing just a key.
1481
- * @returns True if the addition was successful, false otherwise.
1489
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
1490
+ * @returns An array of booleans indicating the success of each individual `set` operation.
1482
1491
  */
1483
- set(keyNodeOrEntry, value) {
1484
- return this.add(keyNodeOrEntry, value);
1492
+ addMany(keysNodesEntriesOrRaws) {
1493
+ return this.setMany(keysNodesEntriesOrRaws);
1485
1494
  }
1486
1495
  /**
1487
- * Adds multiple items to the tree.
1488
- * @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).
1496
+ * Adds or updates multiple items to the tree.
1497
+ * @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).
1489
1498
  *
1490
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
1499
+ * @param keysNodesEntriesOrRaws - An iterable of items to set or update.
1491
1500
  * @param [values] - An optional parallel iterable of values.
1492
- * @returns An array of booleans indicating the success of each individual `add` operation.
1501
+ * @returns An array of booleans indicating the success of each individual `set` operation.
1493
1502
  */
1494
- addMany(keysNodesEntriesOrRaws, values) {
1503
+ setMany(keysNodesEntriesOrRaws, values) {
1495
1504
  const inserted = [];
1496
1505
  let valuesIterator;
1497
1506
  if (values) {
@@ -1506,40 +1515,29 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1506
1515
  }
1507
1516
  }
1508
1517
  if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
1509
- inserted.push(this.add(keyNodeEntryOrRaw, value));
1518
+ inserted.push(this.set(keyNodeEntryOrRaw, value));
1510
1519
  }
1511
1520
  return inserted;
1512
1521
  }
1513
1522
  /**
1514
- * Adds or updates multiple items to the tree.
1515
- * @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).
1516
- *
1517
- * @param keysNodesEntriesOrRaws - An iterable of items to add or update.
1518
- * @param [values] - An optional parallel iterable of values.
1519
- * @returns An array of booleans indicating the success of each individual `add` operation.
1520
- */
1521
- setMany(keysNodesEntriesOrRaws, values) {
1522
- return this.addMany(keysNodesEntriesOrRaws, values);
1523
- }
1524
- /**
1525
- * Merges another tree into this one by adding all its nodes.
1526
- * @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`).
1523
+ * Merges another tree into this one by seting all its nodes.
1524
+ * @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`).
1527
1525
  *
1528
1526
  * @param anotherTree - The tree to merge.
1529
1527
  */
1530
1528
  merge(anotherTree) {
1531
- this.addMany(anotherTree, []);
1529
+ this.setMany(anotherTree, []);
1532
1530
  }
1533
1531
  /**
1534
1532
  * Clears the tree and refills it with new items.
1535
- * @remarks Time O(N) (for `clear`) + O(N * M) (for `addMany`) = O(N * M). Space O(M) (from `addMany`).
1533
+ * @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
1536
1534
  *
1537
- * @param keysNodesEntriesOrRaws - An iterable of items to add.
1535
+ * @param keysNodesEntriesOrRaws - An iterable of items to set.
1538
1536
  * @param [values] - An optional parallel iterable of values.
1539
1537
  */
1540
1538
  refill(keysNodesEntriesOrRaws, values) {
1541
1539
  this.clear();
1542
- this.addMany(keysNodesEntriesOrRaws, values);
1540
+ this.setMany(keysNodesEntriesOrRaws, values);
1543
1541
  }
1544
1542
  /**
1545
1543
  * Deletes a node from the tree.
@@ -2205,7 +2203,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2205
2203
  }
2206
2204
  /**
2207
2205
  * Clones the tree.
2208
- * @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.
2206
+ * @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.
2209
2207
  *
2210
2208
  * @returns A new, cloned instance of the tree.
2211
2209
  */
@@ -2216,7 +2214,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2216
2214
  }
2217
2215
  /**
2218
2216
  * Creates a new tree containing only the entries that satisfy the predicate.
2219
- * @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.
2217
+ * @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.
2220
2218
  *
2221
2219
  * @param predicate - A function to test each [key, value] pair.
2222
2220
  * @param [thisArg] - `this` context for the predicate.
@@ -2225,7 +2223,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2225
2223
  filter(predicate, thisArg) {
2226
2224
  const out = this._createInstance();
2227
2225
  let i = 0;
2228
- for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
2226
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
2229
2227
  return out;
2230
2228
  }
2231
2229
  /**
@@ -2243,7 +2241,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2243
2241
  map(cb, options, thisArg) {
2244
2242
  const out = this._createLike([], options);
2245
2243
  let i = 0;
2246
- for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
2244
+ for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
2247
2245
  return out;
2248
2246
  }
2249
2247
  /**
@@ -2489,18 +2487,18 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2489
2487
  return [this.createNode(keyNodeOrEntry, value), value];
2490
2488
  }
2491
2489
  /**
2492
- * (Protected) Helper for cloning. Performs a BFS and adds all nodes to the new tree.
2493
- * @remarks Time O(N * M) (O(N) BFS + O(M) `add` for each node).
2490
+ * (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
2491
+ * @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
2494
2492
  *
2495
2493
  * @param cloned - The new, empty tree instance to populate.
2496
2494
  */
2497
2495
  _clone(cloned) {
2498
2496
  this.bfs(
2499
2497
  (node) => {
2500
- if (node === null) cloned.add(null);
2498
+ if (node === null) cloned.set(null);
2501
2499
  else {
2502
- if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
2503
- else cloned.add([node.key, node.value]);
2500
+ if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
2501
+ else cloned.set([node.key, node.value]);
2504
2502
  }
2505
2503
  },
2506
2504
  this._root,