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
|
@@ -180,6 +180,7 @@ var _IterableEntryBase = class _IterableEntryBase {
|
|
|
180
180
|
* @remarks Time O(n), Space O(n)
|
|
181
181
|
*/
|
|
182
182
|
print() {
|
|
183
|
+
console.log(this.toVisual());
|
|
183
184
|
}
|
|
184
185
|
};
|
|
185
186
|
__name(_IterableEntryBase, "IterableEntryBase");
|
|
@@ -401,6 +402,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
401
402
|
* Time O(n) due to materialization, Space O(n) for the intermediate representation.
|
|
402
403
|
*/
|
|
403
404
|
print() {
|
|
405
|
+
console.log(this.toVisual());
|
|
404
406
|
}
|
|
405
407
|
};
|
|
406
408
|
__name(_IterableElementBase, "IterableElementBase");
|
|
@@ -6971,9 +6973,9 @@ var BinaryTreeNode = _BinaryTreeNode;
|
|
|
6971
6973
|
var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
6972
6974
|
/**
|
|
6973
6975
|
* Creates an instance of BinaryTree.
|
|
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) `
|
|
6976
|
+
* @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.
|
|
6975
6977
|
*
|
|
6976
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
6978
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
6977
6979
|
* @param [options] - Configuration options for the tree.
|
|
6978
6980
|
*/
|
|
6979
6981
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -7002,7 +7004,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7002
7004
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
7003
7005
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
7004
7006
|
}
|
|
7005
|
-
if (keysNodesEntriesOrRaws) this.
|
|
7007
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
7006
7008
|
}
|
|
7007
7009
|
/**
|
|
7008
7010
|
* Gets whether the tree is in Map mode.
|
|
@@ -7209,10 +7211,20 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7209
7211
|
* @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).
|
|
7210
7212
|
*
|
|
7211
7213
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
7214
|
+
* @returns True if the addition was successful, false otherwise.
|
|
7215
|
+
*/
|
|
7216
|
+
add(keyNodeOrEntry) {
|
|
7217
|
+
return this.set(keyNodeOrEntry);
|
|
7218
|
+
}
|
|
7219
|
+
/**
|
|
7220
|
+
* Adds or updates a new node to the tree.
|
|
7221
|
+
* @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).
|
|
7222
|
+
*
|
|
7223
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
7212
7224
|
* @param [value] - The value, if providing just a key.
|
|
7213
7225
|
* @returns True if the addition was successful, false otherwise.
|
|
7214
7226
|
*/
|
|
7215
|
-
|
|
7227
|
+
set(keyNodeOrEntry, value) {
|
|
7216
7228
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
7217
7229
|
if (newNode === void 0) return false;
|
|
7218
7230
|
if (!this._root) {
|
|
@@ -7256,25 +7268,25 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7256
7268
|
return false;
|
|
7257
7269
|
}
|
|
7258
7270
|
/**
|
|
7259
|
-
* Adds
|
|
7260
|
-
* @remarks Time O(
|
|
7271
|
+
* Adds multiple items to the tree.
|
|
7272
|
+
* @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).
|
|
7261
7273
|
*
|
|
7262
|
-
* @param
|
|
7263
|
-
* @param [
|
|
7264
|
-
* @returns
|
|
7274
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
7275
|
+
* @param [values] - An optional parallel iterable of values.
|
|
7276
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
7265
7277
|
*/
|
|
7266
|
-
|
|
7267
|
-
return this.
|
|
7278
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
7279
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
7268
7280
|
}
|
|
7269
7281
|
/**
|
|
7270
|
-
* Adds multiple items to the tree.
|
|
7271
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
7282
|
+
* Adds or updates multiple items to the tree.
|
|
7283
|
+
* @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).
|
|
7272
7284
|
*
|
|
7273
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
7285
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
7274
7286
|
* @param [values] - An optional parallel iterable of values.
|
|
7275
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
7287
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
7276
7288
|
*/
|
|
7277
|
-
|
|
7289
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
7278
7290
|
const inserted = [];
|
|
7279
7291
|
let valuesIterator;
|
|
7280
7292
|
if (values) {
|
|
@@ -7289,40 +7301,29 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7289
7301
|
}
|
|
7290
7302
|
}
|
|
7291
7303
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
7292
|
-
inserted.push(this.
|
|
7304
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
7293
7305
|
}
|
|
7294
7306
|
return inserted;
|
|
7295
7307
|
}
|
|
7296
7308
|
/**
|
|
7297
|
-
*
|
|
7298
|
-
* @remarks Time O(N * M), where N is the
|
|
7299
|
-
*
|
|
7300
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
7301
|
-
* @param [values] - An optional parallel iterable of values.
|
|
7302
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
7303
|
-
*/
|
|
7304
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
7305
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
7306
|
-
}
|
|
7307
|
-
/**
|
|
7308
|
-
* Merges another tree into this one by adding all its nodes.
|
|
7309
|
-
* @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`).
|
|
7309
|
+
* Merges another tree into this one by seting all its nodes.
|
|
7310
|
+
* @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`).
|
|
7310
7311
|
*
|
|
7311
7312
|
* @param anotherTree - The tree to merge.
|
|
7312
7313
|
*/
|
|
7313
7314
|
merge(anotherTree) {
|
|
7314
|
-
this.
|
|
7315
|
+
this.setMany(anotherTree, []);
|
|
7315
7316
|
}
|
|
7316
7317
|
/**
|
|
7317
7318
|
* Clears the tree and refills it with new items.
|
|
7318
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
7319
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
7319
7320
|
*
|
|
7320
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
7321
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
7321
7322
|
* @param [values] - An optional parallel iterable of values.
|
|
7322
7323
|
*/
|
|
7323
7324
|
refill(keysNodesEntriesOrRaws, values) {
|
|
7324
7325
|
this.clear();
|
|
7325
|
-
this.
|
|
7326
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
7326
7327
|
}
|
|
7327
7328
|
/**
|
|
7328
7329
|
* Deletes a node from the tree.
|
|
@@ -7988,7 +7989,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7988
7989
|
}
|
|
7989
7990
|
/**
|
|
7990
7991
|
* Clones the tree.
|
|
7991
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
7992
|
+
* @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.
|
|
7992
7993
|
*
|
|
7993
7994
|
* @returns A new, cloned instance of the tree.
|
|
7994
7995
|
*/
|
|
@@ -7999,7 +8000,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
7999
8000
|
}
|
|
8000
8001
|
/**
|
|
8001
8002
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
8002
|
-
* @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) `
|
|
8003
|
+
* @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.
|
|
8003
8004
|
*
|
|
8004
8005
|
* @param predicate - A function to test each [key, value] pair.
|
|
8005
8006
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -8008,7 +8009,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8008
8009
|
filter(predicate, thisArg) {
|
|
8009
8010
|
const out = this._createInstance();
|
|
8010
8011
|
let i = 0;
|
|
8011
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
8012
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
8012
8013
|
return out;
|
|
8013
8014
|
}
|
|
8014
8015
|
/**
|
|
@@ -8026,7 +8027,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8026
8027
|
map(cb, options, thisArg) {
|
|
8027
8028
|
const out = this._createLike([], options);
|
|
8028
8029
|
let i = 0;
|
|
8029
|
-
for (const [k, v] of this) out.
|
|
8030
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
8030
8031
|
return out;
|
|
8031
8032
|
}
|
|
8032
8033
|
/**
|
|
@@ -8067,6 +8068,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8067
8068
|
* @param [startNode=this._root] - The node to start printing from.
|
|
8068
8069
|
*/
|
|
8069
8070
|
print(options, startNode = this._root) {
|
|
8071
|
+
console.log(this.toVisual(startNode, options));
|
|
8070
8072
|
}
|
|
8071
8073
|
/**
|
|
8072
8074
|
* (Protected) Core DFS implementation.
|
|
@@ -8271,18 +8273,18 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
8271
8273
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
8272
8274
|
}
|
|
8273
8275
|
/**
|
|
8274
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
8275
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
8276
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
8277
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
8276
8278
|
*
|
|
8277
8279
|
* @param cloned - The new, empty tree instance to populate.
|
|
8278
8280
|
*/
|
|
8279
8281
|
_clone(cloned) {
|
|
8280
8282
|
this.bfs(
|
|
8281
8283
|
(node) => {
|
|
8282
|
-
if (node === null) cloned.
|
|
8284
|
+
if (node === null) cloned.set(null);
|
|
8283
8285
|
else {
|
|
8284
|
-
if (this._isMapMode) cloned.
|
|
8285
|
-
else cloned.
|
|
8286
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
8287
|
+
else cloned.set([node.key, node.value]);
|
|
8286
8288
|
}
|
|
8287
8289
|
},
|
|
8288
8290
|
this._root,
|
|
@@ -8613,7 +8615,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8613
8615
|
* Creates an instance of BST.
|
|
8614
8616
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
8615
8617
|
*
|
|
8616
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
8618
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
8617
8619
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
8618
8620
|
*/
|
|
8619
8621
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -8634,7 +8636,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8634
8636
|
} else {
|
|
8635
8637
|
this._comparator = this._createDefaultComparator();
|
|
8636
8638
|
}
|
|
8637
|
-
if (keysNodesEntriesOrRaws) this.
|
|
8639
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
8638
8640
|
}
|
|
8639
8641
|
/**
|
|
8640
8642
|
* Gets the root node of the tree.
|
|
@@ -8845,11 +8847,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8845
8847
|
* Adds a new node to the BST based on key comparison.
|
|
8846
8848
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
8847
8849
|
*
|
|
8848
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
8850
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
8849
8851
|
* @param [value] - The value, if providing just a key.
|
|
8850
8852
|
* @returns True if the addition was successful, false otherwise.
|
|
8851
8853
|
*/
|
|
8852
|
-
|
|
8854
|
+
set(keyNodeOrEntry, value) {
|
|
8853
8855
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
8854
8856
|
if (newNode === void 0) return false;
|
|
8855
8857
|
if (this._root === void 0) {
|
|
@@ -8886,24 +8888,24 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8886
8888
|
}
|
|
8887
8889
|
/**
|
|
8888
8890
|
* Adds multiple items to the tree.
|
|
8889
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
8891
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
8890
8892
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
8891
8893
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
8892
8894
|
*
|
|
8893
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
8895
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
8894
8896
|
* @param [values] - An optional parallel iterable of values.
|
|
8895
8897
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
8896
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
8897
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
8898
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
8899
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
8898
8900
|
*/
|
|
8899
|
-
|
|
8901
|
+
setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
8900
8902
|
const inserted = [];
|
|
8901
8903
|
const valuesIterator = values == null ? void 0 : values[Symbol.iterator]();
|
|
8902
8904
|
if (!isBalanceAdd) {
|
|
8903
8905
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
8904
8906
|
const val = valuesIterator == null ? void 0 : valuesIterator.next().value;
|
|
8905
8907
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
8906
|
-
inserted.push(this.
|
|
8908
|
+
inserted.push(this.set(kve, val));
|
|
8907
8909
|
}
|
|
8908
8910
|
return inserted;
|
|
8909
8911
|
}
|
|
@@ -8931,9 +8933,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8931
8933
|
const { key, value, orgIndex } = arr[mid];
|
|
8932
8934
|
if (this.isRaw(key)) {
|
|
8933
8935
|
const entry = this._toEntryFn(key);
|
|
8934
|
-
inserted[orgIndex] = this.
|
|
8936
|
+
inserted[orgIndex] = this.set(entry);
|
|
8935
8937
|
} else {
|
|
8936
|
-
inserted[orgIndex] = this.
|
|
8938
|
+
inserted[orgIndex] = this.set(key, value);
|
|
8937
8939
|
}
|
|
8938
8940
|
_dfs(arr.slice(0, mid));
|
|
8939
8941
|
_dfs(arr.slice(mid + 1));
|
|
@@ -8950,9 +8952,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
8950
8952
|
const { key, value, orgIndex } = sorted[m];
|
|
8951
8953
|
if (this.isRaw(key)) {
|
|
8952
8954
|
const entry = this._toEntryFn(key);
|
|
8953
|
-
inserted[orgIndex] = this.
|
|
8955
|
+
inserted[orgIndex] = this.set(entry);
|
|
8954
8956
|
} else {
|
|
8955
|
-
inserted[orgIndex] = this.
|
|
8957
|
+
inserted[orgIndex] = this.set(key, value);
|
|
8956
8958
|
}
|
|
8957
8959
|
stack.push([m + 1, r]);
|
|
8958
8960
|
stack.push([l, m - 1]);
|
|
@@ -9227,7 +9229,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
9227
9229
|
const out = this._createLike([], options);
|
|
9228
9230
|
let index = 0;
|
|
9229
9231
|
for (const [key, value] of this) {
|
|
9230
|
-
out.
|
|
9232
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
9231
9233
|
}
|
|
9232
9234
|
return out;
|
|
9233
9235
|
}
|
|
@@ -10413,14 +10415,14 @@ var AVLTreeNode = _AVLTreeNode;
|
|
|
10413
10415
|
var _AVLTree = class _AVLTree extends BST {
|
|
10414
10416
|
/**
|
|
10415
10417
|
* Creates an instance of AVLTree.
|
|
10416
|
-
* @remarks Time O(N log N) (from `
|
|
10418
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
10417
10419
|
*
|
|
10418
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
10420
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
10419
10421
|
* @param [options] - Configuration options for the AVL tree.
|
|
10420
10422
|
*/
|
|
10421
10423
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
10422
10424
|
super([], options);
|
|
10423
|
-
if (keysNodesEntriesOrRaws) super.
|
|
10425
|
+
if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
|
|
10424
10426
|
}
|
|
10425
10427
|
/**
|
|
10426
10428
|
* (Protected) Creates a new AVL tree node.
|
|
@@ -10444,16 +10446,16 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10444
10446
|
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
10445
10447
|
}
|
|
10446
10448
|
/**
|
|
10447
|
-
*
|
|
10448
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
10449
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
10450
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
10449
10451
|
*
|
|
10450
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
10452
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
10451
10453
|
* @param [value] - The value, if providing just a key.
|
|
10452
10454
|
* @returns True if the addition was successful, false otherwise.
|
|
10453
10455
|
*/
|
|
10454
|
-
|
|
10456
|
+
set(keyNodeOrEntry, value) {
|
|
10455
10457
|
if (keyNodeOrEntry === null) return false;
|
|
10456
|
-
const inserted = super.
|
|
10458
|
+
const inserted = super.set(keyNodeOrEntry, value);
|
|
10457
10459
|
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
10458
10460
|
return inserted;
|
|
10459
10461
|
}
|
|
@@ -10505,7 +10507,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10505
10507
|
}
|
|
10506
10508
|
/**
|
|
10507
10509
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
10508
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
10510
|
+
* @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.
|
|
10509
10511
|
*
|
|
10510
10512
|
* @template MK - New key type.
|
|
10511
10513
|
* @template MV - New value type.
|
|
@@ -10519,7 +10521,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
10519
10521
|
const out = this._createLike([], options);
|
|
10520
10522
|
let index = 0;
|
|
10521
10523
|
for (const [key, value] of this) {
|
|
10522
|
-
out.
|
|
10524
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
10523
10525
|
}
|
|
10524
10526
|
return out;
|
|
10525
10527
|
}
|
|
@@ -10944,7 +10946,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
10944
10946
|
__publicField(this, "_root");
|
|
10945
10947
|
this._root = this.NIL;
|
|
10946
10948
|
if (keysNodesEntriesOrRaws) {
|
|
10947
|
-
this.
|
|
10949
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
10948
10950
|
}
|
|
10949
10951
|
}
|
|
10950
10952
|
/**
|
|
@@ -10991,7 +10993,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
10991
10993
|
* @param [value]- See parameter type for details.
|
|
10992
10994
|
* @returns True if inserted or updated; false if ignored.
|
|
10993
10995
|
*/
|
|
10994
|
-
|
|
10996
|
+
set(keyNodeOrEntry, value) {
|
|
10995
10997
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
10996
10998
|
if (!this.isRealNode(newNode)) return false;
|
|
10997
10999
|
const insertStatus = this._insert(newNode);
|
|
@@ -11085,7 +11087,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
11085
11087
|
const out = this._createLike([], options);
|
|
11086
11088
|
let index = 0;
|
|
11087
11089
|
for (const [key, value] of this) {
|
|
11088
|
-
out.
|
|
11090
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
11089
11091
|
}
|
|
11090
11092
|
return out;
|
|
11091
11093
|
}
|
|
@@ -11474,7 +11476,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11474
11476
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11475
11477
|
super([], { ...options, isMapMode: true });
|
|
11476
11478
|
if (keysNodesEntriesOrRaws) {
|
|
11477
|
-
this.
|
|
11479
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
11478
11480
|
}
|
|
11479
11481
|
}
|
|
11480
11482
|
createNode(key, value = []) {
|
|
@@ -11494,27 +11496,27 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11494
11496
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
11495
11497
|
* @remarks Time O(log N + M), Space O(1)
|
|
11496
11498
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
11497
|
-
* @param [value] - Single value to
|
|
11499
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
11498
11500
|
* @returns True if inserted or appended; false if ignored.
|
|
11499
11501
|
*/
|
|
11500
|
-
|
|
11501
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
11502
|
+
set(keyNodeOrEntry, value) {
|
|
11503
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
11502
11504
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
11503
11505
|
if (key === void 0 || key === null) return false;
|
|
11504
|
-
const
|
|
11506
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
11505
11507
|
const existingValues = this.get(key);
|
|
11506
11508
|
if (existingValues !== void 0 && values !== void 0) {
|
|
11507
11509
|
for (const value2 of values) existingValues.push(value2);
|
|
11508
11510
|
return true;
|
|
11509
11511
|
}
|
|
11510
11512
|
return false;
|
|
11511
|
-
}, "
|
|
11512
|
-
const
|
|
11513
|
+
}, "_setToValues");
|
|
11514
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
11513
11515
|
const existingNode = this.getNode(key);
|
|
11514
11516
|
if (this.isRealNode(existingNode)) {
|
|
11515
11517
|
const existingValues = this.get(existingNode);
|
|
11516
11518
|
if (existingValues === void 0) {
|
|
11517
|
-
super.
|
|
11519
|
+
super.set(key, values);
|
|
11518
11520
|
return true;
|
|
11519
11521
|
}
|
|
11520
11522
|
if (values !== void 0) {
|
|
@@ -11524,13 +11526,13 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11524
11526
|
return false;
|
|
11525
11527
|
}
|
|
11526
11528
|
} else {
|
|
11527
|
-
return super.
|
|
11529
|
+
return super.set(key, values);
|
|
11528
11530
|
}
|
|
11529
|
-
}, "
|
|
11531
|
+
}, "_setByNode");
|
|
11530
11532
|
if (this._isMapMode) {
|
|
11531
|
-
return
|
|
11533
|
+
return _setByNode() || _setToValues();
|
|
11532
11534
|
}
|
|
11533
|
-
return
|
|
11535
|
+
return _setToValues() || _setByNode();
|
|
11534
11536
|
}, "_commonAdd");
|
|
11535
11537
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11536
11538
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -11598,7 +11600,7 @@ var _AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
|
|
|
11598
11600
|
map(callback, options, thisArg) {
|
|
11599
11601
|
const out = this._createLike([], options);
|
|
11600
11602
|
let i = 0;
|
|
11601
|
-
for (const [k, v] of this) out.
|
|
11603
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
11602
11604
|
return out;
|
|
11603
11605
|
}
|
|
11604
11606
|
/**
|
|
@@ -11781,7 +11783,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11781
11783
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11782
11784
|
super([], { ...options });
|
|
11783
11785
|
if (keysNodesEntriesOrRaws) {
|
|
11784
|
-
this.
|
|
11786
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
11785
11787
|
}
|
|
11786
11788
|
}
|
|
11787
11789
|
createNode(key, value = []) {
|
|
@@ -11801,27 +11803,27 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11801
11803
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
11802
11804
|
* @remarks Time O(log N + M), Space O(1)
|
|
11803
11805
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
11804
|
-
* @param [value] - Single value to
|
|
11806
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
11805
11807
|
* @returns True if inserted or appended; false if ignored.
|
|
11806
11808
|
*/
|
|
11807
|
-
|
|
11808
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
11809
|
+
set(keyNodeOrEntry, value) {
|
|
11810
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
11809
11811
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
11810
11812
|
if (key === void 0 || key === null) return false;
|
|
11811
|
-
const
|
|
11813
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
11812
11814
|
const existingValues = this.get(key);
|
|
11813
11815
|
if (existingValues !== void 0 && values !== void 0) {
|
|
11814
11816
|
for (const value2 of values) existingValues.push(value2);
|
|
11815
11817
|
return true;
|
|
11816
11818
|
}
|
|
11817
11819
|
return false;
|
|
11818
|
-
}, "
|
|
11819
|
-
const
|
|
11820
|
+
}, "_setToValues");
|
|
11821
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
11820
11822
|
const existingNode = this.getNode(key);
|
|
11821
11823
|
if (this.isRealNode(existingNode)) {
|
|
11822
11824
|
const existingValues = this.get(existingNode);
|
|
11823
11825
|
if (existingValues === void 0) {
|
|
11824
|
-
super.
|
|
11826
|
+
super.set(key, values);
|
|
11825
11827
|
return true;
|
|
11826
11828
|
}
|
|
11827
11829
|
if (values !== void 0) {
|
|
@@ -11831,13 +11833,13 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11831
11833
|
return false;
|
|
11832
11834
|
}
|
|
11833
11835
|
} else {
|
|
11834
|
-
return super.
|
|
11836
|
+
return super.set(key, values);
|
|
11835
11837
|
}
|
|
11836
|
-
}, "
|
|
11838
|
+
}, "_setByNode");
|
|
11837
11839
|
if (this._isMapMode) {
|
|
11838
|
-
return
|
|
11840
|
+
return _setByNode() || _setToValues();
|
|
11839
11841
|
}
|
|
11840
|
-
return
|
|
11842
|
+
return _setToValues() || _setByNode();
|
|
11841
11843
|
}, "_commonAdd");
|
|
11842
11844
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11843
11845
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -11877,7 +11879,7 @@ var _TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
|
|
|
11877
11879
|
map(callback, options, thisArg) {
|
|
11878
11880
|
const out = this._createLike([], options);
|
|
11879
11881
|
let i = 0;
|
|
11880
|
-
for (const [k, v] of this) out.
|
|
11882
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
11881
11883
|
return out;
|
|
11882
11884
|
}
|
|
11883
11885
|
/**
|
|
@@ -12063,7 +12065,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
|
12063
12065
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12064
12066
|
super([], options);
|
|
12065
12067
|
__publicField(this, "_count", 0);
|
|
12066
|
-
if (keysNodesEntriesOrRaws) this.
|
|
12068
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
12067
12069
|
}
|
|
12068
12070
|
/**
|
|
12069
12071
|
* Get the total aggregate count across all nodes.
|
|
@@ -12102,10 +12104,10 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
|
12102
12104
|
* @param [count] - How much to increase the node's count (default 1).
|
|
12103
12105
|
* @returns True if inserted/updated; false if ignored.
|
|
12104
12106
|
*/
|
|
12105
|
-
|
|
12107
|
+
set(keyNodeOrEntry, value, count = 1) {
|
|
12106
12108
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12107
12109
|
const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12108
|
-
const isSuccessAdded = super.
|
|
12110
|
+
const isSuccessAdded = super.set(newNode, newValue);
|
|
12109
12111
|
if (isSuccessAdded) {
|
|
12110
12112
|
this._count += orgCount;
|
|
12111
12113
|
return true;
|
|
@@ -12258,7 +12260,7 @@ var _TreeCounter = class _TreeCounter extends RedBlackTree {
|
|
|
12258
12260
|
const out = this._createLike([], options);
|
|
12259
12261
|
let index = 0;
|
|
12260
12262
|
for (const [key, value] of this) {
|
|
12261
|
-
out.
|
|
12263
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
12262
12264
|
}
|
|
12263
12265
|
return out;
|
|
12264
12266
|
}
|
|
@@ -12513,7 +12515,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12513
12515
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12514
12516
|
super([], options);
|
|
12515
12517
|
__publicField(this, "_count", 0);
|
|
12516
|
-
if (keysNodesEntriesOrRaws) this.
|
|
12518
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
12517
12519
|
}
|
|
12518
12520
|
get count() {
|
|
12519
12521
|
return this._count;
|
|
@@ -12547,11 +12549,11 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12547
12549
|
* @param [count] - How much to increase the node's count (default 1).
|
|
12548
12550
|
* @returns True if inserted/updated; false if ignored.
|
|
12549
12551
|
*/
|
|
12550
|
-
|
|
12552
|
+
set(keyNodeOrEntry, value, count = 1) {
|
|
12551
12553
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12552
12554
|
if (newNode === void 0) return false;
|
|
12553
12555
|
const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
|
|
12554
|
-
const inserted = super.
|
|
12556
|
+
const inserted = super.set(newNode, newValue);
|
|
12555
12557
|
if (inserted) {
|
|
12556
12558
|
this._count += orgNodeCount;
|
|
12557
12559
|
}
|
|
@@ -12660,9 +12662,9 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12660
12662
|
clone() {
|
|
12661
12663
|
const out = this._createInstance();
|
|
12662
12664
|
if (this._isMapMode) {
|
|
12663
|
-
this.bfs((node) => out.
|
|
12665
|
+
this.bfs((node) => out.set(node.key, void 0, node.count));
|
|
12664
12666
|
} else {
|
|
12665
|
-
this.bfs((node) => out.
|
|
12667
|
+
this.bfs((node) => out.set(node.key, node.value, node.count));
|
|
12666
12668
|
}
|
|
12667
12669
|
if (this._isMapMode) out._store = this._store;
|
|
12668
12670
|
return out;
|
|
@@ -12682,7 +12684,7 @@ var _AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
|
|
|
12682
12684
|
const out = this._createLike([], options);
|
|
12683
12685
|
let index = 0;
|
|
12684
12686
|
for (const [key, value] of this) {
|
|
12685
|
-
out.
|
|
12687
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
12686
12688
|
}
|
|
12687
12689
|
return out;
|
|
12688
12690
|
}
|