avl-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/dist/cjs/index.cjs +67 -69
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +67 -69
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +67 -69
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +67 -69
- 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/avl-tree-typed.js +67 -69
- package/dist/umd/avl-tree-typed.js.map +1 -1
- package/dist/umd/avl-tree-typed.min.js +3 -3
- package/dist/umd/avl-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
|
@@ -1181,9 +1181,9 @@ var BinaryTreeNode = _BinaryTreeNode;
|
|
|
1181
1181
|
var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
1182
1182
|
/**
|
|
1183
1183
|
* Creates an instance of BinaryTree.
|
|
1184
|
-
* @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) `
|
|
1184
|
+
* @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.
|
|
1185
1185
|
*
|
|
1186
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
1186
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
1187
1187
|
* @param [options] - Configuration options for the tree.
|
|
1188
1188
|
*/
|
|
1189
1189
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -1212,7 +1212,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1212
1212
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1213
1213
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
1214
1214
|
}
|
|
1215
|
-
if (keysNodesEntriesOrRaws) this.
|
|
1215
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1216
1216
|
}
|
|
1217
1217
|
/**
|
|
1218
1218
|
* Gets whether the tree is in Map mode.
|
|
@@ -1419,10 +1419,20 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1419
1419
|
* @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).
|
|
1420
1420
|
*
|
|
1421
1421
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1422
|
+
* @returns True if the addition was successful, false otherwise.
|
|
1423
|
+
*/
|
|
1424
|
+
add(keyNodeOrEntry) {
|
|
1425
|
+
return this.set(keyNodeOrEntry);
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Adds or updates a new node to the tree.
|
|
1429
|
+
* @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).
|
|
1430
|
+
*
|
|
1431
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
1422
1432
|
* @param [value] - The value, if providing just a key.
|
|
1423
1433
|
* @returns True if the addition was successful, false otherwise.
|
|
1424
1434
|
*/
|
|
1425
|
-
|
|
1435
|
+
set(keyNodeOrEntry, value) {
|
|
1426
1436
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
1427
1437
|
if (newNode === void 0) return false;
|
|
1428
1438
|
if (!this._root) {
|
|
@@ -1466,25 +1476,25 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1466
1476
|
return false;
|
|
1467
1477
|
}
|
|
1468
1478
|
/**
|
|
1469
|
-
* Adds
|
|
1470
|
-
* @remarks Time O(
|
|
1479
|
+
* Adds multiple items to the tree.
|
|
1480
|
+
* @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).
|
|
1471
1481
|
*
|
|
1472
|
-
* @param
|
|
1473
|
-
* @param [
|
|
1474
|
-
* @returns
|
|
1482
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1483
|
+
* @param [values] - An optional parallel iterable of values.
|
|
1484
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1475
1485
|
*/
|
|
1476
|
-
|
|
1477
|
-
return this.
|
|
1486
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
1487
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
1478
1488
|
}
|
|
1479
1489
|
/**
|
|
1480
|
-
* Adds multiple items to the tree.
|
|
1481
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
1490
|
+
* Adds or updates multiple items to the tree.
|
|
1491
|
+
* @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).
|
|
1482
1492
|
*
|
|
1483
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1493
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
1484
1494
|
* @param [values] - An optional parallel iterable of values.
|
|
1485
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
1495
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1486
1496
|
*/
|
|
1487
|
-
|
|
1497
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
1488
1498
|
const inserted = [];
|
|
1489
1499
|
let valuesIterator;
|
|
1490
1500
|
if (values) {
|
|
@@ -1499,40 +1509,29 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1499
1509
|
}
|
|
1500
1510
|
}
|
|
1501
1511
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
1502
|
-
inserted.push(this.
|
|
1512
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
1503
1513
|
}
|
|
1504
1514
|
return inserted;
|
|
1505
1515
|
}
|
|
1506
1516
|
/**
|
|
1507
|
-
*
|
|
1508
|
-
* @remarks Time O(N * M), where N is the
|
|
1509
|
-
*
|
|
1510
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
1511
|
-
* @param [values] - An optional parallel iterable of values.
|
|
1512
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
1513
|
-
*/
|
|
1514
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
1515
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
1516
|
-
}
|
|
1517
|
-
/**
|
|
1518
|
-
* Merges another tree into this one by adding all its nodes.
|
|
1519
|
-
* @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`).
|
|
1517
|
+
* Merges another tree into this one by seting all its nodes.
|
|
1518
|
+
* @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`).
|
|
1520
1519
|
*
|
|
1521
1520
|
* @param anotherTree - The tree to merge.
|
|
1522
1521
|
*/
|
|
1523
1522
|
merge(anotherTree) {
|
|
1524
|
-
this.
|
|
1523
|
+
this.setMany(anotherTree, []);
|
|
1525
1524
|
}
|
|
1526
1525
|
/**
|
|
1527
1526
|
* Clears the tree and refills it with new items.
|
|
1528
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
1527
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
1529
1528
|
*
|
|
1530
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1529
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1531
1530
|
* @param [values] - An optional parallel iterable of values.
|
|
1532
1531
|
*/
|
|
1533
1532
|
refill(keysNodesEntriesOrRaws, values) {
|
|
1534
1533
|
this.clear();
|
|
1535
|
-
this.
|
|
1534
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
1536
1535
|
}
|
|
1537
1536
|
/**
|
|
1538
1537
|
* Deletes a node from the tree.
|
|
@@ -2198,7 +2197,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2198
2197
|
}
|
|
2199
2198
|
/**
|
|
2200
2199
|
* Clones the tree.
|
|
2201
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
2200
|
+
* @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.
|
|
2202
2201
|
*
|
|
2203
2202
|
* @returns A new, cloned instance of the tree.
|
|
2204
2203
|
*/
|
|
@@ -2209,7 +2208,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2209
2208
|
}
|
|
2210
2209
|
/**
|
|
2211
2210
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
2212
|
-
* @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) `
|
|
2211
|
+
* @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.
|
|
2213
2212
|
*
|
|
2214
2213
|
* @param predicate - A function to test each [key, value] pair.
|
|
2215
2214
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -2218,7 +2217,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2218
2217
|
filter(predicate, thisArg) {
|
|
2219
2218
|
const out = this._createInstance();
|
|
2220
2219
|
let i = 0;
|
|
2221
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
2220
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
2222
2221
|
return out;
|
|
2223
2222
|
}
|
|
2224
2223
|
/**
|
|
@@ -2236,7 +2235,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2236
2235
|
map(cb, options, thisArg) {
|
|
2237
2236
|
const out = this._createLike([], options);
|
|
2238
2237
|
let i = 0;
|
|
2239
|
-
for (const [k, v] of this) out.
|
|
2238
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
2240
2239
|
return out;
|
|
2241
2240
|
}
|
|
2242
2241
|
/**
|
|
@@ -2482,18 +2481,18 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2482
2481
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
2483
2482
|
}
|
|
2484
2483
|
/**
|
|
2485
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
2486
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
2484
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
2485
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
2487
2486
|
*
|
|
2488
2487
|
* @param cloned - The new, empty tree instance to populate.
|
|
2489
2488
|
*/
|
|
2490
2489
|
_clone(cloned) {
|
|
2491
2490
|
this.bfs(
|
|
2492
2491
|
(node) => {
|
|
2493
|
-
if (node === null) cloned.
|
|
2492
|
+
if (node === null) cloned.set(null);
|
|
2494
2493
|
else {
|
|
2495
|
-
if (this._isMapMode) cloned.
|
|
2496
|
-
else cloned.
|
|
2494
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
2495
|
+
else cloned.set([node.key, node.value]);
|
|
2497
2496
|
}
|
|
2498
2497
|
},
|
|
2499
2498
|
this._root,
|
|
@@ -2824,7 +2823,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
2824
2823
|
* Creates an instance of BST.
|
|
2825
2824
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
2826
2825
|
*
|
|
2827
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
2826
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
2828
2827
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
2829
2828
|
*/
|
|
2830
2829
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -2845,7 +2844,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
2845
2844
|
} else {
|
|
2846
2845
|
this._comparator = this._createDefaultComparator();
|
|
2847
2846
|
}
|
|
2848
|
-
if (keysNodesEntriesOrRaws) this.
|
|
2847
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
2849
2848
|
}
|
|
2850
2849
|
/**
|
|
2851
2850
|
* Gets the root node of the tree.
|
|
@@ -3056,11 +3055,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3056
3055
|
* Adds a new node to the BST based on key comparison.
|
|
3057
3056
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
3058
3057
|
*
|
|
3059
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
3058
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
3060
3059
|
* @param [value] - The value, if providing just a key.
|
|
3061
3060
|
* @returns True if the addition was successful, false otherwise.
|
|
3062
3061
|
*/
|
|
3063
|
-
|
|
3062
|
+
set(keyNodeOrEntry, value) {
|
|
3064
3063
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
3065
3064
|
if (newNode === void 0) return false;
|
|
3066
3065
|
if (this._root === void 0) {
|
|
@@ -3097,24 +3096,24 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3097
3096
|
}
|
|
3098
3097
|
/**
|
|
3099
3098
|
* Adds multiple items to the tree.
|
|
3100
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
3099
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
3101
3100
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
3102
3101
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
3103
3102
|
*
|
|
3104
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
3103
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
3105
3104
|
* @param [values] - An optional parallel iterable of values.
|
|
3106
3105
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
3107
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
3108
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
3106
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
3107
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
3109
3108
|
*/
|
|
3110
|
-
|
|
3109
|
+
setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
3111
3110
|
const inserted = [];
|
|
3112
3111
|
const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
|
|
3113
3112
|
if (!isBalanceAdd) {
|
|
3114
3113
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
3115
3114
|
const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
|
|
3116
3115
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
3117
|
-
inserted.push(this.
|
|
3116
|
+
inserted.push(this.set(kve, val));
|
|
3118
3117
|
}
|
|
3119
3118
|
return inserted;
|
|
3120
3119
|
}
|
|
@@ -3142,9 +3141,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3142
3141
|
const { key, value, orgIndex } = arr[mid];
|
|
3143
3142
|
if (this.isRaw(key)) {
|
|
3144
3143
|
const entry = this._toEntryFn(key);
|
|
3145
|
-
inserted[orgIndex] = this.
|
|
3144
|
+
inserted[orgIndex] = this.set(entry);
|
|
3146
3145
|
} else {
|
|
3147
|
-
inserted[orgIndex] = this.
|
|
3146
|
+
inserted[orgIndex] = this.set(key, value);
|
|
3148
3147
|
}
|
|
3149
3148
|
_dfs(arr.slice(0, mid));
|
|
3150
3149
|
_dfs(arr.slice(mid + 1));
|
|
@@ -3161,9 +3160,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3161
3160
|
const { key, value, orgIndex } = sorted[m];
|
|
3162
3161
|
if (this.isRaw(key)) {
|
|
3163
3162
|
const entry = this._toEntryFn(key);
|
|
3164
|
-
inserted[orgIndex] = this.
|
|
3163
|
+
inserted[orgIndex] = this.set(entry);
|
|
3165
3164
|
} else {
|
|
3166
|
-
inserted[orgIndex] = this.
|
|
3165
|
+
inserted[orgIndex] = this.set(key, value);
|
|
3167
3166
|
}
|
|
3168
3167
|
stack.push([m + 1, r]);
|
|
3169
3168
|
stack.push([l, m - 1]);
|
|
@@ -3438,7 +3437,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3438
3437
|
const out = this._createLike([], options);
|
|
3439
3438
|
let index = 0;
|
|
3440
3439
|
for (const [key, value] of this) {
|
|
3441
|
-
out.
|
|
3440
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
3442
3441
|
}
|
|
3443
3442
|
return out;
|
|
3444
3443
|
}
|
|
@@ -3494,7 +3493,6 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3494
3493
|
*/
|
|
3495
3494
|
_createDefaultComparator() {
|
|
3496
3495
|
return (a, b) => {
|
|
3497
|
-
debugger;
|
|
3498
3496
|
if (isComparable(a) && isComparable(b)) {
|
|
3499
3497
|
if (a > b) return 1;
|
|
3500
3498
|
if (a < b) return -1;
|
|
@@ -4056,14 +4054,14 @@ var AVLTreeNode = _AVLTreeNode;
|
|
|
4056
4054
|
var _AVLTree = class _AVLTree extends BST {
|
|
4057
4055
|
/**
|
|
4058
4056
|
* Creates an instance of AVLTree.
|
|
4059
|
-
* @remarks Time O(N log N) (from `
|
|
4057
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
4060
4058
|
*
|
|
4061
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
4059
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
4062
4060
|
* @param [options] - Configuration options for the AVL tree.
|
|
4063
4061
|
*/
|
|
4064
4062
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
4065
4063
|
super([], options);
|
|
4066
|
-
if (keysNodesEntriesOrRaws) super.
|
|
4064
|
+
if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
|
|
4067
4065
|
}
|
|
4068
4066
|
/**
|
|
4069
4067
|
* (Protected) Creates a new AVL tree node.
|
|
@@ -4087,16 +4085,16 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
4087
4085
|
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
4088
4086
|
}
|
|
4089
4087
|
/**
|
|
4090
|
-
*
|
|
4091
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
4088
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
4089
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
4092
4090
|
*
|
|
4093
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
4091
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
4094
4092
|
* @param [value] - The value, if providing just a key.
|
|
4095
4093
|
* @returns True if the addition was successful, false otherwise.
|
|
4096
4094
|
*/
|
|
4097
|
-
|
|
4095
|
+
set(keyNodeOrEntry, value) {
|
|
4098
4096
|
if (keyNodeOrEntry === null) return false;
|
|
4099
|
-
const inserted = super.
|
|
4097
|
+
const inserted = super.set(keyNodeOrEntry, value);
|
|
4100
4098
|
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
4101
4099
|
return inserted;
|
|
4102
4100
|
}
|
|
@@ -4148,7 +4146,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
4148
4146
|
}
|
|
4149
4147
|
/**
|
|
4150
4148
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
4151
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
4149
|
+
* @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.
|
|
4152
4150
|
*
|
|
4153
4151
|
* @template MK - New key type.
|
|
4154
4152
|
* @template MV - New value type.
|
|
@@ -4162,7 +4160,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
4162
4160
|
const out = this._createLike([], options);
|
|
4163
4161
|
let index = 0;
|
|
4164
4162
|
for (const [key, value] of this) {
|
|
4165
|
-
out.
|
|
4163
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
4166
4164
|
}
|
|
4167
4165
|
return out;
|
|
4168
4166
|
}
|