data-structure-typed 2.2.7 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +14 -3
- package/README_CN.md +119 -275
- package/benchmark/report.html +1 -1
- package/benchmark/report.json +20 -324
- package/dist/cjs/index.cjs +106 -107
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +106 -107
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +106 -107
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +106 -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 +102 -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.umd.config.js +29 -0
- package/tsup.node.config.js +0 -83
package/dist/esm/index.mjs
CHANGED
|
@@ -6993,9 +6993,9 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
6993
6993
|
iterationType = "ITERATIVE";
|
|
6994
6994
|
/**
|
|
6995
6995
|
* Creates an instance of BinaryTree.
|
|
6996
|
-
* @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) `
|
|
6996
|
+
* @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.
|
|
6997
6997
|
*
|
|
6998
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
6998
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
6999
6999
|
* @param [options] - Configuration options for the tree.
|
|
7000
7000
|
*/
|
|
7001
7001
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -7008,7 +7008,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7008
7008
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
7009
7009
|
else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
|
|
7010
7010
|
}
|
|
7011
|
-
if (keysNodesEntriesOrRaws) this.
|
|
7011
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
7012
7012
|
}
|
|
7013
7013
|
_isMapMode = true;
|
|
7014
7014
|
/**
|
|
@@ -7222,10 +7222,20 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7222
7222
|
* @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).
|
|
7223
7223
|
*
|
|
7224
7224
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
7225
|
+
* @returns True if the addition was successful, false otherwise.
|
|
7226
|
+
*/
|
|
7227
|
+
add(keyNodeOrEntry) {
|
|
7228
|
+
return this.set(keyNodeOrEntry);
|
|
7229
|
+
}
|
|
7230
|
+
/**
|
|
7231
|
+
* Adds or updates a new node to the tree.
|
|
7232
|
+
* @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).
|
|
7233
|
+
*
|
|
7234
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
7225
7235
|
* @param [value] - The value, if providing just a key.
|
|
7226
7236
|
* @returns True if the addition was successful, false otherwise.
|
|
7227
7237
|
*/
|
|
7228
|
-
|
|
7238
|
+
set(keyNodeOrEntry, value) {
|
|
7229
7239
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
7230
7240
|
if (newNode === void 0) return false;
|
|
7231
7241
|
if (!this._root) {
|
|
@@ -7269,25 +7279,25 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7269
7279
|
return false;
|
|
7270
7280
|
}
|
|
7271
7281
|
/**
|
|
7272
|
-
* Adds
|
|
7273
|
-
* @remarks Time O(
|
|
7282
|
+
* Adds 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).
|
|
7274
7284
|
*
|
|
7275
|
-
* @param
|
|
7276
|
-
* @param [
|
|
7277
|
-
* @returns
|
|
7285
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
7286
|
+
* @param [values] - An optional parallel iterable of values.
|
|
7287
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
7278
7288
|
*/
|
|
7279
|
-
|
|
7280
|
-
return this.
|
|
7289
|
+
addMany(keysNodesEntriesOrRaws) {
|
|
7290
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
7281
7291
|
}
|
|
7282
7292
|
/**
|
|
7283
|
-
* Adds multiple items to the tree.
|
|
7284
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
7293
|
+
* Adds or updates multiple items to the tree.
|
|
7294
|
+
* @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).
|
|
7285
7295
|
*
|
|
7286
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
7296
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
7287
7297
|
* @param [values] - An optional parallel iterable of values.
|
|
7288
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
7298
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
7289
7299
|
*/
|
|
7290
|
-
|
|
7300
|
+
setMany(keysNodesEntriesOrRaws, values) {
|
|
7291
7301
|
const inserted = [];
|
|
7292
7302
|
let valuesIterator;
|
|
7293
7303
|
if (values) {
|
|
@@ -7302,40 +7312,29 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
7302
7312
|
}
|
|
7303
7313
|
}
|
|
7304
7314
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
|
|
7305
|
-
inserted.push(this.
|
|
7315
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
7306
7316
|
}
|
|
7307
7317
|
return inserted;
|
|
7308
7318
|
}
|
|
7309
7319
|
/**
|
|
7310
|
-
*
|
|
7311
|
-
* @remarks Time O(N * M), where N is the
|
|
7312
|
-
*
|
|
7313
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
7314
|
-
* @param [values] - An optional parallel iterable of values.
|
|
7315
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
7316
|
-
*/
|
|
7317
|
-
setMany(keysNodesEntriesOrRaws, values) {
|
|
7318
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
7319
|
-
}
|
|
7320
|
-
/**
|
|
7321
|
-
* Merges another tree into this one by adding all its nodes.
|
|
7322
|
-
* @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`).
|
|
7320
|
+
* Merges another tree into this one by seting all its nodes.
|
|
7321
|
+
* @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`).
|
|
7323
7322
|
*
|
|
7324
7323
|
* @param anotherTree - The tree to merge.
|
|
7325
7324
|
*/
|
|
7326
7325
|
merge(anotherTree) {
|
|
7327
|
-
this.
|
|
7326
|
+
this.setMany(anotherTree, []);
|
|
7328
7327
|
}
|
|
7329
7328
|
/**
|
|
7330
7329
|
* Clears the tree and refills it with new items.
|
|
7331
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
7330
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
7332
7331
|
*
|
|
7333
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
7332
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
7334
7333
|
* @param [values] - An optional parallel iterable of values.
|
|
7335
7334
|
*/
|
|
7336
7335
|
refill(keysNodesEntriesOrRaws, values) {
|
|
7337
7336
|
this.clear();
|
|
7338
|
-
this.
|
|
7337
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
7339
7338
|
}
|
|
7340
7339
|
/**
|
|
7341
7340
|
* Deletes a node from the tree.
|
|
@@ -8000,7 +7999,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8000
7999
|
}
|
|
8001
8000
|
/**
|
|
8002
8001
|
* Clones the tree.
|
|
8003
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
8002
|
+
* @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.
|
|
8004
8003
|
*
|
|
8005
8004
|
* @returns A new, cloned instance of the tree.
|
|
8006
8005
|
*/
|
|
@@ -8011,7 +8010,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8011
8010
|
}
|
|
8012
8011
|
/**
|
|
8013
8012
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
8014
|
-
* @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) `
|
|
8013
|
+
* @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.
|
|
8015
8014
|
*
|
|
8016
8015
|
* @param predicate - A function to test each [key, value] pair.
|
|
8017
8016
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -8020,7 +8019,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8020
8019
|
filter(predicate, thisArg) {
|
|
8021
8020
|
const out = this._createInstance();
|
|
8022
8021
|
let i = 0;
|
|
8023
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
8022
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
8024
8023
|
return out;
|
|
8025
8024
|
}
|
|
8026
8025
|
/**
|
|
@@ -8038,7 +8037,7 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8038
8037
|
map(cb, options, thisArg) {
|
|
8039
8038
|
const out = this._createLike([], options);
|
|
8040
8039
|
let i = 0;
|
|
8041
|
-
for (const [k, v] of this) out.
|
|
8040
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
8042
8041
|
return out;
|
|
8043
8042
|
}
|
|
8044
8043
|
/**
|
|
@@ -8290,18 +8289,18 @@ var BinaryTree = class extends IterableEntryBase {
|
|
|
8290
8289
|
return [this.createNode(keyNodeOrEntry, value), value];
|
|
8291
8290
|
}
|
|
8292
8291
|
/**
|
|
8293
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
8294
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
8292
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
8293
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
8295
8294
|
*
|
|
8296
8295
|
* @param cloned - The new, empty tree instance to populate.
|
|
8297
8296
|
*/
|
|
8298
8297
|
_clone(cloned) {
|
|
8299
8298
|
this.bfs(
|
|
8300
8299
|
(node) => {
|
|
8301
|
-
if (node === null) cloned.
|
|
8300
|
+
if (node === null) cloned.set(null);
|
|
8302
8301
|
else {
|
|
8303
|
-
if (this._isMapMode) cloned.
|
|
8304
|
-
else cloned.
|
|
8302
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
8303
|
+
else cloned.set([node.key, node.value]);
|
|
8305
8304
|
}
|
|
8306
8305
|
},
|
|
8307
8306
|
this._root,
|
|
@@ -8634,7 +8633,7 @@ var BST = class extends BinaryTree {
|
|
|
8634
8633
|
* Creates an instance of BST.
|
|
8635
8634
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
8636
8635
|
*
|
|
8637
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
8636
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
8638
8637
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
8639
8638
|
*/
|
|
8640
8639
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
@@ -8648,7 +8647,7 @@ var BST = class extends BinaryTree {
|
|
|
8648
8647
|
} else {
|
|
8649
8648
|
this._comparator = this._createDefaultComparator();
|
|
8650
8649
|
}
|
|
8651
|
-
if (keysNodesEntriesOrRaws) this.
|
|
8650
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
8652
8651
|
}
|
|
8653
8652
|
_root = void 0;
|
|
8654
8653
|
/**
|
|
@@ -8864,11 +8863,11 @@ var BST = class extends BinaryTree {
|
|
|
8864
8863
|
* Adds a new node to the BST based on key comparison.
|
|
8865
8864
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
8866
8865
|
*
|
|
8867
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
8866
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
8868
8867
|
* @param [value] - The value, if providing just a key.
|
|
8869
8868
|
* @returns True if the addition was successful, false otherwise.
|
|
8870
8869
|
*/
|
|
8871
|
-
|
|
8870
|
+
set(keyNodeOrEntry, value) {
|
|
8872
8871
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
8873
8872
|
if (newNode === void 0) return false;
|
|
8874
8873
|
if (this._root === void 0) {
|
|
@@ -8905,24 +8904,24 @@ var BST = class extends BinaryTree {
|
|
|
8905
8904
|
}
|
|
8906
8905
|
/**
|
|
8907
8906
|
* Adds multiple items to the tree.
|
|
8908
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
8907
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
8909
8908
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
8910
8909
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
8911
8910
|
*
|
|
8912
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
8911
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
8913
8912
|
* @param [values] - An optional parallel iterable of values.
|
|
8914
8913
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
8915
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
8916
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
8914
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
8915
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
8917
8916
|
*/
|
|
8918
|
-
|
|
8917
|
+
setMany(keysNodesEntriesOrRaws, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
8919
8918
|
const inserted = [];
|
|
8920
8919
|
const valuesIterator = values?.[Symbol.iterator]();
|
|
8921
8920
|
if (!isBalanceAdd) {
|
|
8922
8921
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
8923
8922
|
const val = valuesIterator?.next().value;
|
|
8924
8923
|
if (this.isRaw(kve)) kve = this._toEntryFn(kve);
|
|
8925
|
-
inserted.push(this.
|
|
8924
|
+
inserted.push(this.set(kve, val));
|
|
8926
8925
|
}
|
|
8927
8926
|
return inserted;
|
|
8928
8927
|
}
|
|
@@ -8950,9 +8949,9 @@ var BST = class extends BinaryTree {
|
|
|
8950
8949
|
const { key, value, orgIndex } = arr[mid];
|
|
8951
8950
|
if (this.isRaw(key)) {
|
|
8952
8951
|
const entry = this._toEntryFn(key);
|
|
8953
|
-
inserted[orgIndex] = this.
|
|
8952
|
+
inserted[orgIndex] = this.set(entry);
|
|
8954
8953
|
} else {
|
|
8955
|
-
inserted[orgIndex] = this.
|
|
8954
|
+
inserted[orgIndex] = this.set(key, value);
|
|
8956
8955
|
}
|
|
8957
8956
|
_dfs(arr.slice(0, mid));
|
|
8958
8957
|
_dfs(arr.slice(mid + 1));
|
|
@@ -8969,9 +8968,9 @@ var BST = class extends BinaryTree {
|
|
|
8969
8968
|
const { key, value, orgIndex } = sorted[m];
|
|
8970
8969
|
if (this.isRaw(key)) {
|
|
8971
8970
|
const entry = this._toEntryFn(key);
|
|
8972
|
-
inserted[orgIndex] = this.
|
|
8971
|
+
inserted[orgIndex] = this.set(entry);
|
|
8973
8972
|
} else {
|
|
8974
|
-
inserted[orgIndex] = this.
|
|
8973
|
+
inserted[orgIndex] = this.set(key, value);
|
|
8975
8974
|
}
|
|
8976
8975
|
stack.push([m + 1, r]);
|
|
8977
8976
|
stack.push([l, m - 1]);
|
|
@@ -9246,7 +9245,7 @@ var BST = class extends BinaryTree {
|
|
|
9246
9245
|
const out = this._createLike([], options);
|
|
9247
9246
|
let index = 0;
|
|
9248
9247
|
for (const [key, value] of this) {
|
|
9249
|
-
out.
|
|
9248
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
9250
9249
|
}
|
|
9251
9250
|
return out;
|
|
9252
9251
|
}
|
|
@@ -10433,14 +10432,14 @@ var AVLTree = class extends BST {
|
|
|
10433
10432
|
}
|
|
10434
10433
|
/**
|
|
10435
10434
|
* Creates an instance of AVLTree.
|
|
10436
|
-
* @remarks Time O(N log N) (from `
|
|
10435
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
10437
10436
|
*
|
|
10438
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
10437
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
10439
10438
|
* @param [options] - Configuration options for the AVL tree.
|
|
10440
10439
|
*/
|
|
10441
10440
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
10442
10441
|
super([], options);
|
|
10443
|
-
if (keysNodesEntriesOrRaws) super.
|
|
10442
|
+
if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
|
|
10444
10443
|
}
|
|
10445
10444
|
/**
|
|
10446
10445
|
* (Protected) Creates a new AVL tree node.
|
|
@@ -10464,16 +10463,16 @@ var AVLTree = class extends BST {
|
|
|
10464
10463
|
return keyNodeOrEntry instanceof AVLTreeNode;
|
|
10465
10464
|
}
|
|
10466
10465
|
/**
|
|
10467
|
-
*
|
|
10468
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
10466
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
10467
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
10469
10468
|
*
|
|
10470
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
10469
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
10471
10470
|
* @param [value] - The value, if providing just a key.
|
|
10472
10471
|
* @returns True if the addition was successful, false otherwise.
|
|
10473
10472
|
*/
|
|
10474
|
-
|
|
10473
|
+
set(keyNodeOrEntry, value) {
|
|
10475
10474
|
if (keyNodeOrEntry === null) return false;
|
|
10476
|
-
const inserted = super.
|
|
10475
|
+
const inserted = super.set(keyNodeOrEntry, value);
|
|
10477
10476
|
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
10478
10477
|
return inserted;
|
|
10479
10478
|
}
|
|
@@ -10525,7 +10524,7 @@ var AVLTree = class extends BST {
|
|
|
10525
10524
|
}
|
|
10526
10525
|
/**
|
|
10527
10526
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
10528
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
10527
|
+
* @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.
|
|
10529
10528
|
*
|
|
10530
10529
|
* @template MK - New key type.
|
|
10531
10530
|
* @template MV - New value type.
|
|
@@ -10539,7 +10538,7 @@ var AVLTree = class extends BST {
|
|
|
10539
10538
|
const out = this._createLike([], options);
|
|
10540
10539
|
let index = 0;
|
|
10541
10540
|
for (const [key, value] of this) {
|
|
10542
|
-
out.
|
|
10541
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
10543
10542
|
}
|
|
10544
10543
|
return out;
|
|
10545
10544
|
}
|
|
@@ -10965,7 +10964,7 @@ var RedBlackTree = class extends BST {
|
|
|
10965
10964
|
super([], options);
|
|
10966
10965
|
this._root = this.NIL;
|
|
10967
10966
|
if (keysNodesEntriesOrRaws) {
|
|
10968
|
-
this.
|
|
10967
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
10969
10968
|
}
|
|
10970
10969
|
}
|
|
10971
10970
|
_root;
|
|
@@ -11013,7 +11012,7 @@ var RedBlackTree = class extends BST {
|
|
|
11013
11012
|
* @param [value]- See parameter type for details.
|
|
11014
11013
|
* @returns True if inserted or updated; false if ignored.
|
|
11015
11014
|
*/
|
|
11016
|
-
|
|
11015
|
+
set(keyNodeOrEntry, value) {
|
|
11017
11016
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
11018
11017
|
if (!this.isRealNode(newNode)) return false;
|
|
11019
11018
|
const insertStatus = this._insert(newNode);
|
|
@@ -11107,7 +11106,7 @@ var RedBlackTree = class extends BST {
|
|
|
11107
11106
|
const out = this._createLike([], options);
|
|
11108
11107
|
let index = 0;
|
|
11109
11108
|
for (const [key, value] of this) {
|
|
11110
|
-
out.
|
|
11109
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
11111
11110
|
}
|
|
11112
11111
|
return out;
|
|
11113
11112
|
}
|
|
@@ -11495,7 +11494,7 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
11495
11494
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11496
11495
|
super([], { ...options, isMapMode: true });
|
|
11497
11496
|
if (keysNodesEntriesOrRaws) {
|
|
11498
|
-
this.
|
|
11497
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
11499
11498
|
}
|
|
11500
11499
|
}
|
|
11501
11500
|
createNode(key, value = []) {
|
|
@@ -11515,27 +11514,27 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
11515
11514
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
11516
11515
|
* @remarks Time O(log N + M), Space O(1)
|
|
11517
11516
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
11518
|
-
* @param [value] - Single value to
|
|
11517
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
11519
11518
|
* @returns True if inserted or appended; false if ignored.
|
|
11520
11519
|
*/
|
|
11521
|
-
|
|
11522
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
11520
|
+
set(keyNodeOrEntry, value) {
|
|
11521
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
11523
11522
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
11524
11523
|
if (key === void 0 || key === null) return false;
|
|
11525
|
-
const
|
|
11524
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
11526
11525
|
const existingValues = this.get(key);
|
|
11527
11526
|
if (existingValues !== void 0 && values !== void 0) {
|
|
11528
11527
|
for (const value2 of values) existingValues.push(value2);
|
|
11529
11528
|
return true;
|
|
11530
11529
|
}
|
|
11531
11530
|
return false;
|
|
11532
|
-
}, "
|
|
11533
|
-
const
|
|
11531
|
+
}, "_setToValues");
|
|
11532
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
11534
11533
|
const existingNode = this.getNode(key);
|
|
11535
11534
|
if (this.isRealNode(existingNode)) {
|
|
11536
11535
|
const existingValues = this.get(existingNode);
|
|
11537
11536
|
if (existingValues === void 0) {
|
|
11538
|
-
super.
|
|
11537
|
+
super.set(key, values);
|
|
11539
11538
|
return true;
|
|
11540
11539
|
}
|
|
11541
11540
|
if (values !== void 0) {
|
|
@@ -11545,13 +11544,13 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
11545
11544
|
return false;
|
|
11546
11545
|
}
|
|
11547
11546
|
} else {
|
|
11548
|
-
return super.
|
|
11547
|
+
return super.set(key, values);
|
|
11549
11548
|
}
|
|
11550
|
-
}, "
|
|
11549
|
+
}, "_setByNode");
|
|
11551
11550
|
if (this._isMapMode) {
|
|
11552
|
-
return
|
|
11551
|
+
return _setByNode() || _setToValues();
|
|
11553
11552
|
}
|
|
11554
|
-
return
|
|
11553
|
+
return _setToValues() || _setByNode();
|
|
11555
11554
|
}, "_commonAdd");
|
|
11556
11555
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11557
11556
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -11619,7 +11618,7 @@ var AVLTreeMultiMap = class extends AVLTree {
|
|
|
11619
11618
|
map(callback, options, thisArg) {
|
|
11620
11619
|
const out = this._createLike([], options);
|
|
11621
11620
|
let i = 0;
|
|
11622
|
-
for (const [k, v] of this) out.
|
|
11621
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
11623
11622
|
return out;
|
|
11624
11623
|
}
|
|
11625
11624
|
/**
|
|
@@ -11802,7 +11801,7 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
11802
11801
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
11803
11802
|
super([], { ...options });
|
|
11804
11803
|
if (keysNodesEntriesOrRaws) {
|
|
11805
|
-
this.
|
|
11804
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
11806
11805
|
}
|
|
11807
11806
|
}
|
|
11808
11807
|
createNode(key, value = []) {
|
|
@@ -11822,27 +11821,27 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
11822
11821
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
11823
11822
|
* @remarks Time O(log N + M), Space O(1)
|
|
11824
11823
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
11825
|
-
* @param [value] - Single value to
|
|
11824
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
11826
11825
|
* @returns True if inserted or appended; false if ignored.
|
|
11827
11826
|
*/
|
|
11828
|
-
|
|
11829
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
11827
|
+
set(keyNodeOrEntry, value) {
|
|
11828
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
11830
11829
|
const _commonAdd = /* @__PURE__ */ __name((key, values) => {
|
|
11831
11830
|
if (key === void 0 || key === null) return false;
|
|
11832
|
-
const
|
|
11831
|
+
const _setToValues = /* @__PURE__ */ __name(() => {
|
|
11833
11832
|
const existingValues = this.get(key);
|
|
11834
11833
|
if (existingValues !== void 0 && values !== void 0) {
|
|
11835
11834
|
for (const value2 of values) existingValues.push(value2);
|
|
11836
11835
|
return true;
|
|
11837
11836
|
}
|
|
11838
11837
|
return false;
|
|
11839
|
-
}, "
|
|
11840
|
-
const
|
|
11838
|
+
}, "_setToValues");
|
|
11839
|
+
const _setByNode = /* @__PURE__ */ __name(() => {
|
|
11841
11840
|
const existingNode = this.getNode(key);
|
|
11842
11841
|
if (this.isRealNode(existingNode)) {
|
|
11843
11842
|
const existingValues = this.get(existingNode);
|
|
11844
11843
|
if (existingValues === void 0) {
|
|
11845
|
-
super.
|
|
11844
|
+
super.set(key, values);
|
|
11846
11845
|
return true;
|
|
11847
11846
|
}
|
|
11848
11847
|
if (values !== void 0) {
|
|
@@ -11852,13 +11851,13 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
11852
11851
|
return false;
|
|
11853
11852
|
}
|
|
11854
11853
|
} else {
|
|
11855
|
-
return super.
|
|
11854
|
+
return super.set(key, values);
|
|
11856
11855
|
}
|
|
11857
|
-
}, "
|
|
11856
|
+
}, "_setByNode");
|
|
11858
11857
|
if (this._isMapMode) {
|
|
11859
|
-
return
|
|
11858
|
+
return _setByNode() || _setToValues();
|
|
11860
11859
|
}
|
|
11861
|
-
return
|
|
11860
|
+
return _setToValues() || _setByNode();
|
|
11862
11861
|
}, "_commonAdd");
|
|
11863
11862
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
11864
11863
|
const [key, values] = keyNodeOrEntry;
|
|
@@ -11898,7 +11897,7 @@ var TreeMultiMap = class extends RedBlackTree {
|
|
|
11898
11897
|
map(callback, options, thisArg) {
|
|
11899
11898
|
const out = this._createLike([], options);
|
|
11900
11899
|
let i = 0;
|
|
11901
|
-
for (const [k, v] of this) out.
|
|
11900
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
11902
11901
|
return out;
|
|
11903
11902
|
}
|
|
11904
11903
|
/**
|
|
@@ -12083,7 +12082,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
12083
12082
|
*/
|
|
12084
12083
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12085
12084
|
super([], options);
|
|
12086
|
-
if (keysNodesEntriesOrRaws) this.
|
|
12085
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
12087
12086
|
}
|
|
12088
12087
|
_count = 0;
|
|
12089
12088
|
/**
|
|
@@ -12123,10 +12122,10 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
12123
12122
|
* @param [count] - How much to increase the node's count (default 1).
|
|
12124
12123
|
* @returns True if inserted/updated; false if ignored.
|
|
12125
12124
|
*/
|
|
12126
|
-
|
|
12125
|
+
set(keyNodeOrEntry, value, count = 1) {
|
|
12127
12126
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12128
12127
|
const orgCount = newNode?.count || 0;
|
|
12129
|
-
const isSuccessAdded = super.
|
|
12128
|
+
const isSuccessAdded = super.set(newNode, newValue);
|
|
12130
12129
|
if (isSuccessAdded) {
|
|
12131
12130
|
this._count += orgCount;
|
|
12132
12131
|
return true;
|
|
@@ -12279,7 +12278,7 @@ var TreeCounter = class extends RedBlackTree {
|
|
|
12279
12278
|
const out = this._createLike([], options);
|
|
12280
12279
|
let index = 0;
|
|
12281
12280
|
for (const [key, value] of this) {
|
|
12282
|
-
out.
|
|
12281
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
12283
12282
|
}
|
|
12284
12283
|
return out;
|
|
12285
12284
|
}
|
|
@@ -12535,7 +12534,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
12535
12534
|
*/
|
|
12536
12535
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
12537
12536
|
super([], options);
|
|
12538
|
-
if (keysNodesEntriesOrRaws) this.
|
|
12537
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
12539
12538
|
}
|
|
12540
12539
|
_count = 0;
|
|
12541
12540
|
get count() {
|
|
@@ -12570,11 +12569,11 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
12570
12569
|
* @param [count] - How much to increase the node's count (default 1).
|
|
12571
12570
|
* @returns True if inserted/updated; false if ignored.
|
|
12572
12571
|
*/
|
|
12573
|
-
|
|
12572
|
+
set(keyNodeOrEntry, value, count = 1) {
|
|
12574
12573
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
12575
12574
|
if (newNode === void 0) return false;
|
|
12576
12575
|
const orgNodeCount = newNode?.count || 0;
|
|
12577
|
-
const inserted = super.
|
|
12576
|
+
const inserted = super.set(newNode, newValue);
|
|
12578
12577
|
if (inserted) {
|
|
12579
12578
|
this._count += orgNodeCount;
|
|
12580
12579
|
}
|
|
@@ -12682,9 +12681,9 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
12682
12681
|
clone() {
|
|
12683
12682
|
const out = this._createInstance();
|
|
12684
12683
|
if (this._isMapMode) {
|
|
12685
|
-
this.bfs((node) => out.
|
|
12684
|
+
this.bfs((node) => out.set(node.key, void 0, node.count));
|
|
12686
12685
|
} else {
|
|
12687
|
-
this.bfs((node) => out.
|
|
12686
|
+
this.bfs((node) => out.set(node.key, node.value, node.count));
|
|
12688
12687
|
}
|
|
12689
12688
|
if (this._isMapMode) out._store = this._store;
|
|
12690
12689
|
return out;
|
|
@@ -12704,7 +12703,7 @@ var AVLTreeCounter = class extends AVLTree {
|
|
|
12704
12703
|
const out = this._createLike([], options);
|
|
12705
12704
|
let index = 0;
|
|
12706
12705
|
for (const [key, value] of this) {
|
|
12707
|
-
out.
|
|
12706
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
12708
12707
|
}
|
|
12709
12708
|
return out;
|
|
12710
12709
|
}
|