max-priority-queue-typed 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +174 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +174 -16
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +174 -16
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +174 -16
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/max-priority-queue-typed.js +174 -16
- 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/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
|
@@ -241,6 +241,41 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
241
241
|
|
|
242
242
|
|
|
243
243
|
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
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
|
+
|
|
244
279
|
|
|
245
280
|
|
|
246
281
|
|
|
@@ -432,6 +467,41 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
432
467
|
|
|
433
468
|
|
|
434
469
|
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
435
505
|
|
|
436
506
|
|
|
437
507
|
|
|
@@ -473,8 +543,11 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
473
543
|
}
|
|
474
544
|
|
|
475
545
|
/**
|
|
476
|
-
*
|
|
477
|
-
* @remarks Expected time O(log n)
|
|
546
|
+
* Add multiple keys at once.
|
|
547
|
+
* @remarks Expected time O(m log n), where m is the number of keys.
|
|
548
|
+
* @param keys - Iterable of keys to add.
|
|
549
|
+
* @returns Array of booleans indicating whether each key was newly added.
|
|
550
|
+
|
|
478
551
|
|
|
479
552
|
|
|
480
553
|
|
|
@@ -502,6 +575,25 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
502
575
|
|
|
503
576
|
|
|
504
577
|
|
|
578
|
+
* @example
|
|
579
|
+
* // Add multiple keys
|
|
580
|
+
* const ts = new TreeSet<number>();
|
|
581
|
+
* ts.addMany([5, 3, 7, 1, 9]);
|
|
582
|
+
* console.log(ts.size); // 5;
|
|
583
|
+
*/
|
|
584
|
+
addMany(keys: Iterable<K>): boolean[] {
|
|
585
|
+
const results: boolean[] = [];
|
|
586
|
+
for (const key of keys) {
|
|
587
|
+
this._validateKey(key);
|
|
588
|
+
results.push(this.#core.set(key, undefined));
|
|
589
|
+
}
|
|
590
|
+
return results;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Test whether a key exists.
|
|
595
|
+
* @remarks Expected time O(log n)
|
|
596
|
+
|
|
505
597
|
|
|
506
598
|
|
|
507
599
|
|
|
@@ -644,22 +736,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
644
736
|
|
|
645
737
|
|
|
646
738
|
|
|
647
|
-
* @example
|
|
648
|
-
* // Checking membership in a sorted collection
|
|
649
|
-
* const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
|
|
650
|
-
*
|
|
651
|
-
* console.log(allowed.has('admin')); // true;
|
|
652
|
-
* console.log(allowed.has('guest')); // false;
|
|
653
|
-
*/
|
|
654
|
-
has(key: K): boolean {
|
|
655
|
-
this._validateKey(key);
|
|
656
|
-
return this.#core.has(key);
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
/**
|
|
660
|
-
* Delete a key.
|
|
661
|
-
* @returns `true` if the key existed; otherwise `false`.
|
|
662
|
-
* @remarks Expected time O(log n)
|
|
663
739
|
|
|
664
740
|
|
|
665
741
|
|
|
@@ -721,6 +797,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
721
797
|
|
|
722
798
|
|
|
723
799
|
|
|
800
|
+
* @example
|
|
801
|
+
* // Checking membership in a sorted collection
|
|
802
|
+
* const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
|
|
803
|
+
*
|
|
804
|
+
* console.log(allowed.has('admin')); // true;
|
|
805
|
+
* console.log(allowed.has('guest')); // false;
|
|
806
|
+
*/
|
|
807
|
+
has(key: K): boolean {
|
|
808
|
+
this._validateKey(key);
|
|
809
|
+
return this.#core.has(key);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Delete a key.
|
|
814
|
+
* @returns `true` if the key existed; otherwise `false`.
|
|
815
|
+
* @remarks Expected time O(log n)
|
|
724
816
|
|
|
725
817
|
|
|
726
818
|
|
|
@@ -829,22 +921,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
829
921
|
|
|
830
922
|
|
|
831
923
|
|
|
832
|
-
* @example
|
|
833
|
-
* // Removing elements while maintaining order
|
|
834
|
-
* const nums = new TreeSet<number>([1, 3, 5, 7, 9]);
|
|
835
|
-
*
|
|
836
|
-
* console.log(nums.delete(5)); // true;
|
|
837
|
-
* console.log(nums.delete(5)); // false; // already gone
|
|
838
|
-
* console.log([...nums]); // [1, 3, 7, 9];
|
|
839
|
-
*/
|
|
840
|
-
delete(key: K): boolean {
|
|
841
|
-
this._validateKey(key);
|
|
842
|
-
const res = this.#core.delete(key);
|
|
843
|
-
return Array.isArray(res) && res.length > 0 && !!res[0]?.deleted;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
/**
|
|
847
|
-
* Remove all keys.
|
|
848
924
|
|
|
849
925
|
|
|
850
926
|
|
|
@@ -941,6 +1017,39 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
941
1017
|
|
|
942
1018
|
|
|
943
1019
|
|
|
1020
|
+
* @example
|
|
1021
|
+
* // Removing elements while maintaining order
|
|
1022
|
+
* const nums = new TreeSet<number>([1, 3, 5, 7, 9]);
|
|
1023
|
+
*
|
|
1024
|
+
* console.log(nums.delete(5)); // true;
|
|
1025
|
+
* console.log(nums.delete(5)); // false; // already gone
|
|
1026
|
+
* console.log([...nums]); // [1, 3, 7, 9];
|
|
1027
|
+
*/
|
|
1028
|
+
delete(key: K): boolean {
|
|
1029
|
+
this._validateKey(key);
|
|
1030
|
+
return this.#core.delete(key);
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Delete all keys matching a predicate.
|
|
1035
|
+
* @remarks Time O(N), Space O(N)
|
|
1036
|
+
* @param predicate - Function (key, index, set) → boolean; return true to delete.
|
|
1037
|
+
* @returns True if at least one key was deleted.
|
|
1038
|
+
*/
|
|
1039
|
+
deleteWhere(predicate: (key: K, index: number, set: this) => boolean): boolean {
|
|
1040
|
+
let deleted = false;
|
|
1041
|
+
let index = 0;
|
|
1042
|
+
for (const key of this) {
|
|
1043
|
+
if (predicate(key, index++, this)) {
|
|
1044
|
+
this.delete(key);
|
|
1045
|
+
deleted = true;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return deleted;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Remove all keys.
|
|
944
1053
|
|
|
945
1054
|
|
|
946
1055
|
|
|
@@ -1003,18 +1112,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1003
1112
|
|
|
1004
1113
|
|
|
1005
1114
|
|
|
1006
|
-
* @example
|
|
1007
|
-
* // Remove all
|
|
1008
|
-
* const ts = new TreeSet<number>([1, 2]);
|
|
1009
|
-
* ts.clear();
|
|
1010
|
-
* console.log(ts.isEmpty()); // true;
|
|
1011
|
-
*/
|
|
1012
|
-
clear(): void {
|
|
1013
|
-
this.#core.clear();
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
/**
|
|
1017
|
-
* Iterate over keys in ascending order.
|
|
1018
1115
|
|
|
1019
1116
|
|
|
1020
1117
|
|
|
@@ -1146,6 +1243,26 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1146
1243
|
|
|
1147
1244
|
|
|
1148
1245
|
|
|
1246
|
+
* @example
|
|
1247
|
+
* // Remove all
|
|
1248
|
+
* const ts = new TreeSet<number>([1, 2]);
|
|
1249
|
+
* ts.clear();
|
|
1250
|
+
* console.log(ts.isEmpty()); // true;
|
|
1251
|
+
*/
|
|
1252
|
+
clear(): void {
|
|
1253
|
+
this.#core.clear();
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Iterate over keys in ascending order.
|
|
1258
|
+
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
|
|
1149
1266
|
|
|
1150
1267
|
|
|
1151
1268
|
|
|
@@ -1173,19 +1290,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1173
1290
|
|
|
1174
1291
|
|
|
1175
1292
|
|
|
1176
|
-
* @example
|
|
1177
|
-
* // Get sorted keys
|
|
1178
|
-
* const ts = new TreeSet<number>([30, 10, 20]);
|
|
1179
|
-
* console.log([...ts.keys()]); // [10, 20, 30];
|
|
1180
|
-
*/
|
|
1181
|
-
keys(): IterableIterator<K> {
|
|
1182
|
-
return this.#core.keys();
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
/**
|
|
1186
|
-
* Iterate over values in ascending order.
|
|
1187
|
-
*
|
|
1188
|
-
* Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
1189
1293
|
|
|
1190
1294
|
|
|
1191
1295
|
|
|
@@ -1345,20 +1449,18 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1345
1449
|
|
|
1346
1450
|
|
|
1347
1451
|
* @example
|
|
1348
|
-
* // Get
|
|
1349
|
-
* const ts = new TreeSet<number>([
|
|
1350
|
-
* console.log([...ts.
|
|
1452
|
+
* // Get sorted keys
|
|
1453
|
+
* const ts = new TreeSet<number>([30, 10, 20]);
|
|
1454
|
+
* console.log([...ts.keys()]); // [10, 20, 30];
|
|
1351
1455
|
*/
|
|
1352
|
-
|
|
1353
|
-
return this.keys();
|
|
1456
|
+
keys(): IterableIterator<K> {
|
|
1457
|
+
return this.#core.keys();
|
|
1354
1458
|
}
|
|
1355
1459
|
|
|
1356
1460
|
/**
|
|
1357
|
-
* Iterate over
|
|
1461
|
+
* Iterate over values in ascending order.
|
|
1358
1462
|
*
|
|
1359
|
-
* Note:
|
|
1360
|
-
|
|
1361
|
-
|
|
1463
|
+
* Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
1362
1464
|
|
|
1363
1465
|
|
|
1364
1466
|
|
|
@@ -1515,23 +1617,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1515
1617
|
|
|
1516
1618
|
|
|
1517
1619
|
|
|
1518
|
-
* @example
|
|
1519
|
-
* // Iterate entries
|
|
1520
|
-
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1521
|
-
* console.log([...ts.entries()].map(([k]) => k)); // [1, 2, 3];
|
|
1522
|
-
*/
|
|
1523
|
-
*entries(): IterableIterator<[K, K]> {
|
|
1524
|
-
for (const k of this.keys()) yield [k, k];
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
[Symbol.iterator](): IterableIterator<K> {
|
|
1528
|
-
return this.keys();
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
/**
|
|
1532
|
-
* Visit each value in ascending order.
|
|
1533
|
-
*
|
|
1534
|
-
* Callback follows native Set convention: `(value, value2, set)`.
|
|
1535
1620
|
|
|
1536
1621
|
|
|
1537
1622
|
|
|
@@ -1569,6 +1654,19 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1569
1654
|
|
|
1570
1655
|
|
|
1571
1656
|
|
|
1657
|
+
* @example
|
|
1658
|
+
* // Get values (same as keys for Set)
|
|
1659
|
+
* const ts = new TreeSet<number>([2, 1, 3]);
|
|
1660
|
+
* console.log([...ts.values()]); // [1, 2, 3];
|
|
1661
|
+
*/
|
|
1662
|
+
values(): IterableIterator<K> {
|
|
1663
|
+
return this.keys();
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
/**
|
|
1667
|
+
* Iterate over `[value, value]` pairs (native Set convention).
|
|
1668
|
+
*
|
|
1669
|
+
* Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
1572
1670
|
|
|
1573
1671
|
|
|
1574
1672
|
|
|
@@ -1690,38 +1788,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1690
1788
|
|
|
1691
1789
|
|
|
1692
1790
|
|
|
1693
|
-
* @example
|
|
1694
|
-
* // Execute for each
|
|
1695
|
-
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1696
|
-
* const keys: number[] = [];
|
|
1697
|
-
* ts.forEach(k => keys.push(k));
|
|
1698
|
-
* console.log(keys); // [1, 2, 3];
|
|
1699
|
-
*/
|
|
1700
|
-
forEach(cb: (value: K, value2: K, set: TreeSet<K>) => void, thisArg?: unknown): void {
|
|
1701
|
-
for (const k of this) cb.call(thisArg, k, k, this);
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
/**
|
|
1705
|
-
* Create a new TreeSet by mapping each value to a new key.
|
|
1706
|
-
*
|
|
1707
|
-
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
1708
|
-
* @remarks Time O(n log n) expected, Space O(n)
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
1791
|
|
|
1726
1792
|
|
|
1727
1793
|
|
|
@@ -1794,6 +1860,23 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1794
1860
|
|
|
1795
1861
|
|
|
1796
1862
|
|
|
1863
|
+
* @example
|
|
1864
|
+
* // Iterate entries
|
|
1865
|
+
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
1866
|
+
* console.log([...ts.entries()].map(([k]) => k)); // [1, 2, 3];
|
|
1867
|
+
*/
|
|
1868
|
+
*entries(): IterableIterator<[K, K]> {
|
|
1869
|
+
for (const k of this.keys()) yield [k, k];
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
[Symbol.iterator](): IterableIterator<K> {
|
|
1873
|
+
return this.keys();
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
* Visit each value in ascending order.
|
|
1878
|
+
*
|
|
1879
|
+
* Callback follows native Set convention: `(value, value2, set)`.
|
|
1797
1880
|
|
|
1798
1881
|
|
|
1799
1882
|
|
|
@@ -1864,31 +1947,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
1864
1947
|
|
|
1865
1948
|
|
|
1866
1949
|
|
|
1867
|
-
* @example
|
|
1868
|
-
* // Transform
|
|
1869
|
-
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
1870
|
-
* const doubled = ts.map(k => k * 2);
|
|
1871
|
-
* console.log([...doubled]); // [2, 4, 6];
|
|
1872
|
-
*/
|
|
1873
|
-
map<MK>(
|
|
1874
|
-
callbackfn: TreeSetElementCallback<K, MK, TreeSet<K>>,
|
|
1875
|
-
options: Omit<TreeSetOptions<MK>, 'toElementFn'> & { comparator?: (a: MK, b: MK) => number } = {},
|
|
1876
|
-
thisArg?: unknown
|
|
1877
|
-
): TreeSet<MK> {
|
|
1878
|
-
const out = new TreeSet<MK>([], options as TreeSetOptions<MK>);
|
|
1879
|
-
let index = 0;
|
|
1880
|
-
for (const v of this) {
|
|
1881
|
-
const mk = thisArg === undefined
|
|
1882
|
-
? callbackfn(v, index++, this)
|
|
1883
|
-
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => MK).call(thisArg, v, index++, this);
|
|
1884
|
-
out.add(mk);
|
|
1885
|
-
}
|
|
1886
|
-
return out;
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
/**
|
|
1890
|
-
* Create a new TreeSet containing only values that satisfy the predicate.
|
|
1891
|
-
* @remarks Time O(n log n) expected, Space O(n)
|
|
1892
1950
|
|
|
1893
1951
|
|
|
1894
1952
|
|
|
@@ -2012,6 +2070,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2012
2070
|
|
|
2013
2071
|
|
|
2014
2072
|
|
|
2073
|
+
* @example
|
|
2074
|
+
* // Execute for each
|
|
2075
|
+
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
2076
|
+
* const keys: number[] = [];
|
|
2077
|
+
* ts.forEach(k => keys.push(k));
|
|
2078
|
+
* console.log(keys); // [1, 2, 3];
|
|
2079
|
+
*/
|
|
2080
|
+
forEach(cb: (value: K, value2: K, set: TreeSet<K>) => void, thisArg?: unknown): void {
|
|
2081
|
+
for (const k of this) cb.call(thisArg, k, k, this);
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
/**
|
|
2085
|
+
* Create a new TreeSet by mapping each value to a new key.
|
|
2086
|
+
*
|
|
2087
|
+
* This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
2088
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
2015
2089
|
|
|
2016
2090
|
|
|
2017
2091
|
|
|
@@ -2047,27 +2121,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2047
2121
|
|
|
2048
2122
|
|
|
2049
2123
|
|
|
2050
|
-
* @example
|
|
2051
|
-
* // Filter
|
|
2052
|
-
* const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
2053
|
-
* const evens = ts.filter(k => k % 2 === 0);
|
|
2054
|
-
* console.log([...evens]); // [2, 4];
|
|
2055
|
-
*/
|
|
2056
|
-
filter(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): TreeSet<K> {
|
|
2057
|
-
const out = new TreeSet<K>([], { comparator: this.#userComparator });
|
|
2058
|
-
let index = 0;
|
|
2059
|
-
for (const v of this) {
|
|
2060
|
-
const ok = thisArg === undefined
|
|
2061
|
-
? callbackfn(v, index++, this)
|
|
2062
|
-
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
2063
|
-
if (ok) out.add(v);
|
|
2064
|
-
}
|
|
2065
|
-
return out;
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
/**
|
|
2069
|
-
* Reduce values into a single accumulator.
|
|
2070
|
-
* @remarks Time O(n), Space O(1)
|
|
2071
2124
|
|
|
2072
2125
|
|
|
2073
2126
|
|
|
@@ -2227,29 +2280,30 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2227
2280
|
|
|
2228
2281
|
|
|
2229
2282
|
* @example
|
|
2230
|
-
* //
|
|
2283
|
+
* // Transform
|
|
2231
2284
|
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2232
|
-
* const
|
|
2233
|
-
* console.log(
|
|
2285
|
+
* const doubled = ts.map(k => k * 2);
|
|
2286
|
+
* console.log([...doubled]); // [2, 4, 6];
|
|
2234
2287
|
*/
|
|
2235
|
-
|
|
2236
|
-
|
|
2288
|
+
map<MK>(
|
|
2289
|
+
callbackfn: TreeSetElementCallback<K, MK, TreeSet<K>>,
|
|
2290
|
+
options: Omit<TreeSetOptions<MK>, 'toElementFn'> & { comparator?: (a: MK, b: MK) => number } = {},
|
|
2291
|
+
thisArg?: unknown
|
|
2292
|
+
): TreeSet<MK> {
|
|
2293
|
+
const out = new TreeSet<MK>([], options as TreeSetOptions<MK>);
|
|
2237
2294
|
let index = 0;
|
|
2238
|
-
for (const v of this)
|
|
2239
|
-
|
|
2295
|
+
for (const v of this) {
|
|
2296
|
+
const mk = thisArg === undefined
|
|
2297
|
+
? callbackfn(v, index++, this)
|
|
2298
|
+
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => MK).call(thisArg, v, index++, this);
|
|
2299
|
+
out.add(mk);
|
|
2300
|
+
}
|
|
2301
|
+
return out;
|
|
2240
2302
|
}
|
|
2241
2303
|
|
|
2242
2304
|
/**
|
|
2243
|
-
*
|
|
2244
|
-
* @remarks Time O(n), Space O(
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2305
|
+
* Create a new TreeSet containing only values that satisfy the predicate.
|
|
2306
|
+
* @remarks Time O(n log n) expected, Space O(n)
|
|
2253
2307
|
|
|
2254
2308
|
|
|
2255
2309
|
|
|
@@ -2398,25 +2452,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2398
2452
|
|
|
2399
2453
|
|
|
2400
2454
|
|
|
2401
|
-
* @example
|
|
2402
|
-
* // Test all
|
|
2403
|
-
* const ts = new TreeSet<number>([2, 4, 6]);
|
|
2404
|
-
* console.log(ts.every(k => k > 0)); // true;
|
|
2405
|
-
*/
|
|
2406
|
-
every(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean {
|
|
2407
|
-
let index = 0;
|
|
2408
|
-
for (const v of this) {
|
|
2409
|
-
const ok = thisArg === undefined
|
|
2410
|
-
? callbackfn(v, index++, this)
|
|
2411
|
-
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
2412
|
-
if (!ok) return false;
|
|
2413
|
-
}
|
|
2414
|
-
return true;
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
/**
|
|
2418
|
-
* Test whether any value satisfies a predicate.
|
|
2419
|
-
* @remarks Time O(n), Space O(1)
|
|
2420
2455
|
|
|
2421
2456
|
|
|
2422
2457
|
|
|
@@ -2462,6 +2497,27 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2462
2497
|
|
|
2463
2498
|
|
|
2464
2499
|
|
|
2500
|
+
* @example
|
|
2501
|
+
* // Filter
|
|
2502
|
+
* const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
2503
|
+
* const evens = ts.filter(k => k % 2 === 0);
|
|
2504
|
+
* console.log([...evens]); // [2, 4];
|
|
2505
|
+
*/
|
|
2506
|
+
filter(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): TreeSet<K> {
|
|
2507
|
+
const out = new TreeSet<K>([], { comparator: this.#userComparator });
|
|
2508
|
+
let index = 0;
|
|
2509
|
+
for (const v of this) {
|
|
2510
|
+
const ok = thisArg === undefined
|
|
2511
|
+
? callbackfn(v, index++, this)
|
|
2512
|
+
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
2513
|
+
if (ok) out.add(v);
|
|
2514
|
+
}
|
|
2515
|
+
return out;
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
/**
|
|
2519
|
+
* Reduce values into a single accumulator.
|
|
2520
|
+
* @remarks Time O(n), Space O(1)
|
|
2465
2521
|
|
|
2466
2522
|
|
|
2467
2523
|
|
|
@@ -2573,25 +2629,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2573
2629
|
|
|
2574
2630
|
|
|
2575
2631
|
|
|
2576
|
-
* @example
|
|
2577
|
-
* // Test any
|
|
2578
|
-
* const ts = new TreeSet<number>([1, 3, 5]);
|
|
2579
|
-
* console.log(ts.some(k => k === 3)); // true;
|
|
2580
|
-
*/
|
|
2581
|
-
some(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean {
|
|
2582
|
-
let index = 0;
|
|
2583
|
-
for (const v of this) {
|
|
2584
|
-
const ok = thisArg === undefined
|
|
2585
|
-
? callbackfn(v, index++, this)
|
|
2586
|
-
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
2587
|
-
if (ok) return true;
|
|
2588
|
-
}
|
|
2589
|
-
return false;
|
|
2590
|
-
}
|
|
2591
|
-
|
|
2592
|
-
/**
|
|
2593
|
-
* Find the first value that satisfies a predicate.
|
|
2594
|
-
* @remarks Time O(n), Space O(1)
|
|
2595
2632
|
|
|
2596
2633
|
|
|
2597
2634
|
|
|
@@ -2674,6 +2711,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2674
2711
|
|
|
2675
2712
|
|
|
2676
2713
|
|
|
2714
|
+
* @example
|
|
2715
|
+
* // Aggregate
|
|
2716
|
+
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2717
|
+
* const sum = ts.reduce((acc, k) => acc + k, 0);
|
|
2718
|
+
* console.log(sum); // 6;
|
|
2719
|
+
*/
|
|
2720
|
+
reduce<A>(callbackfn: TreeSetReduceCallback<K, A, TreeSet<K>>, initialValue: A): A {
|
|
2721
|
+
let acc = initialValue;
|
|
2722
|
+
let index = 0;
|
|
2723
|
+
for (const v of this) acc = callbackfn(acc, v, index++, this);
|
|
2724
|
+
return acc;
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
/**
|
|
2728
|
+
* Test whether all values satisfy a predicate.
|
|
2729
|
+
* @remarks Time O(n), Space O(1)
|
|
2677
2730
|
|
|
2678
2731
|
|
|
2679
2732
|
|
|
@@ -2748,26 +2801,6 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2748
2801
|
|
|
2749
2802
|
|
|
2750
2803
|
|
|
2751
|
-
* @example
|
|
2752
|
-
* // Find entry
|
|
2753
|
-
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
2754
|
-
* const found = ts.find(k => k === 2);
|
|
2755
|
-
* console.log(found); // 2;
|
|
2756
|
-
*/
|
|
2757
|
-
find(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): K | undefined {
|
|
2758
|
-
let index = 0;
|
|
2759
|
-
for (const v of this) {
|
|
2760
|
-
const ok = thisArg === undefined
|
|
2761
|
-
? callbackfn(v, index++, this)
|
|
2762
|
-
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
2763
|
-
if (ok) return v;
|
|
2764
|
-
}
|
|
2765
|
-
return undefined;
|
|
2766
|
-
}
|
|
2767
|
-
|
|
2768
|
-
/**
|
|
2769
|
-
* Materialize the set into an array of keys.
|
|
2770
|
-
* @remarks Time O(n), Space O(n)
|
|
2771
2804
|
|
|
2772
2805
|
|
|
2773
2806
|
|
|
@@ -2885,6 +2918,25 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2885
2918
|
|
|
2886
2919
|
|
|
2887
2920
|
|
|
2921
|
+
* @example
|
|
2922
|
+
* // Test all
|
|
2923
|
+
* const ts = new TreeSet<number>([2, 4, 6]);
|
|
2924
|
+
* console.log(ts.every(k => k > 0)); // true;
|
|
2925
|
+
*/
|
|
2926
|
+
every(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean {
|
|
2927
|
+
let index = 0;
|
|
2928
|
+
for (const v of this) {
|
|
2929
|
+
const ok = thisArg === undefined
|
|
2930
|
+
? callbackfn(v, index++, this)
|
|
2931
|
+
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
2932
|
+
if (!ok) return false;
|
|
2933
|
+
}
|
|
2934
|
+
return true;
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
/**
|
|
2938
|
+
* Test whether any value satisfies a predicate.
|
|
2939
|
+
* @remarks Time O(n), Space O(1)
|
|
2888
2940
|
|
|
2889
2941
|
|
|
2890
2942
|
|
|
@@ -2926,18 +2978,626 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
2926
2978
|
|
|
2927
2979
|
|
|
2928
2980
|
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2981
|
+
|
|
2982
|
+
|
|
2983
|
+
|
|
2984
|
+
|
|
2985
|
+
|
|
2986
|
+
|
|
2987
|
+
|
|
2988
|
+
|
|
2989
|
+
|
|
2990
|
+
|
|
2991
|
+
|
|
2992
|
+
|
|
2993
|
+
|
|
2994
|
+
|
|
2995
|
+
|
|
2996
|
+
|
|
2997
|
+
|
|
2998
|
+
|
|
2999
|
+
|
|
3000
|
+
|
|
3001
|
+
|
|
3002
|
+
|
|
3003
|
+
|
|
3004
|
+
|
|
3005
|
+
|
|
3006
|
+
|
|
3007
|
+
|
|
3008
|
+
|
|
3009
|
+
|
|
3010
|
+
|
|
3011
|
+
|
|
3012
|
+
|
|
3013
|
+
|
|
3014
|
+
|
|
3015
|
+
|
|
3016
|
+
|
|
3017
|
+
|
|
3018
|
+
|
|
3019
|
+
|
|
3020
|
+
|
|
3021
|
+
|
|
3022
|
+
|
|
3023
|
+
|
|
3024
|
+
|
|
3025
|
+
|
|
3026
|
+
|
|
3027
|
+
|
|
3028
|
+
|
|
3029
|
+
|
|
3030
|
+
|
|
3031
|
+
|
|
3032
|
+
|
|
3033
|
+
|
|
3034
|
+
|
|
3035
|
+
|
|
3036
|
+
|
|
3037
|
+
|
|
3038
|
+
|
|
3039
|
+
|
|
3040
|
+
|
|
3041
|
+
|
|
3042
|
+
|
|
3043
|
+
|
|
3044
|
+
|
|
3045
|
+
|
|
3046
|
+
|
|
3047
|
+
|
|
3048
|
+
|
|
3049
|
+
|
|
3050
|
+
|
|
3051
|
+
|
|
3052
|
+
|
|
3053
|
+
|
|
3054
|
+
|
|
3055
|
+
|
|
3056
|
+
|
|
3057
|
+
|
|
3058
|
+
|
|
3059
|
+
|
|
3060
|
+
|
|
3061
|
+
|
|
3062
|
+
|
|
3063
|
+
|
|
3064
|
+
|
|
3065
|
+
|
|
3066
|
+
|
|
3067
|
+
|
|
3068
|
+
|
|
3069
|
+
|
|
3070
|
+
|
|
3071
|
+
|
|
3072
|
+
|
|
3073
|
+
|
|
3074
|
+
|
|
3075
|
+
|
|
3076
|
+
|
|
3077
|
+
|
|
3078
|
+
|
|
3079
|
+
|
|
3080
|
+
|
|
3081
|
+
|
|
3082
|
+
|
|
3083
|
+
|
|
3084
|
+
|
|
3085
|
+
|
|
3086
|
+
|
|
3087
|
+
|
|
3088
|
+
|
|
3089
|
+
|
|
3090
|
+
|
|
3091
|
+
|
|
3092
|
+
|
|
3093
|
+
|
|
3094
|
+
|
|
3095
|
+
|
|
3096
|
+
|
|
3097
|
+
|
|
3098
|
+
|
|
3099
|
+
|
|
3100
|
+
|
|
3101
|
+
|
|
3102
|
+
|
|
3103
|
+
|
|
3104
|
+
|
|
3105
|
+
|
|
3106
|
+
|
|
3107
|
+
|
|
3108
|
+
|
|
3109
|
+
|
|
3110
|
+
|
|
3111
|
+
|
|
3112
|
+
|
|
3113
|
+
|
|
3114
|
+
|
|
3115
|
+
|
|
3116
|
+
|
|
3117
|
+
|
|
3118
|
+
|
|
3119
|
+
|
|
3120
|
+
|
|
3121
|
+
|
|
3122
|
+
|
|
3123
|
+
|
|
3124
|
+
|
|
3125
|
+
|
|
3126
|
+
|
|
3127
|
+
|
|
3128
|
+
|
|
3129
|
+
|
|
3130
|
+
|
|
3131
|
+
* @example
|
|
3132
|
+
* // Test any
|
|
3133
|
+
* const ts = new TreeSet<number>([1, 3, 5]);
|
|
3134
|
+
* console.log(ts.some(k => k === 3)); // true;
|
|
3135
|
+
*/
|
|
3136
|
+
some(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): boolean {
|
|
3137
|
+
let index = 0;
|
|
3138
|
+
for (const v of this) {
|
|
3139
|
+
const ok = thisArg === undefined
|
|
3140
|
+
? callbackfn(v, index++, this)
|
|
3141
|
+
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
3142
|
+
if (ok) return true;
|
|
3143
|
+
}
|
|
3144
|
+
return false;
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3147
|
+
/**
|
|
3148
|
+
* Find the first value that satisfies a predicate.
|
|
3149
|
+
* @remarks Time O(n), Space O(1)
|
|
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
|
+
|
|
3185
|
+
|
|
3186
|
+
|
|
3187
|
+
|
|
3188
|
+
|
|
3189
|
+
|
|
3190
|
+
|
|
3191
|
+
|
|
3192
|
+
|
|
3193
|
+
|
|
3194
|
+
|
|
3195
|
+
|
|
3196
|
+
|
|
3197
|
+
|
|
3198
|
+
|
|
3199
|
+
|
|
3200
|
+
|
|
3201
|
+
|
|
3202
|
+
|
|
3203
|
+
|
|
3204
|
+
|
|
3205
|
+
|
|
3206
|
+
|
|
3207
|
+
|
|
3208
|
+
|
|
3209
|
+
|
|
3210
|
+
|
|
3211
|
+
|
|
3212
|
+
|
|
3213
|
+
|
|
3214
|
+
|
|
3215
|
+
|
|
3216
|
+
|
|
3217
|
+
|
|
3218
|
+
|
|
3219
|
+
|
|
3220
|
+
|
|
3221
|
+
|
|
3222
|
+
|
|
3223
|
+
|
|
3224
|
+
|
|
3225
|
+
|
|
3226
|
+
|
|
3227
|
+
|
|
3228
|
+
|
|
3229
|
+
|
|
3230
|
+
|
|
3231
|
+
|
|
3232
|
+
|
|
3233
|
+
|
|
3234
|
+
|
|
3235
|
+
|
|
3236
|
+
|
|
3237
|
+
|
|
3238
|
+
|
|
3239
|
+
|
|
3240
|
+
|
|
3241
|
+
|
|
3242
|
+
|
|
3243
|
+
|
|
3244
|
+
|
|
3245
|
+
|
|
3246
|
+
|
|
3247
|
+
|
|
3248
|
+
|
|
3249
|
+
|
|
3250
|
+
|
|
3251
|
+
|
|
3252
|
+
|
|
3253
|
+
|
|
3254
|
+
|
|
3255
|
+
|
|
3256
|
+
|
|
3257
|
+
|
|
3258
|
+
|
|
3259
|
+
|
|
3260
|
+
|
|
3261
|
+
|
|
3262
|
+
|
|
3263
|
+
|
|
3264
|
+
|
|
3265
|
+
|
|
3266
|
+
|
|
3267
|
+
|
|
3268
|
+
|
|
3269
|
+
|
|
3270
|
+
|
|
3271
|
+
|
|
3272
|
+
|
|
3273
|
+
|
|
3274
|
+
|
|
3275
|
+
|
|
3276
|
+
|
|
3277
|
+
|
|
3278
|
+
|
|
3279
|
+
|
|
3280
|
+
|
|
3281
|
+
|
|
3282
|
+
|
|
3283
|
+
|
|
3284
|
+
|
|
3285
|
+
|
|
3286
|
+
|
|
3287
|
+
|
|
3288
|
+
|
|
3289
|
+
|
|
3290
|
+
|
|
3291
|
+
|
|
3292
|
+
|
|
3293
|
+
|
|
3294
|
+
|
|
3295
|
+
|
|
3296
|
+
|
|
3297
|
+
|
|
3298
|
+
|
|
3299
|
+
|
|
3300
|
+
|
|
3301
|
+
|
|
3302
|
+
|
|
3303
|
+
|
|
3304
|
+
|
|
3305
|
+
|
|
3306
|
+
|
|
3307
|
+
|
|
3308
|
+
|
|
3309
|
+
|
|
3310
|
+
|
|
3311
|
+
|
|
3312
|
+
|
|
3313
|
+
|
|
3314
|
+
|
|
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
|
+
* @example
|
|
3342
|
+
* // Find entry
|
|
3343
|
+
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
3344
|
+
* const found = ts.find(k => k === 2);
|
|
3345
|
+
* console.log(found); // 2;
|
|
3346
|
+
*/
|
|
3347
|
+
find(callbackfn: TreeSetElementCallback<K, boolean, TreeSet<K>>, thisArg?: unknown): K | undefined {
|
|
3348
|
+
let index = 0;
|
|
3349
|
+
for (const v of this) {
|
|
3350
|
+
const ok = thisArg === undefined
|
|
3351
|
+
? callbackfn(v, index++, this)
|
|
3352
|
+
: (callbackfn as (this: unknown, v: K, i: number, self: TreeSet<K>) => boolean).call(thisArg, v, index++, this);
|
|
3353
|
+
if (ok) return v;
|
|
3354
|
+
}
|
|
3355
|
+
return undefined;
|
|
3356
|
+
}
|
|
3357
|
+
|
|
3358
|
+
/**
|
|
3359
|
+
* Materialize the set into an array of keys.
|
|
3360
|
+
* @remarks Time O(n), Space O(n)
|
|
3361
|
+
|
|
3362
|
+
|
|
3363
|
+
|
|
3364
|
+
|
|
3365
|
+
|
|
3366
|
+
|
|
3367
|
+
|
|
3368
|
+
|
|
3369
|
+
|
|
3370
|
+
|
|
3371
|
+
|
|
3372
|
+
|
|
3373
|
+
|
|
3374
|
+
|
|
3375
|
+
|
|
3376
|
+
|
|
3377
|
+
|
|
3378
|
+
|
|
3379
|
+
|
|
3380
|
+
|
|
3381
|
+
|
|
3382
|
+
|
|
3383
|
+
|
|
3384
|
+
|
|
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
|
+
|
|
3425
|
+
|
|
3426
|
+
|
|
3427
|
+
|
|
3428
|
+
|
|
3429
|
+
|
|
3430
|
+
|
|
3431
|
+
|
|
3432
|
+
|
|
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
|
+
|
|
3473
|
+
|
|
3474
|
+
|
|
3475
|
+
|
|
3476
|
+
|
|
3477
|
+
|
|
3478
|
+
|
|
3479
|
+
|
|
3480
|
+
|
|
3481
|
+
|
|
3482
|
+
|
|
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
|
+
|
|
3523
|
+
|
|
3524
|
+
|
|
3525
|
+
|
|
3526
|
+
|
|
3527
|
+
|
|
3528
|
+
|
|
3529
|
+
|
|
3530
|
+
|
|
3531
|
+
|
|
3532
|
+
|
|
3533
|
+
|
|
3534
|
+
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
|
|
3538
|
+
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
|
|
3545
|
+
|
|
3546
|
+
|
|
3547
|
+
|
|
3548
|
+
|
|
3549
|
+
|
|
3550
|
+
|
|
3551
|
+
|
|
3552
|
+
|
|
3553
|
+
|
|
3554
|
+
* @example
|
|
3555
|
+
* // Convert to array
|
|
3556
|
+
* const ts = new TreeSet<number>([3, 1, 2]);
|
|
3557
|
+
* console.log(ts.toArray()); // [1, 2, 3];
|
|
3558
|
+
*/
|
|
3559
|
+
toArray(): K[] {
|
|
3560
|
+
return [...this];
|
|
3561
|
+
}
|
|
3562
|
+
|
|
3563
|
+
/**
|
|
3564
|
+
* Print a human-friendly representation.
|
|
3565
|
+
* @remarks Time O(n), Space O(n)
|
|
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
|
+
|
|
2941
3601
|
|
|
2942
3602
|
|
|
2943
3603
|
|
|
@@ -3137,6 +3797,13 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3137
3797
|
|
|
3138
3798
|
|
|
3139
3799
|
|
|
3800
|
+
|
|
3801
|
+
|
|
3802
|
+
|
|
3803
|
+
|
|
3804
|
+
|
|
3805
|
+
|
|
3806
|
+
|
|
3140
3807
|
|
|
3141
3808
|
|
|
3142
3809
|
|
|
@@ -3206,6 +3873,13 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3206
3873
|
|
|
3207
3874
|
|
|
3208
3875
|
|
|
3876
|
+
|
|
3877
|
+
|
|
3878
|
+
|
|
3879
|
+
|
|
3880
|
+
|
|
3881
|
+
|
|
3882
|
+
|
|
3209
3883
|
|
|
3210
3884
|
|
|
3211
3885
|
|
|
@@ -3253,6 +3927,13 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3253
3927
|
|
|
3254
3928
|
|
|
3255
3929
|
|
|
3930
|
+
|
|
3931
|
+
|
|
3932
|
+
|
|
3933
|
+
|
|
3934
|
+
|
|
3935
|
+
|
|
3936
|
+
|
|
3256
3937
|
|
|
3257
3938
|
|
|
3258
3939
|
|
|
@@ -3305,6 +3986,13 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3305
3986
|
|
|
3306
3987
|
|
|
3307
3988
|
|
|
3989
|
+
|
|
3990
|
+
|
|
3991
|
+
|
|
3992
|
+
|
|
3993
|
+
|
|
3994
|
+
|
|
3995
|
+
|
|
3308
3996
|
|
|
3309
3997
|
|
|
3310
3998
|
|
|
@@ -3442,6 +4130,34 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3442
4130
|
|
|
3443
4131
|
|
|
3444
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
|
+
|
|
3445
4161
|
|
|
3446
4162
|
|
|
3447
4163
|
|
|
@@ -3600,6 +4316,34 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3600
4316
|
|
|
3601
4317
|
|
|
3602
4318
|
|
|
4319
|
+
|
|
4320
|
+
|
|
4321
|
+
|
|
4322
|
+
|
|
4323
|
+
|
|
4324
|
+
|
|
4325
|
+
|
|
4326
|
+
|
|
4327
|
+
|
|
4328
|
+
|
|
4329
|
+
|
|
4330
|
+
|
|
4331
|
+
|
|
4332
|
+
|
|
4333
|
+
|
|
4334
|
+
|
|
4335
|
+
|
|
4336
|
+
|
|
4337
|
+
|
|
4338
|
+
|
|
4339
|
+
|
|
4340
|
+
|
|
4341
|
+
|
|
4342
|
+
|
|
4343
|
+
|
|
4344
|
+
|
|
4345
|
+
|
|
4346
|
+
|
|
3603
4347
|
|
|
3604
4348
|
|
|
3605
4349
|
|
|
@@ -3750,6 +4494,34 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3750
4494
|
|
|
3751
4495
|
|
|
3752
4496
|
|
|
4497
|
+
|
|
4498
|
+
|
|
4499
|
+
|
|
4500
|
+
|
|
4501
|
+
|
|
4502
|
+
|
|
4503
|
+
|
|
4504
|
+
|
|
4505
|
+
|
|
4506
|
+
|
|
4507
|
+
|
|
4508
|
+
|
|
4509
|
+
|
|
4510
|
+
|
|
4511
|
+
|
|
4512
|
+
|
|
4513
|
+
|
|
4514
|
+
|
|
4515
|
+
|
|
4516
|
+
|
|
4517
|
+
|
|
4518
|
+
|
|
4519
|
+
|
|
4520
|
+
|
|
4521
|
+
|
|
4522
|
+
|
|
4523
|
+
|
|
4524
|
+
|
|
3753
4525
|
|
|
3754
4526
|
|
|
3755
4527
|
|
|
@@ -3898,6 +4670,34 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
3898
4670
|
|
|
3899
4671
|
|
|
3900
4672
|
|
|
4673
|
+
|
|
4674
|
+
|
|
4675
|
+
|
|
4676
|
+
|
|
4677
|
+
|
|
4678
|
+
|
|
4679
|
+
|
|
4680
|
+
|
|
4681
|
+
|
|
4682
|
+
|
|
4683
|
+
|
|
4684
|
+
|
|
4685
|
+
|
|
4686
|
+
|
|
4687
|
+
|
|
4688
|
+
|
|
4689
|
+
|
|
4690
|
+
|
|
4691
|
+
|
|
4692
|
+
|
|
4693
|
+
|
|
4694
|
+
|
|
4695
|
+
|
|
4696
|
+
|
|
4697
|
+
|
|
4698
|
+
|
|
4699
|
+
|
|
4700
|
+
|
|
3901
4701
|
|
|
3902
4702
|
|
|
3903
4703
|
|
|
@@ -4049,6 +4849,34 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
4049
4849
|
|
|
4050
4850
|
|
|
4051
4851
|
|
|
4852
|
+
|
|
4853
|
+
|
|
4854
|
+
|
|
4855
|
+
|
|
4856
|
+
|
|
4857
|
+
|
|
4858
|
+
|
|
4859
|
+
|
|
4860
|
+
|
|
4861
|
+
|
|
4862
|
+
|
|
4863
|
+
|
|
4864
|
+
|
|
4865
|
+
|
|
4866
|
+
|
|
4867
|
+
|
|
4868
|
+
|
|
4869
|
+
|
|
4870
|
+
|
|
4871
|
+
|
|
4872
|
+
|
|
4873
|
+
|
|
4874
|
+
|
|
4875
|
+
|
|
4876
|
+
|
|
4877
|
+
|
|
4878
|
+
|
|
4879
|
+
|
|
4052
4880
|
|
|
4053
4881
|
|
|
4054
4882
|
|
|
@@ -4150,8 +4978,22 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
4150
4978
|
* Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
4151
4979
|
* @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
4152
4980
|
|
|
4981
|
+
|
|
4982
|
+
|
|
4983
|
+
|
|
4984
|
+
|
|
4985
|
+
|
|
4986
|
+
|
|
4987
|
+
|
|
4988
|
+
|
|
4989
|
+
|
|
4990
|
+
|
|
4991
|
+
|
|
4992
|
+
|
|
4993
|
+
|
|
4994
|
+
|
|
4153
4995
|
* @example
|
|
4154
|
-
* // Pagination
|
|
4996
|
+
* // Pagination by position in tree order
|
|
4155
4997
|
* const tree = new TreeSet<number>(
|
|
4156
4998
|
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
4157
4999
|
* { enableOrderStatistic: true }
|
|
@@ -4331,6 +5173,173 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
4331
5173
|
|
|
4332
5174
|
|
|
4333
5175
|
|
|
5176
|
+
|
|
5177
|
+
|
|
5178
|
+
|
|
5179
|
+
|
|
5180
|
+
|
|
5181
|
+
|
|
5182
|
+
|
|
5183
|
+
|
|
5184
|
+
|
|
5185
|
+
|
|
5186
|
+
|
|
5187
|
+
|
|
5188
|
+
|
|
5189
|
+
|
|
5190
|
+
|
|
5191
|
+
|
|
5192
|
+
|
|
5193
|
+
|
|
5194
|
+
|
|
5195
|
+
|
|
5196
|
+
|
|
5197
|
+
|
|
5198
|
+
|
|
5199
|
+
|
|
5200
|
+
|
|
5201
|
+
* @example
|
|
5202
|
+
* // Deep clone
|
|
5203
|
+
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
5204
|
+
* const copy = ts.clone();
|
|
5205
|
+
* copy.delete(1);
|
|
5206
|
+
* console.log(ts.has(1)); // true;
|
|
5207
|
+
*/
|
|
5208
|
+
// ---- ES2025 Set-like operations ----
|
|
5209
|
+
|
|
5210
|
+
/**
|
|
5211
|
+
* Return a new TreeSet containing all elements from both sets.
|
|
5212
|
+
* @remarks When both sets share the same comparator, uses O(n+m) merge. Otherwise O(m log n).
|
|
5213
|
+
* @param other - Any iterable of keys.
|
|
5214
|
+
* @returns A new TreeSet.
|
|
5215
|
+
* @example
|
|
5216
|
+
* // Merge two sets
|
|
5217
|
+
* console.log([...a.union(b)]); // [1, 2, 3, 4, 5, 6, 7];
|
|
5218
|
+
*/
|
|
5219
|
+
union(other: Iterable<K>): TreeSet<K> {
|
|
5220
|
+
const result = this.clone();
|
|
5221
|
+
for (const key of other) result.add(key);
|
|
5222
|
+
return result;
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5225
|
+
/**
|
|
5226
|
+
* Return a new TreeSet containing only elements present in both sets.
|
|
5227
|
+
* @remarks Time O(n+m) with ordered merge when possible, otherwise O(n log m).
|
|
5228
|
+
* @param other - Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
5229
|
+
* @returns A new TreeSet.
|
|
5230
|
+
* @example
|
|
5231
|
+
* // Find common elements
|
|
5232
|
+
* console.log([...a.intersection(b)]); // [3, 4, 5];
|
|
5233
|
+
*/
|
|
5234
|
+
intersection(other: Iterable<K>): TreeSet<K> {
|
|
5235
|
+
const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
|
|
5236
|
+
const result = new TreeSet<K>([], { comparator: this.#isDefaultComparator ? undefined : this.#userComparator });
|
|
5237
|
+
for (const key of this) {
|
|
5238
|
+
if (otherSet.has(key)) result.add(key);
|
|
5239
|
+
}
|
|
5240
|
+
return result;
|
|
5241
|
+
}
|
|
5242
|
+
|
|
5243
|
+
/**
|
|
5244
|
+
* Return a new TreeSet containing elements in this set but not in the other.
|
|
5245
|
+
* @remarks Time O(n+m) with ordered merge when possible, otherwise O(n log m).
|
|
5246
|
+
* @param other - Any iterable of keys.
|
|
5247
|
+
* @returns A new TreeSet.
|
|
5248
|
+
* @example
|
|
5249
|
+
* // Find exclusive elements
|
|
5250
|
+
* console.log([...a.difference(b)]); // [1, 2];
|
|
5251
|
+
*/
|
|
5252
|
+
difference(other: Iterable<K>): TreeSet<K> {
|
|
5253
|
+
const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
|
|
5254
|
+
const result = new TreeSet<K>([], { comparator: this.#isDefaultComparator ? undefined : this.#userComparator });
|
|
5255
|
+
for (const key of this) {
|
|
5256
|
+
if (!otherSet.has(key)) result.add(key);
|
|
5257
|
+
}
|
|
5258
|
+
return result;
|
|
5259
|
+
}
|
|
5260
|
+
|
|
5261
|
+
/**
|
|
5262
|
+
* Return a new TreeSet containing elements in either set but not both.
|
|
5263
|
+
* @remarks Time O(n+m).
|
|
5264
|
+
* @param other - Any iterable of keys.
|
|
5265
|
+
* @returns A new TreeSet.
|
|
5266
|
+
* @example
|
|
5267
|
+
* // Find symmetric difference
|
|
5268
|
+
* console.log([...a.symmetricDifference(b)]); // [1, 2, 6, 7];
|
|
5269
|
+
*/
|
|
5270
|
+
symmetricDifference(other: Iterable<K>): TreeSet<K> {
|
|
5271
|
+
const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
|
|
5272
|
+
const result = new TreeSet<K>([], { comparator: this.#isDefaultComparator ? undefined : this.#userComparator });
|
|
5273
|
+
for (const key of this) {
|
|
5274
|
+
if (!otherSet.has(key)) result.add(key);
|
|
5275
|
+
}
|
|
5276
|
+
for (const key of otherSet) {
|
|
5277
|
+
if (!this.has(key)) result.add(key);
|
|
5278
|
+
}
|
|
5279
|
+
return result;
|
|
5280
|
+
}
|
|
5281
|
+
|
|
5282
|
+
/**
|
|
5283
|
+
* Check whether every element in this set is also in the other.
|
|
5284
|
+
* @remarks Time O(n).
|
|
5285
|
+
* @param other - Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
5286
|
+
* @returns `true` if this is a subset of other.
|
|
5287
|
+
* @example
|
|
5288
|
+
* // Check subset
|
|
5289
|
+
* console.log(new TreeSet([3, 4]).isSubsetOf(a)); // true;
|
|
5290
|
+
*/
|
|
5291
|
+
isSubsetOf(other: Iterable<K>): boolean {
|
|
5292
|
+
const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
|
|
5293
|
+
for (const key of this) {
|
|
5294
|
+
if (!otherSet.has(key)) return false;
|
|
5295
|
+
}
|
|
5296
|
+
return true;
|
|
5297
|
+
}
|
|
5298
|
+
|
|
5299
|
+
/**
|
|
5300
|
+
* Check whether every element in the other set is also in this set.
|
|
5301
|
+
* @remarks Time O(m).
|
|
5302
|
+
* @param other - Any iterable of keys.
|
|
5303
|
+
* @returns `true` if this is a superset of other.
|
|
5304
|
+
* @example
|
|
5305
|
+
* // Check superset
|
|
5306
|
+
* console.log(a.isSupersetOf(new TreeSet([2, 3]))); // true;
|
|
5307
|
+
*/
|
|
5308
|
+
isSupersetOf(other: Iterable<K>): boolean {
|
|
5309
|
+
for (const key of other) {
|
|
5310
|
+
if (!this.has(key)) return false;
|
|
5311
|
+
}
|
|
5312
|
+
return true;
|
|
5313
|
+
}
|
|
5314
|
+
|
|
5315
|
+
/**
|
|
5316
|
+
* Check whether this set and the other share no common elements.
|
|
5317
|
+
* @remarks Time O(min(n,m)), can short-circuit on first overlap.
|
|
5318
|
+
* @param other - Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
5319
|
+
* @returns `true` if sets are disjoint.
|
|
5320
|
+
* @example
|
|
5321
|
+
* // Check disjoint
|
|
5322
|
+
* console.log(a.isDisjointFrom(new TreeSet([8, 9]))); // true;
|
|
5323
|
+
*/
|
|
5324
|
+
isDisjointFrom(other: Iterable<K>): boolean {
|
|
5325
|
+
const otherSet = other instanceof TreeSet || other instanceof Set ? other : new Set(other);
|
|
5326
|
+
for (const key of this) {
|
|
5327
|
+
if (otherSet.has(key)) return false;
|
|
5328
|
+
}
|
|
5329
|
+
return true;
|
|
5330
|
+
}
|
|
5331
|
+
|
|
5332
|
+
/**
|
|
5333
|
+
* Deep copy
|
|
5334
|
+
|
|
5335
|
+
|
|
5336
|
+
|
|
5337
|
+
|
|
5338
|
+
|
|
5339
|
+
|
|
5340
|
+
|
|
5341
|
+
|
|
5342
|
+
|
|
4334
5343
|
* @example
|
|
4335
5344
|
* // Deep clone
|
|
4336
5345
|
* const ts = new TreeSet<number>([1, 2, 3]);
|