data-structure-typed 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +7 -2
- package/.github/workflows/release-package.yml +9 -2
- package/CHANGELOG.md +9 -1
- package/dist/cjs/binary-tree.cjs +2927 -23688
- package/dist/cjs/graph.cjs +845 -2634
- package/dist/cjs/hash.cjs +185 -616
- package/dist/cjs/heap.cjs +266 -818
- package/dist/cjs/index.cjs +5116 -31358
- package/dist/cjs/linked-list.cjs +644 -2615
- package/dist/cjs/matrix.cjs +220 -535
- package/dist/cjs/priority-queue.cjs +266 -818
- package/dist/cjs/queue.cjs +637 -2343
- package/dist/cjs/stack.cjs +124 -530
- package/dist/cjs/trie.cjs +145 -592
- package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
- package/dist/cjs-legacy/graph.cjs +847 -2636
- package/dist/cjs-legacy/hash.cjs +181 -612
- package/dist/cjs-legacy/heap.cjs +266 -818
- package/dist/cjs-legacy/index.cjs +6657 -32899
- package/dist/cjs-legacy/linked-list.cjs +640 -2611
- package/dist/cjs-legacy/matrix.cjs +220 -535
- package/dist/cjs-legacy/priority-queue.cjs +266 -818
- package/dist/cjs-legacy/queue.cjs +634 -2340
- package/dist/cjs-legacy/stack.cjs +124 -530
- package/dist/cjs-legacy/trie.cjs +145 -592
- package/dist/esm/binary-tree.mjs +2927 -23688
- package/dist/esm/graph.mjs +845 -2634
- package/dist/esm/hash.mjs +185 -616
- package/dist/esm/heap.mjs +266 -818
- package/dist/esm/index.mjs +5116 -31358
- package/dist/esm/linked-list.mjs +644 -2615
- package/dist/esm/matrix.mjs +220 -535
- package/dist/esm/priority-queue.mjs +266 -818
- package/dist/esm/queue.mjs +637 -2343
- package/dist/esm/stack.mjs +124 -530
- package/dist/esm/trie.mjs +145 -592
- package/dist/esm-legacy/binary-tree.mjs +4352 -25113
- package/dist/esm-legacy/graph.mjs +847 -2636
- package/dist/esm-legacy/hash.mjs +181 -612
- package/dist/esm-legacy/heap.mjs +266 -818
- package/dist/esm-legacy/index.mjs +6657 -32899
- package/dist/esm-legacy/linked-list.mjs +640 -2611
- package/dist/esm-legacy/matrix.mjs +220 -535
- package/dist/esm-legacy/priority-queue.mjs +266 -818
- package/dist/esm-legacy/queue.mjs +634 -2340
- package/dist/esm-legacy/stack.mjs +124 -530
- package/dist/esm-legacy/trie.mjs +145 -592
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
- package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
- package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
- package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
- package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
- package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
- package/dist/types/data-structures/heap/heap.d.ts +194 -746
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
- package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/types/data-structures/queue/deque.d.ts +196 -804
- package/dist/types/data-structures/queue/queue.d.ts +99 -585
- package/dist/types/data-structures/stack/stack.d.ts +75 -481
- package/dist/types/data-structures/trie/trie.d.ts +98 -584
- package/dist/umd/data-structure-typed.js +6580 -32822
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
- 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 +52 -48
- package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
- package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
- package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
- package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
- 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 +299 -3983
- 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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# Class: TreeSet\<K, R\>
|
|
8
8
|
|
|
9
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
9
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:30](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L30)
|
|
10
10
|
|
|
11
11
|
An ordered Set backed by a red-black tree.
|
|
12
12
|
|
|
@@ -44,7 +44,7 @@ An ordered Set backed by a red-black tree.
|
|
|
44
44
|
new TreeSet<K, R>(elements?, options?): TreeSet<K, R>;
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
47
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:50](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L50)
|
|
48
48
|
|
|
49
49
|
Create a TreeSet from an iterable of keys or raw elements.
|
|
50
50
|
|
|
@@ -92,7 +92,7 @@ const set = new TreeSet<number, User>(users, { toElementFn: u => u.id });
|
|
|
92
92
|
get size(): number;
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
95
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:70](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L70)
|
|
96
96
|
|
|
97
97
|
Number of elements in the set.
|
|
98
98
|
|
|
@@ -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:133](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L133)
|
|
112
112
|
|
|
113
113
|
Add a key to the set (no-op if already present).
|
|
114
114
|
|
|
@@ -126,8 +126,6 @@ Add a key to the set (no-op if already present).
|
|
|
126
126
|
|
|
127
127
|
Expected time O(log n)
|
|
128
128
|
|
|
129
|
-
*
|
|
130
|
-
|
|
131
129
|
#### Example
|
|
132
130
|
|
|
133
131
|
```ts
|
|
@@ -151,7 +149,7 @@ Expected time O(log n)
|
|
|
151
149
|
addMany(keys): boolean[];
|
|
152
150
|
```
|
|
153
151
|
|
|
154
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
152
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:151](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L151)
|
|
155
153
|
|
|
156
154
|
Add multiple keys at once.
|
|
157
155
|
|
|
@@ -169,8 +167,6 @@ Iterable of keys to add.
|
|
|
169
167
|
|
|
170
168
|
Array of booleans indicating whether each key was newly added.
|
|
171
169
|
|
|
172
|
-
*
|
|
173
|
-
|
|
174
170
|
#### Remarks
|
|
175
171
|
|
|
176
172
|
Expected time O(m log n), where m is the number of keys.
|
|
@@ -192,12 +188,10 @@ Expected time O(m log n), where m is the number of keys.
|
|
|
192
188
|
ceiling(key): K | undefined;
|
|
193
189
|
```
|
|
194
190
|
|
|
195
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
191
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:550](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L550)
|
|
196
192
|
|
|
197
193
|
Smallest key that is >= the given key.
|
|
198
194
|
|
|
199
|
-
*
|
|
200
|
-
|
|
201
195
|
#### Parameters
|
|
202
196
|
|
|
203
197
|
##### key
|
|
@@ -236,12 +230,10 @@ Smallest key that is >= the given key.
|
|
|
236
230
|
clear(): void;
|
|
237
231
|
```
|
|
238
232
|
|
|
239
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
233
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:218](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L218)
|
|
240
234
|
|
|
241
235
|
Remove all keys.
|
|
242
236
|
|
|
243
|
-
*
|
|
244
|
-
|
|
245
237
|
#### Returns
|
|
246
238
|
|
|
247
239
|
`void`
|
|
@@ -263,20 +255,14 @@ Remove all keys.
|
|
|
263
255
|
clone(): TreeSet<K>;
|
|
264
256
|
```
|
|
265
257
|
|
|
266
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
258
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:837](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L837)
|
|
267
259
|
|
|
268
|
-
|
|
260
|
+
Deep copy
|
|
269
261
|
|
|
270
262
|
#### Returns
|
|
271
263
|
|
|
272
264
|
`TreeSet`\<`K`\>
|
|
273
265
|
|
|
274
|
-
#### Remarks
|
|
275
|
-
|
|
276
|
-
Time O(n log n), Space O(n)
|
|
277
|
-
|
|
278
|
-
*
|
|
279
|
-
|
|
280
266
|
#### Example
|
|
281
267
|
|
|
282
268
|
```ts
|
|
@@ -295,7 +281,7 @@ Time O(n log n), Space O(n)
|
|
|
295
281
|
delete(key): boolean;
|
|
296
282
|
```
|
|
297
283
|
|
|
298
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
284
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:187](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L187)
|
|
299
285
|
|
|
300
286
|
Delete a key.
|
|
301
287
|
|
|
@@ -315,8 +301,6 @@ Delete a key.
|
|
|
315
301
|
|
|
316
302
|
Expected time O(log n)
|
|
317
303
|
|
|
318
|
-
*
|
|
319
|
-
|
|
320
304
|
#### Example
|
|
321
305
|
|
|
322
306
|
```ts
|
|
@@ -336,7 +320,7 @@ Expected time O(log n)
|
|
|
336
320
|
deleteWhere(predicate): boolean;
|
|
337
321
|
```
|
|
338
322
|
|
|
339
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
323
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:198](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L198)
|
|
340
324
|
|
|
341
325
|
Delete all keys matching a predicate.
|
|
342
326
|
|
|
@@ -360,20 +344,55 @@ Time O(N), Space O(N)
|
|
|
360
344
|
|
|
361
345
|
***
|
|
362
346
|
|
|
347
|
+
### difference()
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
difference(other): TreeSet<K>;
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:748](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L748)
|
|
354
|
+
|
|
355
|
+
Return a new TreeSet containing elements in this set but not in the other.
|
|
356
|
+
|
|
357
|
+
#### Parameters
|
|
358
|
+
|
|
359
|
+
##### other
|
|
360
|
+
|
|
361
|
+
`Iterable`\<`K`\>
|
|
362
|
+
|
|
363
|
+
Any iterable of keys.
|
|
364
|
+
|
|
365
|
+
#### Returns
|
|
366
|
+
|
|
367
|
+
`TreeSet`\<`K`\>
|
|
368
|
+
|
|
369
|
+
A new TreeSet.
|
|
370
|
+
|
|
371
|
+
#### Remarks
|
|
372
|
+
|
|
373
|
+
Time O(n+m) with ordered merge when possible, otherwise O(n log m).
|
|
374
|
+
|
|
375
|
+
#### Example
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
// Find exclusive elements
|
|
379
|
+
console.log([...a.difference(b)]); // [1, 2];
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
***
|
|
383
|
+
|
|
363
384
|
### entries()
|
|
364
385
|
|
|
365
386
|
```ts
|
|
366
387
|
entries(): IterableIterator<[K, K]>;
|
|
367
388
|
```
|
|
368
389
|
|
|
369
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
390
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:255](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L255)
|
|
370
391
|
|
|
371
392
|
Iterate over `[value, value]` pairs (native Set convention).
|
|
372
393
|
|
|
373
394
|
Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
374
395
|
|
|
375
|
-
*
|
|
376
|
-
|
|
377
396
|
#### Returns
|
|
378
397
|
|
|
379
398
|
`IterableIterator`\<\[`K`, `K`\]\>
|
|
@@ -394,7 +413,7 @@ Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during
|
|
|
394
413
|
every(callbackfn, thisArg?): boolean;
|
|
395
414
|
```
|
|
396
415
|
|
|
397
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
416
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:357](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L357)
|
|
398
417
|
|
|
399
418
|
Test whether all values satisfy a predicate.
|
|
400
419
|
|
|
@@ -416,8 +435,6 @@ Test whether all values satisfy a predicate.
|
|
|
416
435
|
|
|
417
436
|
Time O(n), Space O(1)
|
|
418
437
|
|
|
419
|
-
*
|
|
420
|
-
|
|
421
438
|
#### Example
|
|
422
439
|
|
|
423
440
|
```ts
|
|
@@ -434,7 +451,7 @@ Time O(n), Space O(1)
|
|
|
434
451
|
filter(callbackfn, thisArg?): TreeSet<K>;
|
|
435
452
|
```
|
|
436
453
|
|
|
437
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
454
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:315](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L315)
|
|
438
455
|
|
|
439
456
|
Create a new TreeSet containing only values that satisfy the predicate.
|
|
440
457
|
|
|
@@ -456,8 +473,6 @@ Create a new TreeSet containing only values that satisfy the predicate.
|
|
|
456
473
|
|
|
457
474
|
Time O(n log n) expected, Space O(n)
|
|
458
475
|
|
|
459
|
-
*
|
|
460
|
-
|
|
461
476
|
#### Example
|
|
462
477
|
|
|
463
478
|
```ts
|
|
@@ -475,7 +490,7 @@ Time O(n log n) expected, Space O(n)
|
|
|
475
490
|
find(callbackfn, thisArg?): K | undefined;
|
|
476
491
|
```
|
|
477
492
|
|
|
478
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
493
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:408](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L408)
|
|
479
494
|
|
|
480
495
|
Find the first value that satisfies a predicate.
|
|
481
496
|
|
|
@@ -497,8 +512,6 @@ Find the first value that satisfies a predicate.
|
|
|
497
512
|
|
|
498
513
|
Time O(n), Space O(1)
|
|
499
514
|
|
|
500
|
-
*
|
|
501
|
-
|
|
502
515
|
#### Example
|
|
503
516
|
|
|
504
517
|
```ts
|
|
@@ -516,12 +529,10 @@ Time O(n), Space O(1)
|
|
|
516
529
|
first(): K | undefined;
|
|
517
530
|
```
|
|
518
531
|
|
|
519
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
532
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:480](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L480)
|
|
520
533
|
|
|
521
534
|
Smallest key in the set.
|
|
522
535
|
|
|
523
|
-
*
|
|
524
|
-
|
|
525
536
|
#### Returns
|
|
526
537
|
|
|
527
538
|
`K` \| `undefined`
|
|
@@ -565,12 +576,10 @@ Smallest key in the set.
|
|
|
565
576
|
floor(key): K | undefined;
|
|
566
577
|
```
|
|
567
578
|
|
|
568
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
579
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:566](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L566)
|
|
569
580
|
|
|
570
581
|
Largest key that is <= the given key.
|
|
571
582
|
|
|
572
|
-
*
|
|
573
|
-
|
|
574
583
|
#### Parameters
|
|
575
584
|
|
|
576
585
|
##### key
|
|
@@ -601,14 +610,12 @@ Largest key that is <= the given key.
|
|
|
601
610
|
forEach(cb, thisArg?): void;
|
|
602
611
|
```
|
|
603
612
|
|
|
604
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
613
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:274](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L274)
|
|
605
614
|
|
|
606
615
|
Visit each value in ascending order.
|
|
607
616
|
|
|
608
617
|
Callback follows native Set convention: `(value, value2, set)`.
|
|
609
618
|
|
|
610
|
-
*
|
|
611
|
-
|
|
612
619
|
#### Parameters
|
|
613
620
|
|
|
614
621
|
##### cb
|
|
@@ -641,7 +648,7 @@ Callback follows native Set convention: `(value, value2, set)`.
|
|
|
641
648
|
getByRank(k): K | undefined;
|
|
642
649
|
```
|
|
643
650
|
|
|
644
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
651
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:650](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L650)
|
|
645
652
|
|
|
646
653
|
Returns the element at the k-th position in tree order (0-indexed).
|
|
647
654
|
|
|
@@ -659,8 +666,6 @@ Returns the element at the k-th position in tree order (0-indexed).
|
|
|
659
666
|
|
|
660
667
|
Time O(log n). Requires `enableOrderStatistic: true`.
|
|
661
668
|
|
|
662
|
-
*
|
|
663
|
-
|
|
664
669
|
#### Example
|
|
665
670
|
|
|
666
671
|
```ts
|
|
@@ -679,7 +684,7 @@ Time O(log n). Requires `enableOrderStatistic: true`.
|
|
|
679
684
|
getRank(key): number;
|
|
680
685
|
```
|
|
681
686
|
|
|
682
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
687
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:670](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L670)
|
|
683
688
|
|
|
684
689
|
Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
685
690
|
|
|
@@ -696,7 +701,6 @@ Returns the 0-based rank of a key (number of elements that precede it in tree or
|
|
|
696
701
|
#### Remarks
|
|
697
702
|
|
|
698
703
|
Time O(log n). Requires `enableOrderStatistic: true`.
|
|
699
|
-
*
|
|
700
704
|
|
|
701
705
|
#### Example
|
|
702
706
|
|
|
@@ -720,7 +724,7 @@ Time O(log n). Requires `enableOrderStatistic: true`.
|
|
|
720
724
|
has(key): boolean;
|
|
721
725
|
```
|
|
722
726
|
|
|
723
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
727
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:170](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L170)
|
|
724
728
|
|
|
725
729
|
Test whether a key exists.
|
|
726
730
|
|
|
@@ -738,8 +742,6 @@ Test whether a key exists.
|
|
|
738
742
|
|
|
739
743
|
Expected time O(log n)
|
|
740
744
|
|
|
741
|
-
*
|
|
742
|
-
|
|
743
745
|
#### Example
|
|
744
746
|
|
|
745
747
|
```ts
|
|
@@ -758,12 +760,10 @@ Expected time O(log n)
|
|
|
758
760
|
higher(key): K | undefined;
|
|
759
761
|
```
|
|
760
762
|
|
|
761
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
763
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:580](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L580)
|
|
762
764
|
|
|
763
765
|
Smallest key that is > the given key.
|
|
764
766
|
|
|
765
|
-
*
|
|
766
|
-
|
|
767
767
|
#### Parameters
|
|
768
768
|
|
|
769
769
|
##### key
|
|
@@ -786,18 +786,90 @@ Smallest key that is > the given key.
|
|
|
786
786
|
|
|
787
787
|
***
|
|
788
788
|
|
|
789
|
+
### intersection()
|
|
790
|
+
|
|
791
|
+
```ts
|
|
792
|
+
intersection(other): TreeSet<K>;
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:730](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L730)
|
|
796
|
+
|
|
797
|
+
Return a new TreeSet containing only elements present in both sets.
|
|
798
|
+
|
|
799
|
+
#### Parameters
|
|
800
|
+
|
|
801
|
+
##### other
|
|
802
|
+
|
|
803
|
+
`Iterable`\<`K`\>
|
|
804
|
+
|
|
805
|
+
Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
806
|
+
|
|
807
|
+
#### Returns
|
|
808
|
+
|
|
809
|
+
`TreeSet`\<`K`\>
|
|
810
|
+
|
|
811
|
+
A new TreeSet.
|
|
812
|
+
|
|
813
|
+
#### Remarks
|
|
814
|
+
|
|
815
|
+
Time O(n+m) with ordered merge when possible, otherwise O(n log m).
|
|
816
|
+
|
|
817
|
+
#### Example
|
|
818
|
+
|
|
819
|
+
```ts
|
|
820
|
+
// Find common elements
|
|
821
|
+
console.log([...a.intersection(b)]); // [3, 4, 5];
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
***
|
|
825
|
+
|
|
826
|
+
### isDisjointFrom()
|
|
827
|
+
|
|
828
|
+
```ts
|
|
829
|
+
isDisjointFrom(other): boolean;
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:820](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L820)
|
|
833
|
+
|
|
834
|
+
Check whether this set and the other share no common elements.
|
|
835
|
+
|
|
836
|
+
#### Parameters
|
|
837
|
+
|
|
838
|
+
##### other
|
|
839
|
+
|
|
840
|
+
`Iterable`\<`K`\>
|
|
841
|
+
|
|
842
|
+
Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
843
|
+
|
|
844
|
+
#### Returns
|
|
845
|
+
|
|
846
|
+
`boolean`
|
|
847
|
+
|
|
848
|
+
`true` if sets are disjoint.
|
|
849
|
+
|
|
850
|
+
#### Remarks
|
|
851
|
+
|
|
852
|
+
Time O(min(n,m)), can short-circuit on first overlap.
|
|
853
|
+
|
|
854
|
+
#### Example
|
|
855
|
+
|
|
856
|
+
```ts
|
|
857
|
+
// Check disjoint
|
|
858
|
+
console.log(a.isDisjointFrom(new TreeSet([8, 9]))); // true;
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
***
|
|
862
|
+
|
|
789
863
|
### isEmpty()
|
|
790
864
|
|
|
791
865
|
```ts
|
|
792
866
|
isEmpty(): boolean;
|
|
793
867
|
```
|
|
794
868
|
|
|
795
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
869
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:114](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L114)
|
|
796
870
|
|
|
797
871
|
Whether the set is empty.
|
|
798
872
|
|
|
799
|
-
*
|
|
800
|
-
|
|
801
873
|
#### Returns
|
|
802
874
|
|
|
803
875
|
`boolean`
|
|
@@ -811,18 +883,90 @@ Whether the set is empty.
|
|
|
811
883
|
|
|
812
884
|
***
|
|
813
885
|
|
|
886
|
+
### isSubsetOf()
|
|
887
|
+
|
|
888
|
+
```ts
|
|
889
|
+
isSubsetOf(other): boolean;
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:787](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L787)
|
|
893
|
+
|
|
894
|
+
Check whether every element in this set is also in the other.
|
|
895
|
+
|
|
896
|
+
#### Parameters
|
|
897
|
+
|
|
898
|
+
##### other
|
|
899
|
+
|
|
900
|
+
`Iterable`\<`K`\>
|
|
901
|
+
|
|
902
|
+
Any iterable of keys (converted to Set for fast lookup if not a TreeSet).
|
|
903
|
+
|
|
904
|
+
#### Returns
|
|
905
|
+
|
|
906
|
+
`boolean`
|
|
907
|
+
|
|
908
|
+
`true` if this is a subset of other.
|
|
909
|
+
|
|
910
|
+
#### Remarks
|
|
911
|
+
|
|
912
|
+
Time O(n).
|
|
913
|
+
|
|
914
|
+
#### Example
|
|
915
|
+
|
|
916
|
+
```ts
|
|
917
|
+
// Check subset
|
|
918
|
+
console.log(new TreeSet([3, 4]).isSubsetOf(a)); // true;
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
***
|
|
922
|
+
|
|
923
|
+
### isSupersetOf()
|
|
924
|
+
|
|
925
|
+
```ts
|
|
926
|
+
isSupersetOf(other): boolean;
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:804](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L804)
|
|
930
|
+
|
|
931
|
+
Check whether every element in the other set is also in this set.
|
|
932
|
+
|
|
933
|
+
#### Parameters
|
|
934
|
+
|
|
935
|
+
##### other
|
|
936
|
+
|
|
937
|
+
`Iterable`\<`K`\>
|
|
938
|
+
|
|
939
|
+
Any iterable of keys.
|
|
940
|
+
|
|
941
|
+
#### Returns
|
|
942
|
+
|
|
943
|
+
`boolean`
|
|
944
|
+
|
|
945
|
+
`true` if this is a superset of other.
|
|
946
|
+
|
|
947
|
+
#### Remarks
|
|
948
|
+
|
|
949
|
+
Time O(m).
|
|
950
|
+
|
|
951
|
+
#### Example
|
|
952
|
+
|
|
953
|
+
```ts
|
|
954
|
+
// Check superset
|
|
955
|
+
console.log(a.isSupersetOf(new TreeSet([2, 3]))); // true;
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
***
|
|
959
|
+
|
|
814
960
|
### keys()
|
|
815
961
|
|
|
816
962
|
```ts
|
|
817
963
|
keys(): IterableIterator<K>;
|
|
818
964
|
```
|
|
819
965
|
|
|
820
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
966
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:229](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L229)
|
|
821
967
|
|
|
822
968
|
Iterate over keys in ascending order.
|
|
823
969
|
|
|
824
|
-
*
|
|
825
|
-
|
|
826
970
|
#### Returns
|
|
827
971
|
|
|
828
972
|
`IterableIterator`\<`K`\>
|
|
@@ -843,12 +987,10 @@ Iterate over keys in ascending order.
|
|
|
843
987
|
last(): K | undefined;
|
|
844
988
|
```
|
|
845
989
|
|
|
846
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
990
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:494](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L494)
|
|
847
991
|
|
|
848
992
|
Largest key in the set.
|
|
849
993
|
|
|
850
|
-
*
|
|
851
|
-
|
|
852
994
|
#### Returns
|
|
853
995
|
|
|
854
996
|
`K` \| `undefined`
|
|
@@ -870,12 +1012,10 @@ Largest key in the set.
|
|
|
870
1012
|
lower(key): K | undefined;
|
|
871
1013
|
```
|
|
872
1014
|
|
|
873
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1015
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:594](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L594)
|
|
874
1016
|
|
|
875
1017
|
Largest key that is < the given key.
|
|
876
1018
|
|
|
877
|
-
*
|
|
878
|
-
|
|
879
1019
|
#### Parameters
|
|
880
1020
|
|
|
881
1021
|
##### key
|
|
@@ -907,7 +1047,7 @@ map<MK>(
|
|
|
907
1047
|
thisArg?): TreeSet<MK>;
|
|
908
1048
|
```
|
|
909
1049
|
|
|
910
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1050
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:289](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L289)
|
|
911
1051
|
|
|
912
1052
|
Create a new TreeSet by mapping each value to a new key.
|
|
913
1053
|
|
|
@@ -941,8 +1081,6 @@ This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
|
941
1081
|
|
|
942
1082
|
Time O(n log n) expected, Space O(n)
|
|
943
1083
|
|
|
944
|
-
*
|
|
945
|
-
|
|
946
1084
|
#### Example
|
|
947
1085
|
|
|
948
1086
|
```ts
|
|
@@ -960,12 +1098,10 @@ Time O(n log n) expected, Space O(n)
|
|
|
960
1098
|
pollFirst(): K | undefined;
|
|
961
1099
|
```
|
|
962
1100
|
|
|
963
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1101
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:508](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L508)
|
|
964
1102
|
|
|
965
1103
|
Remove and return the smallest key.
|
|
966
1104
|
|
|
967
|
-
*
|
|
968
|
-
|
|
969
1105
|
#### Returns
|
|
970
1106
|
|
|
971
1107
|
`K` \| `undefined`
|
|
@@ -989,12 +1125,10 @@ Remove and return the smallest key.
|
|
|
989
1125
|
pollLast(): K | undefined;
|
|
990
1126
|
```
|
|
991
1127
|
|
|
992
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1128
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:524](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L524)
|
|
993
1129
|
|
|
994
1130
|
Remove and return the largest key.
|
|
995
1131
|
|
|
996
|
-
*
|
|
997
|
-
|
|
998
1132
|
#### Returns
|
|
999
1133
|
|
|
1000
1134
|
`K` \| `undefined`
|
|
@@ -1017,7 +1151,7 @@ Remove and return the largest key.
|
|
|
1017
1151
|
print(): void;
|
|
1018
1152
|
```
|
|
1019
1153
|
|
|
1020
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1154
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:445](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L445)
|
|
1021
1155
|
|
|
1022
1156
|
Print a human-friendly representation.
|
|
1023
1157
|
|
|
@@ -1029,8 +1163,6 @@ Print a human-friendly representation.
|
|
|
1029
1163
|
|
|
1030
1164
|
Time O(n), Space O(n)
|
|
1031
1165
|
|
|
1032
|
-
*
|
|
1033
|
-
|
|
1034
1166
|
#### Example
|
|
1035
1167
|
|
|
1036
1168
|
```ts
|
|
@@ -1047,7 +1179,7 @@ Time O(n), Space O(n)
|
|
|
1047
1179
|
rangeByRank(start, end): K[];
|
|
1048
1180
|
```
|
|
1049
1181
|
|
|
1050
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1182
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:689](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L689)
|
|
1051
1183
|
|
|
1052
1184
|
Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
1053
1185
|
|
|
@@ -1069,16 +1201,11 @@ Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
|
1069
1201
|
|
|
1070
1202
|
Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
1071
1203
|
|
|
1072
|
-
*
|
|
1073
|
-
|
|
1074
1204
|
#### Example
|
|
1075
1205
|
|
|
1076
1206
|
```ts
|
|
1077
1207
|
// Pagination by position in tree order
|
|
1078
|
-
const tree = new TreeSet<number>(
|
|
1079
|
-
[10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
1080
|
-
{ enableOrderStatistic: true }
|
|
1081
|
-
);
|
|
1208
|
+
const tree = new TreeSet<number>([10, 20, 30, 40, 50, 60, 70, 80, 90], { enableOrderStatistic: true });
|
|
1082
1209
|
const pageSize = 3;
|
|
1083
1210
|
|
|
1084
1211
|
// Page 1
|
|
@@ -1097,7 +1224,7 @@ Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
|
1097
1224
|
rangeSearch(range, options?): K[];
|
|
1098
1225
|
```
|
|
1099
1226
|
|
|
1100
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1227
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:622](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L622)
|
|
1101
1228
|
|
|
1102
1229
|
Return all keys in a given range.
|
|
1103
1230
|
|
|
@@ -1115,8 +1242,6 @@ Return all keys in a given range.
|
|
|
1115
1242
|
|
|
1116
1243
|
Inclusive/exclusive bounds (defaults to inclusive).
|
|
1117
1244
|
|
|
1118
|
-
*
|
|
1119
|
-
|
|
1120
1245
|
#### Returns
|
|
1121
1246
|
|
|
1122
1247
|
`K`[]
|
|
@@ -1130,7 +1255,7 @@ Inclusive/exclusive bounds (defaults to inclusive).
|
|
|
1130
1255
|
167772160, // 10.0.0.0
|
|
1131
1256
|
167772416, // 10.0.1.0
|
|
1132
1257
|
167772672, // 10.0.2.0
|
|
1133
|
-
167773184
|
|
1258
|
+
167773184 // 10.0.4.0
|
|
1134
1259
|
]);
|
|
1135
1260
|
|
|
1136
1261
|
// Check if any blocked IP is in range 10.0.1.0 - 10.0.3.0
|
|
@@ -1150,7 +1275,7 @@ Inclusive/exclusive bounds (defaults to inclusive).
|
|
|
1150
1275
|
reduce<A>(callbackfn, initialValue): A;
|
|
1151
1276
|
```
|
|
1152
1277
|
|
|
1153
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1278
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:342](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L342)
|
|
1154
1279
|
|
|
1155
1280
|
Reduce values into a single accumulator.
|
|
1156
1281
|
|
|
@@ -1178,8 +1303,6 @@ Reduce values into a single accumulator.
|
|
|
1178
1303
|
|
|
1179
1304
|
Time O(n), Space O(1)
|
|
1180
1305
|
|
|
1181
|
-
*
|
|
1182
|
-
|
|
1183
1306
|
#### Example
|
|
1184
1307
|
|
|
1185
1308
|
```ts
|
|
@@ -1197,7 +1320,7 @@ Time O(n), Space O(1)
|
|
|
1197
1320
|
some(callbackfn, thisArg?): boolean;
|
|
1198
1321
|
```
|
|
1199
1322
|
|
|
1200
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1323
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:382](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L382)
|
|
1201
1324
|
|
|
1202
1325
|
Test whether any value satisfies a predicate.
|
|
1203
1326
|
|
|
@@ -1219,8 +1342,6 @@ Test whether any value satisfies a predicate.
|
|
|
1219
1342
|
|
|
1220
1343
|
Time O(n), Space O(1)
|
|
1221
1344
|
|
|
1222
|
-
*
|
|
1223
|
-
|
|
1224
1345
|
#### Example
|
|
1225
1346
|
|
|
1226
1347
|
```ts
|
|
@@ -1231,13 +1352,50 @@ Time O(n), Space O(1)
|
|
|
1231
1352
|
|
|
1232
1353
|
***
|
|
1233
1354
|
|
|
1355
|
+
### symmetricDifference()
|
|
1356
|
+
|
|
1357
|
+
```ts
|
|
1358
|
+
symmetricDifference(other): TreeSet<K>;
|
|
1359
|
+
```
|
|
1360
|
+
|
|
1361
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:766](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L766)
|
|
1362
|
+
|
|
1363
|
+
Return a new TreeSet containing elements in either set but not both.
|
|
1364
|
+
|
|
1365
|
+
#### Parameters
|
|
1366
|
+
|
|
1367
|
+
##### other
|
|
1368
|
+
|
|
1369
|
+
`Iterable`\<`K`\>
|
|
1370
|
+
|
|
1371
|
+
Any iterable of keys.
|
|
1372
|
+
|
|
1373
|
+
#### Returns
|
|
1374
|
+
|
|
1375
|
+
`TreeSet`\<`K`\>
|
|
1376
|
+
|
|
1377
|
+
A new TreeSet.
|
|
1378
|
+
|
|
1379
|
+
#### Remarks
|
|
1380
|
+
|
|
1381
|
+
Time O(n+m).
|
|
1382
|
+
|
|
1383
|
+
#### Example
|
|
1384
|
+
|
|
1385
|
+
```ts
|
|
1386
|
+
// Find symmetric difference
|
|
1387
|
+
console.log([...a.symmetricDifference(b)]); // [1, 2, 6, 7];
|
|
1388
|
+
```
|
|
1389
|
+
|
|
1390
|
+
***
|
|
1391
|
+
|
|
1234
1392
|
### toArray()
|
|
1235
1393
|
|
|
1236
1394
|
```ts
|
|
1237
1395
|
toArray(): K[];
|
|
1238
1396
|
```
|
|
1239
1397
|
|
|
1240
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1398
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:433](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L433)
|
|
1241
1399
|
|
|
1242
1400
|
Materialize the set into an array of keys.
|
|
1243
1401
|
|
|
@@ -1249,8 +1407,6 @@ Materialize the set into an array of keys.
|
|
|
1249
1407
|
|
|
1250
1408
|
Time O(n), Space O(n)
|
|
1251
1409
|
|
|
1252
|
-
*
|
|
1253
|
-
|
|
1254
1410
|
#### Example
|
|
1255
1411
|
|
|
1256
1412
|
```ts
|
|
@@ -1261,20 +1417,55 @@ Time O(n), Space O(n)
|
|
|
1261
1417
|
|
|
1262
1418
|
***
|
|
1263
1419
|
|
|
1420
|
+
### union()
|
|
1421
|
+
|
|
1422
|
+
```ts
|
|
1423
|
+
union(other): TreeSet<K>;
|
|
1424
|
+
```
|
|
1425
|
+
|
|
1426
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:702](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L702)
|
|
1427
|
+
|
|
1428
|
+
Return a new TreeSet containing all elements from both sets.
|
|
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
|
+
#### Remarks
|
|
1445
|
+
|
|
1446
|
+
When both sets share the same comparator, uses O(n+m) merge. Otherwise O(m log n).
|
|
1447
|
+
|
|
1448
|
+
#### Example
|
|
1449
|
+
|
|
1450
|
+
```ts
|
|
1451
|
+
// Merge two sets
|
|
1452
|
+
console.log([...a.union(b)]); // [1, 2, 3, 4, 5, 6, 7];
|
|
1453
|
+
```
|
|
1454
|
+
|
|
1455
|
+
***
|
|
1456
|
+
|
|
1264
1457
|
### values()
|
|
1265
1458
|
|
|
1266
1459
|
```ts
|
|
1267
1460
|
values(): IterableIterator<K>;
|
|
1268
1461
|
```
|
|
1269
1462
|
|
|
1270
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1463
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:242](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L242)
|
|
1271
1464
|
|
|
1272
1465
|
Iterate over values in ascending order.
|
|
1273
1466
|
|
|
1274
1467
|
Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
1275
1468
|
|
|
1276
|
-
*
|
|
1277
|
-
|
|
1278
1469
|
#### Returns
|
|
1279
1470
|
|
|
1280
1471
|
`IterableIterator`\<`K`\>
|
|
@@ -1295,7 +1486,7 @@ Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
|
1295
1486
|
static createDefaultComparator<K>(): Comparator<K>;
|
|
1296
1487
|
```
|
|
1297
1488
|
|
|
1298
|
-
Defined in: [data-structures/binary-tree/tree-set.ts:
|
|
1489
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:84](https://github.com/zrwusa/data-structure-typed/blob/main/src/data-structures/binary-tree/tree-set.ts#L84)
|
|
1299
1490
|
|
|
1300
1491
|
Create the strict default comparator.
|
|
1301
1492
|
|