max-priority-queue-typed 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +174 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +174 -16
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +174 -16
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +174 -16
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/max-priority-queue-typed.js +174 -16
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
|
@@ -103,6 +103,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
106
120
|
|
|
107
121
|
|
|
108
122
|
|
|
@@ -180,6 +194,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
180
194
|
|
|
181
195
|
|
|
182
196
|
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
183
211
|
|
|
184
212
|
|
|
185
213
|
|
|
@@ -257,6 +285,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
257
285
|
|
|
258
286
|
|
|
259
287
|
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
260
302
|
|
|
261
303
|
|
|
262
304
|
|
|
@@ -334,6 +376,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
334
376
|
|
|
335
377
|
|
|
336
378
|
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
337
393
|
|
|
338
394
|
|
|
339
395
|
|
|
@@ -409,6 +465,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
409
465
|
|
|
410
466
|
|
|
411
467
|
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
412
482
|
|
|
413
483
|
|
|
414
484
|
|
|
@@ -492,6 +562,20 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
492
562
|
|
|
493
563
|
|
|
494
564
|
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
495
579
|
|
|
496
580
|
|
|
497
581
|
|
|
@@ -552,6 +636,13 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
552
636
|
|
|
553
637
|
|
|
554
638
|
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
555
646
|
|
|
556
647
|
|
|
557
648
|
|
|
@@ -621,6 +712,13 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
621
712
|
|
|
622
713
|
|
|
623
714
|
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
624
722
|
|
|
625
723
|
|
|
626
724
|
|
|
@@ -216,7 +216,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
216
216
|
* node?: BinaryTreeNode<string> | null,
|
|
217
217
|
* conditions?: { [key: string]: boolean }
|
|
218
218
|
* ): string {
|
|
219
|
-
* if (!node)
|
|
219
|
+
* if (!node) throw new Error('Invalid node');
|
|
220
220
|
*
|
|
221
221
|
* // If it's a leaf node, return the decision result
|
|
222
222
|
* if (!node.left && !node.right) return node.key;
|
|
@@ -261,7 +261,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
261
261
|
* case '/':
|
|
262
262
|
* return rightValue !== 0 ? leftValue / rightValue : 0; // Handle division by zero
|
|
263
263
|
* default:
|
|
264
|
-
*
|
|
264
|
+
* throw new Error(`Unsupported operator: ${node.key}`);
|
|
265
265
|
* }
|
|
266
266
|
* }
|
|
267
267
|
*
|
|
@@ -562,7 +562,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
562
562
|
|
|
563
563
|
/**
|
|
564
564
|
* Adds a new node to the tree.
|
|
565
|
-
* @remarks Time O(
|
|
565
|
+
* @remarks Time O(N) — level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
566
566
|
*
|
|
567
567
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
568
568
|
* @returns True if the addition was successful, false otherwise.
|
|
@@ -588,6 +588,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
588
588
|
|
|
589
589
|
|
|
590
590
|
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
591
598
|
|
|
592
599
|
|
|
593
600
|
|
|
@@ -613,7 +620,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
613
620
|
|
|
614
621
|
/**
|
|
615
622
|
* Adds or updates a new node to the tree.
|
|
616
|
-
* @remarks Time O(
|
|
623
|
+
* @remarks Time O(N) — level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
617
624
|
*
|
|
618
625
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
619
626
|
* @param [value] - The value, if providing just a key.
|
|
@@ -645,6 +652,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
645
652
|
|
|
646
653
|
|
|
647
654
|
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
648
662
|
|
|
649
663
|
|
|
650
664
|
|
|
@@ -764,6 +778,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
764
778
|
|
|
765
779
|
|
|
766
780
|
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
767
788
|
|
|
768
789
|
|
|
769
790
|
|
|
@@ -811,6 +832,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
811
832
|
|
|
812
833
|
|
|
813
834
|
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
814
842
|
|
|
815
843
|
|
|
816
844
|
|
|
@@ -884,6 +912,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
884
912
|
|
|
885
913
|
|
|
886
914
|
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
887
922
|
|
|
888
923
|
|
|
889
924
|
|
|
@@ -904,71 +939,14 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
904
939
|
}
|
|
905
940
|
|
|
906
941
|
/**
|
|
907
|
-
*
|
|
908
|
-
* @remarks Time O(N)
|
|
909
|
-
*
|
|
910
|
-
* @param keysNodesEntriesOrRaws - An iterable of items to set.
|
|
911
|
-
* @param [values] - An optional parallel iterable of values.
|
|
912
|
-
*/
|
|
913
|
-
refill(
|
|
914
|
-
keysNodesEntriesOrRaws: Iterable<
|
|
915
|
-
K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
916
|
-
>,
|
|
917
|
-
values?: Iterable<V | undefined>
|
|
918
|
-
): void {
|
|
919
|
-
this.clear();
|
|
920
|
-
this.setMany(keysNodesEntriesOrRaws, values);
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
/**
|
|
924
|
-
* Deletes a node from the tree.
|
|
925
|
-
* @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation finds the node, and if it has two children, swaps it with the rightmost node of its left subtree (in-order predecessor) before deleting. Time O(N) in the worst case. O(N) to find the node (`getNode`) and O(H) (which is O(N) worst-case) to find the rightmost node. Space O(1) (if `getNode` is iterative, which it is).
|
|
942
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
943
|
+
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
944
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
926
945
|
*
|
|
927
946
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
928
|
-
* @returns An array containing deletion results
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
* @example
|
|
965
|
-
* // Remove a node
|
|
966
|
-
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
967
|
-
* tree.delete(3);
|
|
968
|
-
* console.log(tree.has(3)); // false;
|
|
969
|
-
* console.log(tree.size); // 4;
|
|
947
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
970
948
|
*/
|
|
971
|
-
|
|
949
|
+
protected _deleteInternal(
|
|
972
950
|
keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>
|
|
973
951
|
): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[] {
|
|
974
952
|
const deletedResult: BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[] = [];
|
|
@@ -982,26 +960,19 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
982
960
|
let orgCurrent: BinaryTreeNode<K, V> | undefined = curr;
|
|
983
961
|
|
|
984
962
|
if (!curr.left && !curr.right && !parent) {
|
|
985
|
-
// Deleting the root with no children
|
|
986
963
|
this._setRoot(undefined);
|
|
987
964
|
} else if (curr.left) {
|
|
988
|
-
// Node has a left child (or two children)
|
|
989
|
-
// Find the rightmost node in the left subtree
|
|
990
965
|
const leftSubTreeRightMost = this.getRightMost(node => node, curr.left);
|
|
991
966
|
if (leftSubTreeRightMost) {
|
|
992
967
|
const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
|
|
993
|
-
// Swap properties
|
|
994
968
|
orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
|
|
995
969
|
|
|
996
|
-
// Map mode store tracks key -> node reference; after swapping keys we must re-index both nodes.
|
|
997
970
|
if (this._isMapMode) {
|
|
998
971
|
this._store.set(curr.key, curr);
|
|
999
972
|
this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
|
|
1000
973
|
}
|
|
1001
974
|
|
|
1002
|
-
// `orgCurrent` is now the node to be physically deleted (which was the rightmost)
|
|
1003
975
|
if (parentOfLeftSubTreeMax) {
|
|
1004
|
-
// Unlink the rightmost node
|
|
1005
976
|
if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
|
|
1006
977
|
parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
|
|
1007
978
|
else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
|
|
@@ -1009,8 +980,6 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1009
980
|
}
|
|
1010
981
|
}
|
|
1011
982
|
} else if (parent) {
|
|
1012
|
-
// Node has no left child, but has a parent
|
|
1013
|
-
// Promote the right child (which could be null)
|
|
1014
983
|
const { familyPosition: fp } = curr;
|
|
1015
984
|
if (fp === 'LEFT' || fp === 'ROOT_LEFT') {
|
|
1016
985
|
parent.left = curr.right;
|
|
@@ -1019,8 +988,6 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1019
988
|
}
|
|
1020
989
|
needBalanced = parent;
|
|
1021
990
|
} else {
|
|
1022
|
-
// Deleting the root, which has no left child
|
|
1023
|
-
// Promote the right child as the new root
|
|
1024
991
|
this._setRoot(curr.right);
|
|
1025
992
|
curr.right = undefined;
|
|
1026
993
|
}
|
|
@@ -1032,6 +999,67 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1032
999
|
return deletedResult;
|
|
1033
1000
|
}
|
|
1034
1001
|
|
|
1002
|
+
/**
|
|
1003
|
+
* Deletes a node from the tree.
|
|
1004
|
+
* @remarks Time O(N) — O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
|
|
1005
|
+
*
|
|
1006
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
1007
|
+
* @returns True if the node was found and deleted, false otherwise.
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
* @example
|
|
1051
|
+
* // Remove a node
|
|
1052
|
+
* const tree = new BinaryTree<number>([1, 2, 3, 4, 5]);
|
|
1053
|
+
* tree.delete(3);
|
|
1054
|
+
* console.log(tree.has(3)); // false;
|
|
1055
|
+
* console.log(tree.size); // 4;
|
|
1056
|
+
*/
|
|
1057
|
+
delete(
|
|
1058
|
+
keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>
|
|
1059
|
+
): boolean {
|
|
1060
|
+
return this._deleteInternal(keyNodeEntryRawOrPredicate).length > 0;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1035
1063
|
/**
|
|
1036
1064
|
* Search by predicate
|
|
1037
1065
|
|
|
@@ -1052,6 +1080,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1052
1080
|
|
|
1053
1081
|
|
|
1054
1082
|
|
|
1083
|
+
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1055
1090
|
|
|
1056
1091
|
|
|
1057
1092
|
|
|
@@ -1093,7 +1128,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1093
1128
|
|
|
1094
1129
|
/**
|
|
1095
1130
|
* Searches the tree for nodes matching a predicate.
|
|
1096
|
-
* @remarks Time O(
|
|
1131
|
+
* @remarks Time O(N) — full DFS scan; may visit every node. Space O(H) for call/explicit stack (O(N) worst-case). BST subclasses with key search override to O(log N).
|
|
1097
1132
|
*
|
|
1098
1133
|
* @template C - The type of the callback function.
|
|
1099
1134
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
@@ -1188,6 +1223,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1188
1223
|
|
|
1189
1224
|
|
|
1190
1225
|
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1191
1233
|
|
|
1192
1234
|
|
|
1193
1235
|
|
|
@@ -1232,7 +1274,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1232
1274
|
|
|
1233
1275
|
/**
|
|
1234
1276
|
* Gets the first node matching a predicate.
|
|
1235
|
-
* @remarks Time O(
|
|
1277
|
+
* @remarks Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
|
|
1236
1278
|
*
|
|
1237
1279
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
1238
1280
|
* @param [startNode=this._root] - The node to start the search from.
|
|
@@ -1263,6 +1305,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1263
1305
|
|
|
1264
1306
|
|
|
1265
1307
|
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1266
1315
|
|
|
1267
1316
|
|
|
1268
1317
|
|
|
@@ -1299,7 +1348,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1299
1348
|
|
|
1300
1349
|
/**
|
|
1301
1350
|
* Gets the value associated with a key.
|
|
1302
|
-
* @remarks Time O(
|
|
1351
|
+
* @remarks Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O(H) or O(N) otherwise. BST subclasses override non-Map-mode to O(log N).
|
|
1303
1352
|
*
|
|
1304
1353
|
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
1305
1354
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
@@ -1332,6 +1381,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1332
1381
|
|
|
1333
1382
|
|
|
1334
1383
|
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
|
|
1387
|
+
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
|
|
1335
1391
|
|
|
1336
1392
|
|
|
1337
1393
|
|
|
@@ -1361,7 +1417,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1361
1417
|
|
|
1362
1418
|
/**
|
|
1363
1419
|
* Checks if a node matching the predicate exists in the tree.
|
|
1364
|
-
* @remarks Time O(
|
|
1420
|
+
* @remarks Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
|
|
1365
1421
|
*
|
|
1366
1422
|
* @param [keyNodeEntryOrPredicate] - The key, node, entry, or predicate to check for.
|
|
1367
1423
|
* @param [startNode] - The node to start the search from.
|
|
@@ -1394,6 +1450,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1394
1450
|
|
|
1395
1451
|
|
|
1396
1452
|
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1397
1460
|
|
|
1398
1461
|
|
|
1399
1462
|
|
|
@@ -1492,6 +1555,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1492
1555
|
|
|
1493
1556
|
|
|
1494
1557
|
|
|
1558
|
+
|
|
1559
|
+
|
|
1560
|
+
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
|
|
1564
|
+
|
|
1495
1565
|
|
|
1496
1566
|
|
|
1497
1567
|
|
|
@@ -1541,6 +1611,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1541
1611
|
|
|
1542
1612
|
|
|
1543
1613
|
|
|
1614
|
+
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
|
|
1620
|
+
|
|
1544
1621
|
|
|
1545
1622
|
|
|
1546
1623
|
|
|
@@ -1602,6 +1679,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1602
1679
|
|
|
1603
1680
|
|
|
1604
1681
|
|
|
1682
|
+
|
|
1683
|
+
|
|
1684
|
+
|
|
1685
|
+
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
|
|
1605
1689
|
|
|
1606
1690
|
|
|
1607
1691
|
|
|
@@ -1693,6 +1777,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1693
1777
|
|
|
1694
1778
|
|
|
1695
1779
|
|
|
1780
|
+
|
|
1781
|
+
|
|
1782
|
+
|
|
1783
|
+
|
|
1784
|
+
|
|
1785
|
+
|
|
1786
|
+
|
|
1696
1787
|
|
|
1697
1788
|
|
|
1698
1789
|
|
|
@@ -1758,6 +1849,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1758
1849
|
|
|
1759
1850
|
|
|
1760
1851
|
|
|
1852
|
+
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
|
|
1761
1859
|
|
|
1762
1860
|
|
|
1763
1861
|
|
|
@@ -2064,6 +2162,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2064
2162
|
|
|
2065
2163
|
|
|
2066
2164
|
|
|
2165
|
+
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
|
|
2169
|
+
|
|
2170
|
+
|
|
2171
|
+
|
|
2067
2172
|
|
|
2068
2173
|
|
|
2069
2174
|
|
|
@@ -2152,6 +2257,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2152
2257
|
|
|
2153
2258
|
|
|
2154
2259
|
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2265
|
+
|
|
2266
|
+
|
|
2155
2267
|
|
|
2156
2268
|
|
|
2157
2269
|
|
|
@@ -2299,6 +2411,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2299
2411
|
|
|
2300
2412
|
|
|
2301
2413
|
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2302
2421
|
|
|
2303
2422
|
|
|
2304
2423
|
|
|
@@ -2399,6 +2518,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2399
2518
|
|
|
2400
2519
|
|
|
2401
2520
|
|
|
2521
|
+
|
|
2522
|
+
|
|
2523
|
+
|
|
2524
|
+
|
|
2525
|
+
|
|
2526
|
+
|
|
2527
|
+
|
|
2402
2528
|
|
|
2403
2529
|
|
|
2404
2530
|
|
|
@@ -2517,6 +2643,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2517
2643
|
|
|
2518
2644
|
|
|
2519
2645
|
|
|
2646
|
+
|
|
2647
|
+
|
|
2648
|
+
|
|
2649
|
+
|
|
2650
|
+
|
|
2651
|
+
|
|
2652
|
+
|
|
2520
2653
|
|
|
2521
2654
|
|
|
2522
2655
|
|
|
@@ -2679,6 +2812,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2679
2812
|
|
|
2680
2813
|
|
|
2681
2814
|
|
|
2815
|
+
|
|
2816
|
+
|
|
2817
|
+
|
|
2818
|
+
|
|
2819
|
+
|
|
2820
|
+
|
|
2821
|
+
|
|
2682
2822
|
|
|
2683
2823
|
|
|
2684
2824
|
|
|
@@ -2732,6 +2872,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2732
2872
|
|
|
2733
2873
|
|
|
2734
2874
|
|
|
2875
|
+
|
|
2876
|
+
|
|
2877
|
+
|
|
2878
|
+
|
|
2879
|
+
|
|
2880
|
+
|
|
2881
|
+
|
|
2735
2882
|
|
|
2736
2883
|
|
|
2737
2884
|
|
|
@@ -2789,6 +2936,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2789
2936
|
|
|
2790
2937
|
|
|
2791
2938
|
|
|
2939
|
+
|
|
2940
|
+
|
|
2941
|
+
|
|
2942
|
+
|
|
2943
|
+
|
|
2944
|
+
|
|
2945
|
+
|
|
2792
2946
|
|
|
2793
2947
|
|
|
2794
2948
|
|
|
@@ -2879,6 +3033,13 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2879
3033
|
|
|
2880
3034
|
|
|
2881
3035
|
|
|
3036
|
+
|
|
3037
|
+
|
|
3038
|
+
|
|
3039
|
+
|
|
3040
|
+
|
|
3041
|
+
|
|
3042
|
+
|
|
2882
3043
|
|
|
2883
3044
|
|
|
2884
3045
|
|