tree-multimap-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.
- package/dist/cjs/index.cjs +72 -75
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +72 -75
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +72 -75
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +72 -75
- 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 -24
- 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/tree-multimap-typed.js +70 -73
- package/dist/umd/tree-multimap-typed.js.map +1 -1
- package/dist/umd/tree-multimap-typed.min.js +3 -3
- package/dist/umd/tree-multimap-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 +52 -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/dist/esm/index.mjs
CHANGED
|
@@ -1192,9 +1192,9 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1192
1192
|
iterationType = "ITERATIVE";
|
|
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) {
|
|
@@ -1207,7 +1207,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1207
1207
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1208
1208
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
1209
1209
|
}
|
|
1210
|
-
if (keysNodesEntriesOrRaws) this.
|
|
1210
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1211
1211
|
}
|
|
1212
1212
|
_isMapMode = true;
|
|
1213
1213
|
/**
|
|
@@ -1421,10 +1421,20 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1421
1421
|
* @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).
|
|
1422
1422
|
*
|
|
1423
1423
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
1424
|
+
* @returns True if the addition was successful, false otherwise.
|
|
1425
|
+
*/
|
|
1426
|
+
add(keyNodeOrEntry) {
|
|
1427
|
+
return this.set(keyNodeOrEntry);
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Adds or updates a new node to the tree.
|
|
1431
|
+
* @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).
|
|
1432
|
+
*
|
|
1433
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
1424
1434
|
* @param [value] - The value, if providing just a key.
|
|
1425
1435
|
* @returns True if the addition was successful, false otherwise.
|
|
1426
1436
|
*/
|
|
1427
|
-
|
|
1437
|
+
set(keyNodeOrEntry, value) {
|
|
1428
1438
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
1429
1439
|
if (newNode === void 0) return false;
|
|
1430
1440
|
if (!this._root) {
|
|
@@ -1468,25 +1478,24 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1468
1478
|
return false;
|
|
1469
1479
|
}
|
|
1470
1480
|
/**
|
|
1471
|
-
* Adds
|
|
1472
|
-
* @remarks Time O(
|
|
1481
|
+
* Adds multiple items to the tree.
|
|
1482
|
+
* @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).
|
|
1473
1483
|
*
|
|
1474
|
-
* @param
|
|
1475
|
-
* @
|
|
1476
|
-
* @returns True if the addition was successful, false otherwise.
|
|
1484
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1485
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1477
1486
|
*/
|
|
1478
|
-
|
|
1479
|
-
return this.
|
|
1487
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
1488
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
1480
1489
|
}
|
|
1481
1490
|
/**
|
|
1482
|
-
* Adds multiple items to the tree.
|
|
1483
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
1491
|
+
* Adds or updates multiple items to the tree.
|
|
1492
|
+
* @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).
|
|
1484
1493
|
*
|
|
1485
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1494
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
1486
1495
|
* @param [values] - An optional parallel iterable of values.
|
|
1487
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
1496
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
1488
1497
|
*/
|
|
1489
|
-
|
|
1498
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
1490
1499
|
const inserted = [];
|
|
1491
1500
|
let valuesIterator;
|
|
1492
1501
|
if (values) {
|
|
@@ -1501,40 +1510,29 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
1501
1510
|
}
|
|
1502
1511
|
}
|
|
1503
1512
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
1504
|
-
inserted.push(this.
|
|
1513
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
1505
1514
|
}
|
|
1506
1515
|
return inserted;
|
|
1507
1516
|
}
|
|
1508
1517
|
/**
|
|
1509
|
-
*
|
|
1510
|
-
* @remarks Time O(N * M), where N is the
|
|
1511
|
-
*
|
|
1512
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
1513
|
-
* @param [values] - An optional parallel iterable of values.
|
|
1514
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
1515
|
-
*/
|
|
1516
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
1517
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
1518
|
-
}
|
|
1519
|
-
/**
|
|
1520
|
-
* Merges another tree into this one by adding all its nodes.
|
|
1521
|
-
* @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`).
|
|
1518
|
+
* Merges another tree into this one by seting all its nodes.
|
|
1519
|
+
* @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`).
|
|
1522
1520
|
*
|
|
1523
1521
|
* @param anotherTree - The tree to merge.
|
|
1524
1522
|
*/
|
|
1525
1523
|
merge(anotherTree) {
|
|
1526
|
-
this.
|
|
1524
|
+
this.setMany(anotherTree, []);
|
|
1527
1525
|
}
|
|
1528
1526
|
/**
|
|
1529
1527
|
* Clears the tree and refills it with new items.
|
|
1530
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
1528
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
1531
1529
|
*
|
|
1532
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
1530
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
1533
1531
|
* @param [values] - An optional parallel iterable of values.
|
|
1534
1532
|
*/
|
|
1535
1533
|
refill(keysNodesEntriesOrRaws, values) {
|
|
1536
1534
|
this.clear();
|
|
1537
|
-
this.
|
|
1535
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
1538
1536
|
}
|
|
1539
1537
|
/**
|
|
1540
1538
|
* Deletes a node from the tree.
|
|
@@ -2199,7 +2197,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2199
2197
|
}
|
|
2200
2198
|
/**
|
|
2201
2199
|
* Clones the tree.
|
|
2202
|
-
* @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.
|
|
2203
2201
|
*
|
|
2204
2202
|
* @returns A new, cloned instance of the tree.
|
|
2205
2203
|
*/
|
|
@@ -2210,7 +2208,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2210
2208
|
}
|
|
2211
2209
|
/**
|
|
2212
2210
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
2213
|
-
* @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.
|
|
2214
2212
|
*
|
|
2215
2213
|
* @param predicate - A function to test each [key, value] pair.
|
|
2216
2214
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -2219,7 +2217,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2219
2217
|
filter(predicate, thisArg) {
|
|
2220
2218
|
const out = this._createInstance();
|
|
2221
2219
|
let i = 0;
|
|
2222
|
-
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]);
|
|
2223
2221
|
return out;
|
|
2224
2222
|
}
|
|
2225
2223
|
/**
|
|
@@ -2237,7 +2235,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2237
2235
|
map(cb, options, thisArg) {
|
|
2238
2236
|
const out = this._createLike([], options);
|
|
2239
2237
|
let i = 0;
|
|
2240
|
-
for (const [k, v] of this) out.
|
|
2238
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
2241
2239
|
return out;
|
|
2242
2240
|
}
|
|
2243
2241
|
/**
|
|
@@ -2489,18 +2487,18 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
2489
2487
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
2490
2488
|
}
|
|
2491
2489
|
/**
|
|
2492
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
2493
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
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.
|
|
2498
|
+
if (node === null) cloned.set(null);
|
|
2501
2499
|
else {
|
|
2502
|
-
if (this._isMapMode) cloned.
|
|
2503
|
-
else cloned.
|
|
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,
|
|
@@ -2833,7 +2831,7 @@ var BST = class extends BinaryTree {
|
|
|
2833
2831
|
* Creates an instance of BST.
|
|
2834
2832
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
2835
2833
|
*
|
|
2836
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
2834
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
2837
2835
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
2838
2836
|
*/
|
|
2839
2837
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -2847,7 +2845,7 @@ var BST = class extends BinaryTree {
|
|
|
2847
2845
|
} else {
|
|
2848
2846
|
this._comparator = this._createDefaultComparator();
|
|
2849
2847
|
}
|
|
2850
|
-
if (keysNodesEntriesOrRaws) this.
|
|
2848
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
2851
2849
|
}
|
|
2852
2850
|
_root = void 0;
|
|
2853
2851
|
/**
|
|
@@ -3063,11 +3061,11 @@ var BST = class extends BinaryTree {
|
|
|
3063
3061
|
* Adds a new node to the BST based on key comparison.
|
|
3064
3062
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
3065
3063
|
*
|
|
3066
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
3064
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
3067
3065
|
* @param [value] - The value, if providing just a key.
|
|
3068
3066
|
* @returns True if the addition was successful, false otherwise.
|
|
3069
3067
|
*/
|
|
3070
|
-
|
|
3068
|
+
set(keyNodeOrEntry, value) {
|
|
3071
3069
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
3072
3070
|
if (newNode === void 0) return false;
|
|
3073
3071
|
if (this._root === void 0) {
|
|
@@ -3104,24 +3102,24 @@ var BST = class extends BinaryTree {
|
|
|
3104
3102
|
}
|
|
3105
3103
|
/**
|
|
3106
3104
|
* 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
|
|
3105
|
+
* @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
3106
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
3109
3107
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
3110
3108
|
*
|
|
3111
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
3109
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
3112
3110
|
* @param [values] - An optional parallel iterable of values.
|
|
3113
3111
|
* @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 `
|
|
3112
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
3113
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
3116
3114
|
*/
|
|
3117
|
-
|
|
3115
|
+
setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
3118
3116
|
const inserted = [];
|
|
3119
3117
|
const valuesIterator = values?.[Symbol.iterator]();
|
|
3120
3118
|
if (!isBalanceAdd) {
|
|
3121
3119
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
3122
3120
|
const val = valuesIterator?.next().value;
|
|
3123
3121
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
3124
|
-
inserted.push(this.
|
|
3122
|
+
inserted.push(this.set(kve, val));
|
|
3125
3123
|
}
|
|
3126
3124
|
return inserted;
|
|
3127
3125
|
}
|
|
@@ -3149,9 +3147,9 @@ var BST = class extends BinaryTree {
|
|
|
3149
3147
|
const { key, value, orgIndex } = arr[mid];
|
|
3150
3148
|
if (this.isRaw(key)) {
|
|
3151
3149
|
const entry = this._toEntryFn(key);
|
|
3152
|
-
inserted[orgIndex] = this.
|
|
3150
|
+
inserted[orgIndex] = this.set(entry);
|
|
3153
3151
|
} else {
|
|
3154
|
-
inserted[orgIndex] = this.
|
|
3152
|
+
inserted[orgIndex] = this.set(key, value);
|
|
3155
3153
|
}
|
|
3156
3154
|
_dfs(arr.slice(0, mid));
|
|
3157
3155
|
_dfs(arr.slice(mid + 1));
|
|
@@ -3168,9 +3166,9 @@ var BST = class extends BinaryTree {
|
|
|
3168
3166
|
const { key, value, orgIndex } = sorted[m];
|
|
3169
3167
|
if (this.isRaw(key)) {
|
|
3170
3168
|
const entry = this._toEntryFn(key);
|
|
3171
|
-
inserted[orgIndex] = this.
|
|
3169
|
+
inserted[orgIndex] = this.set(entry);
|
|
3172
3170
|
} else {
|
|
3173
|
-
inserted[orgIndex] = this.
|
|
3171
|
+
inserted[orgIndex] = this.set(key, value);
|
|
3174
3172
|
}
|
|
3175
3173
|
stack.push([m + 1, r]);
|
|
3176
3174
|
stack.push([l, m - 1]);
|
|
@@ -3445,7 +3443,7 @@ var BST = class extends BinaryTree {
|
|
|
3445
3443
|
const out = this._createLike([], options);
|
|
3446
3444
|
let index = 0;
|
|
3447
3445
|
for (const [key, value] of this) {
|
|
3448
|
-
out.
|
|
3446
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
3449
3447
|
}
|
|
3450
3448
|
return out;
|
|
3451
3449
|
}
|
|
@@ -3501,7 +3499,6 @@ var BST = class extends BinaryTree {
|
|
|
3501
3499
|
*/
|
|
3502
3500
|
_createDefaultComparator() {
|
|
3503
3501
|
return (a, b) => {
|
|
3504
|
-
debugger;
|
|
3505
3502
|
if (isComparable(a) && isComparable(b)) {
|
|
3506
3503
|
if (a > b) return 1;
|
|
3507
3504
|
if (a < b) return -1;
|
|
@@ -4063,7 +4060,7 @@ var RedBlackTree = class extends BST {
|
|
|
4063
4060
|
super([], options);
|
|
4064
4061
|
this._root = this.NIL;
|
|
4065
4062
|
if (keysNodesEntriesOrRaws) {
|
|
4066
|
-
this.
|
|
4063
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
4067
4064
|
}
|
|
4068
4065
|
}
|
|
4069
4066
|
_root;
|
|
@@ -4111,7 +4108,7 @@ var RedBlackTree = class extends BST {
|
|
|
4111
4108
|
* @param [value]- See parameter type for details.
|
|
4112
4109
|
* @returns True if inserted or updated; false if ignored.
|
|
4113
4110
|
*/
|
|
4114
|
-
|
|
4111
|
+
set(keyNodeOrEntry, value) {
|
|
4115
4112
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
4116
4113
|
if (!this.isRealNode(newNode)) return false;
|
|
4117
4114
|
const insertStatus = this._insert(newNode);
|
|
@@ -4205,7 +4202,7 @@ var RedBlackTree = class extends BST {
|
|
|
4205
4202
|
const out = this._createLike([], options);
|
|
4206
4203
|
let index = 0;
|
|
4207
4204
|
for (const [key, value] of this) {
|
|
4208
|
-
out.
|
|
4205
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
4209
4206
|
}
|
|
4210
4207
|
return out;
|
|
4211
4208
|
}
|
|
@@ -4594,7 +4591,7 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
4594
4591
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
4595
4592
|
super([], { ...options });
|
|
4596
4593
|
if (keysNodesEntriesOrRaws) {
|
|
4597
|
-
this.
|
|
4594
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
4598
4595
|
}
|
|
4599
4596
|
}
|
|
4600
4597
|
createNode(key, value = []) {
|
|
@@ -4614,27 +4611,27 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
4614
4611
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
4615
4612
|
* @remarks Time O(log N + M), Space O(1)
|
|
4616
4613
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
4617
|
-
* @param [value] - Single value to
|
|
4614
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
4618
4615
|
* @returns True if inserted or appended; false if ignored.
|
|
4619
4616
|
*/
|
|
4620
|
-
|
|
4621
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
4617
|
+
set(keyNodeOrEntry, value) {
|
|
4618
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
4622
4619
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
4623
4620
|
if (key === void 0 || key === null) return false;
|
|
4624
|
-
const
|
|
4621
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
4625
4622
|
const existingValues = this.get(key);
|
|
4626
4623
|
if (existingValues !== void 0 && values !== void 0) {
|
|
4627
4624
|
for (const value2 of values) existingValues.push(value2);
|
|
4628
4625
|
return true;
|
|
4629
4626
|
}
|
|
4630
4627
|
return false;
|
|
4631
|
-
}, "
|
|
4632
|
-
const
|
|
4628
|
+
}, "_setToValues");
|
|
4629
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
4633
4630
|
const existingNode = this.getNode(key);
|
|
4634
4631
|
if (this.isRealNode(existingNode)) {
|
|
4635
4632
|
const existingValues = this.get(existingNode);
|
|
4636
4633
|
if (existingValues === void 0) {
|
|
4637
|
-
super.
|
|
4634
|
+
super.set(key, values);
|
|
4638
4635
|
return true;
|
|
4639
4636
|
}
|
|
4640
4637
|
if (values !== void 0) {
|
|
@@ -4644,13 +4641,13 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
4644
4641
|
return false;
|
|
4645
4642
|
}
|
|
4646
4643
|
} else {
|
|
4647
|
-
return super.
|
|
4644
|
+
return super.set(key, values);
|
|
4648
4645
|
}
|
|
4649
|
-
}, "
|
|
4646
|
+
}, "_setByNode");
|
|
4650
4647
|
if (this._isMapMode) {
|
|
4651
|
-
return
|
|
4648
|
+
return _setByNode() || _setToValues();
|
|
4652
4649
|
}
|
|
4653
|
-
return
|
|
4650
|
+
return _setToValues() || _setByNode();
|
|
4654
4651
|
}, "_commonAdd");
|
|
4655
4652
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
4656
4653
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -4690,7 +4687,7 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
4690
4687
|
map(callback, options, thisArg) {
|
|
4691
4688
|
const out = this._createLike([], options);
|
|
4692
4689
|
let i = 0;
|
|
4693
|
-
for (const [k, v] of this) out.
|
|
4690
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
4694
4691
|
return out;
|
|
4695
4692
|
}
|
|
4696
4693
|
/**
|