doubly-linked-list-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/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/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
- package/src/data-structures/binary-tree/avl-tree.ts +15 -15
- package/src/data-structures/binary-tree/binary-tree.ts +53 -55
- package/src/data-structures/binary-tree/bst.ts +21 -22
- package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
- package/src/data-structures/binary-tree/tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
|
@@ -147,7 +147,7 @@ export declare class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K
|
|
|
147
147
|
* @param [count] - How much to increase the node's count (default 1).
|
|
148
148
|
* @returns True if inserted/updated; false if ignored.
|
|
149
149
|
*/
|
|
150
|
-
|
|
150
|
+
set(keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
|
|
151
151
|
/**
|
|
152
152
|
* Delete a node (or decrement its count) and rebalance if needed.
|
|
153
153
|
* @remarks Time O(log N), Space O(1)
|
|
@@ -132,8 +132,8 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<
|
|
|
132
132
|
* @returns True if it's a AVLTreeMultiMapNode, false otherwise.
|
|
133
133
|
*/
|
|
134
134
|
isNode(keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): keyNodeOrEntry is AVLTreeMultiMapNode<K, V>;
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
set(keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
136
|
+
set(key: K, value: V): boolean;
|
|
137
137
|
/**
|
|
138
138
|
* Delete a single value from the bucket at a given key. Removes the key if the bucket becomes empty.
|
|
139
139
|
* @remarks Time O(log N), Space O(1)
|
|
@@ -112,7 +112,7 @@ export declare class AVLTreeNode<K = any, V = any> {
|
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
114
|
* Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
|
|
115
|
-
* This tree extends BST and performs rotations on
|
|
115
|
+
* This tree extends BST and performs rotations on set/delete to maintain balance.
|
|
116
116
|
*
|
|
117
117
|
* @template K - The type of the key.
|
|
118
118
|
* @template V - The type of the value.
|
|
@@ -145,7 +145,7 @@ export declare class AVLTreeNode<K = any, V = any> {
|
|
|
145
145
|
* console.log(tree.size); // 5;
|
|
146
146
|
*
|
|
147
147
|
* // Add a new element
|
|
148
|
-
* tree.
|
|
148
|
+
* tree.set(3);
|
|
149
149
|
* console.log(tree.size); // 6;
|
|
150
150
|
* console.log([...tree.keys()]); // [1, 2, 3, 5, 8, 9];
|
|
151
151
|
* @example
|
|
@@ -208,7 +208,7 @@ export declare class AVLTreeNode<K = any, V = any> {
|
|
|
208
208
|
* console.log(universityTree.isAVLBalanced()); // true;
|
|
209
209
|
*
|
|
210
210
|
* // Add more universities
|
|
211
|
-
* universityTree.
|
|
211
|
+
* universityTree.set(6, { name: 'Oxford', rank: 6, students: 2000 });
|
|
212
212
|
* console.log(universityTree.isAVLBalanced()); // true;
|
|
213
213
|
*
|
|
214
214
|
* // Delete and verify balance is maintained
|
|
@@ -288,9 +288,9 @@ export declare class AVLTreeNode<K = any, V = any> {
|
|
|
288
288
|
export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
|
|
289
289
|
/**
|
|
290
290
|
* Creates an instance of AVLTree.
|
|
291
|
-
* @remarks Time O(N log N) (from `
|
|
291
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
292
292
|
*
|
|
293
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
293
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
294
294
|
* @param [options] - Configuration options for the AVL tree.
|
|
295
295
|
*/
|
|
296
296
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: AVLTreeOptions<K, V, R>);
|
|
@@ -312,14 +312,14 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
312
312
|
*/
|
|
313
313
|
isNode(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is AVLTreeNode<K, V>;
|
|
314
314
|
/**
|
|
315
|
-
*
|
|
316
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
315
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
316
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
317
317
|
*
|
|
318
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
318
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
319
319
|
* @param [value] - The value, if providing just a key.
|
|
320
320
|
* @returns True if the addition was successful, false otherwise.
|
|
321
321
|
*/
|
|
322
|
-
|
|
322
|
+
set(keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
323
323
|
/**
|
|
324
324
|
* Deletes a node from the AVL tree and re-balances the tree.
|
|
325
325
|
* @remarks Time O(log N) (O(H) for BST delete + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
@@ -339,7 +339,7 @@ export declare class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> imp
|
|
|
339
339
|
perfectlyBalance(iterationType?: IterationType): boolean;
|
|
340
340
|
/**
|
|
341
341
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
342
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
342
|
+
* @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.
|
|
343
343
|
*
|
|
344
344
|
* @template MK - New key type.
|
|
345
345
|
* @template MV - New value type.
|
|
@@ -113,7 +113,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
113
113
|
*
|
|
114
114
|
* @remarks
|
|
115
115
|
* This class implements a basic Binary Tree, not a Binary Search Tree.
|
|
116
|
-
* The `
|
|
116
|
+
* The `set` operation inserts nodes level-by-level (BFS) into the first available slot.
|
|
117
117
|
*
|
|
118
118
|
* @template K - The type of the key.
|
|
119
119
|
* @template V - The type of the value.
|
|
@@ -145,7 +145,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
145
145
|
* console.log(tree.size); // 9;
|
|
146
146
|
*
|
|
147
147
|
* // Add new element
|
|
148
|
-
* tree.
|
|
148
|
+
* tree.set(10, 'ten');
|
|
149
149
|
* console.log(tree.size); // 10;
|
|
150
150
|
* @example
|
|
151
151
|
* // BinaryTree get and has operations
|
|
@@ -269,9 +269,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
269
269
|
iterationType: IterationType;
|
|
270
270
|
/**
|
|
271
271
|
* Creates an instance of BinaryTree.
|
|
272
|
-
* @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) `
|
|
272
|
+
* @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.
|
|
273
273
|
*
|
|
274
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
274
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
275
275
|
* @param [options] - Configuration options for the tree.
|
|
276
276
|
*/
|
|
277
277
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BinaryTreeOptions<K, V, R>);
|
|
@@ -434,49 +434,48 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
434
434
|
* @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).
|
|
435
435
|
*
|
|
436
436
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
437
|
-
* @param [value] - The value, if providing just a key.
|
|
438
437
|
* @returns True if the addition was successful, false otherwise.
|
|
439
438
|
*/
|
|
440
|
-
add(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
439
|
+
add(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
441
440
|
/**
|
|
442
441
|
* Adds or updates a new node to the tree.
|
|
443
|
-
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation
|
|
442
|
+
* @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).
|
|
444
443
|
*
|
|
445
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
444
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
446
445
|
* @param [value] - The value, if providing just a key.
|
|
447
446
|
* @returns True if the addition was successful, false otherwise.
|
|
448
447
|
*/
|
|
449
448
|
set(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
450
449
|
/**
|
|
451
450
|
* Adds multiple items to the tree.
|
|
452
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
451
|
+
* @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).
|
|
453
452
|
*
|
|
454
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
453
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
455
454
|
* @param [values] - An optional parallel iterable of values.
|
|
456
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
455
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
457
456
|
*/
|
|
458
|
-
addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
457
|
+
addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>): boolean[];
|
|
459
458
|
/**
|
|
460
459
|
* Adds or updates multiple items to the tree.
|
|
461
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
460
|
+
* @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).
|
|
462
461
|
*
|
|
463
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
462
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
464
463
|
* @param [values] - An optional parallel iterable of values.
|
|
465
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
464
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
466
465
|
*/
|
|
467
466
|
setMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
|
|
468
467
|
/**
|
|
469
|
-
* Merges another tree into this one by
|
|
470
|
-
* @remarks Time O(N * M), same as `
|
|
468
|
+
* Merges another tree into this one by seting all its nodes.
|
|
469
|
+
* @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`).
|
|
471
470
|
*
|
|
472
471
|
* @param anotherTree - The tree to merge.
|
|
473
472
|
*/
|
|
474
473
|
merge(anotherTree: BinaryTree<K, V, R>): void;
|
|
475
474
|
/**
|
|
476
475
|
* Clears the tree and refills it with new items.
|
|
477
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
476
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
478
477
|
*
|
|
479
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
478
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
480
479
|
* @param [values] - An optional parallel iterable of values.
|
|
481
480
|
*/
|
|
482
481
|
refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
|
|
@@ -624,14 +623,14 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
624
623
|
morris<C extends NodeCallback<BinaryTreeNode<K, V>>>(callback?: C, pattern?: DFSOrderPattern, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): ReturnType<C>[];
|
|
625
624
|
/**
|
|
626
625
|
* Clones the tree.
|
|
627
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
626
|
+
* @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.
|
|
628
627
|
*
|
|
629
628
|
* @returns A new, cloned instance of the tree.
|
|
630
629
|
*/
|
|
631
630
|
clone(): this;
|
|
632
631
|
/**
|
|
633
632
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
634
|
-
* @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) `
|
|
633
|
+
* @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.
|
|
635
634
|
*
|
|
636
635
|
* @param predicate - A function to test each [key, value] pair.
|
|
637
636
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -722,8 +721,8 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
722
721
|
*/
|
|
723
722
|
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): [BinaryTreeNode<K, V> | null | undefined, V | undefined];
|
|
724
723
|
/**
|
|
725
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
726
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
724
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
725
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
727
726
|
*
|
|
728
727
|
* @param cloned - The new, empty tree instance to populate.
|
|
729
728
|
*/
|
|
@@ -145,8 +145,8 @@ export declare class BSTNode<K = any, V = any> {
|
|
|
145
145
|
* console.log(bst.size); // 16;
|
|
146
146
|
*
|
|
147
147
|
* // Add new elements
|
|
148
|
-
* bst.
|
|
149
|
-
* bst.
|
|
148
|
+
* bst.set(17);
|
|
149
|
+
* bst.set(0);
|
|
150
150
|
* console.log(bst.size); // 18;
|
|
151
151
|
*
|
|
152
152
|
* // Verify keys are searchable
|
|
@@ -192,7 +192,7 @@ export declare class BSTNode<K = any, V = any> {
|
|
|
192
192
|
*
|
|
193
193
|
* // Merge datasets into a single BinarySearchTree
|
|
194
194
|
* const merged = new BST<number, string>(dataset1);
|
|
195
|
-
* merged.
|
|
195
|
+
* merged.setMany(dataset2);
|
|
196
196
|
* merged.merge(dataset3);
|
|
197
197
|
*
|
|
198
198
|
* // Verify merged dataset is in sorted order
|
|
@@ -276,7 +276,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
276
276
|
* Creates an instance of BST.
|
|
277
277
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
278
278
|
*
|
|
279
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
279
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
280
280
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
281
281
|
*/
|
|
282
282
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
|
|
@@ -359,24 +359,24 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
359
359
|
* Adds a new node to the BST based on key comparison.
|
|
360
360
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
361
361
|
*
|
|
362
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
362
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
363
363
|
* @param [value] - The value, if providing just a key.
|
|
364
364
|
* @returns True if the addition was successful, false otherwise.
|
|
365
365
|
*/
|
|
366
|
-
|
|
366
|
+
set(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
367
367
|
/**
|
|
368
368
|
* Adds multiple items to the tree.
|
|
369
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
369
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
370
370
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
371
371
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
372
372
|
*
|
|
373
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
373
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
374
374
|
* @param [values] - An optional parallel iterable of values.
|
|
375
375
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
376
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
377
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
376
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
377
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
378
378
|
*/
|
|
379
|
-
|
|
379
|
+
setMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
|
|
380
380
|
/**
|
|
381
381
|
* Returns the first key with a value >= target.
|
|
382
382
|
* Equivalent to Java TreeMap.ceiling.
|
|
@@ -242,7 +242,7 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
242
242
|
* @param [value]- See parameter type for details.
|
|
243
243
|
* @returns True if inserted or updated; false if ignored.
|
|
244
244
|
*/
|
|
245
|
-
|
|
245
|
+
set(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
|
|
246
246
|
/**
|
|
247
247
|
* Delete a node by key/node/entry and rebalance as needed.
|
|
248
248
|
* @remarks Time O(log n), Space O(1)
|
|
@@ -154,7 +154,7 @@ export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree
|
|
|
154
154
|
* @param [count] - How much to increase the node's count (default 1).
|
|
155
155
|
* @returns True if inserted/updated; false if ignored.
|
|
156
156
|
*/
|
|
157
|
-
|
|
157
|
+
set(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
|
|
158
158
|
/**
|
|
159
159
|
* Delete a node (or decrement its count) and rebalance if needed.
|
|
160
160
|
* @remarks Time O(log N), Space O(1)
|
|
@@ -297,8 +297,8 @@ export declare class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTre
|
|
|
297
297
|
* @returns True if it's a TreeMultiMapNode, false otherwise.
|
|
298
298
|
*/
|
|
299
299
|
isNode(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): keyNodeOrEntry is TreeMultiMapNode<K, V>;
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
set(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
301
|
+
set(key: K, value: V): boolean;
|
|
302
302
|
/**
|
|
303
303
|
* Delete a single value from the bucket at a given key. Removes the key if the bucket becomes empty.
|
|
304
304
|
* @remarks Time O(log N), Space O(1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doubly-linked-list-typed",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.8",
|
|
4
4
|
"description": "Doubly Linked List",
|
|
5
5
|
"browser": "dist/umd/doubly-linked-list-typed.min.js",
|
|
6
6
|
"umd:main": "dist/umd/doubly-linked-list-typed.min.js",
|
|
@@ -102,6 +102,6 @@
|
|
|
102
102
|
"typescript": "^4.9.5"
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"data-structure-typed": "^2.2.
|
|
105
|
+
"data-structure-typed": "^2.2.8"
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -200,7 +200,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
200
200
|
options?: AVLTreeCounterOptions<K, V, R>
|
|
201
201
|
) {
|
|
202
202
|
super([], options);
|
|
203
|
-
if (keysNodesEntriesOrRaws) this.
|
|
203
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
protected _count = 0;
|
|
@@ -243,7 +243,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
243
243
|
* @param [count] - How much to increase the node's count (default 1).
|
|
244
244
|
* @returns True if inserted/updated; false if ignored.
|
|
245
245
|
*/
|
|
246
|
-
override
|
|
246
|
+
override set(
|
|
247
247
|
keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
248
248
|
value?: V,
|
|
249
249
|
count = 1
|
|
@@ -252,7 +252,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
252
252
|
if (newNode === undefined) return false;
|
|
253
253
|
|
|
254
254
|
const orgNodeCount = newNode?.count || 0;
|
|
255
|
-
const inserted = super.
|
|
255
|
+
const inserted = super.set(newNode, newValue);
|
|
256
256
|
if (inserted) {
|
|
257
257
|
this._count += orgNodeCount;
|
|
258
258
|
}
|
|
@@ -380,9 +380,9 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
380
380
|
const out = this._createInstance();
|
|
381
381
|
|
|
382
382
|
if (this._isMapMode) {
|
|
383
|
-
this.bfs(node => out.
|
|
383
|
+
this.bfs(node => out.set(node.key, undefined, node.count));
|
|
384
384
|
} else {
|
|
385
|
-
this.bfs(node => out.
|
|
385
|
+
this.bfs(node => out.set(node.key, node.value, node.count));
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
if (this._isMapMode) out._store = this._store;
|
|
@@ -410,7 +410,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
|
|
|
410
410
|
|
|
411
411
|
let index = 0;
|
|
412
412
|
for (const [key, value] of this) {
|
|
413
|
-
out.
|
|
413
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
414
414
|
}
|
|
415
415
|
return out;
|
|
416
416
|
}
|
|
@@ -199,7 +199,7 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
199
199
|
) {
|
|
200
200
|
super([], { ...options, isMapMode: true });
|
|
201
201
|
if (keysNodesEntriesOrRaws) {
|
|
202
|
-
this.
|
|
202
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -220,29 +220,29 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
220
220
|
return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
override
|
|
223
|
+
override set(
|
|
224
224
|
keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
225
225
|
): boolean;
|
|
226
226
|
|
|
227
|
-
override
|
|
227
|
+
override set(key: K, value: V): boolean;
|
|
228
228
|
|
|
229
229
|
/**
|
|
230
230
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
231
231
|
* @remarks Time O(log N + M), Space O(1)
|
|
232
232
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
233
|
-
* @param [value] - Single value to
|
|
233
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
234
234
|
* @returns True if inserted or appended; false if ignored.
|
|
235
235
|
*/
|
|
236
|
-
override
|
|
236
|
+
override set(
|
|
237
237
|
keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined,
|
|
238
238
|
value?: V
|
|
239
239
|
): boolean {
|
|
240
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
240
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
241
241
|
|
|
242
242
|
const _commonAdd = (key?: BTNOptKeyOrNull<K>, values?: V[]) => {
|
|
243
243
|
if (key === undefined || key === null) return false;
|
|
244
244
|
|
|
245
|
-
const
|
|
245
|
+
const _setToValues = () => {
|
|
246
246
|
const existingValues = this.get(key);
|
|
247
247
|
if (existingValues !== undefined && values !== undefined) {
|
|
248
248
|
for (const value of values) existingValues.push(value);
|
|
@@ -251,12 +251,12 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
251
251
|
return false;
|
|
252
252
|
};
|
|
253
253
|
|
|
254
|
-
const
|
|
254
|
+
const _setByNode = () => {
|
|
255
255
|
const existingNode = this.getNode(key);
|
|
256
256
|
if (this.isRealNode(existingNode)) {
|
|
257
257
|
const existingValues = this.get(existingNode);
|
|
258
258
|
if (existingValues === undefined) {
|
|
259
|
-
super.
|
|
259
|
+
super.set(key, values);
|
|
260
260
|
return true;
|
|
261
261
|
}
|
|
262
262
|
if (values !== undefined) {
|
|
@@ -266,14 +266,14 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
266
266
|
return false;
|
|
267
267
|
}
|
|
268
268
|
} else {
|
|
269
|
-
return super.
|
|
269
|
+
return super.set(key, values);
|
|
270
270
|
}
|
|
271
271
|
};
|
|
272
272
|
|
|
273
273
|
if (this._isMapMode) {
|
|
274
|
-
return
|
|
274
|
+
return _setByNode() || _setToValues();
|
|
275
275
|
}
|
|
276
|
-
return
|
|
276
|
+
return _setToValues() || _setByNode();
|
|
277
277
|
};
|
|
278
278
|
|
|
279
279
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
@@ -392,7 +392,7 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
|
|
|
392
392
|
): AVLTree<MK, MV, MR> {
|
|
393
393
|
const out = this._createLike<MK, MV, MR>([], options);
|
|
394
394
|
let i = 0;
|
|
395
|
-
for (const [k, v] of this) out.
|
|
395
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
396
396
|
return out;
|
|
397
397
|
}
|
|
398
398
|
|
|
@@ -182,7 +182,7 @@ export class AVLTreeNode<K = any, V = any> {
|
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
184
|
* Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
|
|
185
|
-
* This tree extends BST and performs rotations on
|
|
185
|
+
* This tree extends BST and performs rotations on set/delete to maintain balance.
|
|
186
186
|
*
|
|
187
187
|
* @template K - The type of the key.
|
|
188
188
|
* @template V - The type of the value.
|
|
@@ -215,7 +215,7 @@ export class AVLTreeNode<K = any, V = any> {
|
|
|
215
215
|
* console.log(tree.size); // 5;
|
|
216
216
|
*
|
|
217
217
|
* // Add a new element
|
|
218
|
-
* tree.
|
|
218
|
+
* tree.set(3);
|
|
219
219
|
* console.log(tree.size); // 6;
|
|
220
220
|
* console.log([...tree.keys()]); // [1, 2, 3, 5, 8, 9];
|
|
221
221
|
* @example
|
|
@@ -278,7 +278,7 @@ export class AVLTreeNode<K = any, V = any> {
|
|
|
278
278
|
* console.log(universityTree.isAVLBalanced()); // true;
|
|
279
279
|
*
|
|
280
280
|
* // Add more universities
|
|
281
|
-
* universityTree.
|
|
281
|
+
* universityTree.set(6, { name: 'Oxford', rank: 6, students: 2000 });
|
|
282
282
|
* console.log(universityTree.isAVLBalanced()); // true;
|
|
283
283
|
*
|
|
284
284
|
* // Delete and verify balance is maintained
|
|
@@ -358,9 +358,9 @@ export class AVLTreeNode<K = any, V = any> {
|
|
|
358
358
|
export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
|
|
359
359
|
/**
|
|
360
360
|
* Creates an instance of AVLTree.
|
|
361
|
-
* @remarks Time O(N log N) (from `
|
|
361
|
+
* @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
|
|
362
362
|
*
|
|
363
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
363
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
364
364
|
* @param [options] - Configuration options for the AVL tree.
|
|
365
365
|
*/
|
|
366
366
|
constructor(
|
|
@@ -370,8 +370,8 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
370
370
|
options?: AVLTreeOptions<K, V, R>
|
|
371
371
|
) {
|
|
372
372
|
super([], options);
|
|
373
|
-
// Note: super.
|
|
374
|
-
if (keysNodesEntriesOrRaws) super.
|
|
373
|
+
// Note: super.setMany is called, which in BST defaults to balanced set.
|
|
374
|
+
if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
/**
|
|
@@ -400,19 +400,19 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
/**
|
|
403
|
-
*
|
|
404
|
-
* @remarks Time O(log N) (O(H) for BST
|
|
403
|
+
* Sets a new node to the AVL tree and balances the tree path.
|
|
404
|
+
* @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
|
|
405
405
|
*
|
|
406
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
406
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
407
407
|
* @param [value] - The value, if providing just a key.
|
|
408
408
|
* @returns True if the addition was successful, false otherwise.
|
|
409
409
|
*/
|
|
410
|
-
override
|
|
410
|
+
override set(
|
|
411
411
|
keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
412
412
|
value?: V
|
|
413
413
|
): boolean {
|
|
414
414
|
if (keyNodeOrEntry === null) return false;
|
|
415
|
-
const inserted = super.
|
|
415
|
+
const inserted = super.set(keyNodeOrEntry, value);
|
|
416
416
|
// If insertion was successful, balance the path from the new node up to the root.
|
|
417
417
|
if (inserted) this._balancePath(keyNodeOrEntry);
|
|
418
418
|
return inserted;
|
|
@@ -477,7 +477,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
477
477
|
|
|
478
478
|
/**
|
|
479
479
|
* Creates a new AVLTree by mapping each [key, value] pair.
|
|
480
|
-
* @remarks Time O(N log N) (O(N) iteration + O(log M) `
|
|
480
|
+
* @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.
|
|
481
481
|
*
|
|
482
482
|
* @template MK - New key type.
|
|
483
483
|
* @template MV - New value type.
|
|
@@ -497,8 +497,8 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
497
497
|
let index = 0;
|
|
498
498
|
// Iterates in-order
|
|
499
499
|
for (const [key, value] of this) {
|
|
500
|
-
// `
|
|
501
|
-
out.
|
|
500
|
+
// `set` on the new tree will be O(log N) and will self-balance.
|
|
501
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
502
502
|
}
|
|
503
503
|
return out;
|
|
504
504
|
}
|
|
@@ -71,7 +71,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
71
71
|
*/
|
|
72
72
|
set left(v: BinaryTreeNode<K, V> | null | undefined) {
|
|
73
73
|
if (v) {
|
|
74
|
-
v.parent = this
|
|
74
|
+
v.parent = this;
|
|
75
75
|
}
|
|
76
76
|
this._left = v;
|
|
77
77
|
}
|
|
@@ -193,7 +193,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
193
193
|
*
|
|
194
194
|
* @remarks
|
|
195
195
|
* This class implements a basic Binary Tree, not a Binary Search Tree.
|
|
196
|
-
* The `
|
|
196
|
+
* The `set` operation inserts nodes level-by-level (BFS) into the first available slot.
|
|
197
197
|
*
|
|
198
198
|
* @template K - The type of the key.
|
|
199
199
|
* @template V - The type of the value.
|
|
@@ -225,7 +225,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
225
225
|
* console.log(tree.size); // 9;
|
|
226
226
|
*
|
|
227
227
|
* // Add new element
|
|
228
|
-
* tree.
|
|
228
|
+
* tree.set(10, 'ten');
|
|
229
229
|
* console.log(tree.size); // 10;
|
|
230
230
|
* @example
|
|
231
231
|
* // BinaryTree get and has operations
|
|
@@ -353,9 +353,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
353
353
|
|
|
354
354
|
/**
|
|
355
355
|
* Creates an instance of BinaryTree.
|
|
356
|
-
* @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) `
|
|
356
|
+
* @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.
|
|
357
357
|
*
|
|
358
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
358
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
359
359
|
* @param [options] - Configuration options for the tree.
|
|
360
360
|
*/
|
|
361
361
|
constructor(
|
|
@@ -374,7 +374,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
374
374
|
else if (toEntryFn) throw TypeError('toEntryFn must be a function type');
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
-
if (keysNodesEntriesOrRaws) this.
|
|
377
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
378
378
|
}
|
|
379
379
|
|
|
380
380
|
protected _isMapMode = true;
|
|
@@ -640,13 +640,27 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
640
640
|
* @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).
|
|
641
641
|
*
|
|
642
642
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
643
|
-
* @param [value] - The value, if providing just a key.
|
|
644
643
|
* @returns True if the addition was successful, false otherwise.
|
|
645
644
|
*/
|
|
646
645
|
add(
|
|
646
|
+
keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
647
|
+
): boolean {
|
|
648
|
+
return this.set(keyNodeOrEntry);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Adds or updates a new node to the tree.
|
|
653
|
+
* @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).
|
|
654
|
+
*
|
|
655
|
+
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
656
|
+
* @param [value] - The value, if providing just a key.
|
|
657
|
+
* @returns True if the addition was successful, false otherwise.
|
|
658
|
+
*/
|
|
659
|
+
set(
|
|
647
660
|
keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
648
661
|
value?: V
|
|
649
662
|
): boolean {
|
|
663
|
+
|
|
650
664
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
651
665
|
if (newNode === undefined) return false;
|
|
652
666
|
|
|
@@ -699,29 +713,30 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
699
713
|
}
|
|
700
714
|
|
|
701
715
|
/**
|
|
702
|
-
* Adds
|
|
703
|
-
* @remarks Time O(
|
|
716
|
+
* Adds multiple items to the tree.
|
|
717
|
+
* @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).
|
|
704
718
|
*
|
|
705
|
-
* @param
|
|
706
|
-
* @param [
|
|
707
|
-
* @returns
|
|
719
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
720
|
+
* @param [values] - An optional parallel iterable of values.
|
|
721
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
708
722
|
*/
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
723
|
+
addMany(
|
|
724
|
+
keysNodesEntriesOrRaws: Iterable<
|
|
725
|
+
K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
726
|
+
>
|
|
727
|
+
): boolean[] {
|
|
728
|
+
return this.setMany(keysNodesEntriesOrRaws);
|
|
714
729
|
}
|
|
715
730
|
|
|
716
731
|
/**
|
|
717
|
-
* Adds multiple items to the tree.
|
|
718
|
-
* @remarks Time O(N * M), where N is the number of items to
|
|
732
|
+
* Adds or updates multiple items to the tree.
|
|
733
|
+
* @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).
|
|
719
734
|
*
|
|
720
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
735
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set or update.
|
|
721
736
|
* @param [values] - An optional parallel iterable of values.
|
|
722
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
737
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
723
738
|
*/
|
|
724
|
-
|
|
739
|
+
setMany(
|
|
725
740
|
keysNodesEntriesOrRaws: Iterable<
|
|
726
741
|
K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
727
742
|
>,
|
|
@@ -744,44 +759,27 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
744
759
|
}
|
|
745
760
|
}
|
|
746
761
|
if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn!(keyNodeEntryOrRaw);
|
|
747
|
-
inserted.push(this.
|
|
762
|
+
inserted.push(this.set(keyNodeEntryOrRaw, value));
|
|
748
763
|
}
|
|
749
764
|
|
|
750
765
|
return inserted;
|
|
751
766
|
}
|
|
752
767
|
|
|
753
768
|
/**
|
|
754
|
-
*
|
|
755
|
-
* @remarks Time O(N * M), where N is the
|
|
756
|
-
*
|
|
757
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to add or update.
|
|
758
|
-
* @param [values] - An optional parallel iterable of values.
|
|
759
|
-
* @returns An array of booleans indicating the success of each individual `add` operation.
|
|
760
|
-
*/
|
|
761
|
-
setMany(
|
|
762
|
-
keysNodesEntriesOrRaws: Iterable<
|
|
763
|
-
K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
764
|
-
>,
|
|
765
|
-
values?: Iterable<V | undefined>
|
|
766
|
-
): boolean[] {
|
|
767
|
-
return this.addMany(keysNodesEntriesOrRaws, values);
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Merges another tree into this one by adding all its nodes.
|
|
772
|
-
* @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`).
|
|
769
|
+
* Merges another tree into this one by seting all its nodes.
|
|
770
|
+
* @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`).
|
|
773
771
|
*
|
|
774
772
|
* @param anotherTree - The tree to merge.
|
|
775
773
|
*/
|
|
776
774
|
merge(anotherTree: BinaryTree<K, V, R>) {
|
|
777
|
-
this.
|
|
775
|
+
this.setMany(anotherTree, []);
|
|
778
776
|
}
|
|
779
777
|
|
|
780
778
|
/**
|
|
781
779
|
* Clears the tree and refills it with new items.
|
|
782
|
-
* @remarks Time O(N) (for `clear`) + O(N * M) (for `
|
|
780
|
+
* @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
|
|
783
781
|
*
|
|
784
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
782
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
785
783
|
* @param [values] - An optional parallel iterable of values.
|
|
786
784
|
*/
|
|
787
785
|
refill(
|
|
@@ -791,7 +789,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
791
789
|
values?: Iterable<V | undefined>
|
|
792
790
|
): void {
|
|
793
791
|
this.clear();
|
|
794
|
-
this.
|
|
792
|
+
this.setMany(keysNodesEntriesOrRaws, values);
|
|
795
793
|
}
|
|
796
794
|
|
|
797
795
|
/**
|
|
@@ -1830,7 +1828,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1830
1828
|
|
|
1831
1829
|
/**
|
|
1832
1830
|
* Clones the tree.
|
|
1833
|
-
* @remarks Time O(N * M), where N is the number of nodes and M is the tree size during insertion (due to `bfs` + `
|
|
1831
|
+
* @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.
|
|
1834
1832
|
*
|
|
1835
1833
|
* @returns A new, cloned instance of the tree.
|
|
1836
1834
|
*/
|
|
@@ -1842,7 +1840,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1842
1840
|
|
|
1843
1841
|
/**
|
|
1844
1842
|
* Creates a new tree containing only the entries that satisfy the predicate.
|
|
1845
|
-
* @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) `
|
|
1843
|
+
* @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.
|
|
1846
1844
|
*
|
|
1847
1845
|
* @param predicate - A function to test each [key, value] pair.
|
|
1848
1846
|
* @param [thisArg] - `this` context for the predicate.
|
|
@@ -1851,7 +1849,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1851
1849
|
filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this {
|
|
1852
1850
|
const out = this._createInstance<K, V, R>();
|
|
1853
1851
|
let i = 0;
|
|
1854
|
-
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.
|
|
1852
|
+
for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.set([k, v]);
|
|
1855
1853
|
return out;
|
|
1856
1854
|
}
|
|
1857
1855
|
|
|
@@ -1874,7 +1872,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1874
1872
|
): BinaryTree<MK, MV, MR> {
|
|
1875
1873
|
const out = this._createLike<MK, MV, MR>([], options);
|
|
1876
1874
|
let i = 0;
|
|
1877
|
-
for (const [k, v] of this) out.
|
|
1875
|
+
for (const [k, v] of this) out.set(cb.call(thisArg, v, k, i++, this));
|
|
1878
1876
|
return out;
|
|
1879
1877
|
}
|
|
1880
1878
|
|
|
@@ -2204,8 +2202,8 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2204
2202
|
}
|
|
2205
2203
|
|
|
2206
2204
|
/**
|
|
2207
|
-
* (Protected) Helper for cloning. Performs a BFS and
|
|
2208
|
-
* @remarks Time O(N * M) (O(N) BFS + O(M) `
|
|
2205
|
+
* (Protected) Helper for cloning. Performs a BFS and sets all nodes to the new tree.
|
|
2206
|
+
* @remarks Time O(N * M) (O(N) BFS + O(M) `set` for each node).
|
|
2209
2207
|
*
|
|
2210
2208
|
* @param cloned - The new, empty tree instance to populate.
|
|
2211
2209
|
*/
|
|
@@ -2213,10 +2211,10 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2213
2211
|
// Use BFS with nulls to preserve the tree structure
|
|
2214
2212
|
this.bfs(
|
|
2215
2213
|
node => {
|
|
2216
|
-
if (node === null) cloned.
|
|
2214
|
+
if (node === null) cloned.set(null);
|
|
2217
2215
|
else {
|
|
2218
|
-
if (this._isMapMode) cloned.
|
|
2219
|
-
else cloned.
|
|
2216
|
+
if (this._isMapMode) cloned.set([node.key, this._store.get(node.key)]);
|
|
2217
|
+
else cloned.set([node.key, node.value]);
|
|
2220
2218
|
}
|
|
2221
2219
|
},
|
|
2222
2220
|
this._root,
|
|
@@ -219,8 +219,8 @@ export class BSTNode<K = any, V = any> {
|
|
|
219
219
|
* console.log(bst.size); // 16;
|
|
220
220
|
*
|
|
221
221
|
* // Add new elements
|
|
222
|
-
* bst.
|
|
223
|
-
* bst.
|
|
222
|
+
* bst.set(17);
|
|
223
|
+
* bst.set(0);
|
|
224
224
|
* console.log(bst.size); // 18;
|
|
225
225
|
*
|
|
226
226
|
* // Verify keys are searchable
|
|
@@ -266,7 +266,7 @@ export class BSTNode<K = any, V = any> {
|
|
|
266
266
|
*
|
|
267
267
|
* // Merge datasets into a single BinarySearchTree
|
|
268
268
|
* const merged = new BST<number, string>(dataset1);
|
|
269
|
-
* merged.
|
|
269
|
+
* merged.setMany(dataset2);
|
|
270
270
|
* merged.merge(dataset3);
|
|
271
271
|
*
|
|
272
272
|
* // Verify merged dataset is in sorted order
|
|
@@ -350,7 +350,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
350
350
|
* Creates an instance of BST.
|
|
351
351
|
* @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
|
|
352
352
|
*
|
|
353
|
-
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to
|
|
353
|
+
* @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
|
|
354
354
|
* @param [options] - Configuration options for the BST, including comparator.
|
|
355
355
|
*/
|
|
356
356
|
constructor(
|
|
@@ -370,7 +370,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
370
370
|
this._comparator = this._createDefaultComparator();
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
-
if (keysNodesEntriesOrRaws) this.
|
|
373
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
protected override _root?: BSTNode<K, V> = undefined;
|
|
@@ -625,7 +625,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
625
625
|
if (isRange) {
|
|
626
626
|
predicate = node => {
|
|
627
627
|
if (!node) return false;
|
|
628
|
-
return (keyNodeEntryOrPredicate
|
|
628
|
+
return (keyNodeEntryOrPredicate).isInRange(node.key, this._comparator);
|
|
629
629
|
};
|
|
630
630
|
} else {
|
|
631
631
|
predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
|
|
@@ -637,7 +637,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
637
637
|
if (!this.isRealNode(cur.left)) return false;
|
|
638
638
|
if (isRange) {
|
|
639
639
|
// Range search: Only go left if the current key is >= the lower bound
|
|
640
|
-
const range = keyNodeEntryOrPredicate
|
|
640
|
+
const range = keyNodeEntryOrPredicate;
|
|
641
641
|
const leftS = range.low;
|
|
642
642
|
const leftI = range.includeLow;
|
|
643
643
|
return (leftI && this._compare(cur.key, leftS) >= 0) || (!leftI && this._compare(cur.key, leftS) > 0);
|
|
@@ -655,7 +655,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
655
655
|
if (!this.isRealNode(cur.right)) return false;
|
|
656
656
|
if (isRange) {
|
|
657
657
|
// Range search: Only go right if current key <= upper bound
|
|
658
|
-
const range = keyNodeEntryOrPredicate
|
|
658
|
+
const range = keyNodeEntryOrPredicate;
|
|
659
659
|
const rightS = range.high;
|
|
660
660
|
const rightI = range.includeHigh;
|
|
661
661
|
return (rightI && this._compare(cur.key, rightS) <= 0) || (!rightI && this._compare(cur.key, rightS) < 0);
|
|
@@ -716,11 +716,11 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
716
716
|
* Adds a new node to the BST based on key comparison.
|
|
717
717
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
718
718
|
*
|
|
719
|
-
* @param keyNodeOrEntry - The key, node, or entry to
|
|
719
|
+
* @param keyNodeOrEntry - The key, node, or entry to set.
|
|
720
720
|
* @param [value] - The value, if providing just a key.
|
|
721
721
|
* @returns True if the addition was successful, false otherwise.
|
|
722
722
|
*/
|
|
723
|
-
override
|
|
723
|
+
override set(
|
|
724
724
|
keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
725
725
|
value?: V
|
|
726
726
|
): boolean {
|
|
@@ -766,17 +766,17 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
766
766
|
|
|
767
767
|
/**
|
|
768
768
|
* Adds multiple items to the tree.
|
|
769
|
-
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced
|
|
769
|
+
* @remarks If `isBalanceAdd` is true, sorts the input and builds a balanced tree. Time O(N log N) (due to sort and balanced set).
|
|
770
770
|
* If false, adds items one by one. Time O(N * H), which is O(N^2) worst-case.
|
|
771
771
|
* Space O(N) for sorting and recursion/iteration stack.
|
|
772
772
|
*
|
|
773
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to
|
|
773
|
+
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
774
774
|
* @param [values] - An optional parallel iterable of values.
|
|
775
775
|
* @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
|
|
776
|
-
* @param [iterationType=this.iterationType] - The traversal method for balanced
|
|
777
|
-
* @returns An array of booleans indicating the success of each individual `
|
|
776
|
+
* @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
|
|
777
|
+
* @returns An array of booleans indicating the success of each individual `set` operation.
|
|
778
778
|
*/
|
|
779
|
-
override
|
|
779
|
+
override setMany(
|
|
780
780
|
keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>,
|
|
781
781
|
values?: Iterable<V | undefined>,
|
|
782
782
|
isBalanceAdd = true,
|
|
@@ -790,7 +790,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
790
790
|
for (let kve of keysNodesEntriesOrRaws) {
|
|
791
791
|
const val = valuesIterator?.next().value;
|
|
792
792
|
if (this.isRaw(kve)) kve = this._toEntryFn!(kve);
|
|
793
|
-
inserted.push(this.
|
|
793
|
+
inserted.push(this.set(kve, val));
|
|
794
794
|
}
|
|
795
795
|
return inserted;
|
|
796
796
|
}
|
|
@@ -831,9 +831,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
831
831
|
const { key, value, orgIndex } = arr[mid];
|
|
832
832
|
if (this.isRaw(key)) {
|
|
833
833
|
const entry = this._toEntryFn!(key);
|
|
834
|
-
inserted[orgIndex] = this.
|
|
834
|
+
inserted[orgIndex] = this.set(entry);
|
|
835
835
|
} else {
|
|
836
|
-
inserted[orgIndex] = this.
|
|
836
|
+
inserted[orgIndex] = this.set(key, value);
|
|
837
837
|
}
|
|
838
838
|
_dfs(arr.slice(0, mid));
|
|
839
839
|
_dfs(arr.slice(mid + 1));
|
|
@@ -852,9 +852,9 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
852
852
|
const { key, value, orgIndex } = sorted[m];
|
|
853
853
|
if (this.isRaw(key)) {
|
|
854
854
|
const entry = this._toEntryFn!(key);
|
|
855
|
-
inserted[orgIndex] = this.
|
|
855
|
+
inserted[orgIndex] = this.set(entry);
|
|
856
856
|
} else {
|
|
857
|
-
inserted[orgIndex] = this.
|
|
857
|
+
inserted[orgIndex] = this.set(key, value);
|
|
858
858
|
}
|
|
859
859
|
stack.push([m + 1, r]);
|
|
860
860
|
stack.push([l, m - 1]);
|
|
@@ -1369,7 +1369,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1369
1369
|
let index = 0;
|
|
1370
1370
|
// Iterates in-order
|
|
1371
1371
|
for (const [key, value] of this) {
|
|
1372
|
-
out.
|
|
1372
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
1373
1373
|
}
|
|
1374
1374
|
return out;
|
|
1375
1375
|
}
|
|
@@ -1441,7 +1441,6 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
|
|
|
1441
1441
|
*/
|
|
1442
1442
|
protected _createDefaultComparator(): Comparator<K> {
|
|
1443
1443
|
return (a: K, b: K): number => {
|
|
1444
|
-
debugger;
|
|
1445
1444
|
// If both keys are comparable (primitive types), use direct comparison
|
|
1446
1445
|
if (isComparable(a) && isComparable(b)) {
|
|
1447
1446
|
if (a > b) return 1;
|
|
@@ -292,7 +292,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
292
292
|
this._root = this.NIL;
|
|
293
293
|
|
|
294
294
|
if (keysNodesEntriesOrRaws) {
|
|
295
|
-
this.
|
|
295
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -350,7 +350,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
350
350
|
* @param [value]- See parameter type for details.
|
|
351
351
|
* @returns True if inserted or updated; false if ignored.
|
|
352
352
|
*/
|
|
353
|
-
override
|
|
353
|
+
override set(
|
|
354
354
|
keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
355
355
|
value?: V
|
|
356
356
|
): boolean {
|
|
@@ -469,7 +469,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
|
|
|
469
469
|
|
|
470
470
|
let index = 0;
|
|
471
471
|
for (const [key, value] of this) {
|
|
472
|
-
out.
|
|
472
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
473
473
|
}
|
|
474
474
|
return out;
|
|
475
475
|
}
|
|
@@ -204,7 +204,7 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
|
|
|
204
204
|
options?: TreeCounterOptions<K, V, R>
|
|
205
205
|
) {
|
|
206
206
|
super([], options);
|
|
207
|
-
if (keysNodesEntriesOrRaws) this.
|
|
207
|
+
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
protected _count = 0;
|
|
@@ -255,14 +255,14 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
|
|
|
255
255
|
* @param [count] - How much to increase the node's count (default 1).
|
|
256
256
|
* @returns True if inserted/updated; false if ignored.
|
|
257
257
|
*/
|
|
258
|
-
override
|
|
258
|
+
override set(
|
|
259
259
|
keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
260
260
|
value?: V,
|
|
261
261
|
count = 1
|
|
262
262
|
): boolean {
|
|
263
263
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
264
264
|
const orgCount = newNode?.count || 0;
|
|
265
|
-
const isSuccessAdded = super.
|
|
265
|
+
const isSuccessAdded = super.set(newNode, newValue);
|
|
266
266
|
if (isSuccessAdded) {
|
|
267
267
|
this._count += orgCount;
|
|
268
268
|
return true;
|
|
@@ -437,7 +437,7 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
|
|
|
437
437
|
|
|
438
438
|
let index = 0;
|
|
439
439
|
for (const [key, value] of this) {
|
|
440
|
-
out.
|
|
440
|
+
out.set(callback.call(thisArg, value, key, index++, this));
|
|
441
441
|
}
|
|
442
442
|
return out;
|
|
443
443
|
}
|
|
@@ -364,7 +364,7 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
|
|
|
364
364
|
) {
|
|
365
365
|
super([], { ...options });
|
|
366
366
|
if (keysNodesEntriesOrRaws) {
|
|
367
|
-
this.
|
|
367
|
+
this.setMany(keysNodesEntriesOrRaws);
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
|
|
@@ -385,29 +385,29 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
|
|
|
385
385
|
return keyNodeOrEntry instanceof TreeMultiMapNode;
|
|
386
386
|
}
|
|
387
387
|
|
|
388
|
-
override
|
|
388
|
+
override set(
|
|
389
389
|
keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
|
|
390
390
|
): boolean;
|
|
391
391
|
|
|
392
|
-
override
|
|
392
|
+
override set(key: K, value: V): boolean;
|
|
393
393
|
|
|
394
394
|
/**
|
|
395
395
|
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
396
396
|
* @remarks Time O(log N + M), Space O(1)
|
|
397
397
|
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
398
|
-
* @param [value] - Single value to
|
|
398
|
+
* @param [value] - Single value to set when a bare key is provided.
|
|
399
399
|
* @returns True if inserted or appended; false if ignored.
|
|
400
400
|
*/
|
|
401
|
-
override
|
|
401
|
+
override set(
|
|
402
402
|
keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined,
|
|
403
403
|
value?: V
|
|
404
404
|
): boolean {
|
|
405
|
-
if (this.isRealNode(keyNodeOrEntry)) return super.
|
|
405
|
+
if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
|
|
406
406
|
|
|
407
407
|
const _commonAdd = (key?: BTNOptKeyOrNull<K>, values?: V[]) => {
|
|
408
408
|
if (key === undefined || key === null) return false;
|
|
409
409
|
|
|
410
|
-
const
|
|
410
|
+
const _setToValues = () => {
|
|
411
411
|
const existingValues = this.get(key);
|
|
412
412
|
if (existingValues !== undefined && values !== undefined) {
|
|
413
413
|
for (const value of values) existingValues.push(value);
|
|
@@ -416,12 +416,12 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
|
|
|
416
416
|
return false;
|
|
417
417
|
};
|
|
418
418
|
|
|
419
|
-
const
|
|
419
|
+
const _setByNode = () => {
|
|
420
420
|
const existingNode = this.getNode(key);
|
|
421
421
|
if (this.isRealNode(existingNode)) {
|
|
422
422
|
const existingValues = this.get(existingNode);
|
|
423
423
|
if (existingValues === undefined) {
|
|
424
|
-
super.
|
|
424
|
+
super.set(key, values);
|
|
425
425
|
return true;
|
|
426
426
|
}
|
|
427
427
|
if (values !== undefined) {
|
|
@@ -431,14 +431,14 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
|
|
|
431
431
|
return false;
|
|
432
432
|
}
|
|
433
433
|
} else {
|
|
434
|
-
return super.
|
|
434
|
+
return super.set(key, values);
|
|
435
435
|
}
|
|
436
436
|
};
|
|
437
437
|
|
|
438
438
|
if (this._isMapMode) {
|
|
439
|
-
return
|
|
439
|
+
return _setByNode() || _setToValues();
|
|
440
440
|
}
|
|
441
|
-
return
|
|
441
|
+
return _setToValues() || _setByNode();
|
|
442
442
|
};
|
|
443
443
|
|
|
444
444
|
if (this.isEntry(keyNodeOrEntry)) {
|
|
@@ -503,7 +503,7 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
|
|
|
503
503
|
): RedBlackTree<MK, MV, MR> {
|
|
504
504
|
const out = this._createLike<MK, MV, MR>([], options);
|
|
505
505
|
let i = 0;
|
|
506
|
-
for (const [k, v] of this) out.
|
|
506
|
+
for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
|
|
507
507
|
return out;
|
|
508
508
|
}
|
|
509
509
|
|