max-priority-queue-typed 2.5.1 → 2.5.2
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 +104 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +103 -54
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +104 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +103 -55
- 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 +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +45 -0
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -0
- 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/max-priority-queue-typed.js +101 -53
- 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/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 +47 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
- package/src/data-structures/binary-tree/binary-tree.ts +79 -4
- package/src/data-structures/binary-tree/bst.ts +441 -6
- package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +434 -9
- package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
- package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
- package/src/data-structures/binary-tree/tree-set.ts +410 -8
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +35 -4
- package/src/data-structures/heap/heap.ts +46 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
- package/src/data-structures/matrix/matrix.ts +33 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +45 -0
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +38 -2
- 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
|
@@ -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) raise(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
|
+
* raise(Error, `Unsupported operator: ${node.key}`);
|
|
185
185
|
* }
|
|
186
186
|
* }
|
|
187
187
|
*
|
|
@@ -380,6 +380,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
380
380
|
|
|
381
381
|
|
|
382
382
|
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
383
386
|
|
|
384
387
|
|
|
385
388
|
|
|
@@ -429,6 +432,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
429
432
|
|
|
430
433
|
|
|
431
434
|
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
432
438
|
|
|
433
439
|
|
|
434
440
|
|
|
@@ -490,6 +496,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
490
496
|
|
|
491
497
|
|
|
492
498
|
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
493
502
|
|
|
494
503
|
|
|
495
504
|
|
|
@@ -527,6 +536,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
527
536
|
|
|
528
537
|
|
|
529
538
|
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
530
542
|
|
|
531
543
|
|
|
532
544
|
|
|
@@ -569,6 +581,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
569
581
|
|
|
570
582
|
|
|
571
583
|
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
572
587
|
|
|
573
588
|
|
|
574
589
|
|
|
@@ -623,6 +638,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
623
638
|
|
|
624
639
|
|
|
625
640
|
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
626
644
|
|
|
627
645
|
|
|
628
646
|
|
|
@@ -656,6 +674,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
656
674
|
|
|
657
675
|
|
|
658
676
|
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
659
680
|
|
|
660
681
|
|
|
661
682
|
|
|
@@ -702,6 +723,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
702
723
|
|
|
703
724
|
|
|
704
725
|
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
705
729
|
|
|
706
730
|
|
|
707
731
|
|
|
@@ -747,6 +771,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
747
771
|
|
|
748
772
|
|
|
749
773
|
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
750
777
|
|
|
751
778
|
|
|
752
779
|
|
|
@@ -793,6 +820,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
793
820
|
|
|
794
821
|
|
|
795
822
|
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
796
826
|
|
|
797
827
|
|
|
798
828
|
|
|
@@ -840,6 +870,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
840
870
|
|
|
841
871
|
|
|
842
872
|
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
|
|
843
876
|
|
|
844
877
|
|
|
845
878
|
|
|
@@ -903,6 +936,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
903
936
|
|
|
904
937
|
|
|
905
938
|
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
906
942
|
|
|
907
943
|
|
|
908
944
|
|
|
@@ -945,6 +981,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
945
981
|
|
|
946
982
|
|
|
947
983
|
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
948
987
|
|
|
949
988
|
|
|
950
989
|
|
|
@@ -995,6 +1034,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
995
1034
|
|
|
996
1035
|
|
|
997
1036
|
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
998
1040
|
|
|
999
1041
|
|
|
1000
1042
|
|
|
@@ -1041,6 +1083,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1041
1083
|
|
|
1042
1084
|
|
|
1043
1085
|
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
|
|
1044
1089
|
|
|
1045
1090
|
|
|
1046
1091
|
|
|
@@ -1087,6 +1132,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1087
1132
|
|
|
1088
1133
|
|
|
1089
1134
|
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
|
|
1090
1138
|
|
|
1091
1139
|
|
|
1092
1140
|
|
|
@@ -1158,6 +1206,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1158
1206
|
|
|
1159
1207
|
|
|
1160
1208
|
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1161
1212
|
|
|
1162
1213
|
|
|
1163
1214
|
|
|
@@ -1201,6 +1252,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1201
1252
|
|
|
1202
1253
|
|
|
1203
1254
|
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1204
1258
|
|
|
1205
1259
|
|
|
1206
1260
|
|
|
@@ -1264,6 +1318,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1264
1318
|
|
|
1265
1319
|
|
|
1266
1320
|
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
|
|
1267
1324
|
|
|
1268
1325
|
|
|
1269
1326
|
|
|
@@ -1303,6 +1360,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1303
1360
|
|
|
1304
1361
|
|
|
1305
1362
|
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1306
1366
|
|
|
1307
1367
|
|
|
1308
1368
|
|
|
@@ -1344,6 +1404,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1344
1404
|
|
|
1345
1405
|
|
|
1346
1406
|
|
|
1407
|
+
|
|
1408
|
+
|
|
1409
|
+
|
|
1347
1410
|
|
|
1348
1411
|
|
|
1349
1412
|
|
|
@@ -1387,6 +1450,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1387
1450
|
|
|
1388
1451
|
|
|
1389
1452
|
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1390
1456
|
|
|
1391
1457
|
|
|
1392
1458
|
|
|
@@ -1432,6 +1498,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1432
1498
|
|
|
1433
1499
|
|
|
1434
1500
|
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
|
|
1435
1504
|
|
|
1436
1505
|
|
|
1437
1506
|
|
|
@@ -1480,6 +1549,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1480
1549
|
|
|
1481
1550
|
|
|
1482
1551
|
|
|
1552
|
+
|
|
1553
|
+
|
|
1554
|
+
|
|
1483
1555
|
|
|
1484
1556
|
|
|
1485
1557
|
|
|
@@ -1532,6 +1604,9 @@ export declare class BinaryTree<K = any, V = any, R = any> extends IterableEntry
|
|
|
1532
1604
|
|
|
1533
1605
|
|
|
1534
1606
|
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
|
|
1535
1610
|
|
|
1536
1611
|
|
|
1537
1612
|
|
|
@@ -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)
|
|
@@ -367,6 +368,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
367
368
|
|
|
368
369
|
|
|
369
370
|
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
370
377
|
|
|
371
378
|
|
|
372
379
|
|
|
@@ -433,6 +440,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
433
440
|
|
|
434
441
|
|
|
435
442
|
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
436
449
|
|
|
437
450
|
|
|
438
451
|
|
|
@@ -502,6 +515,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
502
515
|
|
|
503
516
|
|
|
504
517
|
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
505
524
|
|
|
506
525
|
|
|
507
526
|
|
|
@@ -582,6 +601,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
582
601
|
|
|
583
602
|
|
|
584
603
|
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
585
610
|
|
|
586
611
|
|
|
587
612
|
|
|
@@ -646,6 +671,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
646
671
|
|
|
647
672
|
|
|
648
673
|
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
649
680
|
|
|
650
681
|
|
|
651
682
|
|
|
@@ -691,6 +722,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
691
722
|
|
|
692
723
|
|
|
693
724
|
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
694
728
|
|
|
695
729
|
|
|
696
730
|
|
|
@@ -702,6 +736,69 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
702
736
|
*/
|
|
703
737
|
rangeSearch(range: Range<K> | [K, K]): (K | undefined)[];
|
|
704
738
|
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>[];
|
|
739
|
+
/**
|
|
740
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
741
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
742
|
+
* Tree order is defined by the comparator — ascending by default, but respects custom comparators (e.g. descending).
|
|
743
|
+
*
|
|
744
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
745
|
+
* @returns The key at position k, or `undefined` if out of bounds.
|
|
746
|
+
* @example
|
|
747
|
+
* // Order-statistic on BST
|
|
748
|
+
* const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
749
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
750
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
751
|
+
* console.log(tree.getRank(30)); // 2;
|
|
752
|
+
*/
|
|
753
|
+
getByRank(k: number): K | undefined;
|
|
754
|
+
/**
|
|
755
|
+
* Returns the element at the k-th position in tree order and applies a callback.
|
|
756
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
757
|
+
*
|
|
758
|
+
* @param k - The 0-based position in tree order (0 = first element).
|
|
759
|
+
* @param callback - Callback to apply to the found node.
|
|
760
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
761
|
+
* @returns The callback result, or `undefined` if out of bounds.
|
|
762
|
+
*/
|
|
763
|
+
getByRank<C extends NodeCallback<BSTNode<K, V>>>(k: number, callback: C, iterationType?: IterationType): ReturnType<C> | undefined;
|
|
764
|
+
/**
|
|
765
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
766
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
767
|
+
* Tree order is defined by the comparator. When the key is not found, returns the insertion position.
|
|
768
|
+
*
|
|
769
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry `[K, V]`, or predicate to find.
|
|
770
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
771
|
+
*/
|
|
772
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): number;
|
|
773
|
+
/**
|
|
774
|
+
* Returns the 0-based rank (number of preceding elements in tree order) with explicit iteration type.
|
|
775
|
+
* @remarks Time O(log n), Space O(1) iterative / O(log n) recursive. Requires `enableOrderStatistic: true`.
|
|
776
|
+
*
|
|
777
|
+
* @param keyNodeEntryOrPredicate - The key, node, entry, or predicate to find.
|
|
778
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
779
|
+
* @returns The rank (0-indexed), or -1 if the tree is empty or input is invalid.
|
|
780
|
+
*/
|
|
781
|
+
getRank(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, iterationType: IterationType): number;
|
|
782
|
+
/**
|
|
783
|
+
* Returns elements by position range in tree order (0-indexed, inclusive on both ends).
|
|
784
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
785
|
+
*
|
|
786
|
+
* @param start - Start position (inclusive, 0-indexed). Clamped to 0 if negative.
|
|
787
|
+
* @param end - End position (inclusive, 0-indexed). Clamped to size-1 if too large.
|
|
788
|
+
* @returns Array of keys in tree order within the specified range.
|
|
789
|
+
*/
|
|
790
|
+
rangeByRank(start: number, end: number): (K | undefined)[];
|
|
791
|
+
/**
|
|
792
|
+
* Returns elements by position range in tree order with callback and optional iteration type.
|
|
793
|
+
* @remarks Time O(log n + k), Space O(k), where k = end - start + 1. Requires `enableOrderStatistic: true`.
|
|
794
|
+
*
|
|
795
|
+
* @param start - Start rank (inclusive, 0-indexed).
|
|
796
|
+
* @param end - End rank (inclusive, 0-indexed).
|
|
797
|
+
* @param callback - Callback to apply to each node in the range.
|
|
798
|
+
* @param iterationType - Iteration strategy ('ITERATIVE' or 'RECURSIVE').
|
|
799
|
+
* @returns Array of callback results for nodes in the rank range.
|
|
800
|
+
*/
|
|
801
|
+
rangeByRank<C extends NodeCallback<BSTNode<K, V>>>(start: number, end: number, callback: C, iterationType?: IterationType): ReturnType<C>[];
|
|
705
802
|
/**
|
|
706
803
|
* Adds a new node to the BST based on key comparison.
|
|
707
804
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -787,6 +884,15 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
787
884
|
|
|
788
885
|
|
|
789
886
|
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
790
896
|
|
|
791
897
|
|
|
792
898
|
|
|
@@ -862,6 +968,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
862
968
|
|
|
863
969
|
|
|
864
970
|
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
865
977
|
|
|
866
978
|
|
|
867
979
|
|
|
@@ -910,6 +1022,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
910
1022
|
|
|
911
1023
|
|
|
912
1024
|
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
913
1028
|
|
|
914
1029
|
|
|
915
1030
|
|
|
@@ -961,6 +1076,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
961
1076
|
|
|
962
1077
|
|
|
963
1078
|
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
|
|
964
1082
|
|
|
965
1083
|
|
|
966
1084
|
|
|
@@ -1011,6 +1129,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1011
1129
|
|
|
1012
1130
|
|
|
1013
1131
|
|
|
1132
|
+
|
|
1133
|
+
|
|
1134
|
+
|
|
1014
1135
|
|
|
1015
1136
|
|
|
1016
1137
|
|
|
@@ -1062,6 +1183,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1062
1183
|
|
|
1063
1184
|
|
|
1064
1185
|
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1065
1189
|
|
|
1066
1190
|
|
|
1067
1191
|
|
|
@@ -1113,6 +1237,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1113
1237
|
|
|
1114
1238
|
|
|
1115
1239
|
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1116
1243
|
|
|
1117
1244
|
|
|
1118
1245
|
|
|
@@ -1159,6 +1286,9 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1159
1286
|
|
|
1160
1287
|
|
|
1161
1288
|
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
|
|
1162
1292
|
|
|
1163
1293
|
|
|
1164
1294
|
|
|
@@ -1235,6 +1365,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1235
1365
|
|
|
1236
1366
|
|
|
1237
1367
|
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1238
1374
|
|
|
1239
1375
|
|
|
1240
1376
|
|
|
@@ -1412,6 +1548,41 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
|
|
|
1412
1548
|
*
|
|
1413
1549
|
* @param v - The node to set as root.
|
|
1414
1550
|
*/
|
|
1551
|
+
/**
|
|
1552
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
1553
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
1554
|
+
*/
|
|
1555
|
+
protected _updateCount(node: BSTNode<K, V>): void;
|
|
1556
|
+
/**
|
|
1557
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
1558
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
1559
|
+
*/
|
|
1560
|
+
protected _updateCountAlongPath(node: OptNode<BSTNode<K, V>>): void;
|
|
1561
|
+
/**
|
|
1562
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
1563
|
+
* @remarks Time O(log n), Space O(1)
|
|
1564
|
+
*/
|
|
1565
|
+
protected _getByRankIterative(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1566
|
+
/**
|
|
1567
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
1568
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1569
|
+
*/
|
|
1570
|
+
protected _getByRankRecursive(node: OptNode<BSTNode<K, V>>, k: number): BSTNode<K, V> | undefined;
|
|
1571
|
+
/**
|
|
1572
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
1573
|
+
* @remarks Time O(log n), Space O(1)
|
|
1574
|
+
*/
|
|
1575
|
+
protected _getRankIterative(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1576
|
+
/**
|
|
1577
|
+
* (Protected) Computes the rank of a key recursively.
|
|
1578
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
1579
|
+
*/
|
|
1580
|
+
protected _getRankRecursive(node: OptNode<BSTNode<K, V>>, key: K): number;
|
|
1581
|
+
/**
|
|
1582
|
+
* (Protected) Finds the in-order successor of a node.
|
|
1583
|
+
* @remarks Time O(log n), Space O(1)
|
|
1584
|
+
*/
|
|
1585
|
+
protected _next(node: BSTNode<K, V>): BSTNode<K, V> | undefined;
|
|
1415
1586
|
protected _setRoot(v: OptNode<BSTNode<K, V>>): void;
|
|
1416
1587
|
/**
|
|
1417
1588
|
* (Protected) Compares two keys using the tree's comparator and reverse setting.
|
|
@@ -330,6 +330,18 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
330
330
|
|
|
331
331
|
|
|
332
332
|
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
333
345
|
|
|
334
346
|
|
|
335
347
|
|
|
@@ -556,6 +568,18 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
556
568
|
|
|
557
569
|
|
|
558
570
|
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
559
583
|
|
|
560
584
|
|
|
561
585
|
|
|
@@ -702,6 +726,18 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
702
726
|
|
|
703
727
|
|
|
704
728
|
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
705
741
|
|
|
706
742
|
|
|
707
743
|
|
|
@@ -816,6 +852,15 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
816
852
|
|
|
817
853
|
|
|
818
854
|
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
819
864
|
|
|
820
865
|
|
|
821
866
|
|
|
@@ -941,6 +986,18 @@ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R
|
|
|
941
986
|
|
|
942
987
|
|
|
943
988
|
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
944
1001
|
|
|
945
1002
|
|
|
946
1003
|
|
|
@@ -73,6 +73,9 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
76
79
|
|
|
77
80
|
|
|
78
81
|
|
|
@@ -131,6 +134,9 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
131
134
|
|
|
132
135
|
|
|
133
136
|
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
134
140
|
|
|
135
141
|
|
|
136
142
|
|
|
@@ -185,6 +191,9 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
185
191
|
|
|
186
192
|
|
|
187
193
|
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
188
197
|
|
|
189
198
|
|
|
190
199
|
|
|
@@ -234,6 +243,9 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
234
243
|
|
|
235
244
|
|
|
236
245
|
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
237
249
|
|
|
238
250
|
|
|
239
251
|
|
|
@@ -278,6 +290,9 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
278
290
|
|
|
279
291
|
|
|
280
292
|
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
281
296
|
|
|
282
297
|
|
|
283
298
|
|
|
@@ -325,6 +340,9 @@ export declare class SegmentTree<E = number> implements Iterable<E> {
|
|
|
325
340
|
|
|
326
341
|
|
|
327
342
|
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
328
346
|
|
|
329
347
|
|
|
330
348
|
|