data-structure-typed 2.2.6 → 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/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +47 -1
- package/README.md +19 -8
- package/README_CN.md +119 -275
- package/benchmark/report.html +1 -1
- package/benchmark/report.json +20 -324
- package/dist/cjs/index.cjs +109 -107
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +109 -107
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +109 -107
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +109 -107
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/leetcode/avl-tree-counter.mjs +2957 -0
- package/dist/leetcode/avl-tree-multi-map.mjs +2889 -0
- package/dist/leetcode/avl-tree.mjs +2720 -0
- package/dist/leetcode/binary-tree.mjs +1594 -0
- package/dist/leetcode/bst.mjs +2398 -0
- package/dist/leetcode/deque.mjs +683 -0
- package/dist/leetcode/directed-graph.mjs +1733 -0
- package/dist/leetcode/doubly-linked-list.mjs +709 -0
- package/dist/leetcode/hash-map.mjs +493 -0
- package/dist/leetcode/heap.mjs +542 -0
- package/dist/leetcode/max-heap.mjs +375 -0
- package/dist/leetcode/max-priority-queue.mjs +383 -0
- package/dist/leetcode/min-heap.mjs +363 -0
- package/dist/leetcode/min-priority-queue.mjs +371 -0
- package/dist/leetcode/priority-queue.mjs +363 -0
- package/dist/leetcode/queue.mjs +943 -0
- package/dist/leetcode/red-black-tree.mjs +2765 -0
- package/dist/leetcode/singly-linked-list.mjs +754 -0
- package/dist/leetcode/stack.mjs +217 -0
- package/dist/leetcode/tree-counter.mjs +3039 -0
- package/dist/leetcode/tree-multi-map.mjs +2913 -0
- package/dist/leetcode/trie.mjs +413 -0
- package/dist/leetcode/undirected-graph.mjs +1650 -0
- 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/data-structure-typed.js +105 -103
- package/dist/umd/data-structure-typed.js.map +1 -1
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +48 -171
- 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/test/performance/data-structures/binary-tree/red-black-tree.test.ts +1 -2
- package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +30 -30
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +46 -46
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +43 -43
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +151 -151
- package/test/unit/data-structures/binary-tree/bst.test.ts +99 -99
- package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +141 -141
- package/test/unit/data-structures/binary-tree/tree-counter.test.ts +37 -37
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +145 -145
- package/tsup.config.js +50 -21
- package/tsup.leetcode.config.js +1 -1
- package/tsup.umd.config.js +29 -0
- package/tsup.node.config.js +0 -83
|
@@ -178,6 +178,7 @@ var _IterableEntryBase = class _IterableEntryBase {
|
|
|
178
178
|
* @remarks Time O(n), Space O(n)
|
|
179
179
|
*/
|
|
180
180
|
print() {
|
|
181
|
+
console.log(this.toVisual());
|
|
181
182
|
}
|
|
182
183
|
};
|
|
183
184
|
__name(_IterableEntryBase, "IterableEntryBase");
|
|
@@ -399,6 +400,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
399
400
|
* Time O(n) due to materialization, Space O(n) for the intermediate representation.
|
|
400
401
|
*/
|
|
401
402
|
print() {
|
|
403
|
+
console.log(this.toVisual());
|
|
402
404
|
}
|
|
403
405
|
};
|
|
404
406
|
__name(_IterableElementBase, "IterableElementBase");
|
|
@@ -6969,9 +6971,9 @@ var BinaryTreeNode = _BinaryTreeNode;
|
|
|
6969
6971
|
var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
6970
6972
|
/**
|
|
6971
6973
|
* Creates an instance of BinaryTree.
|
|
6972
|
-
* @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) `
|
|
6974
|
+
* @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.
|
|
6973
6975
|
*
|
|
6974
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
6976
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
6975
6977
|
* @param [options] - Configuration options for the tree.
|
|
6976
6978
|
*/
|
|
6977
6979
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -7000,7 +7002,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7000
7002
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
7001
7003
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
7002
7004
|
}
|
|
7003
|
-
if (keysNodesEntriesOrRaws) this.
|
|
7005
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
7004
7006
|
}
|
|
7005
7007
|
/**
|
|
7006
7008
|
* Gets whether the tree is in Map mode.
|
|
@@ -7207,10 +7209,20 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7207
7209
|
* @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).
|
|
7208
7210
|
*
|
|
7209
7211
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
7212
|
+
* @returns True if the addition was successful, false otherwise.
|
|
7213
|
+
*/
|
|
7214
|
+
add(keyNodeOrEntry) {
|
|
7215
|
+
return this.set(keyNodeOrEntry);
|
|
7216
|
+
}
|
|
7217
|
+
/**
|
|
7218
|
+
* Adds or updates a new node to the tree.
|
|
7219
|
+
* @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).
|
|
7220
|
+
*
|
|
7221
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
7210
7222
|
* @param [value] - The value, if providing just a key.
|
|
7211
7223
|
* @returns True if the addition was successful, false otherwise.
|
|
7212
7224
|
*/
|
|
7213
|
-
|
|
7225
|
+
set(keyNodeOrEntry, value) {
|
|
7214
7226
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
7215
7227
|
if (newNode === void 0) return false;
|
|
7216
7228
|
if (!this._root) {
|
|
@@ -7254,25 +7266,25 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7254
7266
|
return false;
|
|
7255
7267
|
}
|
|
7256
7268
|
/**
|
|
7257
|
-
* Adds
|
|
7258
|
-
* @remarks Time O(
|
|
7269
|
+
* Adds multiple items to the tree.
|
|
7270
|
+
* @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).
|
|
7259
7271
|
*
|
|
7260
|
-
* @param
|
|
7261
|
-
* @param [
|
|
7262
|
-
* @returns
|
|
7272
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
7273
|
+
* @param [values] - An optional parallel iterable of values.
|
|
7274
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
7263
7275
|
*/
|
|
7264
|
-
|
|
7265
|
-
return this.
|
|
7276
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
7277
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
7266
7278
|
}
|
|
7267
7279
|
/**
|
|
7268
|
-
* Adds multiple items to the tree.
|
|
7269
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
7280
|
+
* Adds or updates multiple items to the tree.
|
|
7281
|
+
* @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).
|
|
7270
7282
|
*
|
|
7271
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
7283
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
7272
7284
|
* @param [values] - An optional parallel iterable of values.
|
|
7273
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
7285
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
7274
7286
|
*/
|
|
7275
|
-
|
|
7287
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
7276
7288
|
const inserted = [];
|
|
7277
7289
|
let valuesIterator;
|
|
7278
7290
|
if (values) {
|
|
@@ -7287,40 +7299,29 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7287
7299
|
}
|
|
7288
7300
|
}
|
|
7289
7301
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
7290
|
-
inserted.push(this.
|
|
7302
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
7291
7303
|
}
|
|
7292
7304
|
return inserted;
|
|
7293
7305
|
}
|
|
7294
7306
|
/**
|
|
7295
|
-
*
|
|
7296
|
-
* @remarks Time O(N * M), where N is the
|
|
7297
|
-
*
|
|
7298
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
7299
|
-
* @param [values] - An optional parallel iterable of values.
|
|
7300
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
7301
|
-
*/
|
|
7302
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
7303
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
7304
|
-
}
|
|
7305
|
-
/**
|
|
7306
|
-
* Merges another tree into this one by adding all its nodes.
|
|
7307
|
-
* @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`).
|
|
7307
|
+
* Merges another tree into this one by seting all its nodes.
|
|
7308
|
+
* @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`).
|
|
7308
7309
|
*
|
|
7309
7310
|
* @param anotherTree - The tree to merge.
|
|
7310
7311
|
*/
|
|
7311
7312
|
merge(anotherTree) {
|
|
7312
|
-
this.
|
|
7313
|
+
this.setMany(anotherTree, []);
|
|
7313
7314
|
}
|
|
7314
7315
|
/**
|
|
7315
7316
|
* Clears the tree and refills it with new items.
|
|
7316
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
7317
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
7317
7318
|
*
|
|
7318
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
7319
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
7319
7320
|
* @param [values] - An optional parallel iterable of values.
|
|
7320
7321
|
*/
|
|
7321
7322
|
refill(keysNodesEntriesOrRaws, values) {
|
|
7322
7323
|
this.clear();
|
|
7323
|
-
this.
|
|
7324
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
7324
7325
|
}
|
|
7325
7326
|
/**
|
|
7326
7327
|
* Deletes a node from the tree.
|
|
@@ -7986,7 +7987,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7986
7987
|
}
|
|
7987
7988
|
/**
|
|
7988
7989
|
* Clones the tree.
|
|
7989
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
7990
|
+
* @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.
|
|
7990
7991
|
*
|
|
7991
7992
|
* @returns A new, cloned instance of the tree.
|
|
7992
7993
|
*/
|
|
@@ -7997,7 +7998,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7997
7998
|
}
|
|
7998
7999
|
/**
|
|
7999
8000
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
8000
|
-
* @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) `
|
|
8001
|
+
* @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.
|
|
8001
8002
|
*
|
|
8002
8003
|
* @param predicate - A function to test each [key, value] pair.
|
|
8003
8004
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -8006,7 +8007,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8006
8007
|
filter(predicate, thisArg) {
|
|
8007
8008
|
const out = this._createInstance();
|
|
8008
8009
|
let i = 0;
|
|
8009
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
8010
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
8010
8011
|
return out;
|
|
8011
8012
|
}
|
|
8012
8013
|
/**
|
|
@@ -8024,7 +8025,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8024
8025
|
map(cb, options, thisArg) {
|
|
8025
8026
|
const out = this._createLike([], options);
|
|
8026
8027
|
let i = 0;
|
|
8027
|
-
for (const [k, v] of this) out.
|
|
8028
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
8028
8029
|
return out;
|
|
8029
8030
|
}
|
|
8030
8031
|
/**
|
|
@@ -8065,6 +8066,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8065
8066
|
* @param [startNode=this._root] - The node to start printing from.
|
|
8066
8067
|
*/
|
|
8067
8068
|
print(options, startNode = this._root) {
|
|
8069
|
+
console.log(this.toVisual(startNode, options));
|
|
8068
8070
|
}
|
|
8069
8071
|
/**
|
|
8070
8072
|
* (Protected) Core DFS implementation.
|
|
@@ -8269,18 +8271,18 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8269
8271
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
8270
8272
|
}
|
|
8271
8273
|
/**
|
|
8272
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
8273
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
8274
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
8275
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
8274
8276
|
*
|
|
8275
8277
|
* @param cloned - The new, empty tree instance to populate.
|
|
8276
8278
|
*/
|
|
8277
8279
|
_clone(cloned) {
|
|
8278
8280
|
this.bfs(
|
|
8279
8281
|
(node) => {
|
|
8280
|
-
if (node === null) cloned.
|
|
8282
|
+
if (node === null) cloned.set(null);
|
|
8281
8283
|
else {
|
|
8282
|
-
if (this._isMapMode) cloned.
|
|
8283
|
-
else cloned.
|
|
8284
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
8285
|
+
else cloned.set([node.key, node.value]);
|
|
8284
8286
|
}
|
|
8285
8287
|
},
|
|
8286
8288
|
this._root,
|
|
@@ -8611,7 +8613,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8611
8613
|
* Creates an instance of BST.
|
|
8612
8614
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
8613
8615
|
*
|
|
8614
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
8616
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
8615
8617
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
8616
8618
|
*/
|
|
8617
8619
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -8632,7 +8634,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8632
8634
|
} else {
|
|
8633
8635
|
this._comparator = this._createDefaultComparator();
|
|
8634
8636
|
}
|
|
8635
|
-
if (keysNodesEntriesOrRaws) this.
|
|
8637
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
8636
8638
|
}
|
|
8637
8639
|
/**
|
|
8638
8640
|
* Gets the root node of the tree.
|
|
@@ -8843,11 +8845,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8843
8845
|
* Adds a new node to the BST based on key comparison.
|
|
8844
8846
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
8845
8847
|
*
|
|
8846
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
8848
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
8847
8849
|
* @param [value] - The value, if providing just a key.
|
|
8848
8850
|
* @returns True if the addition was successful, false otherwise.
|
|
8849
8851
|
*/
|
|
8850
|
-
|
|
8852
|
+
set(keyNodeOrEntry, value) {
|
|
8851
8853
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
8852
8854
|
if (newNode === void 0) return false;
|
|
8853
8855
|
if (this._root === void 0) {
|
|
@@ -8884,24 +8886,24 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8884
8886
|
}
|
|
8885
8887
|
/**
|
|
8886
8888
|
* Adds multiple items to the tree.
|
|
8887
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
8889
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
8888
8890
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
8889
8891
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
8890
8892
|
*
|
|
8891
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
8893
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
8892
8894
|
* @param [values] - An optional parallel iterable of values.
|
|
8893
8895
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
8894
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
8895
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
8896
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
8897
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
8896
8898
|
*/
|
|
8897
|
-
|
|
8899
|
+
setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
8898
8900
|
const inserted = [];
|
|
8899
8901
|
const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
|
|
8900
8902
|
if (!isBalanceAdd) {
|
|
8901
8903
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
8902
8904
|
const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
|
|
8903
8905
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
8904
|
-
inserted.push(this.
|
|
8906
|
+
inserted.push(this.set(kve, val));
|
|
8905
8907
|
}
|
|
8906
8908
|
return inserted;
|
|
8907
8909
|
}
|
|
@@ -8929,9 +8931,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8929
8931
|
const { key, value, orgIndex } = arr[mid];
|
|
8930
8932
|
if (this.isRaw(key)) {
|
|
8931
8933
|
const entry = this._toEntryFn(key);
|
|
8932
|
-
inserted[orgIndex] = this.
|
|
8934
|
+
inserted[orgIndex] = this.set(entry);
|
|
8933
8935
|
} else {
|
|
8934
|
-
inserted[orgIndex] = this.
|
|
8936
|
+
inserted[orgIndex] = this.set(key, value);
|
|
8935
8937
|
}
|
|
8936
8938
|
_dfs(arr.slice(0, mid));
|
|
8937
8939
|
_dfs(arr.slice(mid + 1));
|
|
@@ -8948,9 +8950,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8948
8950
|
const { key, value, orgIndex } = sorted[m];
|
|
8949
8951
|
if (this.isRaw(key)) {
|
|
8950
8952
|
const entry = this._toEntryFn(key);
|
|
8951
|
-
inserted[orgIndex] = this.
|
|
8953
|
+
inserted[orgIndex] = this.set(entry);
|
|
8952
8954
|
} else {
|
|
8953
|
-
inserted[orgIndex] = this.
|
|
8955
|
+
inserted[orgIndex] = this.set(key, value);
|
|
8954
8956
|
}
|
|
8955
8957
|
stack.push([m + 1, r]);
|
|
8956
8958
|
stack.push([l, m - 1]);
|
|
@@ -9225,7 +9227,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
9225
9227
|
const out = this._createLike([], options);
|
|
9226
9228
|
let index = 0;
|
|
9227
9229
|
for (const [key, value] of this) {
|
|
9228
|
-
out.
|
|
9230
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
9229
9231
|
}
|
|
9230
9232
|
return out;
|
|
9231
9233
|
}
|
|
@@ -10411,14 +10413,14 @@ var AVLTreeNode = _AVLTreeNode;
|
|
|
10411
10413
|
var _AVLTree = class _AVLTree extends BST {
|
|
10412
10414
|
/**
|
|
10413
10415
|
* Creates an instance of AVLTree.
|
|
10414
|
-
* @remarks Time O(N log N) (from `
|
|
10416
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
10415
10417
|
*
|
|
10416
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
10418
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
10417
10419
|
* @param [options] - Configuration options for the AVL tree.
|
|
10418
10420
|
*/
|
|
10419
10421
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
10420
10422
|
super([], options);
|
|
10421
|
-
if (keysNodesEntriesOrRaws) super.
|
|
10423
|
+
if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
|
|
10422
10424
|
}
|
|
10423
10425
|
/**
|
|
10424
10426
|
* (Protected) Creates a new AVL tree node.
|
|
@@ -10442,16 +10444,16 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10442
10444
|
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
10443
10445
|
}
|
|
10444
10446
|
/**
|
|
10445
|
-
*
|
|
10446
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
10447
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
10448
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
10447
10449
|
*
|
|
10448
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
10450
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
10449
10451
|
* @param [value] - The value, if providing just a key.
|
|
10450
10452
|
* @returns True if the addition was successful, false otherwise.
|
|
10451
10453
|
*/
|
|
10452
|
-
|
|
10454
|
+
set(keyNodeOrEntry, value) {
|
|
10453
10455
|
if (keyNodeOrEntry === null) return false;
|
|
10454
|
-
const inserted = super.
|
|
10456
|
+
const inserted = super.set(keyNodeOrEntry, value);
|
|
10455
10457
|
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
10456
10458
|
return inserted;
|
|
10457
10459
|
}
|
|
@@ -10503,7 +10505,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10503
10505
|
}
|
|
10504
10506
|
/**
|
|
10505
10507
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
10506
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
10508
|
+
* @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.
|
|
10507
10509
|
*
|
|
10508
10510
|
* @template MK - New key type.
|
|
10509
10511
|
* @template MV - New value type.
|
|
@@ -10517,7 +10519,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10517
10519
|
const out = this._createLike([], options);
|
|
10518
10520
|
let index = 0;
|
|
10519
10521
|
for (const [key, value] of this) {
|
|
10520
|
-
out.
|
|
10522
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
10521
10523
|
}
|
|
10522
10524
|
return out;
|
|
10523
10525
|
}
|
|
@@ -10942,7 +10944,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
10942
10944
|
__publicField(this, "_root");
|
|
10943
10945
|
this._root = this.NIL;
|
|
10944
10946
|
if (keysNodesEntriesOrRaws) {
|
|
10945
|
-
this.
|
|
10947
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
10946
10948
|
}
|
|
10947
10949
|
}
|
|
10948
10950
|
/**
|
|
@@ -10989,7 +10991,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
10989
10991
|
* @param [value]- See parameter type for details.
|
|
10990
10992
|
* @returns True if inserted or updated; false if ignored.
|
|
10991
10993
|
*/
|
|
10992
|
-
|
|
10994
|
+
set(keyNodeOrEntry, value) {
|
|
10993
10995
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
10994
10996
|
if (!this.isRealNode(newNode)) return false;
|
|
10995
10997
|
const insertStatus = this._insert(newNode);
|
|
@@ -11083,7 +11085,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11083
11085
|
const out = this._createLike([], options);
|
|
11084
11086
|
let index = 0;
|
|
11085
11087
|
for (const [key, value] of this) {
|
|
11086
|
-
out.
|
|
11088
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
11087
11089
|
}
|
|
11088
11090
|
return out;
|
|
11089
11091
|
}
|
|
@@ -11472,7 +11474,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11472
11474
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11473
11475
|
super([], { ...options, isMapMode: true });
|
|
11474
11476
|
if (keysNodesEntriesOrRaws) {
|
|
11475
|
-
this.
|
|
11477
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
11476
11478
|
}
|
|
11477
11479
|
}
|
|
11478
11480
|
createNode(key, value = []) {
|
|
@@ -11492,27 +11494,27 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11492
11494
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
11493
11495
|
* @remarks Time O(log N + M), Space O(1)
|
|
11494
11496
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
11495
|
-
* @param [value] - Single value to
|
|
11497
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
11496
11498
|
* @returns True if inserted or appended; false if ignored.
|
|
11497
11499
|
*/
|
|
11498
|
-
|
|
11499
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
11500
|
+
set(keyNodeOrEntry, value) {
|
|
11501
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
11500
11502
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
11501
11503
|
if (key === void 0 || key === null) return false;
|
|
11502
|
-
const
|
|
11504
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
11503
11505
|
const existingValues = this.get(key);
|
|
11504
11506
|
if (existingValues !== void 0 && values !== void 0) {
|
|
11505
11507
|
for (const value2 of values) existingValues.push(value2);
|
|
11506
11508
|
return true;
|
|
11507
11509
|
}
|
|
11508
11510
|
return false;
|
|
11509
|
-
}, "
|
|
11510
|
-
const
|
|
11511
|
+
}, "_setToValues");
|
|
11512
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
11511
11513
|
const existingNode = this.getNode(key);
|
|
11512
11514
|
if (this.isRealNode(existingNode)) {
|
|
11513
11515
|
const existingValues = this.get(existingNode);
|
|
11514
11516
|
if (existingValues === void 0) {
|
|
11515
|
-
super.
|
|
11517
|
+
super.set(key, values);
|
|
11516
11518
|
return true;
|
|
11517
11519
|
}
|
|
11518
11520
|
if (values !== void 0) {
|
|
@@ -11522,13 +11524,13 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11522
11524
|
return false;
|
|
11523
11525
|
}
|
|
11524
11526
|
} else {
|
|
11525
|
-
return super.
|
|
11527
|
+
return super.set(key, values);
|
|
11526
11528
|
}
|
|
11527
|
-
}, "
|
|
11529
|
+
}, "_setByNode");
|
|
11528
11530
|
if (this._isMapMode) {
|
|
11529
|
-
return
|
|
11531
|
+
return _setByNode() || _setToValues();
|
|
11530
11532
|
}
|
|
11531
|
-
return
|
|
11533
|
+
return _setToValues() || _setByNode();
|
|
11532
11534
|
}, "_commonAdd");
|
|
11533
11535
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11534
11536
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -11596,7 +11598,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11596
11598
|
map(callback, options, thisArg) {
|
|
11597
11599
|
const out = this._createLike([], options);
|
|
11598
11600
|
let i = 0;
|
|
11599
|
-
for (const [k, v] of this) out.
|
|
11601
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
11600
11602
|
return out;
|
|
11601
11603
|
}
|
|
11602
11604
|
/**
|
|
@@ -11779,7 +11781,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11779
11781
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11780
11782
|
super([], { ...options });
|
|
11781
11783
|
if (keysNodesEntriesOrRaws) {
|
|
11782
|
-
this.
|
|
11784
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
11783
11785
|
}
|
|
11784
11786
|
}
|
|
11785
11787
|
createNode(key, value = []) {
|
|
@@ -11799,27 +11801,27 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11799
11801
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
11800
11802
|
* @remarks Time O(log N + M), Space O(1)
|
|
11801
11803
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
11802
|
-
* @param [value] - Single value to
|
|
11804
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
11803
11805
|
* @returns True if inserted or appended; false if ignored.
|
|
11804
11806
|
*/
|
|
11805
|
-
|
|
11806
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
11807
|
+
set(keyNodeOrEntry, value) {
|
|
11808
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
11807
11809
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
11808
11810
|
if (key === void 0 || key === null) return false;
|
|
11809
|
-
const
|
|
11811
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
11810
11812
|
const existingValues = this.get(key);
|
|
11811
11813
|
if (existingValues !== void 0 && values !== void 0) {
|
|
11812
11814
|
for (const value2 of values) existingValues.push(value2);
|
|
11813
11815
|
return true;
|
|
11814
11816
|
}
|
|
11815
11817
|
return false;
|
|
11816
|
-
}, "
|
|
11817
|
-
const
|
|
11818
|
+
}, "_setToValues");
|
|
11819
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
11818
11820
|
const existingNode = this.getNode(key);
|
|
11819
11821
|
if (this.isRealNode(existingNode)) {
|
|
11820
11822
|
const existingValues = this.get(existingNode);
|
|
11821
11823
|
if (existingValues === void 0) {
|
|
11822
|
-
super.
|
|
11824
|
+
super.set(key, values);
|
|
11823
11825
|
return true;
|
|
11824
11826
|
}
|
|
11825
11827
|
if (values !== void 0) {
|
|
@@ -11829,13 +11831,13 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11829
11831
|
return false;
|
|
11830
11832
|
}
|
|
11831
11833
|
} else {
|
|
11832
|
-
return super.
|
|
11834
|
+
return super.set(key, values);
|
|
11833
11835
|
}
|
|
11834
|
-
}, "
|
|
11836
|
+
}, "_setByNode");
|
|
11835
11837
|
if (this._isMapMode) {
|
|
11836
|
-
return
|
|
11838
|
+
return _setByNode() || _setToValues();
|
|
11837
11839
|
}
|
|
11838
|
-
return
|
|
11840
|
+
return _setToValues() || _setByNode();
|
|
11839
11841
|
}, "_commonAdd");
|
|
11840
11842
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11841
11843
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -11875,7 +11877,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11875
11877
|
map(callback, options, thisArg) {
|
|
11876
11878
|
const out = this._createLike([], options);
|
|
11877
11879
|
let i = 0;
|
|
11878
|
-
for (const [k, v] of this) out.
|
|
11880
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
11879
11881
|
return out;
|
|
11880
11882
|
}
|
|
11881
11883
|
/**
|
|
@@ -12061,7 +12063,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
|
12061
12063
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12062
12064
|
super([], options);
|
|
12063
12065
|
__publicField(this, "_count", 0);
|
|
12064
|
-
if (keysNodesEntriesOrRaws) this.
|
|
12066
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
12065
12067
|
}
|
|
12066
12068
|
/**
|
|
12067
12069
|
* Get the total aggregate count across all nodes.
|
|
@@ -12100,10 +12102,10 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
|
12100
12102
|
* @param [count] - How much to increase the node's count (default 1).
|
|
12101
12103
|
* @returns True if inserted/updated; false if ignored.
|
|
12102
12104
|
*/
|
|
12103
|
-
|
|
12105
|
+
set(keyNodeOrEntry, value, count = 1) {
|
|
12104
12106
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12105
12107
|
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12106
|
-
const isSuccessAdded = super.
|
|
12108
|
+
const isSuccessAdded = super.set(newNode, newValue);
|
|
12107
12109
|
if (isSuccessAdded) {
|
|
12108
12110
|
this._count += orgCount;
|
|
12109
12111
|
return true;
|
|
@@ -12256,7 +12258,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
|
12256
12258
|
const out = this._createLike([], options);
|
|
12257
12259
|
let index = 0;
|
|
12258
12260
|
for (const [key, value] of this) {
|
|
12259
|
-
out.
|
|
12261
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
12260
12262
|
}
|
|
12261
12263
|
return out;
|
|
12262
12264
|
}
|
|
@@ -12511,7 +12513,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12511
12513
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12512
12514
|
super([], options);
|
|
12513
12515
|
__publicField(this, "_count", 0);
|
|
12514
|
-
if (keysNodesEntriesOrRaws) this.
|
|
12516
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
12515
12517
|
}
|
|
12516
12518
|
get count() {
|
|
12517
12519
|
return this._count;
|
|
@@ -12545,11 +12547,11 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12545
12547
|
* @param [count] - How much to increase the node's count (default 1).
|
|
12546
12548
|
* @returns True if inserted/updated; false if ignored.
|
|
12547
12549
|
*/
|
|
12548
|
-
|
|
12550
|
+
set(keyNodeOrEntry, value, count = 1) {
|
|
12549
12551
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12550
12552
|
if (newNode === void 0) return false;
|
|
12551
12553
|
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12552
|
-
const inserted = super.
|
|
12554
|
+
const inserted = super.set(newNode, newValue);
|
|
12553
12555
|
if (inserted) {
|
|
12554
12556
|
this._count += orgNodeCount;
|
|
12555
12557
|
}
|
|
@@ -12658,9 +12660,9 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12658
12660
|
clone() {
|
|
12659
12661
|
const out = this._createInstance();
|
|
12660
12662
|
if (this._isMapMode) {
|
|
12661
|
-
this.bfs((node) => out.
|
|
12663
|
+
this.bfs((node) => out.set(node.key, void 0, node.count));
|
|
12662
12664
|
} else {
|
|
12663
|
-
this.bfs((node) => out.
|
|
12665
|
+
this.bfs((node) => out.set(node.key, node.value, node.count));
|
|
12664
12666
|
}
|
|
12665
12667
|
if (this._isMapMode) out._store = this._store;
|
|
12666
12668
|
return out;
|
|
@@ -12680,7 +12682,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12680
12682
|
const out = this._createLike([], options);
|
|
12681
12683
|
let index = 0;
|
|
12682
12684
|
for (const [key, value] of this) {
|
|
12683
|
-
out.
|
|
12685
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
12684
12686
|
}
|
|
12685
12687
|
return out;
|
|
12686
12688
|
}
|