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
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { Comparator, TreeMultiSetOptions } from '../../types';
|
|
12
|
-
import { ERR } from '../../common';
|
|
12
|
+
import { ERR, raise } from '../../common';
|
|
13
13
|
import { RedBlackTree } from './red-black-tree';
|
|
14
14
|
import { TreeSet } from './tree-set';
|
|
15
15
|
|
|
@@ -35,7 +35,7 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
35
35
|
const toElementFn = options.toElementFn;
|
|
36
36
|
const comparator = options.comparator ?? TreeSet.createDefaultComparator<K>();
|
|
37
37
|
this.#isDefaultComparator = options.comparator === undefined;
|
|
38
|
-
this.#core = new RedBlackTree<K, number>([], { comparator, isMapMode: options.isMapMode });
|
|
38
|
+
this.#core = new RedBlackTree<K, number>([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic });
|
|
39
39
|
|
|
40
40
|
for (const item of elements) {
|
|
41
41
|
const k = toElementFn ? toElementFn(item as R) : (item as K);
|
|
@@ -51,18 +51,18 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
51
51
|
if (!this.#isDefaultComparator) return;
|
|
52
52
|
|
|
53
53
|
if (typeof key === 'number') {
|
|
54
|
-
if (Number.isNaN(key))
|
|
54
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN('TreeMultiSet'));
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
if (typeof key === 'string') return;
|
|
59
59
|
|
|
60
60
|
if (key instanceof Date) {
|
|
61
|
-
if (Number.isNaN(key.getTime()))
|
|
61
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate('TreeMultiSet'));
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
raise(TypeError, ERR.comparatorRequired('TreeMultiSet'));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -70,7 +70,7 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
70
70
|
* @remarks Time O(1), Space O(1)
|
|
71
71
|
*/
|
|
72
72
|
private _validateCount(n: number): void {
|
|
73
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
73
|
+
if (!Number.isSafeInteger(n) || n < 0) raise(RangeError, ERR.invalidArgument('count must be a safe integer >= 0.', 'TreeMultiSet'));
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
@@ -99,6 +99,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
102
109
|
|
|
103
110
|
|
|
104
111
|
|
|
@@ -243,6 +250,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
243
250
|
|
|
244
251
|
|
|
245
252
|
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
246
288
|
|
|
247
289
|
|
|
248
290
|
|
|
@@ -400,6 +442,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
400
442
|
|
|
401
443
|
|
|
402
444
|
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
403
480
|
|
|
404
481
|
|
|
405
482
|
|
|
@@ -451,6 +528,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
451
528
|
|
|
452
529
|
|
|
453
530
|
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
454
538
|
|
|
455
539
|
|
|
456
540
|
|
|
@@ -590,6 +674,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
590
674
|
|
|
591
675
|
|
|
592
676
|
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
593
712
|
|
|
594
713
|
|
|
595
714
|
|
|
@@ -651,6 +770,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
651
770
|
|
|
652
771
|
|
|
653
772
|
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
654
780
|
|
|
655
781
|
|
|
656
782
|
|
|
@@ -811,6 +937,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
811
937
|
|
|
812
938
|
|
|
813
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
|
+
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
814
975
|
|
|
815
976
|
|
|
816
977
|
|
|
@@ -876,6 +1037,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
876
1037
|
|
|
877
1038
|
|
|
878
1039
|
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
879
1047
|
|
|
880
1048
|
|
|
881
1049
|
|
|
@@ -918,6 +1086,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
918
1086
|
|
|
919
1087
|
|
|
920
1088
|
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
|
|
921
1096
|
|
|
922
1097
|
|
|
923
1098
|
|
|
@@ -1062,6 +1237,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1062
1237
|
|
|
1063
1238
|
|
|
1064
1239
|
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
|
|
1273
|
+
|
|
1274
|
+
|
|
1065
1275
|
|
|
1066
1276
|
|
|
1067
1277
|
|
|
@@ -1230,6 +1440,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1230
1440
|
|
|
1231
1441
|
|
|
1232
1442
|
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
|
|
1447
|
+
|
|
1448
|
+
|
|
1449
|
+
|
|
1450
|
+
|
|
1451
|
+
|
|
1452
|
+
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
|
|
1456
|
+
|
|
1457
|
+
|
|
1458
|
+
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
|
|
1464
|
+
|
|
1465
|
+
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1233
1478
|
|
|
1234
1479
|
|
|
1235
1480
|
|
|
@@ -1280,6 +1525,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1280
1525
|
|
|
1281
1526
|
|
|
1282
1527
|
|
|
1528
|
+
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
|
|
1534
|
+
|
|
1283
1535
|
|
|
1284
1536
|
|
|
1285
1537
|
|
|
@@ -1325,10 +1577,17 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1325
1577
|
|
|
1326
1578
|
|
|
1327
1579
|
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1580
|
+
|
|
1581
|
+
|
|
1582
|
+
|
|
1583
|
+
|
|
1584
|
+
|
|
1585
|
+
|
|
1586
|
+
|
|
1587
|
+
* @example
|
|
1588
|
+
* // Key-count pairs
|
|
1589
|
+
* const ms = new TreeMultiSet<number>();
|
|
1590
|
+
* ms.add(1, 2);
|
|
1332
1591
|
* ms.add(3);
|
|
1333
1592
|
* console.log(ms.toEntries()); // [[1, 2], [3, 1]];
|
|
1334
1593
|
*/
|
|
@@ -1472,6 +1731,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1472
1731
|
|
|
1473
1732
|
|
|
1474
1733
|
|
|
1734
|
+
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
|
|
1738
|
+
|
|
1739
|
+
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
|
|
1743
|
+
|
|
1744
|
+
|
|
1745
|
+
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
|
|
1751
|
+
|
|
1752
|
+
|
|
1753
|
+
|
|
1754
|
+
|
|
1755
|
+
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
|
|
1765
|
+
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
|
|
1475
1769
|
|
|
1476
1770
|
|
|
1477
1771
|
|
|
@@ -1526,6 +1820,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1526
1820
|
|
|
1527
1821
|
|
|
1528
1822
|
|
|
1823
|
+
|
|
1824
|
+
|
|
1825
|
+
|
|
1826
|
+
|
|
1827
|
+
|
|
1828
|
+
|
|
1829
|
+
|
|
1529
1830
|
|
|
1530
1831
|
|
|
1531
1832
|
|
|
@@ -1564,6 +1865,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1564
1865
|
|
|
1565
1866
|
|
|
1566
1867
|
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
|
|
1873
|
+
|
|
1874
|
+
|
|
1567
1875
|
|
|
1568
1876
|
|
|
1569
1877
|
|
|
@@ -1602,6 +1910,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1602
1910
|
|
|
1603
1911
|
|
|
1604
1912
|
|
|
1913
|
+
|
|
1914
|
+
|
|
1915
|
+
|
|
1916
|
+
|
|
1917
|
+
|
|
1918
|
+
|
|
1919
|
+
|
|
1605
1920
|
|
|
1606
1921
|
|
|
1607
1922
|
|
|
@@ -1644,6 +1959,13 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1644
1959
|
|
|
1645
1960
|
|
|
1646
1961
|
|
|
1962
|
+
|
|
1963
|
+
|
|
1964
|
+
|
|
1965
|
+
|
|
1966
|
+
|
|
1967
|
+
|
|
1968
|
+
|
|
1647
1969
|
|
|
1648
1970
|
|
|
1649
1971
|
|
|
@@ -1762,6 +2084,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1762
2084
|
|
|
1763
2085
|
|
|
1764
2086
|
|
|
2087
|
+
|
|
2088
|
+
|
|
2089
|
+
|
|
2090
|
+
|
|
2091
|
+
|
|
2092
|
+
|
|
2093
|
+
|
|
2094
|
+
|
|
2095
|
+
|
|
2096
|
+
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
|
|
2100
|
+
|
|
2101
|
+
|
|
2102
|
+
|
|
2103
|
+
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
|
|
2107
|
+
|
|
2108
|
+
|
|
2109
|
+
|
|
2110
|
+
|
|
2111
|
+
|
|
2112
|
+
|
|
2113
|
+
|
|
2114
|
+
|
|
1765
2115
|
|
|
1766
2116
|
|
|
1767
2117
|
|
|
@@ -1892,6 +2242,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
1892
2242
|
|
|
1893
2243
|
|
|
1894
2244
|
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
|
|
2258
|
+
|
|
2259
|
+
|
|
2260
|
+
|
|
2261
|
+
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
|
|
2265
|
+
|
|
2266
|
+
|
|
2267
|
+
|
|
2268
|
+
|
|
2269
|
+
|
|
2270
|
+
|
|
2271
|
+
|
|
2272
|
+
|
|
1895
2273
|
|
|
1896
2274
|
|
|
1897
2275
|
|
|
@@ -2022,6 +2400,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2022
2400
|
|
|
2023
2401
|
|
|
2024
2402
|
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
|
|
2409
|
+
|
|
2410
|
+
|
|
2411
|
+
|
|
2412
|
+
|
|
2413
|
+
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
|
|
2418
|
+
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
|
|
2422
|
+
|
|
2423
|
+
|
|
2424
|
+
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
|
|
2428
|
+
|
|
2429
|
+
|
|
2430
|
+
|
|
2025
2431
|
|
|
2026
2432
|
|
|
2027
2433
|
|
|
@@ -2151,6 +2557,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2151
2557
|
|
|
2152
2558
|
|
|
2153
2559
|
|
|
2560
|
+
|
|
2561
|
+
|
|
2562
|
+
|
|
2563
|
+
|
|
2564
|
+
|
|
2565
|
+
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
|
|
2569
|
+
|
|
2570
|
+
|
|
2571
|
+
|
|
2572
|
+
|
|
2573
|
+
|
|
2574
|
+
|
|
2575
|
+
|
|
2576
|
+
|
|
2577
|
+
|
|
2578
|
+
|
|
2579
|
+
|
|
2580
|
+
|
|
2581
|
+
|
|
2582
|
+
|
|
2583
|
+
|
|
2584
|
+
|
|
2585
|
+
|
|
2586
|
+
|
|
2587
|
+
|
|
2154
2588
|
|
|
2155
2589
|
|
|
2156
2590
|
|
|
@@ -2312,6 +2746,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2312
2746
|
|
|
2313
2747
|
|
|
2314
2748
|
|
|
2749
|
+
|
|
2750
|
+
|
|
2751
|
+
|
|
2752
|
+
|
|
2753
|
+
|
|
2754
|
+
|
|
2755
|
+
|
|
2756
|
+
|
|
2757
|
+
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
|
|
2761
|
+
|
|
2762
|
+
|
|
2763
|
+
|
|
2764
|
+
|
|
2765
|
+
|
|
2766
|
+
|
|
2767
|
+
|
|
2768
|
+
|
|
2769
|
+
|
|
2770
|
+
|
|
2771
|
+
|
|
2772
|
+
|
|
2773
|
+
|
|
2774
|
+
|
|
2775
|
+
|
|
2776
|
+
|
|
2777
|
+
|
|
2778
|
+
|
|
2779
|
+
|
|
2780
|
+
|
|
2781
|
+
|
|
2782
|
+
|
|
2783
|
+
|
|
2315
2784
|
|
|
2316
2785
|
|
|
2317
2786
|
|
|
@@ -2474,6 +2943,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2474
2943
|
|
|
2475
2944
|
|
|
2476
2945
|
|
|
2946
|
+
|
|
2947
|
+
|
|
2948
|
+
|
|
2949
|
+
|
|
2950
|
+
|
|
2951
|
+
|
|
2952
|
+
|
|
2953
|
+
|
|
2954
|
+
|
|
2955
|
+
|
|
2956
|
+
|
|
2957
|
+
|
|
2958
|
+
|
|
2959
|
+
|
|
2960
|
+
|
|
2961
|
+
|
|
2962
|
+
|
|
2963
|
+
|
|
2964
|
+
|
|
2965
|
+
|
|
2966
|
+
|
|
2967
|
+
|
|
2968
|
+
|
|
2969
|
+
|
|
2970
|
+
|
|
2971
|
+
|
|
2972
|
+
|
|
2973
|
+
|
|
2974
|
+
|
|
2975
|
+
|
|
2976
|
+
|
|
2977
|
+
|
|
2978
|
+
|
|
2979
|
+
|
|
2980
|
+
|
|
2477
2981
|
|
|
2478
2982
|
|
|
2479
2983
|
|
|
@@ -2643,6 +3147,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2643
3147
|
|
|
2644
3148
|
|
|
2645
3149
|
|
|
3150
|
+
|
|
3151
|
+
|
|
3152
|
+
|
|
3153
|
+
|
|
3154
|
+
|
|
3155
|
+
|
|
3156
|
+
|
|
3157
|
+
|
|
3158
|
+
|
|
3159
|
+
|
|
3160
|
+
|
|
3161
|
+
|
|
3162
|
+
|
|
3163
|
+
|
|
3164
|
+
|
|
3165
|
+
|
|
3166
|
+
|
|
3167
|
+
|
|
3168
|
+
|
|
3169
|
+
|
|
3170
|
+
|
|
3171
|
+
|
|
3172
|
+
|
|
3173
|
+
|
|
3174
|
+
|
|
3175
|
+
|
|
3176
|
+
|
|
3177
|
+
|
|
3178
|
+
|
|
3179
|
+
|
|
3180
|
+
|
|
3181
|
+
|
|
3182
|
+
|
|
3183
|
+
|
|
3184
|
+
|
|
2646
3185
|
|
|
2647
3186
|
|
|
2648
3187
|
|
|
@@ -2807,6 +3346,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2807
3346
|
|
|
2808
3347
|
|
|
2809
3348
|
|
|
3349
|
+
|
|
3350
|
+
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
|
|
3354
|
+
|
|
3355
|
+
|
|
3356
|
+
|
|
3357
|
+
|
|
3358
|
+
|
|
3359
|
+
|
|
3360
|
+
|
|
3361
|
+
|
|
3362
|
+
|
|
3363
|
+
|
|
3364
|
+
|
|
3365
|
+
|
|
3366
|
+
|
|
3367
|
+
|
|
3368
|
+
|
|
3369
|
+
|
|
3370
|
+
|
|
3371
|
+
|
|
3372
|
+
|
|
3373
|
+
|
|
3374
|
+
|
|
3375
|
+
|
|
3376
|
+
|
|
3377
|
+
|
|
3378
|
+
|
|
3379
|
+
|
|
3380
|
+
|
|
3381
|
+
|
|
3382
|
+
|
|
3383
|
+
|
|
2810
3384
|
|
|
2811
3385
|
|
|
2812
3386
|
|
|
@@ -2990,6 +3564,105 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
2990
3564
|
|
|
2991
3565
|
|
|
2992
3566
|
|
|
3567
|
+
|
|
3568
|
+
|
|
3569
|
+
|
|
3570
|
+
|
|
3571
|
+
|
|
3572
|
+
|
|
3573
|
+
|
|
3574
|
+
|
|
3575
|
+
|
|
3576
|
+
|
|
3577
|
+
|
|
3578
|
+
|
|
3579
|
+
|
|
3580
|
+
|
|
3581
|
+
|
|
3582
|
+
|
|
3583
|
+
|
|
3584
|
+
|
|
3585
|
+
|
|
3586
|
+
|
|
3587
|
+
|
|
3588
|
+
* @example
|
|
3589
|
+
* // Order-statistic on BST
|
|
3590
|
+
* const tree = new TreeMultiSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
3591
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
3592
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
3593
|
+
* console.log(tree.getRank(30)); // 2;
|
|
3594
|
+
*/
|
|
3595
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
3596
|
+
|
|
3597
|
+
getByRank(k: number): K | undefined {
|
|
3598
|
+
return this.#core.getByRank(k);
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
/**
|
|
3602
|
+
* Get the rank of a key in sorted order
|
|
3603
|
+
* @example
|
|
3604
|
+
* // Get the rank of a key in sorted order
|
|
3605
|
+
* const tree = new TreeMultiSet<number>(
|
|
3606
|
+
* [10, 20, 30, 40, 50],
|
|
3607
|
+
* { enableOrderStatistic: true }
|
|
3608
|
+
* );
|
|
3609
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
3610
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
3611
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
3612
|
+
* console.log(tree.getRank(25)); // 2;
|
|
3613
|
+
*/
|
|
3614
|
+
getRank(key: K): number {
|
|
3615
|
+
return this.#core.getRank(key);
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
/**
|
|
3619
|
+
* Get elements by rank range
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3629
|
+
* @example
|
|
3630
|
+
* // Pagination by position in tree order
|
|
3631
|
+
* const tree = new TreeMultiSet<number>(
|
|
3632
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
3633
|
+
* { enableOrderStatistic: true }
|
|
3634
|
+
* );
|
|
3635
|
+
* const pageSize = 3;
|
|
3636
|
+
*
|
|
3637
|
+
* // Page 1
|
|
3638
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
3639
|
+
* // Page 2
|
|
3640
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
3641
|
+
* // Page 3
|
|
3642
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
3643
|
+
*/
|
|
3644
|
+
rangeByRank(start: number, end: number): K[] {
|
|
3645
|
+
return this.#core.rangeByRank(start, end).filter((k): k is K => k !== undefined);
|
|
3646
|
+
}
|
|
3647
|
+
|
|
3648
|
+
/**
|
|
3649
|
+
* Deep copy
|
|
3650
|
+
|
|
3651
|
+
|
|
3652
|
+
|
|
3653
|
+
|
|
3654
|
+
|
|
3655
|
+
|
|
3656
|
+
|
|
3657
|
+
|
|
3658
|
+
|
|
3659
|
+
|
|
3660
|
+
|
|
3661
|
+
|
|
3662
|
+
|
|
3663
|
+
|
|
3664
|
+
|
|
3665
|
+
|
|
2993
3666
|
|
|
2994
3667
|
|
|
2995
3668
|
|
|
@@ -3115,6 +3788,34 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
3115
3788
|
|
|
3116
3789
|
|
|
3117
3790
|
|
|
3791
|
+
|
|
3792
|
+
|
|
3793
|
+
|
|
3794
|
+
|
|
3795
|
+
|
|
3796
|
+
|
|
3797
|
+
|
|
3798
|
+
|
|
3799
|
+
|
|
3800
|
+
|
|
3801
|
+
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
|
|
3805
|
+
|
|
3806
|
+
|
|
3807
|
+
|
|
3808
|
+
|
|
3809
|
+
|
|
3810
|
+
|
|
3811
|
+
|
|
3812
|
+
|
|
3813
|
+
|
|
3814
|
+
|
|
3815
|
+
|
|
3816
|
+
|
|
3817
|
+
|
|
3818
|
+
|
|
3118
3819
|
|
|
3119
3820
|
|
|
3120
3821
|
|
|
@@ -3279,6 +3980,41 @@ export class TreeMultiSet<K = any, R = K> implements Iterable<K> {
|
|
|
3279
3980
|
|
|
3280
3981
|
|
|
3281
3982
|
|
|
3983
|
+
|
|
3984
|
+
|
|
3985
|
+
|
|
3986
|
+
|
|
3987
|
+
|
|
3988
|
+
|
|
3989
|
+
|
|
3990
|
+
|
|
3991
|
+
|
|
3992
|
+
|
|
3993
|
+
|
|
3994
|
+
|
|
3995
|
+
|
|
3996
|
+
|
|
3997
|
+
|
|
3998
|
+
|
|
3999
|
+
|
|
4000
|
+
|
|
4001
|
+
|
|
4002
|
+
|
|
4003
|
+
|
|
4004
|
+
|
|
4005
|
+
|
|
4006
|
+
|
|
4007
|
+
|
|
4008
|
+
|
|
4009
|
+
|
|
4010
|
+
|
|
4011
|
+
|
|
4012
|
+
|
|
4013
|
+
|
|
4014
|
+
|
|
4015
|
+
|
|
4016
|
+
|
|
4017
|
+
|
|
3282
4018
|
|
|
3283
4019
|
|
|
3284
4020
|
|