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
|
@@ -1192,9 +1192,9 @@ var avlTreeTyped = (() => {
|
|
|
1192
1192
|
var BinaryTree = class extends IterableEntryBase {
|
|
1193
1193
|
/**
|
|
1194
1194
|
* Creates an instance of BinaryTree.
|
|
1195
|
-
* @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) `
|
|
1195
|
+
* @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.
|
|
1196
1196
|
*
|
|
1197
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
1197
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
1198
1198
|
* @param [options] - Configuration options for the tree.
|
|
1199
1199
|
*/
|
|
1200
1200
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -1223,7 +1223,7 @@ var avlTreeTyped = (() => {
|
|
|
1223
1223
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1224
1224
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
1225
1225
|
}
|
|
1226
|
-
if (keysNodesEntriesOrRaws) this.
|
|
1226
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1227
1227
|
}
|
|
1228
1228
|
/**
|
|
1229
1229
|
* Gets whether the tree is in Map mode.
|
|
@@ -1430,10 +1430,20 @@ var avlTreeTyped = (() => {
|
|
|
1430
1430
|
* @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).
|
|
1431
1431
|
*
|
|
1432
1432
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1433
|
+
* @returns True if the addition was successful, false otherwise.
|
|
1434
|
+
*/
|
|
1435
|
+
add(keyNodeOrEntry) {
|
|
1436
|
+
return this.set(keyNodeOrEntry);
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Adds or updates a new node to the tree.
|
|
1440
|
+
* @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).
|
|
1441
|
+
*
|
|
1442
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
1433
1443
|
* @param [value] - The value, if providing just a key.
|
|
1434
1444
|
* @returns True if the addition was successful, false otherwise.
|
|
1435
1445
|
*/
|
|
1436
|
-
|
|
1446
|
+
set(keyNodeOrEntry, value) {
|
|
1437
1447
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
1438
1448
|
if (newNode === void 0) return false;
|
|
1439
1449
|
if (!this._root) {
|
|
@@ -1477,25 +1487,25 @@ var avlTreeTyped = (() => {
|
|
|
1477
1487
|
return false;
|
|
1478
1488
|
}
|
|
1479
1489
|
/**
|
|
1480
|
-
* Adds
|
|
1481
|
-
* @remarks Time O(
|
|
1490
|
+
* Adds 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
|
|
1484
|
-
* @param [
|
|
1485
|
-
* @returns
|
|
1493
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1494
|
+
* @param [values] - An optional parallel iterable of values.
|
|
1495
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1486
1496
|
*/
|
|
1487
|
-
|
|
1488
|
-
return this.
|
|
1497
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
1498
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
1489
1499
|
}
|
|
1490
1500
|
/**
|
|
1491
|
-
* Adds multiple items to the tree.
|
|
1492
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
1501
|
+
* Adds or updates multiple items to the tree.
|
|
1502
|
+
* @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).
|
|
1493
1503
|
*
|
|
1494
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1504
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
1495
1505
|
* @param [values] - An optional parallel iterable of values.
|
|
1496
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
1506
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1497
1507
|
*/
|
|
1498
|
-
|
|
1508
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
1499
1509
|
const inserted = [];
|
|
1500
1510
|
let valuesIterator;
|
|
1501
1511
|
if (values) {
|
|
@@ -1510,40 +1520,29 @@ var avlTreeTyped = (() => {
|
|
|
1510
1520
|
}
|
|
1511
1521
|
}
|
|
1512
1522
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
1513
|
-
inserted.push(this.
|
|
1523
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
1514
1524
|
}
|
|
1515
1525
|
return inserted;
|
|
1516
1526
|
}
|
|
1517
1527
|
/**
|
|
1518
|
-
*
|
|
1519
|
-
* @remarks Time O(N * M), where N is the
|
|
1520
|
-
*
|
|
1521
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
1522
|
-
* @param [values] - An optional parallel iterable of values.
|
|
1523
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
1524
|
-
*/
|
|
1525
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
1526
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
1527
|
-
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Merges another tree into this one by adding all its nodes.
|
|
1530
|
-
* @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`).
|
|
1528
|
+
* Merges another tree into this one by seting all its nodes.
|
|
1529
|
+
* @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`).
|
|
1531
1530
|
*
|
|
1532
1531
|
* @param anotherTree - The tree to merge.
|
|
1533
1532
|
*/
|
|
1534
1533
|
merge(anotherTree) {
|
|
1535
|
-
this.
|
|
1534
|
+
this.setMany(anotherTree, []);
|
|
1536
1535
|
}
|
|
1537
1536
|
/**
|
|
1538
1537
|
* Clears the tree and refills it with new items.
|
|
1539
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
1538
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
1540
1539
|
*
|
|
1541
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1540
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1542
1541
|
* @param [values] - An optional parallel iterable of values.
|
|
1543
1542
|
*/
|
|
1544
1543
|
refill(keysNodesEntriesOrRaws, values) {
|
|
1545
1544
|
this.clear();
|
|
1546
|
-
this.
|
|
1545
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
1547
1546
|
}
|
|
1548
1547
|
/**
|
|
1549
1548
|
* Deletes a node from the tree.
|
|
@@ -2209,7 +2208,7 @@ var avlTreeTyped = (() => {
|
|
|
2209
2208
|
}
|
|
2210
2209
|
/**
|
|
2211
2210
|
* Clones the tree.
|
|
2212
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
2211
|
+
* @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.
|
|
2213
2212
|
*
|
|
2214
2213
|
* @returns A new, cloned instance of the tree.
|
|
2215
2214
|
*/
|
|
@@ -2220,7 +2219,7 @@ var avlTreeTyped = (() => {
|
|
|
2220
2219
|
}
|
|
2221
2220
|
/**
|
|
2222
2221
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
2223
|
-
* @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) `
|
|
2222
|
+
* @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.
|
|
2224
2223
|
*
|
|
2225
2224
|
* @param predicate - A function to test each [key, value] pair.
|
|
2226
2225
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -2229,7 +2228,7 @@ var avlTreeTyped = (() => {
|
|
|
2229
2228
|
filter(predicate, thisArg) {
|
|
2230
2229
|
const out = this._createInstance();
|
|
2231
2230
|
let i = 0;
|
|
2232
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
2231
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
2233
2232
|
return out;
|
|
2234
2233
|
}
|
|
2235
2234
|
/**
|
|
@@ -2247,7 +2246,7 @@ var avlTreeTyped = (() => {
|
|
|
2247
2246
|
map(cb, options, thisArg) {
|
|
2248
2247
|
const out = this._createLike([], options);
|
|
2249
2248
|
let i = 0;
|
|
2250
|
-
for (const [k, v] of this) out.
|
|
2249
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
2251
2250
|
return out;
|
|
2252
2251
|
}
|
|
2253
2252
|
/**
|
|
@@ -2493,18 +2492,18 @@ var avlTreeTyped = (() => {
|
|
|
2493
2492
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
2494
2493
|
}
|
|
2495
2494
|
/**
|
|
2496
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
2497
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
2495
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
2496
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
2498
2497
|
*
|
|
2499
2498
|
* @param cloned - The new, empty tree instance to populate.
|
|
2500
2499
|
*/
|
|
2501
2500
|
_clone(cloned) {
|
|
2502
2501
|
this.bfs(
|
|
2503
2502
|
(node) => {
|
|
2504
|
-
if (node === null) cloned.
|
|
2503
|
+
if (node === null) cloned.set(null);
|
|
2505
2504
|
else {
|
|
2506
|
-
if (this._isMapMode) cloned.
|
|
2507
|
-
else cloned.
|
|
2505
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
2506
|
+
else cloned.set([node.key, node.value]);
|
|
2508
2507
|
}
|
|
2509
2508
|
},
|
|
2510
2509
|
this._root,
|
|
@@ -2831,7 +2830,7 @@ var avlTreeTyped = (() => {
|
|
|
2831
2830
|
* Creates an instance of BST.
|
|
2832
2831
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
2833
2832
|
*
|
|
2834
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
2833
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
2835
2834
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
2836
2835
|
*/
|
|
2837
2836
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -2852,7 +2851,7 @@ var avlTreeTyped = (() => {
|
|
|
2852
2851
|
} else {
|
|
2853
2852
|
this._comparator = this._createDefaultComparator();
|
|
2854
2853
|
}
|
|
2855
|
-
if (keysNodesEntriesOrRaws) this.
|
|
2854
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
2856
2855
|
}
|
|
2857
2856
|
/**
|
|
2858
2857
|
* Gets the root node of the tree.
|
|
@@ -3063,11 +3062,11 @@ var avlTreeTyped = (() => {
|
|
|
3063
3062
|
* Adds a new node to the BST based on key comparison.
|
|
3064
3063
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
3065
3064
|
*
|
|
3066
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
3065
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
3067
3066
|
* @param [value] - The value, if providing just a key.
|
|
3068
3067
|
* @returns True if the addition was successful, false otherwise.
|
|
3069
3068
|
*/
|
|
3070
|
-
|
|
3069
|
+
set(keyNodeOrEntry, value) {
|
|
3071
3070
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
3072
3071
|
if (newNode === void 0) return false;
|
|
3073
3072
|
if (this._root === void 0) {
|
|
@@ -3104,24 +3103,24 @@ var avlTreeTyped = (() => {
|
|
|
3104
3103
|
}
|
|
3105
3104
|
/**
|
|
3106
3105
|
* Adds multiple items to the tree.
|
|
3107
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
3106
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
3108
3107
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
3109
3108
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
3110
3109
|
*
|
|
3111
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
3110
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
3112
3111
|
* @param [values] - An optional parallel iterable of values.
|
|
3113
3112
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
3114
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
3115
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
3113
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
3114
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
3116
3115
|
*/
|
|
3117
|
-
|
|
3116
|
+
setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
3118
3117
|
const inserted = [];
|
|
3119
3118
|
const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
|
|
3120
3119
|
if (!isBalanceAdd) {
|
|
3121
3120
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
3122
3121
|
const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
|
|
3123
3122
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
3124
|
-
inserted.push(this.
|
|
3123
|
+
inserted.push(this.set(kve, val));
|
|
3125
3124
|
}
|
|
3126
3125
|
return inserted;
|
|
3127
3126
|
}
|
|
@@ -3149,9 +3148,9 @@ var avlTreeTyped = (() => {
|
|
|
3149
3148
|
const { key, value, orgIndex } = arr[mid];
|
|
3150
3149
|
if (this.isRaw(key)) {
|
|
3151
3150
|
const entry = this._toEntryFn(key);
|
|
3152
|
-
inserted[orgIndex] = this.
|
|
3151
|
+
inserted[orgIndex] = this.set(entry);
|
|
3153
3152
|
} else {
|
|
3154
|
-
inserted[orgIndex] = this.
|
|
3153
|
+
inserted[orgIndex] = this.set(key, value);
|
|
3155
3154
|
}
|
|
3156
3155
|
_dfs(arr.slice(0, mid));
|
|
3157
3156
|
_dfs(arr.slice(mid + 1));
|
|
@@ -3168,9 +3167,9 @@ var avlTreeTyped = (() => {
|
|
|
3168
3167
|
const { key, value, orgIndex } = sorted[m];
|
|
3169
3168
|
if (this.isRaw(key)) {
|
|
3170
3169
|
const entry = this._toEntryFn(key);
|
|
3171
|
-
inserted[orgIndex] = this.
|
|
3170
|
+
inserted[orgIndex] = this.set(entry);
|
|
3172
3171
|
} else {
|
|
3173
|
-
inserted[orgIndex] = this.
|
|
3172
|
+
inserted[orgIndex] = this.set(key, value);
|
|
3174
3173
|
}
|
|
3175
3174
|
stack.push([m + 1, r]);
|
|
3176
3175
|
stack.push([l, m - 1]);
|
|
@@ -3445,7 +3444,7 @@ var avlTreeTyped = (() => {
|
|
|
3445
3444
|
const out = this._createLike([], options);
|
|
3446
3445
|
let index = 0;
|
|
3447
3446
|
for (const [key, value] of this) {
|
|
3448
|
-
out.
|
|
3447
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
3449
3448
|
}
|
|
3450
3449
|
return out;
|
|
3451
3450
|
}
|
|
@@ -3501,7 +3500,6 @@ var avlTreeTyped = (() => {
|
|
|
3501
3500
|
*/
|
|
3502
3501
|
_createDefaultComparator() {
|
|
3503
3502
|
return (a, b) => {
|
|
3504
|
-
debugger;
|
|
3505
3503
|
if (isComparable(a) && isComparable(b)) {
|
|
3506
3504
|
if (a > b) return 1;
|
|
3507
3505
|
if (a < b) return -1;
|
|
@@ -4059,14 +4057,14 @@ var avlTreeTyped = (() => {
|
|
|
4059
4057
|
var AVLTree = class extends BST {
|
|
4060
4058
|
/**
|
|
4061
4059
|
* Creates an instance of AVLTree.
|
|
4062
|
-
* @remarks Time O(N log N) (from `
|
|
4060
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
4063
4061
|
*
|
|
4064
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
4062
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
4065
4063
|
* @param [options] - Configuration options for the AVL tree.
|
|
4066
4064
|
*/
|
|
4067
4065
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
4068
4066
|
super([], options);
|
|
4069
|
-
if (keysNodesEntriesOrRaws) super.
|
|
4067
|
+
if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
|
|
4070
4068
|
}
|
|
4071
4069
|
/**
|
|
4072
4070
|
* (Protected) Creates a new AVL tree node.
|
|
@@ -4090,16 +4088,16 @@ var avlTreeTyped = (() => {
|
|
|
4090
4088
|
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
4091
4089
|
}
|
|
4092
4090
|
/**
|
|
4093
|
-
*
|
|
4094
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
4091
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
4092
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
4095
4093
|
*
|
|
4096
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
4094
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
4097
4095
|
* @param [value] - The value, if providing just a key.
|
|
4098
4096
|
* @returns True if the addition was successful, false otherwise.
|
|
4099
4097
|
*/
|
|
4100
|
-
|
|
4098
|
+
set(keyNodeOrEntry, value) {
|
|
4101
4099
|
if (keyNodeOrEntry === null) return false;
|
|
4102
|
-
const inserted = super.
|
|
4100
|
+
const inserted = super.set(keyNodeOrEntry, value);
|
|
4103
4101
|
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
4104
4102
|
return inserted;
|
|
4105
4103
|
}
|
|
@@ -4151,7 +4149,7 @@ var avlTreeTyped = (() => {
|
|
|
4151
4149
|
}
|
|
4152
4150
|
/**
|
|
4153
4151
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
4154
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
4152
|
+
* @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.
|
|
4155
4153
|
*
|
|
4156
4154
|
* @template MK - New key type.
|
|
4157
4155
|
* @template MV - New value type.
|
|
@@ -4165,7 +4163,7 @@ var avlTreeTyped = (() => {
|
|
|
4165
4163
|
const out = this._createLike([], options);
|
|
4166
4164
|
let index = 0;
|
|
4167
4165
|
for (const [key, value] of this) {
|
|
4168
|
-
out.
|
|
4166
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
4169
4167
|
}
|
|
4170
4168
|
return out;
|
|
4171
4169
|
}
|