binary-tree-typed 2.5.1 → 2.5.3
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 +340 -107
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +339 -106
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +340 -108
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +339 -107
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- 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 +189 -13
- package/dist/types/data-structures/binary-tree/bst.d.ts +270 -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 +1089 -161
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
- 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 +126 -0
- 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 +127 -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/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/binary-tree-typed.js +337 -105
- 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/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +99 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
- package/src/data-structures/binary-tree/binary-tree.ts +239 -78
- package/src/data-structures/binary-tree/bst.ts +542 -13
- package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +1223 -261
- package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
- package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
- package/src/data-structures/binary-tree/tree-set.ts +1018 -99
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- 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 +102 -16
- package/src/data-structures/heap/heap.ts +153 -23
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
- package/src/data-structures/matrix/matrix.ts +65 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +130 -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 +86 -2
- package/src/interfaces/binary-tree.ts +1 -9
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
|
@@ -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';
|
|
@@ -254,6 +254,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
254
254
|
*/
|
|
255
255
|
constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
|
|
256
256
|
protected _root?: BSTNode<K, V>;
|
|
257
|
+
protected _enableOrderStatistic: boolean;
|
|
257
258
|
/**
|
|
258
259
|
* Gets the root node of the tree.
|
|
259
260
|
* @remarks Time O(1)
|
|
@@ -359,6 +360,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
359
360
|
|
|
360
361
|
|
|
361
362
|
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
362
377
|
|
|
363
378
|
|
|
364
379
|
|
|
@@ -425,6 +440,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
425
440
|
|
|
426
441
|
|
|
427
442
|
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
428
457
|
|
|
429
458
|
|
|
430
459
|
|
|
@@ -494,6 +523,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
494
523
|
|
|
495
524
|
|
|
496
525
|
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
497
540
|
|
|
498
541
|
|
|
499
542
|
|
|
@@ -513,7 +556,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
513
556
|
* // Level-order grouping
|
|
514
557
|
* const bst = new BST<number>([5, 3, 7, 1, 4]);
|
|
515
558
|
* const levels = bst.listLevels(node => node.key);
|
|
516
|
-
* console.log(levels
|
|
559
|
+
* console.log(levels); // toBeInstanceOf;
|
|
517
560
|
* console.log(levels[0].length); // 1; // root level has 1 node
|
|
518
561
|
* const allKeys = levels.flat().sort((a, b) => a - b);
|
|
519
562
|
* console.log(allKeys); // [1, 3, 4, 5, 7];
|
|
@@ -574,6 +617,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
574
617
|
|
|
575
618
|
|
|
576
619
|
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
577
634
|
|
|
578
635
|
|
|
579
636
|
|
|
@@ -638,6 +695,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
638
695
|
|
|
639
696
|
|
|
640
697
|
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
641
712
|
|
|
642
713
|
|
|
643
714
|
|
|
@@ -687,6 +758,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
687
758
|
|
|
688
759
|
|
|
689
760
|
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
690
768
|
|
|
691
769
|
|
|
692
770
|
|
|
@@ -702,6 +780,69 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
702
780
|
*/
|
|
703
781
|
rangeSearch(range: Range<K> | [K, K]): (K | undefined)[];
|
|
704
782
|
rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
|
|
783
|
+
/**
|
|
784
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
785
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
786
|
+
* Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
787
|
+
*
|
|
788
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
789
|
+
* @returns The key at position k, or `undefined` if out of bounds.
|
|
790
|
+
* @example
|
|
791
|
+
* // Order-statistic on BST
|
|
792
|
+
* const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
793
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
794
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
795
|
+
* console.log(tree.getRank(30)); // 2;
|
|
796
|
+
*/
|
|
797
|
+
getByRank(k: number): K | undefined;
|
|
798
|
+
/**
|
|
799
|
+
* Returns the element at the k-th position in tree order and applies a callback.
|
|
800
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
801
|
+
*
|
|
802
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
803
|
+
* @param callback - Callback to apply to the found node.
|
|
804
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
805
|
+
* @returns The callback result, or `undefined` if out of bounds.
|
|
806
|
+
*/
|
|
807
|
+
getByRank<C extends NodeCallback<BSTNode<K, V>>>(k: number, callback: C, iterationType?: IterationType): ReturnType<C> | undefined;
|
|
808
|
+
/**
|
|
809
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
810
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
811
|
+
* Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
812
|
+
*
|
|
813
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry `[K, V]`, or predicate to find.
|
|
814
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
815
|
+
*/
|
|
816
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): number;
|
|
817
|
+
/**
|
|
818
|
+
* Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
819
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
820
|
+
*
|
|
821
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate to find.
|
|
822
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
823
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
824
|
+
*/
|
|
825
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, iterationType: IterationType): number;
|
|
826
|
+
/**
|
|
827
|
+
* Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
828
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
829
|
+
*
|
|
830
|
+
* @param start - Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
831
|
+
* @param end - End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
832
|
+
* @returns Array of keys in tree order within the specified range.
|
|
833
|
+
*/
|
|
834
|
+
rangeByRank(start: number, end: number): (K | undefined)[];
|
|
835
|
+
/**
|
|
836
|
+
* Returns elements by position range in tree order with callback and optional iteration type.
|
|
837
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
838
|
+
*
|
|
839
|
+
* @param start - Start rank (inclusive, 0-indexed).
|
|
840
|
+
* @param end - End rank (inclusive, 0-indexed).
|
|
841
|
+
* @param callback - Callback to apply to each node in the range.
|
|
842
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
843
|
+
* @returns Array of callback results for nodes in the rank range.
|
|
844
|
+
*/
|
|
845
|
+
rangeByRank<C extends NodeCallback<BSTNode<K, V>>>(start: number, end: number, callback: C, iterationType?: IterationType): ReturnType<C>[];
|
|
705
846
|
/**
|
|
706
847
|
* Adds a new node to the BST based on key comparison.
|
|
707
848
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -776,6 +917,27 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
776
917
|
|
|
777
918
|
|
|
778
919
|
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
779
941
|
|
|
780
942
|
|
|
781
943
|
|
|
@@ -854,6 +1016,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
854
1016
|
|
|
855
1017
|
|
|
856
1018
|
|
|
1019
|
+
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
857
1033
|
|
|
858
1034
|
|
|
859
1035
|
|
|
@@ -906,6 +1082,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
906
1082
|
|
|
907
1083
|
|
|
908
1084
|
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
909
1092
|
|
|
910
1093
|
|
|
911
1094
|
|
|
@@ -957,6 +1140,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
957
1140
|
|
|
958
1141
|
|
|
959
1142
|
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
|
|
1149
|
+
|
|
960
1150
|
|
|
961
1151
|
|
|
962
1152
|
|
|
@@ -1007,6 +1197,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1007
1197
|
|
|
1008
1198
|
|
|
1009
1199
|
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1010
1207
|
|
|
1011
1208
|
|
|
1012
1209
|
|
|
@@ -1058,6 +1255,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1058
1255
|
|
|
1059
1256
|
|
|
1060
1257
|
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1061
1265
|
|
|
1062
1266
|
|
|
1063
1267
|
|
|
@@ -1109,6 +1313,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1109
1313
|
|
|
1110
1314
|
|
|
1111
1315
|
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
|
|
1322
|
+
|
|
1112
1323
|
|
|
1113
1324
|
|
|
1114
1325
|
|
|
@@ -1155,6 +1366,13 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1155
1366
|
|
|
1156
1367
|
|
|
1157
1368
|
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1158
1376
|
|
|
1159
1377
|
|
|
1160
1378
|
|
|
@@ -1227,6 +1445,20 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1227
1445
|
|
|
1228
1446
|
|
|
1229
1447
|
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1230
1462
|
|
|
1231
1463
|
|
|
1232
1464
|
|
|
@@ -1285,7 +1517,7 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1285
1517
|
* - Value: true if the deletion succeeded, false if it failed (e.g., key not found during deletion phase).
|
|
1286
1518
|
* - If no nodes match the search criteria, the returned map is empty.
|
|
1287
1519
|
*/
|
|
1288
|
-
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):
|
|
1520
|
+
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;
|
|
1289
1521
|
/**
|
|
1290
1522
|
* (Protected) Creates the default comparator function for keys that don't have a custom comparator.
|
|
1291
1523
|
* @remarks Time O(1) Space O(1)
|
|
@@ -1412,6 +1644,41 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1412
1644
|
*
|
|
1413
1645
|
* @param v - The node to set as root.
|
|
1414
1646
|
*/
|
|
1647
|
+
/**
|
|
1648
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
1649
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
1650
|
+
*/
|
|
1651
|
+
protected _updateCount(node: BSTNode<K, V>): void;
|
|
1652
|
+
/**
|
|
1653
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
1654
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
1655
|
+
*/
|
|
1656
|
+
protected _updateCountAlongPath(node: OptNode<BSTNode<K, V>>): void;
|
|
1657
|
+
/**
|
|
1658
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
1659
|
+
* @remarks Time O(log n), Space O(1)
|
|
1660
|
+
*/
|
|
1661
|
+
protected _getByRankIterative(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1662
|
+
/**
|
|
1663
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
1664
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1665
|
+
*/
|
|
1666
|
+
protected _getByRankRecursive(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1667
|
+
/**
|
|
1668
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
1669
|
+
* @remarks Time O(log n), Space O(1)
|
|
1670
|
+
*/
|
|
1671
|
+
protected _getRankIterative(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1672
|
+
/**
|
|
1673
|
+
* (Protected) Computes the rank of a key recursively.
|
|
1674
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1675
|
+
*/
|
|
1676
|
+
protected _getRankRecursive(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1677
|
+
/**
|
|
1678
|
+
* (Protected) Finds the in-order successor of a node.
|
|
1679
|
+
* @remarks Time O(log n), Space O(1)
|
|
1680
|
+
*/
|
|
1681
|
+
protected _next(node: BSTNode<K, V>): BSTNode<K, V> | undefined;
|
|
1415
1682
|
protected _setRoot(v: OptNode<BSTNode<K, V>>): void;
|
|
1416
1683
|
/**
|
|
1417
1684
|
* (Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
@@ -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 { BTNRep, CRUD, EntryCallback, FamilyPosition, NodePredicate, RBTNColor, IterationType, RedBlackTreeOptions } from '../../types';
|
|
9
9
|
import { BST } from './bst';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
export declare class RedBlackTreeNode<K = any, V = any> {
|
|
@@ -217,13 +217,36 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
217
217
|
*/
|
|
218
218
|
isNode(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is RedBlackTreeNode<K, V>;
|
|
219
219
|
/**
|
|
220
|
-
* Remove all nodes
|
|
220
|
+
* Remove all nodes, clear the key→value store (if in map mode) and internal caches.
|
|
221
221
|
* @remarks Time O(n), Space O(1)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
227
250
|
|
|
228
251
|
|
|
229
252
|
|
|
@@ -548,6 +571,34 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
548
571
|
|
|
549
572
|
|
|
550
573
|
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
551
602
|
|
|
552
603
|
|
|
553
604
|
|
|
@@ -694,6 +745,34 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
694
745
|
|
|
695
746
|
|
|
696
747
|
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
697
776
|
|
|
698
777
|
|
|
699
778
|
|
|
@@ -722,7 +801,7 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
722
801
|
* console.log(rbt.has(5)); // false;
|
|
723
802
|
* console.log(rbt.size); // 4;
|
|
724
803
|
*/
|
|
725
|
-
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>):
|
|
804
|
+
delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, RedBlackTreeNode<K, V>> | NodePredicate<RedBlackTreeNode<K, V> | null>): boolean;
|
|
726
805
|
/**
|
|
727
806
|
* Transform entries into a like-kind red-black tree with possibly different key/value types.
|
|
728
807
|
* @remarks Time O(n) average, Space O(n)
|
|
@@ -805,6 +884,27 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
805
884
|
|
|
806
885
|
|
|
807
886
|
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
808
908
|
|
|
809
909
|
|
|
810
910
|
|
|
@@ -933,6 +1033,34 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
933
1033
|
|
|
934
1034
|
|
|
935
1035
|
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
936
1064
|
|
|
937
1065
|
|
|
938
1066
|
|
|
@@ -69,6 +69,13 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
72
79
|
|
|
73
80
|
|
|
74
81
|
|
|
@@ -127,6 +134,13 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
127
134
|
|
|
128
135
|
|
|
129
136
|
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
130
144
|
|
|
131
145
|
|
|
132
146
|
|
|
@@ -181,6 +195,13 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
181
195
|
|
|
182
196
|
|
|
183
197
|
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
184
205
|
|
|
185
206
|
|
|
186
207
|
|
|
@@ -230,6 +251,13 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
230
251
|
|
|
231
252
|
|
|
232
253
|
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
233
261
|
|
|
234
262
|
|
|
235
263
|
|
|
@@ -274,6 +302,13 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
274
302
|
|
|
275
303
|
|
|
276
304
|
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
277
312
|
|
|
278
313
|
|
|
279
314
|
|
|
@@ -321,6 +356,13 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
321
356
|
|
|
322
357
|
|
|
323
358
|
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
324
366
|
|
|
325
367
|
|
|
326
368
|
|