data-structure-typed 2.6.0 → 2.6.1
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/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +108 -108
- package/docs-site-docusaurus/docs/api/classes/BST.md +101 -101
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +66 -66
- package/docs-site-docusaurus/docs/api/classes/Deque.md +235 -51
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +21 -21
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +231 -67
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +14 -14
- package/docs-site-docusaurus/docs/api/classes/Heap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +83 -13
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +124 -20
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +140 -32
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +159 -51
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +20 -20
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +117 -34
- package/docs-site-docusaurus/docs/api/classes/Queue.md +142 -34
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +117 -117
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +158 -50
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +21 -21
- package/docs-site-docusaurus/docs/api/classes/Stack.md +108 -26
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +33 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +75 -39
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +301 -39
- package/docs-site-docusaurus/docs/api/classes/Trie.md +110 -28
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +20 -20
- package/package.json +45 -46
- package/src/common/error.ts +15 -32
- package/src/common/index.ts +0 -3
- package/src/data-structures/base/iterable-element-base.ts +0 -3
- package/src/data-structures/base/linear-base.ts +2 -36
- package/src/data-structures/binary-tree/avl-tree.ts +31 -529
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
- package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
- package/src/data-structures/binary-tree/bst.ts +158 -1082
- package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
- package/src/data-structures/binary-tree/segment-tree.ts +73 -351
- package/src/data-structures/binary-tree/tree-map.ts +462 -5124
- package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
- package/src/data-structures/binary-tree/tree-multi-set.ts +284 -3972
- package/src/data-structures/binary-tree/tree-set.ts +338 -4836
- package/src/data-structures/graph/abstract-graph.ts +98 -167
- package/src/data-structures/graph/directed-graph.ts +137 -562
- package/src/data-structures/graph/map-graph.ts +0 -3
- package/src/data-structures/graph/undirected-graph.ts +132 -511
- package/src/data-structures/hash/hash-map.ts +154 -582
- package/src/data-structures/heap/heap.ts +200 -795
- package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
- package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
- package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
- package/src/data-structures/matrix/matrix.ts +179 -518
- package/src/data-structures/matrix/navigator.ts +0 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
- package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
- package/src/data-structures/priority-queue/priority-queue.ts +1 -2
- package/src/data-structures/queue/deque.ts +214 -882
- package/src/data-structures/queue/queue.ts +102 -625
- package/src/data-structures/stack/stack.ts +76 -505
- package/src/data-structures/trie/trie.ts +98 -628
- package/src/types/common.ts +0 -10
- package/src/types/data-structures/binary-tree/bst.ts +0 -7
- package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
- package/src/types/data-structures/graph/abstract-graph.ts +0 -2
- package/src/types/data-structures/hash/hash-map.ts +0 -3
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/matrix/navigator.ts +0 -2
- package/src/types/utils/utils.ts +0 -7
- package/src/types/utils/validate-type.ts +0 -7
- package/src/utils/number.ts +0 -2
- package/src/utils/utils.ts +0 -5
|
@@ -108,7 +108,7 @@ Number of elements in the set.
|
|
|
108
108
|
add(key): this;
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
111
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:538](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L538)
|
|
112
112
|
|
|
113
113
|
Add a key to the set (no-op if already present).
|
|
114
114
|
|
|
@@ -151,7 +151,7 @@ Expected time O(log n)
|
|
|
151
151
|
addMany(keys): boolean[];
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
154
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:584](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L584)
|
|
155
155
|
|
|
156
156
|
Add multiple keys at once.
|
|
157
157
|
|
|
@@ -192,7 +192,7 @@ Expected time O(m log n), where m is the number of keys.
|
|
|
192
192
|
ceiling(key): K | undefined;
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
195
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4199](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4199)
|
|
196
196
|
|
|
197
197
|
Smallest key that is >= the given key.
|
|
198
198
|
|
|
@@ -236,7 +236,7 @@ Smallest key that is >= the given key.
|
|
|
236
236
|
clear(): void;
|
|
237
237
|
```
|
|
238
238
|
|
|
239
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
239
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1252](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L1252)
|
|
240
240
|
|
|
241
241
|
Remove all keys.
|
|
242
242
|
|
|
@@ -263,20 +263,16 @@ Remove all keys.
|
|
|
263
263
|
clone(): TreeSet<K>;
|
|
264
264
|
```
|
|
265
265
|
|
|
266
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
266
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5350](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5350)
|
|
267
267
|
|
|
268
|
-
|
|
268
|
+
Deep copy
|
|
269
|
+
|
|
270
|
+
*
|
|
269
271
|
|
|
270
272
|
#### Returns
|
|
271
273
|
|
|
272
274
|
`TreeSet`\<`K`\>
|
|
273
275
|
|
|
274
|
-
#### Remarks
|
|
275
|
-
|
|
276
|
-
Time O(n log n), Space O(n)
|
|
277
|
-
|
|
278
|
-
*
|
|
279
|
-
|
|
280
276
|
#### Example
|
|
281
277
|
|
|
282
278
|
```ts
|
|
@@ -295,7 +291,7 @@ Time O(n log n), Space O(n)
|
|
|
295
291
|
delete(key): boolean;
|
|
296
292
|
```
|
|
297
293
|
|
|
298
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
294
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1028](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L1028)
|
|
299
295
|
|
|
300
296
|
Delete a key.
|
|
301
297
|
|
|
@@ -336,7 +332,7 @@ Expected time O(log n)
|
|
|
336
332
|
deleteWhere(predicate): boolean;
|
|
337
333
|
```
|
|
338
334
|
|
|
339
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
335
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1039](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L1039)
|
|
340
336
|
|
|
341
337
|
Delete all keys matching a predicate.
|
|
342
338
|
|
|
@@ -360,13 +356,51 @@ Time O(N), Space O(N)
|
|
|
360
356
|
|
|
361
357
|
***
|
|
362
358
|
|
|
359
|
+
### difference()
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
difference(other): TreeSet<K>;
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5252](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5252)
|
|
366
|
+
|
|
367
|
+
Return a new TreeSet containing elements in this set but not in the other.
|
|
368
|
+
|
|
369
|
+
#### Parameters
|
|
370
|
+
|
|
371
|
+
##### other
|
|
372
|
+
|
|
373
|
+
`Iterable`\<`K`\>
|
|
374
|
+
|
|
375
|
+
Any iterable of keys.
|
|
376
|
+
|
|
377
|
+
#### Returns
|
|
378
|
+
|
|
379
|
+
`TreeSet`\<`K`\>
|
|
380
|
+
|
|
381
|
+
A new TreeSet.
|
|
382
|
+
*
|
|
383
|
+
|
|
384
|
+
#### Remarks
|
|
385
|
+
|
|
386
|
+
Time O(n+m) with ordered merge when possible, otherwise O(n log m).
|
|
387
|
+
|
|
388
|
+
#### Example
|
|
389
|
+
|
|
390
|
+
```ts
|
|
391
|
+
// Find exclusive elements
|
|
392
|
+
console.log([...a.difference(b)]); // [1, 2];
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
***
|
|
396
|
+
|
|
363
397
|
### entries()
|
|
364
398
|
|
|
365
399
|
```ts
|
|
366
400
|
entries(): IterableIterator<[K, K]>;
|
|
367
401
|
```
|
|
368
402
|
|
|
369
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
403
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1868](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L1868)
|
|
370
404
|
|
|
371
405
|
Iterate over `[value, value]` pairs (native Set convention).
|
|
372
406
|
|
|
@@ -394,7 +428,7 @@ Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during
|
|
|
394
428
|
every(callbackfn, thisArg?): boolean;
|
|
395
429
|
```
|
|
396
430
|
|
|
397
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
431
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2926](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L2926)
|
|
398
432
|
|
|
399
433
|
Test whether all values satisfy a predicate.
|
|
400
434
|
|
|
@@ -434,7 +468,7 @@ Time O(n), Space O(1)
|
|
|
434
468
|
filter(callbackfn, thisArg?): TreeSet<K>;
|
|
435
469
|
```
|
|
436
470
|
|
|
437
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
471
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2506](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L2506)
|
|
438
472
|
|
|
439
473
|
Create a new TreeSet containing only values that satisfy the predicate.
|
|
440
474
|
|
|
@@ -475,7 +509,7 @@ Time O(n log n) expected, Space O(n)
|
|
|
475
509
|
find(callbackfn, thisArg?): K | undefined;
|
|
476
510
|
```
|
|
477
511
|
|
|
478
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
512
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3347](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3347)
|
|
479
513
|
|
|
480
514
|
Find the first value that satisfies a predicate.
|
|
481
515
|
|
|
@@ -516,7 +550,7 @@ Time O(n), Space O(1)
|
|
|
516
550
|
first(): K | undefined;
|
|
517
551
|
```
|
|
518
552
|
|
|
519
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
553
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3843](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3843)
|
|
520
554
|
|
|
521
555
|
Smallest key in the set.
|
|
522
556
|
|
|
@@ -565,7 +599,7 @@ Smallest key in the set.
|
|
|
565
599
|
floor(key): K | undefined;
|
|
566
600
|
```
|
|
567
601
|
|
|
568
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
602
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4377](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4377)
|
|
569
603
|
|
|
570
604
|
Largest key that is <= the given key.
|
|
571
605
|
|
|
@@ -601,7 +635,7 @@ Largest key that is <= the given key.
|
|
|
601
635
|
forEach(cb, thisArg?): void;
|
|
602
636
|
```
|
|
603
637
|
|
|
604
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
638
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2080](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L2080)
|
|
605
639
|
|
|
606
640
|
Visit each value in ascending order.
|
|
607
641
|
|
|
@@ -641,7 +675,7 @@ Callback follows native Set convention: `(value, value2, set)`.
|
|
|
641
675
|
getByRank(k): K | undefined;
|
|
642
676
|
```
|
|
643
677
|
|
|
644
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
678
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4955](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4955)
|
|
645
679
|
|
|
646
680
|
Returns the element at the k-th position in tree order (0-indexed).
|
|
647
681
|
|
|
@@ -679,7 +713,7 @@ Time O(log n). Requires `enableOrderStatistic: true`.
|
|
|
679
713
|
getRank(key): number;
|
|
680
714
|
```
|
|
681
715
|
|
|
682
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
716
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4973](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4973)
|
|
683
717
|
|
|
684
718
|
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
685
719
|
|
|
@@ -720,7 +754,7 @@ Time O(log n). Requires `enableOrderStatistic: true`.
|
|
|
720
754
|
has(key): boolean;
|
|
721
755
|
```
|
|
722
756
|
|
|
723
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
757
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:807](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L807)
|
|
724
758
|
|
|
725
759
|
Test whether a key exists.
|
|
726
760
|
|
|
@@ -758,7 +792,7 @@ Expected time O(log n)
|
|
|
758
792
|
higher(key): K | undefined;
|
|
759
793
|
```
|
|
760
794
|
|
|
761
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
795
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4553](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4553)
|
|
762
796
|
|
|
763
797
|
Smallest key that is > the given key.
|
|
764
798
|
|
|
@@ -786,13 +820,89 @@ Smallest key that is > the given key.
|
|
|
786
820
|
|
|
787
821
|
***
|
|
788
822
|
|
|
823
|
+
### intersection()
|
|
824
|
+
|
|
825
|
+
```ts
|
|
826
|
+
intersection(other): TreeSet<K>;
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5234](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5234)
|
|
830
|
+
|
|
831
|
+
Return a new TreeSet containing only elements present in both sets.
|
|
832
|
+
|
|
833
|
+
#### Parameters
|
|
834
|
+
|
|
835
|
+
##### other
|
|
836
|
+
|
|
837
|
+
`Iterable`\<`K`\>
|
|
838
|
+
|
|
839
|
+
Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
840
|
+
|
|
841
|
+
#### Returns
|
|
842
|
+
|
|
843
|
+
`TreeSet`\<`K`\>
|
|
844
|
+
|
|
845
|
+
A new TreeSet.
|
|
846
|
+
*
|
|
847
|
+
|
|
848
|
+
#### Remarks
|
|
849
|
+
|
|
850
|
+
Time O(n+m) with ordered merge when possible, otherwise O(n log m).
|
|
851
|
+
|
|
852
|
+
#### Example
|
|
853
|
+
|
|
854
|
+
```ts
|
|
855
|
+
// Find common elements
|
|
856
|
+
console.log([...a.intersection(b)]); // [3, 4, 5];
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
***
|
|
860
|
+
|
|
861
|
+
### isDisjointFrom()
|
|
862
|
+
|
|
863
|
+
```ts
|
|
864
|
+
isDisjointFrom(other): boolean;
|
|
865
|
+
```
|
|
866
|
+
|
|
867
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5324](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5324)
|
|
868
|
+
|
|
869
|
+
Check whether this set and the other share no common elements.
|
|
870
|
+
|
|
871
|
+
#### Parameters
|
|
872
|
+
|
|
873
|
+
##### other
|
|
874
|
+
|
|
875
|
+
`Iterable`\<`K`\>
|
|
876
|
+
|
|
877
|
+
Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
878
|
+
|
|
879
|
+
#### Returns
|
|
880
|
+
|
|
881
|
+
`boolean`
|
|
882
|
+
|
|
883
|
+
`true` if sets are disjoint.
|
|
884
|
+
*
|
|
885
|
+
|
|
886
|
+
#### Remarks
|
|
887
|
+
|
|
888
|
+
Time O(min(n,m)), can short-circuit on first overlap.
|
|
889
|
+
|
|
890
|
+
#### Example
|
|
891
|
+
|
|
892
|
+
```ts
|
|
893
|
+
// Check disjoint
|
|
894
|
+
console.log(a.isDisjointFrom(new TreeSet([8, 9]))); // true;
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
***
|
|
898
|
+
|
|
789
899
|
### isEmpty()
|
|
790
900
|
|
|
791
901
|
```ts
|
|
792
902
|
isEmpty(): boolean;
|
|
793
903
|
```
|
|
794
904
|
|
|
795
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
905
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:304](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L304)
|
|
796
906
|
|
|
797
907
|
Whether the set is empty.
|
|
798
908
|
|
|
@@ -811,13 +921,89 @@ Whether the set is empty.
|
|
|
811
921
|
|
|
812
922
|
***
|
|
813
923
|
|
|
924
|
+
### isSubsetOf()
|
|
925
|
+
|
|
926
|
+
```ts
|
|
927
|
+
isSubsetOf(other): boolean;
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5291](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5291)
|
|
931
|
+
|
|
932
|
+
Check whether every element in this set is also in the other.
|
|
933
|
+
|
|
934
|
+
#### Parameters
|
|
935
|
+
|
|
936
|
+
##### other
|
|
937
|
+
|
|
938
|
+
`Iterable`\<`K`\>
|
|
939
|
+
|
|
940
|
+
Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
941
|
+
|
|
942
|
+
#### Returns
|
|
943
|
+
|
|
944
|
+
`boolean`
|
|
945
|
+
|
|
946
|
+
`true` if this is a subset of other.
|
|
947
|
+
*
|
|
948
|
+
|
|
949
|
+
#### Remarks
|
|
950
|
+
|
|
951
|
+
Time O(n).
|
|
952
|
+
|
|
953
|
+
#### Example
|
|
954
|
+
|
|
955
|
+
```ts
|
|
956
|
+
// Check subset
|
|
957
|
+
console.log(new TreeSet([3, 4]).isSubsetOf(a)); // true;
|
|
958
|
+
```
|
|
959
|
+
|
|
960
|
+
***
|
|
961
|
+
|
|
962
|
+
### isSupersetOf()
|
|
963
|
+
|
|
964
|
+
```ts
|
|
965
|
+
isSupersetOf(other): boolean;
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5308](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5308)
|
|
969
|
+
|
|
970
|
+
Check whether every element in the other set is also in this set.
|
|
971
|
+
|
|
972
|
+
#### Parameters
|
|
973
|
+
|
|
974
|
+
##### other
|
|
975
|
+
|
|
976
|
+
`Iterable`\<`K`\>
|
|
977
|
+
|
|
978
|
+
Any iterable of keys.
|
|
979
|
+
|
|
980
|
+
#### Returns
|
|
981
|
+
|
|
982
|
+
`boolean`
|
|
983
|
+
|
|
984
|
+
`true` if this is a superset of other.
|
|
985
|
+
*
|
|
986
|
+
|
|
987
|
+
#### Remarks
|
|
988
|
+
|
|
989
|
+
Time O(m).
|
|
990
|
+
|
|
991
|
+
#### Example
|
|
992
|
+
|
|
993
|
+
```ts
|
|
994
|
+
// Check superset
|
|
995
|
+
console.log(a.isSupersetOf(new TreeSet([2, 3]))); // true;
|
|
996
|
+
```
|
|
997
|
+
|
|
998
|
+
***
|
|
999
|
+
|
|
814
1000
|
### keys()
|
|
815
1001
|
|
|
816
1002
|
```ts
|
|
817
1003
|
keys(): IterableIterator<K>;
|
|
818
1004
|
```
|
|
819
1005
|
|
|
820
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1006
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1456](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L1456)
|
|
821
1007
|
|
|
822
1008
|
Iterate over keys in ascending order.
|
|
823
1009
|
|
|
@@ -843,7 +1029,7 @@ Iterate over keys in ascending order.
|
|
|
843
1029
|
last(): K | undefined;
|
|
844
1030
|
```
|
|
845
1031
|
|
|
846
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1032
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3897](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3897)
|
|
847
1033
|
|
|
848
1034
|
Largest key in the set.
|
|
849
1035
|
|
|
@@ -870,7 +1056,7 @@ Largest key in the set.
|
|
|
870
1056
|
lower(key): K | undefined;
|
|
871
1057
|
```
|
|
872
1058
|
|
|
873
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1059
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4729](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4729)
|
|
874
1060
|
|
|
875
1061
|
Largest key that is < the given key.
|
|
876
1062
|
|
|
@@ -907,7 +1093,7 @@ map<MK>(
|
|
|
907
1093
|
thisArg?): TreeSet<MK>;
|
|
908
1094
|
```
|
|
909
1095
|
|
|
910
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1096
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2288](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L2288)
|
|
911
1097
|
|
|
912
1098
|
Create a new TreeSet by mapping each value to a new key.
|
|
913
1099
|
|
|
@@ -960,7 +1146,7 @@ Time O(n log n) expected, Space O(n)
|
|
|
960
1146
|
pollFirst(): K | undefined;
|
|
961
1147
|
```
|
|
962
1148
|
|
|
963
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1149
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3953](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3953)
|
|
964
1150
|
|
|
965
1151
|
Remove and return the smallest key.
|
|
966
1152
|
|
|
@@ -989,7 +1175,7 @@ Remove and return the smallest key.
|
|
|
989
1175
|
pollLast(): K | undefined;
|
|
990
1176
|
```
|
|
991
1177
|
|
|
992
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1178
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4011](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4011)
|
|
993
1179
|
|
|
994
1180
|
Remove and return the largest key.
|
|
995
1181
|
|
|
@@ -1017,7 +1203,7 @@ Remove and return the largest key.
|
|
|
1017
1203
|
print(): void;
|
|
1018
1204
|
```
|
|
1019
1205
|
|
|
1020
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1206
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3764](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3764)
|
|
1021
1207
|
|
|
1022
1208
|
Print a human-friendly representation.
|
|
1023
1209
|
|
|
@@ -1047,7 +1233,7 @@ Time O(n), Space O(n)
|
|
|
1047
1233
|
rangeByRank(start, end): K[];
|
|
1048
1234
|
```
|
|
1049
1235
|
|
|
1050
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1236
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5010](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5010)
|
|
1051
1237
|
|
|
1052
1238
|
Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
1053
1239
|
|
|
@@ -1097,7 +1283,7 @@ Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
|
1097
1283
|
rangeSearch(range, options?): K[];
|
|
1098
1284
|
```
|
|
1099
1285
|
|
|
1100
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1286
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:4919](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L4919)
|
|
1101
1287
|
|
|
1102
1288
|
Return all keys in a given range.
|
|
1103
1289
|
|
|
@@ -1150,7 +1336,7 @@ Inclusive/exclusive bounds (defaults to inclusive).
|
|
|
1150
1336
|
reduce<A>(callbackfn, initialValue): A;
|
|
1151
1337
|
```
|
|
1152
1338
|
|
|
1153
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1339
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2720](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L2720)
|
|
1154
1340
|
|
|
1155
1341
|
Reduce values into a single accumulator.
|
|
1156
1342
|
|
|
@@ -1197,7 +1383,7 @@ Time O(n), Space O(1)
|
|
|
1197
1383
|
some(callbackfn, thisArg?): boolean;
|
|
1198
1384
|
```
|
|
1199
1385
|
|
|
1200
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1386
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3136](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3136)
|
|
1201
1387
|
|
|
1202
1388
|
Test whether any value satisfies a predicate.
|
|
1203
1389
|
|
|
@@ -1231,13 +1417,51 @@ Time O(n), Space O(1)
|
|
|
1231
1417
|
|
|
1232
1418
|
***
|
|
1233
1419
|
|
|
1420
|
+
### symmetricDifference()
|
|
1421
|
+
|
|
1422
|
+
```ts
|
|
1423
|
+
symmetricDifference(other): TreeSet<K>;
|
|
1424
|
+
```
|
|
1425
|
+
|
|
1426
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5270](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5270)
|
|
1427
|
+
|
|
1428
|
+
Return a new TreeSet containing elements in either set but not both.
|
|
1429
|
+
|
|
1430
|
+
#### Parameters
|
|
1431
|
+
|
|
1432
|
+
##### other
|
|
1433
|
+
|
|
1434
|
+
`Iterable`\<`K`\>
|
|
1435
|
+
|
|
1436
|
+
Any iterable of keys.
|
|
1437
|
+
|
|
1438
|
+
#### Returns
|
|
1439
|
+
|
|
1440
|
+
`TreeSet`\<`K`\>
|
|
1441
|
+
|
|
1442
|
+
A new TreeSet.
|
|
1443
|
+
*
|
|
1444
|
+
|
|
1445
|
+
#### Remarks
|
|
1446
|
+
|
|
1447
|
+
Time O(n+m).
|
|
1448
|
+
|
|
1449
|
+
#### Example
|
|
1450
|
+
|
|
1451
|
+
```ts
|
|
1452
|
+
// Find symmetric difference
|
|
1453
|
+
console.log([...a.symmetricDifference(b)]); // [1, 2, 6, 7];
|
|
1454
|
+
```
|
|
1455
|
+
|
|
1456
|
+
***
|
|
1457
|
+
|
|
1234
1458
|
### toArray()
|
|
1235
1459
|
|
|
1236
1460
|
```ts
|
|
1237
1461
|
toArray(): K[];
|
|
1238
1462
|
```
|
|
1239
1463
|
|
|
1240
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1464
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3559](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L3559)
|
|
1241
1465
|
|
|
1242
1466
|
Materialize the set into an array of keys.
|
|
1243
1467
|
|
|
@@ -1261,13 +1485,51 @@ Time O(n), Space O(n)
|
|
|
1261
1485
|
|
|
1262
1486
|
***
|
|
1263
1487
|
|
|
1488
|
+
### union()
|
|
1489
|
+
|
|
1490
|
+
```ts
|
|
1491
|
+
union(other): TreeSet<K>;
|
|
1492
|
+
```
|
|
1493
|
+
|
|
1494
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:5219](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L5219)
|
|
1495
|
+
|
|
1496
|
+
Return a new TreeSet containing all elements from both sets.
|
|
1497
|
+
|
|
1498
|
+
#### Parameters
|
|
1499
|
+
|
|
1500
|
+
##### other
|
|
1501
|
+
|
|
1502
|
+
`Iterable`\<`K`\>
|
|
1503
|
+
|
|
1504
|
+
Any iterable of keys.
|
|
1505
|
+
|
|
1506
|
+
#### Returns
|
|
1507
|
+
|
|
1508
|
+
`TreeSet`\<`K`\>
|
|
1509
|
+
|
|
1510
|
+
A new TreeSet.
|
|
1511
|
+
*
|
|
1512
|
+
|
|
1513
|
+
#### Remarks
|
|
1514
|
+
|
|
1515
|
+
When both sets share the same comparator, uses O(n+m) merge. Otherwise O(m log n).
|
|
1516
|
+
|
|
1517
|
+
#### Example
|
|
1518
|
+
|
|
1519
|
+
```ts
|
|
1520
|
+
// Merge two sets
|
|
1521
|
+
console.log([...a.union(b)]); // [1, 2, 3, 4, 5, 6, 7];
|
|
1522
|
+
```
|
|
1523
|
+
|
|
1524
|
+
***
|
|
1525
|
+
|
|
1264
1526
|
### values()
|
|
1265
1527
|
|
|
1266
1528
|
```ts
|
|
1267
1529
|
values(): IterableIterator<K>;
|
|
1268
1530
|
```
|
|
1269
1531
|
|
|
1270
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1532
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1662](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L1662)
|
|
1271
1533
|
|
|
1272
1534
|
Iterate over values in ascending order.
|
|
1273
1535
|
|