binary-tree-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.
- package/README.md +1 -1
- package/dist/cjs/index.cjs +42 -43
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +42 -43
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +42 -43
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +42 -43
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -23
- package/dist/types/data-structures/binary-tree/bst.d.ts +11 -11
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
- package/dist/umd/binary-tree-typed.js +42 -43
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +2 -2
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
- package/src/data-structures/binary-tree/avl-tree.ts +15 -15
- package/src/data-structures/binary-tree/binary-tree.ts +53 -55
- package/src/data-structures/binary-tree/bst.ts +21 -22
- package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
- package/src/data-structures/binary-tree/tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
package/README.md
CHANGED
package/dist/cjs/index.cjs
CHANGED
|
@@ -1194,9 +1194,9 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1194
1194
|
iterationType = "ITERATIVE";
|
|
1195
1195
|
/**
|
|
1196
1196
|
* Creates an instance of BinaryTree.
|
|
1197
|
-
* @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) `
|
|
1197
|
+
* @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.
|
|
1198
1198
|
*
|
|
1199
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
1199
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
1200
1200
|
* @param [options] - Configuration options for the tree.
|
|
1201
1201
|
*/
|
|
1202
1202
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -1209,7 +1209,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1209
1209
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1210
1210
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
1211
1211
|
}
|
|
1212
|
-
if (keysNodesEntriesOrRaws) this.
|
|
1212
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1213
1213
|
}
|
|
1214
1214
|
_isMapMode = true;
|
|
1215
1215
|
/**
|
|
@@ -1423,10 +1423,20 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1423
1423
|
* @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).
|
|
1424
1424
|
*
|
|
1425
1425
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1426
|
+
* @returns True if the addition was successful, false otherwise.
|
|
1427
|
+
*/
|
|
1428
|
+
add(keyNodeOrEntry) {
|
|
1429
|
+
return this.set(keyNodeOrEntry);
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Adds or updates a new node to the tree.
|
|
1433
|
+
* @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).
|
|
1434
|
+
*
|
|
1435
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
1426
1436
|
* @param [value] - The value, if providing just a key.
|
|
1427
1437
|
* @returns True if the addition was successful, false otherwise.
|
|
1428
1438
|
*/
|
|
1429
|
-
|
|
1439
|
+
set(keyNodeOrEntry, value) {
|
|
1430
1440
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
1431
1441
|
if (newNode === void 0) return false;
|
|
1432
1442
|
if (!this._root) {
|
|
@@ -1470,25 +1480,25 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1470
1480
|
return false;
|
|
1471
1481
|
}
|
|
1472
1482
|
/**
|
|
1473
|
-
* Adds
|
|
1474
|
-
* @remarks Time O(
|
|
1483
|
+
* Adds multiple items to the tree.
|
|
1484
|
+
* @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).
|
|
1475
1485
|
*
|
|
1476
|
-
* @param
|
|
1477
|
-
* @param [
|
|
1478
|
-
* @returns
|
|
1486
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1487
|
+
* @param [values] - An optional parallel iterable of values.
|
|
1488
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1479
1489
|
*/
|
|
1480
|
-
|
|
1481
|
-
return this.
|
|
1490
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
1491
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
1482
1492
|
}
|
|
1483
1493
|
/**
|
|
1484
|
-
* Adds multiple items to the tree.
|
|
1485
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
1494
|
+
* Adds or updates multiple items to the tree.
|
|
1495
|
+
* @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).
|
|
1486
1496
|
*
|
|
1487
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1497
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
1488
1498
|
* @param [values] - An optional parallel iterable of values.
|
|
1489
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
1499
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1490
1500
|
*/
|
|
1491
|
-
|
|
1501
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
1492
1502
|
const inserted = [];
|
|
1493
1503
|
let valuesIterator;
|
|
1494
1504
|
if (values) {
|
|
@@ -1503,40 +1513,29 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1503
1513
|
}
|
|
1504
1514
|
}
|
|
1505
1515
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
1506
|
-
inserted.push(this.
|
|
1516
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
1507
1517
|
}
|
|
1508
1518
|
return inserted;
|
|
1509
1519
|
}
|
|
1510
1520
|
/**
|
|
1511
|
-
*
|
|
1512
|
-
* @remarks Time O(N * M), where N is the
|
|
1513
|
-
*
|
|
1514
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
1515
|
-
* @param [values] - An optional parallel iterable of values.
|
|
1516
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
1517
|
-
*/
|
|
1518
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
1519
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Merges another tree into this one by adding all its nodes.
|
|
1523
|
-
* @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`).
|
|
1521
|
+
* Merges another tree into this one by seting all its nodes.
|
|
1522
|
+
* @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`).
|
|
1524
1523
|
*
|
|
1525
1524
|
* @param anotherTree - The tree to merge.
|
|
1526
1525
|
*/
|
|
1527
1526
|
merge(anotherTree) {
|
|
1528
|
-
this.
|
|
1527
|
+
this.setMany(anotherTree, []);
|
|
1529
1528
|
}
|
|
1530
1529
|
/**
|
|
1531
1530
|
* Clears the tree and refills it with new items.
|
|
1532
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
1531
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
1533
1532
|
*
|
|
1534
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1533
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1535
1534
|
* @param [values] - An optional parallel iterable of values.
|
|
1536
1535
|
*/
|
|
1537
1536
|
refill(keysNodesEntriesOrRaws, values) {
|
|
1538
1537
|
this.clear();
|
|
1539
|
-
this.
|
|
1538
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
1540
1539
|
}
|
|
1541
1540
|
/**
|
|
1542
1541
|
* Deletes a node from the tree.
|
|
@@ -2201,7 +2200,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2201
2200
|
}
|
|
2202
2201
|
/**
|
|
2203
2202
|
* Clones the tree.
|
|
2204
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
2203
|
+
* @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.
|
|
2205
2204
|
*
|
|
2206
2205
|
* @returns A new, cloned instance of the tree.
|
|
2207
2206
|
*/
|
|
@@ -2212,7 +2211,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2212
2211
|
}
|
|
2213
2212
|
/**
|
|
2214
2213
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
2215
|
-
* @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) `
|
|
2214
|
+
* @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.
|
|
2216
2215
|
*
|
|
2217
2216
|
* @param predicate - A function to test each [key, value] pair.
|
|
2218
2217
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -2221,7 +2220,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2221
2220
|
filter(predicate, thisArg) {
|
|
2222
2221
|
const out = this._createInstance();
|
|
2223
2222
|
let i = 0;
|
|
2224
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
2223
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
2225
2224
|
return out;
|
|
2226
2225
|
}
|
|
2227
2226
|
/**
|
|
@@ -2239,7 +2238,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2239
2238
|
map(cb, options, thisArg) {
|
|
2240
2239
|
const out = this._createLike([], options);
|
|
2241
2240
|
let i = 0;
|
|
2242
|
-
for (const [k, v] of this) out.
|
|
2241
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
2243
2242
|
return out;
|
|
2244
2243
|
}
|
|
2245
2244
|
/**
|
|
@@ -2491,18 +2490,18 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2491
2490
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
2492
2491
|
}
|
|
2493
2492
|
/**
|
|
2494
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
2495
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
2493
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
2494
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
2496
2495
|
*
|
|
2497
2496
|
* @param cloned - The new, empty tree instance to populate.
|
|
2498
2497
|
*/
|
|
2499
2498
|
_clone(cloned) {
|
|
2500
2499
|
this.bfs(
|
|
2501
2500
|
(node) => {
|
|
2502
|
-
if (node === null) cloned.
|
|
2501
|
+
if (node === null) cloned.set(null);
|
|
2503
2502
|
else {
|
|
2504
|
-
if (this._isMapMode) cloned.
|
|
2505
|
-
else cloned.
|
|
2503
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
2504
|
+
else cloned.set([node.key, node.value]);
|
|
2506
2505
|
}
|
|
2507
2506
|
},
|
|
2508
2507
|
this._root,
|