max-priority-queue-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 +207 -71
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +206 -70
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +207 -72
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +206 -71
- 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/max-priority-queue-typed.js +204 -69
- 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 +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
|
@@ -197,15 +197,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
197
197
|
|
|
198
198
|
|
|
199
199
|
|
|
200
|
-
* @example
|
|
201
|
-
* // Check empty
|
|
202
|
-
* console.log(new TreeSet().isEmpty()); // true;
|
|
203
|
-
*/
|
|
204
|
-
isEmpty(): boolean;
|
|
205
|
-
private _validateKey;
|
|
206
|
-
/**
|
|
207
|
-
* Add a key to the set (no-op if already present).
|
|
208
|
-
* @remarks Expected time O(log n)
|
|
209
200
|
|
|
210
201
|
|
|
211
202
|
|
|
@@ -241,6 +232,15 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
241
232
|
|
|
242
233
|
|
|
243
234
|
|
|
235
|
+
* @example
|
|
236
|
+
* // Check empty
|
|
237
|
+
* console.log(new TreeSet().isEmpty()); // true;
|
|
238
|
+
*/
|
|
239
|
+
isEmpty(): boolean;
|
|
240
|
+
private _validateKey;
|
|
241
|
+
/**
|
|
242
|
+
* Add a key to the set (no-op if already present).
|
|
243
|
+
* @remarks Expected time O(log n)
|
|
244
244
|
|
|
245
245
|
|
|
246
246
|
|
|
@@ -352,22 +352,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
352
352
|
|
|
353
353
|
|
|
354
354
|
|
|
355
|
-
* @example
|
|
356
|
-
* // Unique tags with sorted order
|
|
357
|
-
* const tags = new TreeSet<string>(['javascript', 'typescript', 'react', 'typescript', 'node']);
|
|
358
|
-
*
|
|
359
|
-
* // Duplicates removed, sorted alphabetically
|
|
360
|
-
* console.log([...tags]); // ['javascript', 'node', 'react', 'typescript'];
|
|
361
|
-
* console.log(tags.size); // 4;
|
|
362
|
-
*
|
|
363
|
-
* tags.add('angular');
|
|
364
|
-
* console.log(tags.first()); // 'angular';
|
|
365
|
-
* console.log(tags.last()); // 'typescript';
|
|
366
|
-
*/
|
|
367
|
-
add(key: K): this;
|
|
368
|
-
/**
|
|
369
|
-
* Test whether a key exists.
|
|
370
|
-
* @remarks Expected time O(log n)
|
|
371
355
|
|
|
372
356
|
|
|
373
357
|
|
|
@@ -438,6 +422,25 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
438
422
|
|
|
439
423
|
|
|
440
424
|
|
|
425
|
+
* @example
|
|
426
|
+
* // Unique tags with sorted order
|
|
427
|
+
* const tags = new TreeSet<string>(['javascript', 'typescript', 'react', 'typescript', 'node']);
|
|
428
|
+
*
|
|
429
|
+
* // Duplicates removed, sorted alphabetically
|
|
430
|
+
* console.log([...tags]); // ['javascript', 'node', 'react', 'typescript'];
|
|
431
|
+
* console.log(tags.size); // 4;
|
|
432
|
+
*
|
|
433
|
+
* tags.add('angular');
|
|
434
|
+
* console.log(tags.first()); // 'angular';
|
|
435
|
+
* console.log(tags.last()); // 'typescript';
|
|
436
|
+
*/
|
|
437
|
+
add(key: K): this;
|
|
438
|
+
/**
|
|
439
|
+
* Add multiple keys at once.
|
|
440
|
+
* @remarks Expected time O(m log n), where m is the number of keys.
|
|
441
|
+
* @param keys - Iterable of keys to add.
|
|
442
|
+
* @returns Array of booleans indicating whether each key was newly added.
|
|
443
|
+
|
|
441
444
|
|
|
442
445
|
|
|
443
446
|
|
|
@@ -453,6 +456,16 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
453
456
|
|
|
454
457
|
|
|
455
458
|
|
|
459
|
+
* @example
|
|
460
|
+
* // Add multiple keys
|
|
461
|
+
* const ts = new TreeSet<number>();
|
|
462
|
+
* ts.addMany([5, 3, 7, 1, 9]);
|
|
463
|
+
* console.log(ts.size); // 5;
|
|
464
|
+
*/
|
|
465
|
+
addMany(keys: Iterable<K>): boolean[];
|
|
466
|
+
/**
|
|
467
|
+
* Test whether a key exists.
|
|
468
|
+
* @remarks Expected time O(log n)
|
|
456
469
|
|
|
457
470
|
|
|
458
471
|
|
|
@@ -522,18 +535,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
522
535
|
|
|
523
536
|
|
|
524
537
|
|
|
525
|
-
* @example
|
|
526
|
-
* // Checking membership in a sorted collection
|
|
527
|
-
* const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
|
|
528
|
-
*
|
|
529
|
-
* console.log(allowed.has('admin')); // true;
|
|
530
|
-
* console.log(allowed.has('guest')); // false;
|
|
531
|
-
*/
|
|
532
|
-
has(key: K): boolean;
|
|
533
|
-
/**
|
|
534
|
-
* Delete a key.
|
|
535
|
-
* @returns `true` if the key existed; otherwise `false`.
|
|
536
|
-
* @remarks Expected time O(log n)
|
|
537
538
|
|
|
538
539
|
|
|
539
540
|
|
|
@@ -654,6 +655,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
654
655
|
|
|
655
656
|
|
|
656
657
|
|
|
658
|
+
* @example
|
|
659
|
+
* // Checking membership in a sorted collection
|
|
660
|
+
* const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
|
|
661
|
+
*
|
|
662
|
+
* console.log(allowed.has('admin')); // true;
|
|
663
|
+
* console.log(allowed.has('guest')); // false;
|
|
664
|
+
*/
|
|
665
|
+
has(key: K): boolean;
|
|
666
|
+
/**
|
|
667
|
+
* Delete a key.
|
|
668
|
+
* @returns `true` if the key existed; otherwise `false`.
|
|
669
|
+
* @remarks Expected time O(log n)
|
|
657
670
|
|
|
658
671
|
|
|
659
672
|
|
|
@@ -688,17 +701,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
688
701
|
|
|
689
702
|
|
|
690
703
|
|
|
691
|
-
* @example
|
|
692
|
-
* // Removing elements while maintaining order
|
|
693
|
-
* const nums = new TreeSet<number>([1, 3, 5, 7, 9]);
|
|
694
|
-
*
|
|
695
|
-
* console.log(nums.delete(5)); // true;
|
|
696
|
-
* console.log(nums.delete(5)); // false; // already gone
|
|
697
|
-
* console.log([...nums]); // [1, 3, 7, 9];
|
|
698
|
-
*/
|
|
699
|
-
delete(key: K): boolean;
|
|
700
|
-
/**
|
|
701
|
-
* Remove all keys.
|
|
702
704
|
|
|
703
705
|
|
|
704
706
|
|
|
@@ -842,15 +844,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
842
844
|
|
|
843
845
|
|
|
844
846
|
|
|
845
|
-
* @example
|
|
846
|
-
* // Remove all
|
|
847
|
-
* const ts = new TreeSet<number>([1, 2]);
|
|
848
|
-
* ts.clear();
|
|
849
|
-
* console.log(ts.isEmpty()); // true;
|
|
850
|
-
*/
|
|
851
|
-
clear(): void;
|
|
852
|
-
/**
|
|
853
|
-
* Iterate over keys in ascending order.
|
|
854
847
|
|
|
855
848
|
|
|
856
849
|
|
|
@@ -863,6 +856,31 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
863
856
|
|
|
864
857
|
|
|
865
858
|
|
|
859
|
+
* @example
|
|
860
|
+
* // Removing elements while maintaining order
|
|
861
|
+
* const nums = new TreeSet<number>([1, 3, 5, 7, 9]);
|
|
862
|
+
*
|
|
863
|
+
* console.log(nums.delete(5)); // true;
|
|
864
|
+
* console.log(nums.delete(5)); // false; // already gone
|
|
865
|
+
* console.log([...nums]); // [1, 3, 7, 9];
|
|
866
|
+
*/
|
|
867
|
+
delete(key: K): boolean;
|
|
868
|
+
/**
|
|
869
|
+
* Delete all keys matching a predicate.
|
|
870
|
+
* @remarks Time O(N), Space O(N)
|
|
871
|
+
* @param predicate - Function (key, index, set) → boolean; return true to delete.
|
|
872
|
+
* @returns True if at least one key was deleted.
|
|
873
|
+
*/
|
|
874
|
+
deleteWhere(predicate: (key: K, index: number, set: this) => boolean): boolean;
|
|
875
|
+
/**
|
|
876
|
+
* Remove all keys.
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
|
|
866
884
|
|
|
867
885
|
|
|
868
886
|
|
|
@@ -994,16 +1012,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
994
1012
|
|
|
995
1013
|
|
|
996
1014
|
|
|
997
|
-
* @example
|
|
998
|
-
* // Get sorted keys
|
|
999
|
-
* const ts = new TreeSet<number>([30, 10, 20]);
|
|
1000
|
-
* console.log([...ts.keys()]); // [10, 20, 30];
|
|
1001
|
-
*/
|
|
1002
|
-
keys(): IterableIterator<K>;
|
|
1003
|
-
/**
|
|
1004
|
-
* Iterate over values in ascending order.
|
|
1005
|
-
*
|
|
1006
|
-
* Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
1007
1015
|
|
|
1008
1016
|
|
|
1009
1017
|
|
|
@@ -1044,6 +1052,15 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1044
1052
|
|
|
1045
1053
|
|
|
1046
1054
|
|
|
1055
|
+
* @example
|
|
1056
|
+
* // Remove all
|
|
1057
|
+
* const ts = new TreeSet<number>([1, 2]);
|
|
1058
|
+
* ts.clear();
|
|
1059
|
+
* console.log(ts.isEmpty()); // true;
|
|
1060
|
+
*/
|
|
1061
|
+
clear(): void;
|
|
1062
|
+
/**
|
|
1063
|
+
* Iterate over keys in ascending order.
|
|
1047
1064
|
|
|
1048
1065
|
|
|
1049
1066
|
|
|
@@ -1147,16 +1164,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1147
1164
|
|
|
1148
1165
|
|
|
1149
1166
|
|
|
1150
|
-
* @example
|
|
1151
|
-
* // Get values (same as keys for Set)
|
|
1152
|
-
* const ts = new TreeSet<number>([2, 1, 3]);
|
|
1153
|
-
* console.log([...ts.values()]); // [1, 2, 3];
|
|
1154
|
-
*/
|
|
1155
|
-
values(): IterableIterator<K>;
|
|
1156
|
-
/**
|
|
1157
|
-
* Iterate over `[value, value]` pairs (native Set convention).
|
|
1158
|
-
*
|
|
1159
|
-
* Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
1160
1167
|
|
|
1161
1168
|
|
|
1162
1169
|
|
|
@@ -1232,6 +1239,16 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1232
1239
|
|
|
1233
1240
|
|
|
1234
1241
|
|
|
1242
|
+
* @example
|
|
1243
|
+
* // Get sorted keys
|
|
1244
|
+
* const ts = new TreeSet<number>([30, 10, 20]);
|
|
1245
|
+
* console.log([...ts.keys()]); // [10, 20, 30];
|
|
1246
|
+
*/
|
|
1247
|
+
keys(): IterableIterator<K>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Iterate over values in ascending order.
|
|
1250
|
+
*
|
|
1251
|
+
* Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
1235
1252
|
|
|
1236
1253
|
|
|
1237
1254
|
|
|
@@ -1300,17 +1317,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1300
1317
|
|
|
1301
1318
|
|
|
1302
1319
|
|
|
1303
|
-
* @example
|
|
1304
|
-
* // Iterate entries
|
|
1305
|
-
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1306
|
-
* console.log([...ts.entries()].map(([k]) => k)); // [1, 2, 3];
|
|
1307
|
-
*/
|
|
1308
|
-
entries(): IterableIterator<[K, K]>;
|
|
1309
|
-
[Symbol.iterator](): IterableIterator<K>;
|
|
1310
|
-
/**
|
|
1311
|
-
* Visit each value in ascending order.
|
|
1312
|
-
*
|
|
1313
|
-
* Callback follows native Set convention: `(value, value2, set)`.
|
|
1314
1320
|
|
|
1315
1321
|
|
|
1316
1322
|
|
|
@@ -1421,6 +1427,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1421
1427
|
|
|
1422
1428
|
|
|
1423
1429
|
|
|
1430
|
+
* @example
|
|
1431
|
+
* // Get values (same as keys for Set)
|
|
1432
|
+
* const ts = new TreeSet<number>([2, 1, 3]);
|
|
1433
|
+
* console.log([...ts.values()]); // [1, 2, 3];
|
|
1434
|
+
*/
|
|
1435
|
+
values(): IterableIterator<K>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Iterate over `[value, value]` pairs (native Set convention).
|
|
1438
|
+
*
|
|
1439
|
+
* Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
1440
|
+
|
|
1441
|
+
|
|
1424
1442
|
|
|
1425
1443
|
|
|
1426
1444
|
|
|
@@ -1454,19 +1472,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1454
1472
|
|
|
1455
1473
|
|
|
1456
1474
|
|
|
1457
|
-
* @example
|
|
1458
|
-
* // Execute for each
|
|
1459
|
-
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1460
|
-
* const keys: number[] = [];
|
|
1461
|
-
* ts.forEach(k => keys.push(k));
|
|
1462
|
-
* console.log(keys); // [1, 2, 3];
|
|
1463
|
-
*/
|
|
1464
|
-
forEach(cb: (value: K, value2: K, set: TreeSet<K>) => void, thisArg?: unknown): void;
|
|
1465
|
-
/**
|
|
1466
|
-
* Create a new TreeSet by mapping each value to a new key.
|
|
1467
|
-
*
|
|
1468
|
-
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
1469
|
-
* @remarks Time O(n log n) expected, Space O(n)
|
|
1470
1475
|
|
|
1471
1476
|
|
|
1472
1477
|
|
|
@@ -1611,17 +1616,16 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1611
1616
|
|
|
1612
1617
|
|
|
1613
1618
|
* @example
|
|
1614
|
-
* //
|
|
1615
|
-
* const ts = new TreeSet<number>([1, 2
|
|
1616
|
-
*
|
|
1617
|
-
* console.log([...doubled]); // [2, 4, 6];
|
|
1619
|
+
* // Iterate entries
|
|
1620
|
+
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1621
|
+
* console.log([...ts.entries()].map(([k]) => k)); // [1, 2, 3];
|
|
1618
1622
|
*/
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
}, thisArg?: unknown): TreeSet<MK>;
|
|
1623
|
+
entries(): IterableIterator<[K, K]>;
|
|
1624
|
+
[Symbol.iterator](): IterableIterator<K>;
|
|
1622
1625
|
/**
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1626
|
+
* Visit each value in ascending order.
|
|
1627
|
+
*
|
|
1628
|
+
* Callback follows native Set convention: `(value, value2, set)`.
|
|
1625
1629
|
|
|
1626
1630
|
|
|
1627
1631
|
|
|
@@ -1765,16 +1769,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1765
1769
|
|
|
1766
1770
|
|
|
1767
1771
|
|
|
1768
|
-
* @example
|
|
1769
|
-
* // Filter
|
|
1770
|
-
* const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
1771
|
-
* const evens = ts.filter(k => k % 2 === 0);
|
|
1772
|
-
* console.log([...evens]); // [2, 4];
|
|
1773
|
-
*/
|
|
1774
|
-
filter(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): TreeSet<K>;
|
|
1775
|
-
/**
|
|
1776
|
-
* Reduce values into a single accumulator.
|
|
1777
|
-
* @remarks Time O(n), Space O(1)
|
|
1778
1772
|
|
|
1779
1773
|
|
|
1780
1774
|
|
|
@@ -1810,6 +1804,19 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1810
1804
|
|
|
1811
1805
|
|
|
1812
1806
|
|
|
1807
|
+
* @example
|
|
1808
|
+
* // Execute for each
|
|
1809
|
+
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1810
|
+
* const keys: number[] = [];
|
|
1811
|
+
* ts.forEach(k => keys.push(k));
|
|
1812
|
+
* console.log(keys); // [1, 2, 3];
|
|
1813
|
+
*/
|
|
1814
|
+
forEach(cb: (value: K, value2: K, set: TreeSet<K>) => void, thisArg?: unknown): void;
|
|
1815
|
+
/**
|
|
1816
|
+
* Create a new TreeSet by mapping each value to a new key.
|
|
1817
|
+
*
|
|
1818
|
+
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
1819
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
1813
1820
|
|
|
1814
1821
|
|
|
1815
1822
|
|
|
@@ -1918,16 +1925,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1918
1925
|
|
|
1919
1926
|
|
|
1920
1927
|
|
|
1921
|
-
* @example
|
|
1922
|
-
* // Aggregate
|
|
1923
|
-
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
1924
|
-
* const sum = ts.reduce((acc, k) => acc + k, 0);
|
|
1925
|
-
* console.log(sum); // 6;
|
|
1926
|
-
*/
|
|
1927
|
-
reduce<A>(callbackfn: TreeSetReduceCallback<K, A, TreeSet<K>>, initialValue: A): A;
|
|
1928
|
-
/**
|
|
1929
|
-
* Test whether all values satisfy a predicate.
|
|
1930
|
-
* @remarks Time O(n), Space O(1)
|
|
1931
1928
|
|
|
1932
1929
|
|
|
1933
1930
|
|
|
@@ -1998,6 +1995,18 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1998
1995
|
|
|
1999
1996
|
|
|
2000
1997
|
|
|
1998
|
+
* @example
|
|
1999
|
+
* // Transform
|
|
2000
|
+
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2001
|
+
* const doubled = ts.map(k => k * 2);
|
|
2002
|
+
* console.log([...doubled]); // [2, 4, 6];
|
|
2003
|
+
*/
|
|
2004
|
+
map<MK>(callbackfn: TreeSetElementCallback<K, MK, TreeSet<K>>, options?: Omit<TreeSetOptions<MK>, 'toElementFn'> & {
|
|
2005
|
+
comparator?: (a: MK, b: MK) => number;
|
|
2006
|
+
}, thisArg?: unknown): TreeSet<MK>;
|
|
2007
|
+
/**
|
|
2008
|
+
* Create a new TreeSet containing only values that satisfy the predicate.
|
|
2009
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
2001
2010
|
|
|
2002
2011
|
|
|
2003
2012
|
|
|
@@ -2069,15 +2078,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2069
2078
|
|
|
2070
2079
|
|
|
2071
2080
|
|
|
2072
|
-
* @example
|
|
2073
|
-
* // Test all
|
|
2074
|
-
* const ts = new TreeSet<number>([2, 4, 6]);
|
|
2075
|
-
* console.log(ts.every(k => k > 0)); // true;
|
|
2076
|
-
*/
|
|
2077
|
-
every(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean;
|
|
2078
|
-
/**
|
|
2079
|
-
* Test whether any value satisfies a predicate.
|
|
2080
|
-
* @remarks Time O(n), Space O(1)
|
|
2081
2081
|
|
|
2082
2082
|
|
|
2083
2083
|
|
|
@@ -2185,6 +2185,19 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2185
2185
|
|
|
2186
2186
|
|
|
2187
2187
|
|
|
2188
|
+
* @example
|
|
2189
|
+
* // Filter
|
|
2190
|
+
* const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
2191
|
+
* const evens = ts.filter(k => k % 2 === 0);
|
|
2192
|
+
* console.log([...evens]); // [2, 4];
|
|
2193
|
+
*/
|
|
2194
|
+
filter(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): TreeSet<K>;
|
|
2195
|
+
/**
|
|
2196
|
+
* Reduce values into a single accumulator.
|
|
2197
|
+
* @remarks Time O(n), Space O(1)
|
|
2198
|
+
|
|
2199
|
+
|
|
2200
|
+
|
|
2188
2201
|
|
|
2189
2202
|
|
|
2190
2203
|
|
|
@@ -2219,15 +2232,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2219
2232
|
|
|
2220
2233
|
|
|
2221
2234
|
|
|
2222
|
-
* @example
|
|
2223
|
-
* // Test any
|
|
2224
|
-
* const ts = new TreeSet<number>([1, 3, 5]);
|
|
2225
|
-
* console.log(ts.some(k => k === 3)); // true;
|
|
2226
|
-
*/
|
|
2227
|
-
some(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean;
|
|
2228
|
-
/**
|
|
2229
|
-
* Find the first value that satisfies a predicate.
|
|
2230
|
-
* @remarks Time O(n), Space O(1)
|
|
2231
2235
|
|
|
2232
2236
|
|
|
2233
2237
|
|
|
@@ -2370,15 +2374,15 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2370
2374
|
|
|
2371
2375
|
|
|
2372
2376
|
* @example
|
|
2373
|
-
* //
|
|
2377
|
+
* // Aggregate
|
|
2374
2378
|
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2375
|
-
* const
|
|
2376
|
-
* console.log(
|
|
2379
|
+
* const sum = ts.reduce((acc, k) => acc + k, 0);
|
|
2380
|
+
* console.log(sum); // 6;
|
|
2377
2381
|
*/
|
|
2378
|
-
|
|
2382
|
+
reduce<A>(callbackfn: TreeSetReduceCallback<K, A, TreeSet<K>>, initialValue: A): A;
|
|
2379
2383
|
/**
|
|
2380
|
-
*
|
|
2381
|
-
* @remarks Time O(n), Space O(
|
|
2384
|
+
* Test whether all values satisfy a predicate.
|
|
2385
|
+
* @remarks Time O(n), Space O(1)
|
|
2382
2386
|
|
|
2383
2387
|
|
|
2384
2388
|
|
|
@@ -2522,15 +2526,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2522
2526
|
|
|
2523
2527
|
|
|
2524
2528
|
|
|
2525
|
-
* @example
|
|
2526
|
-
* // Convert to array
|
|
2527
|
-
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
2528
|
-
* console.log(ts.toArray()); // [1, 2, 3];
|
|
2529
|
-
*/
|
|
2530
|
-
toArray(): K[];
|
|
2531
|
-
/**
|
|
2532
|
-
* Print a human-friendly representation.
|
|
2533
|
-
* @remarks Time O(n), Space O(n)
|
|
2534
2529
|
|
|
2535
2530
|
|
|
2536
2531
|
|
|
@@ -2564,6 +2559,17 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2564
2559
|
|
|
2565
2560
|
|
|
2566
2561
|
|
|
2562
|
+
* @example
|
|
2563
|
+
* // Test all
|
|
2564
|
+
* const ts = new TreeSet<number>([2, 4, 6]);
|
|
2565
|
+
* console.log(ts.every(k => k > 0)); // true;
|
|
2566
|
+
*/
|
|
2567
|
+
every(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean;
|
|
2568
|
+
/**
|
|
2569
|
+
* Test whether any value satisfies a predicate.
|
|
2570
|
+
* @remarks Time O(n), Space O(1)
|
|
2571
|
+
|
|
2572
|
+
|
|
2567
2573
|
|
|
2568
2574
|
|
|
2569
2575
|
|
|
@@ -2674,14 +2680,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2674
2680
|
|
|
2675
2681
|
|
|
2676
2682
|
|
|
2677
|
-
* @example
|
|
2678
|
-
* // Display tree
|
|
2679
|
-
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2680
|
-
* expect(() => ts.print()).not.toThrow();
|
|
2681
|
-
*/
|
|
2682
|
-
print(): void;
|
|
2683
|
-
/**
|
|
2684
|
-
* Smallest key in the set.
|
|
2685
2683
|
|
|
2686
2684
|
|
|
2687
2685
|
|
|
@@ -2714,37 +2712,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2714
2712
|
|
|
2715
2713
|
|
|
2716
2714
|
|
|
2717
|
-
* @example
|
|
2718
|
-
* // Student grade ranking with custom comparator
|
|
2719
|
-
* interface Student {
|
|
2720
|
-
* name: string;
|
|
2721
|
-
* gpa: number;
|
|
2722
|
-
* }
|
|
2723
|
-
*
|
|
2724
|
-
* const ranking = new TreeSet<Student>(
|
|
2725
|
-
* [
|
|
2726
|
-
* { name: 'Alice', gpa: 3.8 },
|
|
2727
|
-
* { name: 'Bob', gpa: 3.5 },
|
|
2728
|
-
* { name: 'Charlie', gpa: 3.9 },
|
|
2729
|
-
* { name: 'Diana', gpa: 3.5 }
|
|
2730
|
-
* ],
|
|
2731
|
-
* { comparator: (a, b) => b.gpa - a.gpa || a.name.localeCompare(b.name) }
|
|
2732
|
-
* );
|
|
2733
|
-
*
|
|
2734
|
-
* // Sorted by GPA descending, then name ascending
|
|
2735
|
-
* const names = [...ranking].map(s => s.name);
|
|
2736
|
-
* console.log(names); // ['Charlie', 'Alice', 'Bob', 'Diana'];
|
|
2737
|
-
*
|
|
2738
|
-
* // Top student
|
|
2739
|
-
* console.log(ranking.first()?.name); // 'Charlie';
|
|
2740
|
-
*
|
|
2741
|
-
* // Filter students with GPA >= 3.8
|
|
2742
|
-
* const honors = ranking.filter(s => s.gpa >= 3.8);
|
|
2743
|
-
* console.log(honors.toArray().map(s => s.name)); // ['Charlie', 'Alice'];
|
|
2744
|
-
*/
|
|
2745
|
-
first(): K | undefined;
|
|
2746
|
-
/**
|
|
2747
|
-
* Largest key in the set.
|
|
2748
2715
|
|
|
2749
2716
|
|
|
2750
2717
|
|
|
@@ -2778,14 +2745,14 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2778
2745
|
|
|
2779
2746
|
|
|
2780
2747
|
* @example
|
|
2781
|
-
* //
|
|
2782
|
-
* const
|
|
2783
|
-
*
|
|
2784
|
-
* console.log(temps.first()); // 15;
|
|
2748
|
+
* // Test any
|
|
2749
|
+
* const ts = new TreeSet<number>([1, 3, 5]);
|
|
2750
|
+
* console.log(ts.some(k => k === 3)); // true;
|
|
2785
2751
|
*/
|
|
2786
|
-
|
|
2752
|
+
some(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean;
|
|
2787
2753
|
/**
|
|
2788
|
-
*
|
|
2754
|
+
* Find the first value that satisfies a predicate.
|
|
2755
|
+
* @remarks Time O(n), Space O(1)
|
|
2789
2756
|
|
|
2790
2757
|
|
|
2791
2758
|
|
|
@@ -2818,17 +2785,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2818
2785
|
|
|
2819
2786
|
|
|
2820
2787
|
|
|
2821
|
-
* @example
|
|
2822
|
-
* // Remove and return minimum
|
|
2823
|
-
* const queue = new TreeSet<number>([5, 1, 8, 3]);
|
|
2824
|
-
*
|
|
2825
|
-
* console.log(queue.pollFirst()); // 1;
|
|
2826
|
-
* console.log(queue.pollFirst()); // 3;
|
|
2827
|
-
* console.log(queue.size); // 2;
|
|
2828
|
-
*/
|
|
2829
|
-
pollFirst(): K | undefined;
|
|
2830
|
-
/**
|
|
2831
|
-
* Remove and return the largest key.
|
|
2832
2788
|
|
|
2833
2789
|
|
|
2834
2790
|
|
|
@@ -2861,16 +2817,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2861
2817
|
|
|
2862
2818
|
|
|
2863
2819
|
|
|
2864
|
-
* @example
|
|
2865
|
-
* // Remove and return maximum
|
|
2866
|
-
* const stack = new TreeSet<number>([10, 20, 30]);
|
|
2867
|
-
*
|
|
2868
|
-
* console.log(stack.pollLast()); // 30;
|
|
2869
|
-
* console.log(stack.size); // 2;
|
|
2870
|
-
*/
|
|
2871
|
-
pollLast(): K | undefined;
|
|
2872
|
-
/**
|
|
2873
|
-
* Smallest key that is >= the given key.
|
|
2874
2820
|
|
|
2875
2821
|
|
|
2876
2822
|
|
|
@@ -2983,6 +2929,16 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2983
2929
|
|
|
2984
2930
|
|
|
2985
2931
|
|
|
2932
|
+
* @example
|
|
2933
|
+
* // Find entry
|
|
2934
|
+
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2935
|
+
* const found = ts.find(k => k === 2);
|
|
2936
|
+
* console.log(found); // 2;
|
|
2937
|
+
*/
|
|
2938
|
+
find(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): K | undefined;
|
|
2939
|
+
/**
|
|
2940
|
+
* Materialize the set into an array of keys.
|
|
2941
|
+
* @remarks Time O(n), Space O(n)
|
|
2986
2942
|
|
|
2987
2943
|
|
|
2988
2944
|
|
|
@@ -2993,26 +2949,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2993
2949
|
|
|
2994
2950
|
|
|
2995
2951
|
|
|
2996
|
-
* @example
|
|
2997
|
-
* // Finding nearest available time slot
|
|
2998
|
-
* // Available appointment times (minutes from midnight)
|
|
2999
|
-
* const slots = new TreeSet<number>([540, 600, 660, 720, 840, 900]);
|
|
3000
|
-
*
|
|
3001
|
-
* // Customer wants something around 10:30 (630 min)
|
|
3002
|
-
* const nearest = slots.ceiling(630);
|
|
3003
|
-
* console.log(nearest); // 660; // 11:00 AM
|
|
3004
|
-
*
|
|
3005
|
-
* // What's the latest slot before 2:00 PM (840)?
|
|
3006
|
-
* const before2pm = slots.lower(840);
|
|
3007
|
-
* console.log(before2pm); // 720; // 12:00 PM
|
|
3008
|
-
*
|
|
3009
|
-
* // Book the 11:00 slot
|
|
3010
|
-
* slots.delete(660);
|
|
3011
|
-
* console.log(slots.ceiling(630)); // 720;
|
|
3012
|
-
*/
|
|
3013
|
-
ceiling(key: K): K | undefined;
|
|
3014
|
-
/**
|
|
3015
|
-
* Largest key that is <= the given key.
|
|
3016
2952
|
|
|
3017
2953
|
|
|
3018
2954
|
|
|
@@ -3135,18 +3071,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3135
3071
|
|
|
3136
3072
|
|
|
3137
3073
|
|
|
3138
|
-
* @example
|
|
3139
|
-
* // Largest element ≤ target
|
|
3140
|
-
* const breakpoints = new TreeSet<number>([320, 768, 1024, 1280, 1920]);
|
|
3141
|
-
*
|
|
3142
|
-
* // Current width is 800 → which breakpoint applies?
|
|
3143
|
-
* console.log(breakpoints.floor(800)); // 768;
|
|
3144
|
-
* console.log(breakpoints.floor(1024)); // 1024; // exact match
|
|
3145
|
-
* console.log(breakpoints.floor(100)); // undefined;
|
|
3146
|
-
*/
|
|
3147
|
-
floor(key: K): K | undefined;
|
|
3148
|
-
/**
|
|
3149
|
-
* Smallest key that is > the given key.
|
|
3150
3074
|
|
|
3151
3075
|
|
|
3152
3076
|
|
|
@@ -3193,6 +3117,15 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3193
3117
|
|
|
3194
3118
|
|
|
3195
3119
|
|
|
3120
|
+
* @example
|
|
3121
|
+
* // Convert to array
|
|
3122
|
+
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
3123
|
+
* console.log(ts.toArray()); // [1, 2, 3];
|
|
3124
|
+
*/
|
|
3125
|
+
toArray(): K[];
|
|
3126
|
+
/**
|
|
3127
|
+
* Print a human-friendly representation.
|
|
3128
|
+
* @remarks Time O(n), Space O(n)
|
|
3196
3129
|
|
|
3197
3130
|
|
|
3198
3131
|
|
|
@@ -3269,16 +3202,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3269
3202
|
|
|
3270
3203
|
|
|
3271
3204
|
|
|
3272
|
-
* @example
|
|
3273
|
-
* // Smallest element strictly > target
|
|
3274
|
-
* const levels = new TreeSet<number>([1, 5, 10, 25, 50, 100]);
|
|
3275
|
-
*
|
|
3276
|
-
* console.log(levels.higher(10)); // 25;
|
|
3277
|
-
* console.log(levels.higher(100)); // undefined;
|
|
3278
|
-
*/
|
|
3279
|
-
higher(key: K): K | undefined;
|
|
3280
|
-
/**
|
|
3281
|
-
* Largest key that is < the given key.
|
|
3282
3205
|
|
|
3283
3206
|
|
|
3284
3207
|
|
|
@@ -3381,6 +3304,894 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3381
3304
|
|
|
3382
3305
|
|
|
3383
3306
|
|
|
3307
|
+
* @example
|
|
3308
|
+
* // Display tree
|
|
3309
|
+
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
3310
|
+
* expect(() => ts.print()).not.toThrow();
|
|
3311
|
+
*/
|
|
3312
|
+
print(): void;
|
|
3313
|
+
/**
|
|
3314
|
+
* Smallest key in the set.
|
|
3315
|
+
|
|
3316
|
+
|
|
3317
|
+
|
|
3318
|
+
|
|
3319
|
+
|
|
3320
|
+
|
|
3321
|
+
|
|
3322
|
+
|
|
3323
|
+
|
|
3324
|
+
|
|
3325
|
+
|
|
3326
|
+
|
|
3327
|
+
|
|
3328
|
+
|
|
3329
|
+
|
|
3330
|
+
|
|
3331
|
+
|
|
3332
|
+
|
|
3333
|
+
|
|
3334
|
+
|
|
3335
|
+
|
|
3336
|
+
|
|
3337
|
+
|
|
3338
|
+
|
|
3339
|
+
|
|
3340
|
+
|
|
3341
|
+
|
|
3342
|
+
|
|
3343
|
+
|
|
3344
|
+
|
|
3345
|
+
|
|
3346
|
+
|
|
3347
|
+
|
|
3348
|
+
|
|
3349
|
+
|
|
3350
|
+
|
|
3351
|
+
|
|
3352
|
+
|
|
3353
|
+
|
|
3354
|
+
* @example
|
|
3355
|
+
* // Student grade ranking with custom comparator
|
|
3356
|
+
* interface Student {
|
|
3357
|
+
* name: string;
|
|
3358
|
+
* gpa: number;
|
|
3359
|
+
* }
|
|
3360
|
+
*
|
|
3361
|
+
* const ranking = new TreeSet<Student>(
|
|
3362
|
+
* [
|
|
3363
|
+
* { name: 'Alice', gpa: 3.8 },
|
|
3364
|
+
* { name: 'Bob', gpa: 3.5 },
|
|
3365
|
+
* { name: 'Charlie', gpa: 3.9 },
|
|
3366
|
+
* { name: 'Diana', gpa: 3.5 }
|
|
3367
|
+
* ],
|
|
3368
|
+
* { comparator: (a, b) => b.gpa - a.gpa || a.name.localeCompare(b.name) }
|
|
3369
|
+
* );
|
|
3370
|
+
*
|
|
3371
|
+
* // Sorted by GPA descending, then name ascending
|
|
3372
|
+
* const names = [...ranking].map(s => s.name);
|
|
3373
|
+
* console.log(names); // ['Charlie', 'Alice', 'Bob', 'Diana'];
|
|
3374
|
+
*
|
|
3375
|
+
* // Top student
|
|
3376
|
+
* console.log(ranking.first()?.name); // 'Charlie';
|
|
3377
|
+
*
|
|
3378
|
+
* // Filter students with GPA >= 3.8
|
|
3379
|
+
* const honors = ranking.filter(s => s.gpa >= 3.8);
|
|
3380
|
+
* console.log(honors.toArray().map(s => s.name)); // ['Charlie', 'Alice'];
|
|
3381
|
+
*/
|
|
3382
|
+
first(): K | undefined;
|
|
3383
|
+
/**
|
|
3384
|
+
* Largest key in the set.
|
|
3385
|
+
|
|
3386
|
+
|
|
3387
|
+
|
|
3388
|
+
|
|
3389
|
+
|
|
3390
|
+
|
|
3391
|
+
|
|
3392
|
+
|
|
3393
|
+
|
|
3394
|
+
|
|
3395
|
+
|
|
3396
|
+
|
|
3397
|
+
|
|
3398
|
+
|
|
3399
|
+
|
|
3400
|
+
|
|
3401
|
+
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
|
|
3405
|
+
|
|
3406
|
+
|
|
3407
|
+
|
|
3408
|
+
|
|
3409
|
+
|
|
3410
|
+
|
|
3411
|
+
|
|
3412
|
+
|
|
3413
|
+
|
|
3414
|
+
|
|
3415
|
+
|
|
3416
|
+
|
|
3417
|
+
|
|
3418
|
+
|
|
3419
|
+
|
|
3420
|
+
|
|
3421
|
+
|
|
3422
|
+
|
|
3423
|
+
|
|
3424
|
+
* @example
|
|
3425
|
+
* // Get the maximum element
|
|
3426
|
+
* const temps = new TreeSet<number>([18, 22, 15, 30, 25]);
|
|
3427
|
+
* console.log(temps.last()); // 30;
|
|
3428
|
+
* console.log(temps.first()); // 15;
|
|
3429
|
+
*/
|
|
3430
|
+
last(): K | undefined;
|
|
3431
|
+
/**
|
|
3432
|
+
* Remove and return the smallest key.
|
|
3433
|
+
|
|
3434
|
+
|
|
3435
|
+
|
|
3436
|
+
|
|
3437
|
+
|
|
3438
|
+
|
|
3439
|
+
|
|
3440
|
+
|
|
3441
|
+
|
|
3442
|
+
|
|
3443
|
+
|
|
3444
|
+
|
|
3445
|
+
|
|
3446
|
+
|
|
3447
|
+
|
|
3448
|
+
|
|
3449
|
+
|
|
3450
|
+
|
|
3451
|
+
|
|
3452
|
+
|
|
3453
|
+
|
|
3454
|
+
|
|
3455
|
+
|
|
3456
|
+
|
|
3457
|
+
|
|
3458
|
+
|
|
3459
|
+
|
|
3460
|
+
|
|
3461
|
+
|
|
3462
|
+
|
|
3463
|
+
|
|
3464
|
+
|
|
3465
|
+
|
|
3466
|
+
|
|
3467
|
+
|
|
3468
|
+
|
|
3469
|
+
|
|
3470
|
+
|
|
3471
|
+
|
|
3472
|
+
* @example
|
|
3473
|
+
* // Remove and return minimum
|
|
3474
|
+
* const queue = new TreeSet<number>([5, 1, 8, 3]);
|
|
3475
|
+
*
|
|
3476
|
+
* console.log(queue.pollFirst()); // 1;
|
|
3477
|
+
* console.log(queue.pollFirst()); // 3;
|
|
3478
|
+
* console.log(queue.size); // 2;
|
|
3479
|
+
*/
|
|
3480
|
+
pollFirst(): K | undefined;
|
|
3481
|
+
/**
|
|
3482
|
+
* Remove and return the largest key.
|
|
3483
|
+
|
|
3484
|
+
|
|
3485
|
+
|
|
3486
|
+
|
|
3487
|
+
|
|
3488
|
+
|
|
3489
|
+
|
|
3490
|
+
|
|
3491
|
+
|
|
3492
|
+
|
|
3493
|
+
|
|
3494
|
+
|
|
3495
|
+
|
|
3496
|
+
|
|
3497
|
+
|
|
3498
|
+
|
|
3499
|
+
|
|
3500
|
+
|
|
3501
|
+
|
|
3502
|
+
|
|
3503
|
+
|
|
3504
|
+
|
|
3505
|
+
|
|
3506
|
+
|
|
3507
|
+
|
|
3508
|
+
|
|
3509
|
+
|
|
3510
|
+
|
|
3511
|
+
|
|
3512
|
+
|
|
3513
|
+
|
|
3514
|
+
|
|
3515
|
+
|
|
3516
|
+
|
|
3517
|
+
|
|
3518
|
+
|
|
3519
|
+
|
|
3520
|
+
|
|
3521
|
+
|
|
3522
|
+
* @example
|
|
3523
|
+
* // Remove and return maximum
|
|
3524
|
+
* const stack = new TreeSet<number>([10, 20, 30]);
|
|
3525
|
+
*
|
|
3526
|
+
* console.log(stack.pollLast()); // 30;
|
|
3527
|
+
* console.log(stack.size); // 2;
|
|
3528
|
+
*/
|
|
3529
|
+
pollLast(): K | undefined;
|
|
3530
|
+
/**
|
|
3531
|
+
* Smallest key that is >= the given key.
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
|
|
3545
|
+
|
|
3546
|
+
|
|
3547
|
+
|
|
3548
|
+
|
|
3549
|
+
|
|
3550
|
+
|
|
3551
|
+
|
|
3552
|
+
|
|
3553
|
+
|
|
3554
|
+
|
|
3555
|
+
|
|
3556
|
+
|
|
3557
|
+
|
|
3558
|
+
|
|
3559
|
+
|
|
3560
|
+
|
|
3561
|
+
|
|
3562
|
+
|
|
3563
|
+
|
|
3564
|
+
|
|
3565
|
+
|
|
3566
|
+
|
|
3567
|
+
|
|
3568
|
+
|
|
3569
|
+
|
|
3570
|
+
|
|
3571
|
+
|
|
3572
|
+
|
|
3573
|
+
|
|
3574
|
+
|
|
3575
|
+
|
|
3576
|
+
|
|
3577
|
+
|
|
3578
|
+
|
|
3579
|
+
|
|
3580
|
+
|
|
3581
|
+
|
|
3582
|
+
|
|
3583
|
+
|
|
3584
|
+
|
|
3585
|
+
|
|
3586
|
+
|
|
3587
|
+
|
|
3588
|
+
|
|
3589
|
+
|
|
3590
|
+
|
|
3591
|
+
|
|
3592
|
+
|
|
3593
|
+
|
|
3594
|
+
|
|
3595
|
+
|
|
3596
|
+
|
|
3597
|
+
|
|
3598
|
+
|
|
3599
|
+
|
|
3600
|
+
|
|
3601
|
+
|
|
3602
|
+
|
|
3603
|
+
|
|
3604
|
+
|
|
3605
|
+
|
|
3606
|
+
|
|
3607
|
+
|
|
3608
|
+
|
|
3609
|
+
|
|
3610
|
+
|
|
3611
|
+
|
|
3612
|
+
|
|
3613
|
+
|
|
3614
|
+
|
|
3615
|
+
|
|
3616
|
+
|
|
3617
|
+
|
|
3618
|
+
|
|
3619
|
+
|
|
3620
|
+
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3624
|
+
|
|
3625
|
+
|
|
3626
|
+
|
|
3627
|
+
|
|
3628
|
+
|
|
3629
|
+
|
|
3630
|
+
|
|
3631
|
+
|
|
3632
|
+
|
|
3633
|
+
|
|
3634
|
+
|
|
3635
|
+
|
|
3636
|
+
|
|
3637
|
+
|
|
3638
|
+
|
|
3639
|
+
|
|
3640
|
+
|
|
3641
|
+
|
|
3642
|
+
|
|
3643
|
+
|
|
3644
|
+
|
|
3645
|
+
|
|
3646
|
+
|
|
3647
|
+
|
|
3648
|
+
|
|
3649
|
+
|
|
3650
|
+
|
|
3651
|
+
|
|
3652
|
+
|
|
3653
|
+
|
|
3654
|
+
|
|
3655
|
+
|
|
3656
|
+
|
|
3657
|
+
|
|
3658
|
+
|
|
3659
|
+
|
|
3660
|
+
|
|
3661
|
+
|
|
3662
|
+
|
|
3663
|
+
|
|
3664
|
+
|
|
3665
|
+
|
|
3666
|
+
|
|
3667
|
+
|
|
3668
|
+
|
|
3669
|
+
|
|
3670
|
+
|
|
3671
|
+
|
|
3672
|
+
|
|
3673
|
+
|
|
3674
|
+
|
|
3675
|
+
|
|
3676
|
+
|
|
3677
|
+
|
|
3678
|
+
|
|
3679
|
+
|
|
3680
|
+
|
|
3681
|
+
|
|
3682
|
+
* @example
|
|
3683
|
+
* // Finding nearest available time slot
|
|
3684
|
+
* // Available appointment times (minutes from midnight)
|
|
3685
|
+
* const slots = new TreeSet<number>([540, 600, 660, 720, 840, 900]);
|
|
3686
|
+
*
|
|
3687
|
+
* // Customer wants something around 10:30 (630 min)
|
|
3688
|
+
* const nearest = slots.ceiling(630);
|
|
3689
|
+
* console.log(nearest); // 660; // 11:00 AM
|
|
3690
|
+
*
|
|
3691
|
+
* // What's the latest slot before 2:00 PM (840)?
|
|
3692
|
+
* const before2pm = slots.lower(840);
|
|
3693
|
+
* console.log(before2pm); // 720; // 12:00 PM
|
|
3694
|
+
*
|
|
3695
|
+
* // Book the 11:00 slot
|
|
3696
|
+
* slots.delete(660);
|
|
3697
|
+
* console.log(slots.ceiling(630)); // 720;
|
|
3698
|
+
*/
|
|
3699
|
+
ceiling(key: K): K | undefined;
|
|
3700
|
+
/**
|
|
3701
|
+
* Largest key that is <= the given key.
|
|
3702
|
+
|
|
3703
|
+
|
|
3704
|
+
|
|
3705
|
+
|
|
3706
|
+
|
|
3707
|
+
|
|
3708
|
+
|
|
3709
|
+
|
|
3710
|
+
|
|
3711
|
+
|
|
3712
|
+
|
|
3713
|
+
|
|
3714
|
+
|
|
3715
|
+
|
|
3716
|
+
|
|
3717
|
+
|
|
3718
|
+
|
|
3719
|
+
|
|
3720
|
+
|
|
3721
|
+
|
|
3722
|
+
|
|
3723
|
+
|
|
3724
|
+
|
|
3725
|
+
|
|
3726
|
+
|
|
3727
|
+
|
|
3728
|
+
|
|
3729
|
+
|
|
3730
|
+
|
|
3731
|
+
|
|
3732
|
+
|
|
3733
|
+
|
|
3734
|
+
|
|
3735
|
+
|
|
3736
|
+
|
|
3737
|
+
|
|
3738
|
+
|
|
3739
|
+
|
|
3740
|
+
|
|
3741
|
+
|
|
3742
|
+
|
|
3743
|
+
|
|
3744
|
+
|
|
3745
|
+
|
|
3746
|
+
|
|
3747
|
+
|
|
3748
|
+
|
|
3749
|
+
|
|
3750
|
+
|
|
3751
|
+
|
|
3752
|
+
|
|
3753
|
+
|
|
3754
|
+
|
|
3755
|
+
|
|
3756
|
+
|
|
3757
|
+
|
|
3758
|
+
|
|
3759
|
+
|
|
3760
|
+
|
|
3761
|
+
|
|
3762
|
+
|
|
3763
|
+
|
|
3764
|
+
|
|
3765
|
+
|
|
3766
|
+
|
|
3767
|
+
|
|
3768
|
+
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
|
|
3772
|
+
|
|
3773
|
+
|
|
3774
|
+
|
|
3775
|
+
|
|
3776
|
+
|
|
3777
|
+
|
|
3778
|
+
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
|
|
3788
|
+
|
|
3789
|
+
|
|
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
|
+
|
|
3819
|
+
|
|
3820
|
+
|
|
3821
|
+
|
|
3822
|
+
|
|
3823
|
+
|
|
3824
|
+
|
|
3825
|
+
|
|
3826
|
+
|
|
3827
|
+
|
|
3828
|
+
|
|
3829
|
+
|
|
3830
|
+
|
|
3831
|
+
|
|
3832
|
+
|
|
3833
|
+
|
|
3834
|
+
|
|
3835
|
+
|
|
3836
|
+
|
|
3837
|
+
|
|
3838
|
+
|
|
3839
|
+
|
|
3840
|
+
|
|
3841
|
+
|
|
3842
|
+
|
|
3843
|
+
|
|
3844
|
+
|
|
3845
|
+
|
|
3846
|
+
|
|
3847
|
+
|
|
3848
|
+
|
|
3849
|
+
|
|
3850
|
+
|
|
3851
|
+
|
|
3852
|
+
* @example
|
|
3853
|
+
* // Largest element ≤ target
|
|
3854
|
+
* const breakpoints = new TreeSet<number>([320, 768, 1024, 1280, 1920]);
|
|
3855
|
+
*
|
|
3856
|
+
* // Current width is 800 → which breakpoint applies?
|
|
3857
|
+
* console.log(breakpoints.floor(800)); // 768;
|
|
3858
|
+
* console.log(breakpoints.floor(1024)); // 1024; // exact match
|
|
3859
|
+
* console.log(breakpoints.floor(100)); // undefined;
|
|
3860
|
+
*/
|
|
3861
|
+
floor(key: K): K | undefined;
|
|
3862
|
+
/**
|
|
3863
|
+
* Smallest key that is > the given key.
|
|
3864
|
+
|
|
3865
|
+
|
|
3866
|
+
|
|
3867
|
+
|
|
3868
|
+
|
|
3869
|
+
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
|
|
3873
|
+
|
|
3874
|
+
|
|
3875
|
+
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
|
|
3879
|
+
|
|
3880
|
+
|
|
3881
|
+
|
|
3882
|
+
|
|
3883
|
+
|
|
3884
|
+
|
|
3885
|
+
|
|
3886
|
+
|
|
3887
|
+
|
|
3888
|
+
|
|
3889
|
+
|
|
3890
|
+
|
|
3891
|
+
|
|
3892
|
+
|
|
3893
|
+
|
|
3894
|
+
|
|
3895
|
+
|
|
3896
|
+
|
|
3897
|
+
|
|
3898
|
+
|
|
3899
|
+
|
|
3900
|
+
|
|
3901
|
+
|
|
3902
|
+
|
|
3903
|
+
|
|
3904
|
+
|
|
3905
|
+
|
|
3906
|
+
|
|
3907
|
+
|
|
3908
|
+
|
|
3909
|
+
|
|
3910
|
+
|
|
3911
|
+
|
|
3912
|
+
|
|
3913
|
+
|
|
3914
|
+
|
|
3915
|
+
|
|
3916
|
+
|
|
3917
|
+
|
|
3918
|
+
|
|
3919
|
+
|
|
3920
|
+
|
|
3921
|
+
|
|
3922
|
+
|
|
3923
|
+
|
|
3924
|
+
|
|
3925
|
+
|
|
3926
|
+
|
|
3927
|
+
|
|
3928
|
+
|
|
3929
|
+
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3937
|
+
|
|
3938
|
+
|
|
3939
|
+
|
|
3940
|
+
|
|
3941
|
+
|
|
3942
|
+
|
|
3943
|
+
|
|
3944
|
+
|
|
3945
|
+
|
|
3946
|
+
|
|
3947
|
+
|
|
3948
|
+
|
|
3949
|
+
|
|
3950
|
+
|
|
3951
|
+
|
|
3952
|
+
|
|
3953
|
+
|
|
3954
|
+
|
|
3955
|
+
|
|
3956
|
+
|
|
3957
|
+
|
|
3958
|
+
|
|
3959
|
+
|
|
3960
|
+
|
|
3961
|
+
|
|
3962
|
+
|
|
3963
|
+
|
|
3964
|
+
|
|
3965
|
+
|
|
3966
|
+
|
|
3967
|
+
|
|
3968
|
+
|
|
3969
|
+
|
|
3970
|
+
|
|
3971
|
+
|
|
3972
|
+
|
|
3973
|
+
|
|
3974
|
+
|
|
3975
|
+
|
|
3976
|
+
|
|
3977
|
+
|
|
3978
|
+
|
|
3979
|
+
|
|
3980
|
+
|
|
3981
|
+
|
|
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
|
+
* @example
|
|
4015
|
+
* // Smallest element strictly > target
|
|
4016
|
+
* const levels = new TreeSet<number>([1, 5, 10, 25, 50, 100]);
|
|
4017
|
+
*
|
|
4018
|
+
* console.log(levels.higher(10)); // 25;
|
|
4019
|
+
* console.log(levels.higher(100)); // undefined;
|
|
4020
|
+
*/
|
|
4021
|
+
higher(key: K): K | undefined;
|
|
4022
|
+
/**
|
|
4023
|
+
* Largest key that is < the given key.
|
|
4024
|
+
|
|
4025
|
+
|
|
4026
|
+
|
|
4027
|
+
|
|
4028
|
+
|
|
4029
|
+
|
|
4030
|
+
|
|
4031
|
+
|
|
4032
|
+
|
|
4033
|
+
|
|
4034
|
+
|
|
4035
|
+
|
|
4036
|
+
|
|
4037
|
+
|
|
4038
|
+
|
|
4039
|
+
|
|
4040
|
+
|
|
4041
|
+
|
|
4042
|
+
|
|
4043
|
+
|
|
4044
|
+
|
|
4045
|
+
|
|
4046
|
+
|
|
4047
|
+
|
|
4048
|
+
|
|
4049
|
+
|
|
4050
|
+
|
|
4051
|
+
|
|
4052
|
+
|
|
4053
|
+
|
|
4054
|
+
|
|
4055
|
+
|
|
4056
|
+
|
|
4057
|
+
|
|
4058
|
+
|
|
4059
|
+
|
|
4060
|
+
|
|
4061
|
+
|
|
4062
|
+
|
|
4063
|
+
|
|
4064
|
+
|
|
4065
|
+
|
|
4066
|
+
|
|
4067
|
+
|
|
4068
|
+
|
|
4069
|
+
|
|
4070
|
+
|
|
4071
|
+
|
|
4072
|
+
|
|
4073
|
+
|
|
4074
|
+
|
|
4075
|
+
|
|
4076
|
+
|
|
4077
|
+
|
|
4078
|
+
|
|
4079
|
+
|
|
4080
|
+
|
|
4081
|
+
|
|
4082
|
+
|
|
4083
|
+
|
|
4084
|
+
|
|
4085
|
+
|
|
4086
|
+
|
|
4087
|
+
|
|
4088
|
+
|
|
4089
|
+
|
|
4090
|
+
|
|
4091
|
+
|
|
4092
|
+
|
|
4093
|
+
|
|
4094
|
+
|
|
4095
|
+
|
|
4096
|
+
|
|
4097
|
+
|
|
4098
|
+
|
|
4099
|
+
|
|
4100
|
+
|
|
4101
|
+
|
|
4102
|
+
|
|
4103
|
+
|
|
4104
|
+
|
|
4105
|
+
|
|
4106
|
+
|
|
4107
|
+
|
|
4108
|
+
|
|
4109
|
+
|
|
4110
|
+
|
|
4111
|
+
|
|
4112
|
+
|
|
4113
|
+
|
|
4114
|
+
|
|
4115
|
+
|
|
4116
|
+
|
|
4117
|
+
|
|
4118
|
+
|
|
4119
|
+
|
|
4120
|
+
|
|
4121
|
+
|
|
4122
|
+
|
|
4123
|
+
|
|
4124
|
+
|
|
4125
|
+
|
|
4126
|
+
|
|
4127
|
+
|
|
4128
|
+
|
|
4129
|
+
|
|
4130
|
+
|
|
4131
|
+
|
|
4132
|
+
|
|
4133
|
+
|
|
4134
|
+
|
|
4135
|
+
|
|
4136
|
+
|
|
4137
|
+
|
|
4138
|
+
|
|
4139
|
+
|
|
4140
|
+
|
|
4141
|
+
|
|
4142
|
+
|
|
4143
|
+
|
|
4144
|
+
|
|
4145
|
+
|
|
4146
|
+
|
|
4147
|
+
|
|
4148
|
+
|
|
4149
|
+
|
|
4150
|
+
|
|
4151
|
+
|
|
4152
|
+
|
|
4153
|
+
|
|
4154
|
+
|
|
4155
|
+
|
|
4156
|
+
|
|
4157
|
+
|
|
4158
|
+
|
|
4159
|
+
|
|
4160
|
+
|
|
4161
|
+
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
|
|
4167
|
+
|
|
4168
|
+
|
|
4169
|
+
|
|
4170
|
+
|
|
4171
|
+
|
|
4172
|
+
|
|
4173
|
+
|
|
4174
|
+
* @example
|
|
4175
|
+
* // Largest element strictly < target
|
|
4176
|
+
* const tiers = new TreeSet<number>([100, 200, 500, 1000]);
|
|
4177
|
+
*
|
|
4178
|
+
* console.log(tiers.lower(500)); // 200;
|
|
4179
|
+
* console.log(tiers.lower(100)); // undefined;
|
|
4180
|
+
*/
|
|
4181
|
+
lower(key: K): K | undefined;
|
|
4182
|
+
/**
|
|
4183
|
+
* Return all keys in a given range.
|
|
4184
|
+
*
|
|
4185
|
+
* @param range `[low, high]`
|
|
4186
|
+
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
4187
|
+
|
|
4188
|
+
|
|
4189
|
+
|
|
4190
|
+
|
|
4191
|
+
|
|
4192
|
+
|
|
4193
|
+
|
|
4194
|
+
|
|
3384
4195
|
|
|
3385
4196
|
|
|
3386
4197
|
|
|
@@ -3401,19 +4212,6 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3401
4212
|
|
|
3402
4213
|
|
|
3403
4214
|
|
|
3404
|
-
* @example
|
|
3405
|
-
* // Largest element strictly < target
|
|
3406
|
-
* const tiers = new TreeSet<number>([100, 200, 500, 1000]);
|
|
3407
|
-
*
|
|
3408
|
-
* console.log(tiers.lower(500)); // 200;
|
|
3409
|
-
* console.log(tiers.lower(100)); // undefined;
|
|
3410
|
-
*/
|
|
3411
|
-
lower(key: K): K | undefined;
|
|
3412
|
-
/**
|
|
3413
|
-
* Return all keys in a given range.
|
|
3414
|
-
*
|
|
3415
|
-
* @param range `[low, high]`
|
|
3416
|
-
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
3417
4215
|
|
|
3418
4216
|
|
|
3419
4217
|
|
|
@@ -3555,6 +4353,63 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3555
4353
|
* console.log(blocklist.has(167772800)); // false;
|
|
3556
4354
|
*/
|
|
3557
4355
|
rangeSearch(range: [K, K], options?: TreeSetRangeOptions): K[];
|
|
4356
|
+
/**
|
|
4357
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
4358
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
4359
|
+
|
|
4360
|
+
|
|
4361
|
+
|
|
4362
|
+
* @example
|
|
4363
|
+
* // Find k-th element in a TreeSet
|
|
4364
|
+
* const set = new TreeSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
4365
|
+
* console.log(set.getByRank(0)); // 10;
|
|
4366
|
+
* console.log(set.getByRank(2)); // 30;
|
|
4367
|
+
* console.log(set.getRank(30)); // 2;
|
|
4368
|
+
*/
|
|
4369
|
+
getByRank(k: number): K | undefined;
|
|
4370
|
+
/**
|
|
4371
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
4372
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
4373
|
+
* @example
|
|
4374
|
+
* // Get the rank of a key in sorted order
|
|
4375
|
+
* const tree = new TreeSet<number>(
|
|
4376
|
+
* [10, 20, 30, 40, 50],
|
|
4377
|
+
* { enableOrderStatistic: true }
|
|
4378
|
+
* );
|
|
4379
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
4380
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
4381
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
4382
|
+
* console.log(tree.getRank(25)); // 2;
|
|
4383
|
+
*/
|
|
4384
|
+
getRank(key: K): number;
|
|
4385
|
+
/**
|
|
4386
|
+
* Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
4387
|
+
* @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
4388
|
+
|
|
4389
|
+
|
|
4390
|
+
|
|
4391
|
+
|
|
4392
|
+
|
|
4393
|
+
|
|
4394
|
+
|
|
4395
|
+
|
|
4396
|
+
|
|
4397
|
+
* @example
|
|
4398
|
+
* // Pagination by position in tree order
|
|
4399
|
+
* const tree = new TreeSet<number>(
|
|
4400
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
4401
|
+
* { enableOrderStatistic: true }
|
|
4402
|
+
* );
|
|
4403
|
+
* const pageSize = 3;
|
|
4404
|
+
*
|
|
4405
|
+
* // Page 1
|
|
4406
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
4407
|
+
* // Page 2
|
|
4408
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
4409
|
+
* // Page 3
|
|
4410
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
4411
|
+
*/
|
|
4412
|
+
rangeByRank(start: number, end: number): K[];
|
|
3558
4413
|
/**
|
|
3559
4414
|
* Creates a shallow clone of this set.
|
|
3560
4415
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -3681,6 +4536,41 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3681
4536
|
|
|
3682
4537
|
|
|
3683
4538
|
|
|
4539
|
+
|
|
4540
|
+
|
|
4541
|
+
|
|
4542
|
+
|
|
4543
|
+
|
|
4544
|
+
|
|
4545
|
+
|
|
4546
|
+
|
|
4547
|
+
|
|
4548
|
+
|
|
4549
|
+
|
|
4550
|
+
|
|
4551
|
+
|
|
4552
|
+
|
|
4553
|
+
|
|
4554
|
+
|
|
4555
|
+
|
|
4556
|
+
|
|
4557
|
+
|
|
4558
|
+
|
|
4559
|
+
|
|
4560
|
+
|
|
4561
|
+
|
|
4562
|
+
|
|
4563
|
+
|
|
4564
|
+
|
|
4565
|
+
|
|
4566
|
+
|
|
4567
|
+
|
|
4568
|
+
|
|
4569
|
+
|
|
4570
|
+
|
|
4571
|
+
|
|
4572
|
+
|
|
4573
|
+
|
|
3684
4574
|
|
|
3685
4575
|
|
|
3686
4576
|
|