binary-tree-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 +320 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +320 -55
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +320 -55
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +320 -55
- 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/binary-tree-typed.js +320 -55
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-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
|
@@ -136,7 +136,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
136
136
|
* node?: BinaryTreeNode<string> | null,
|
|
137
137
|
* conditions?: { [key: string]: boolean }
|
|
138
138
|
* ): string {
|
|
139
|
-
* if (!node)
|
|
139
|
+
* if (!node) throw new Error('Invalid node');
|
|
140
140
|
*
|
|
141
141
|
* // If it's a leaf node, return the decision result
|
|
142
142
|
* if (!node.left && !node.right) return node.key;
|
|
@@ -181,7 +181,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
|
|
|
181
181
|
* case '/':
|
|
182
182
|
* return rightValue !== 0 ? leftValue / rightValue : 0; // Handle division by zero
|
|
183
183
|
* default:
|
|
184
|
-
*
|
|
184
|
+
* throw new Error(`Unsupported operator: ${node.key}`);
|
|
185
185
|
* }
|
|
186
186
|
* }
|
|
187
187
|
*
|
|
@@ -353,7 +353,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
353
353
|
isValidKey(key: unknown): key is K;
|
|
354
354
|
/**
|
|
355
355
|
* Adds a new node to the tree.
|
|
356
|
-
* @remarks Time O(
|
|
356
|
+
* @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).
|
|
357
357
|
*
|
|
358
358
|
* @param keyNodeOrEntry - The key, node, or entry to add.
|
|
359
359
|
* @returns True if the addition was successful, false otherwise.
|
|
@@ -379,6 +379,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
379
379
|
|
|
380
380
|
|
|
381
381
|
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
382
389
|
|
|
383
390
|
|
|
384
391
|
|
|
@@ -399,7 +406,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
399
406
|
add(keyNodeOrEntry: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): boolean;
|
|
400
407
|
/**
|
|
401
408
|
* Adds or updates a new node to the tree.
|
|
402
|
-
* @remarks Time O(
|
|
409
|
+
* @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).
|
|
403
410
|
*
|
|
404
411
|
* @param keyNodeOrEntry - The key, node, or entry to set or update.
|
|
405
412
|
* @param [value] - The value, if providing just a key.
|
|
@@ -431,6 +438,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
431
438
|
|
|
432
439
|
|
|
433
440
|
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
434
448
|
|
|
435
449
|
|
|
436
450
|
|
|
@@ -495,6 +509,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
495
509
|
|
|
496
510
|
|
|
497
511
|
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
498
519
|
|
|
499
520
|
|
|
500
521
|
|
|
@@ -535,6 +556,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
535
556
|
|
|
536
557
|
|
|
537
558
|
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
538
566
|
|
|
539
567
|
|
|
540
568
|
|
|
@@ -580,6 +608,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
580
608
|
|
|
581
609
|
|
|
582
610
|
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
583
618
|
|
|
584
619
|
|
|
585
620
|
|
|
@@ -597,19 +632,27 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
597
632
|
*/
|
|
598
633
|
merge(anotherTree: BinaryTree<K, V, R>): void;
|
|
599
634
|
/**
|
|
600
|
-
*
|
|
601
|
-
* @remarks Time O(N)
|
|
635
|
+
* Deletes a node from the tree (internal, returns balancing metadata).
|
|
636
|
+
* @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).
|
|
637
|
+
* @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
|
|
602
638
|
*
|
|
603
|
-
* @param
|
|
604
|
-
* @
|
|
639
|
+
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
640
|
+
* @returns An array containing deletion results with balancing metadata.
|
|
605
641
|
*/
|
|
606
|
-
|
|
642
|
+
protected _deleteInternal(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
|
|
607
643
|
/**
|
|
608
644
|
* Deletes a node from the tree.
|
|
609
|
-
* @remarks Time O(
|
|
645
|
+
* @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).
|
|
610
646
|
*
|
|
611
647
|
* @param keyNodeEntryRawOrPredicate - The node to delete.
|
|
612
|
-
* @returns
|
|
648
|
+
* @returns True if the node was found and deleted, false otherwise.
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
613
656
|
|
|
614
657
|
|
|
615
658
|
|
|
@@ -652,7 +695,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
652
695
|
* console.log(tree.has(3)); // false;
|
|
653
696
|
* console.log(tree.size); // 4;
|
|
654
697
|
*/
|
|
655
|
-
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>):
|
|
698
|
+
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): boolean;
|
|
656
699
|
/**
|
|
657
700
|
* Search by predicate
|
|
658
701
|
|
|
@@ -673,6 +716,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
673
716
|
|
|
674
717
|
|
|
675
718
|
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
676
726
|
|
|
677
727
|
|
|
678
728
|
|
|
@@ -722,6 +772,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
722
772
|
|
|
723
773
|
|
|
724
774
|
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
725
782
|
|
|
726
783
|
|
|
727
784
|
|
|
@@ -739,7 +796,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
739
796
|
getNodes(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>, onlyOne?: boolean, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V>[];
|
|
740
797
|
/**
|
|
741
798
|
* Gets the first node matching a predicate.
|
|
742
|
-
* @remarks Time O(
|
|
799
|
+
* @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.
|
|
743
800
|
*
|
|
744
801
|
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
|
|
745
802
|
* @param [startNode=this._root] - The node to start the search from.
|
|
@@ -770,6 +827,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
770
827
|
|
|
771
828
|
|
|
772
829
|
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
773
837
|
|
|
774
838
|
|
|
775
839
|
|
|
@@ -786,7 +850,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
786
850
|
getNode(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V> | null>, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): BinaryTreeNode<K, V> | null | undefined;
|
|
787
851
|
/**
|
|
788
852
|
* Gets the value associated with a key.
|
|
789
|
-
* @remarks Time O(
|
|
853
|
+
* @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).
|
|
790
854
|
*
|
|
791
855
|
* @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
|
|
792
856
|
* @param [startNode=this._root] - The node to start searching from (if not in Map mode).
|
|
@@ -819,6 +883,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
819
883
|
|
|
820
884
|
|
|
821
885
|
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
822
893
|
|
|
823
894
|
|
|
824
895
|
|
|
@@ -836,7 +907,7 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
836
907
|
get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
|
|
837
908
|
/**
|
|
838
909
|
* Checks if a node matching the predicate exists in the tree.
|
|
839
|
-
* @remarks Time O(
|
|
910
|
+
* @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.
|
|
840
911
|
*
|
|
841
912
|
* @param [keyNodeEntryOrPredicate] - The key, node, entry, or predicate to check for.
|
|
842
913
|
* @param [startNode] - The node to start the search from.
|
|
@@ -869,6 +940,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
869
940
|
|
|
870
941
|
|
|
871
942
|
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+
|
|
872
950
|
|
|
873
951
|
|
|
874
952
|
|
|
@@ -935,6 +1013,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
935
1013
|
|
|
936
1014
|
|
|
937
1015
|
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
938
1023
|
|
|
939
1024
|
|
|
940
1025
|
|
|
@@ -980,6 +1065,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
980
1065
|
|
|
981
1066
|
|
|
982
1067
|
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
983
1075
|
|
|
984
1076
|
|
|
985
1077
|
|
|
@@ -1033,6 +1125,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1033
1125
|
|
|
1034
1126
|
|
|
1035
1127
|
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1036
1135
|
|
|
1037
1136
|
|
|
1038
1137
|
|
|
@@ -1082,6 +1181,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1082
1181
|
|
|
1083
1182
|
|
|
1084
1183
|
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1085
1191
|
|
|
1086
1192
|
|
|
1087
1193
|
|
|
@@ -1131,6 +1237,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1131
1237
|
|
|
1132
1238
|
|
|
1133
1239
|
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1134
1247
|
|
|
1135
1248
|
|
|
1136
1249
|
|
|
@@ -1205,6 +1318,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1205
1318
|
|
|
1206
1319
|
|
|
1207
1320
|
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
|
|
1208
1328
|
|
|
1209
1329
|
|
|
1210
1330
|
|
|
@@ -1251,6 +1371,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1251
1371
|
|
|
1252
1372
|
|
|
1253
1373
|
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
|
|
1380
|
+
|
|
1254
1381
|
|
|
1255
1382
|
|
|
1256
1383
|
|
|
@@ -1317,6 +1444,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1317
1444
|
|
|
1318
1445
|
|
|
1319
1446
|
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1320
1454
|
|
|
1321
1455
|
|
|
1322
1456
|
|
|
@@ -1359,6 +1493,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1359
1493
|
|
|
1360
1494
|
|
|
1361
1495
|
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1499
|
+
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
|
|
1362
1503
|
|
|
1363
1504
|
|
|
1364
1505
|
|
|
@@ -1403,6 +1544,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1403
1544
|
|
|
1404
1545
|
|
|
1405
1546
|
|
|
1547
|
+
|
|
1548
|
+
|
|
1549
|
+
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
|
|
1406
1554
|
|
|
1407
1555
|
|
|
1408
1556
|
|
|
@@ -1449,6 +1597,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1449
1597
|
|
|
1450
1598
|
|
|
1451
1599
|
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
|
|
1606
|
+
|
|
1452
1607
|
|
|
1453
1608
|
|
|
1454
1609
|
|
|
@@ -1497,6 +1652,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1497
1652
|
|
|
1498
1653
|
|
|
1499
1654
|
|
|
1655
|
+
|
|
1656
|
+
|
|
1657
|
+
|
|
1658
|
+
|
|
1659
|
+
|
|
1660
|
+
|
|
1661
|
+
|
|
1500
1662
|
|
|
1501
1663
|
|
|
1502
1664
|
|
|
@@ -1548,6 +1710,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1548
1710
|
|
|
1549
1711
|
|
|
1550
1712
|
|
|
1713
|
+
|
|
1714
|
+
|
|
1715
|
+
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
|
|
1719
|
+
|
|
1551
1720
|
|
|
1552
1721
|
|
|
1553
1722
|
|
|
@@ -1603,6 +1772,13 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1603
1772
|
|
|
1604
1773
|
|
|
1605
1774
|
|
|
1775
|
+
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
|
|
1779
|
+
|
|
1780
|
+
|
|
1781
|
+
|
|
1606
1782
|
|
|
1607
1783
|
|
|
1608
1784
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { BSTNOptKeyOrNode, BSTOptions, BTNRep, Comparator, DFSOrderPattern, EntryCallback, FamilyPosition, IterationType, NodeCallback, NodePredicate, OptNode, RBTNColor } from '../../types';
|
|
9
9
|
import { BinaryTree } from './binary-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
import { Range } from '../../common';
|
|
@@ -366,6 +366,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
366
366
|
|
|
367
367
|
|
|
368
368
|
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
369
383
|
|
|
370
384
|
|
|
371
385
|
|
|
@@ -438,6 +452,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
438
452
|
|
|
439
453
|
|
|
440
454
|
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
441
469
|
|
|
442
470
|
|
|
443
471
|
|
|
@@ -513,6 +541,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
513
541
|
|
|
514
542
|
|
|
515
543
|
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
516
558
|
|
|
517
559
|
|
|
518
560
|
|
|
@@ -532,7 +574,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
532
574
|
* // Level-order grouping
|
|
533
575
|
* const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
534
576
|
* const levels = bst.listLevels(node => node.key);
|
|
535
|
-
* console.log(levels
|
|
577
|
+
* console.log(levels); // toBeInstanceOf;
|
|
536
578
|
* console.log(levels[0].length); // 1; // root level has 1 node
|
|
537
579
|
* const allKeys = levels.flat().sort((a, b) => a - b);
|
|
538
580
|
* console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -599,6 +641,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
599
641
|
|
|
600
642
|
|
|
601
643
|
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
602
658
|
|
|
603
659
|
|
|
604
660
|
|
|
@@ -669,6 +725,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
669
725
|
|
|
670
726
|
|
|
671
727
|
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
672
742
|
|
|
673
743
|
|
|
674
744
|
|
|
@@ -721,6 +791,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
721
791
|
|
|
722
792
|
|
|
723
793
|
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
724
801
|
|
|
725
802
|
|
|
726
803
|
|
|
@@ -882,6 +959,27 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
882
959
|
|
|
883
960
|
|
|
884
961
|
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
885
983
|
|
|
886
984
|
|
|
887
985
|
|
|
@@ -966,6 +1064,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
966
1064
|
|
|
967
1065
|
|
|
968
1066
|
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
969
1081
|
|
|
970
1082
|
|
|
971
1083
|
|
|
@@ -1021,6 +1133,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1021
1133
|
|
|
1022
1134
|
|
|
1023
1135
|
|
|
1136
|
+
|
|
1137
|
+
|
|
1138
|
+
|
|
1139
|
+
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
|
|
1024
1143
|
|
|
1025
1144
|
|
|
1026
1145
|
|
|
@@ -1075,6 +1194,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1075
1194
|
|
|
1076
1195
|
|
|
1077
1196
|
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1078
1204
|
|
|
1079
1205
|
|
|
1080
1206
|
|
|
@@ -1128,6 +1254,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1128
1254
|
|
|
1129
1255
|
|
|
1130
1256
|
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1131
1264
|
|
|
1132
1265
|
|
|
1133
1266
|
|
|
@@ -1182,6 +1315,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1182
1315
|
|
|
1183
1316
|
|
|
1184
1317
|
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1324
|
+
|
|
1185
1325
|
|
|
1186
1326
|
|
|
1187
1327
|
|
|
@@ -1236,6 +1376,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1236
1376
|
|
|
1237
1377
|
|
|
1238
1378
|
|
|
1379
|
+
|
|
1380
|
+
|
|
1381
|
+
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
|
|
1239
1386
|
|
|
1240
1387
|
|
|
1241
1388
|
|
|
@@ -1285,6 +1432,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1285
1432
|
|
|
1286
1433
|
|
|
1287
1434
|
|
|
1435
|
+
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
|
|
1288
1442
|
|
|
1289
1443
|
|
|
1290
1444
|
|
|
@@ -1363,6 +1517,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1363
1517
|
|
|
1364
1518
|
|
|
1365
1519
|
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
|
|
1527
|
+
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1366
1534
|
|
|
1367
1535
|
|
|
1368
1536
|
|
|
@@ -1421,7 +1589,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1421
1589
|
* - Value: true if the deletion succeeded, false if it failed (e.g., key not found during deletion phase).
|
|
1422
1590
|
* - If no nodes match the search criteria, the returned map is empty.
|
|
1423
1591
|
*/
|
|
1424
|
-
deleteWhere(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType):
|
|
1592
|
+
deleteWhere(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): boolean;
|
|
1425
1593
|
/**
|
|
1426
1594
|
* (Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
1427
1595
|
* @remarks Time O(1) Space O(1)
|