data-structure-typed 2.4.5 → 2.5.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/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
- package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
- package/CHANGELOG.md +3 -1
- package/README.md +78 -31
- package/dist/cjs/binary-tree.cjs +23698 -0
- package/dist/cjs/graph.cjs +5236 -0
- package/dist/cjs/hash.cjs +1262 -0
- package/dist/cjs/heap.cjs +1540 -0
- package/dist/cjs/index.cjs +24509 -2899
- package/dist/cjs/linked-list.cjs +4370 -0
- package/dist/cjs/matrix.cjs +1042 -0
- package/dist/cjs/priority-queue.cjs +1314 -0
- package/dist/cjs/queue.cjs +4090 -0
- package/dist/cjs/stack.cjs +861 -0
- package/dist/cjs/trie.cjs +1173 -0
- package/dist/cjs-legacy/binary-tree.cjs +23730 -0
- package/dist/cjs-legacy/graph.cjs +5234 -0
- package/dist/cjs-legacy/hash.cjs +1262 -0
- package/dist/cjs-legacy/heap.cjs +1537 -0
- package/dist/cjs-legacy/index.cjs +32555 -10936
- package/dist/cjs-legacy/linked-list.cjs +4376 -0
- package/dist/cjs-legacy/matrix.cjs +1045 -0
- package/dist/cjs-legacy/priority-queue.cjs +1312 -0
- package/dist/cjs-legacy/queue.cjs +4088 -0
- package/dist/cjs-legacy/stack.cjs +861 -0
- package/dist/cjs-legacy/trie.cjs +1172 -0
- package/dist/esm/binary-tree.mjs +23683 -0
- package/dist/esm/graph.mjs +5223 -0
- package/dist/esm/hash.mjs +1259 -0
- package/dist/esm/heap.mjs +1534 -0
- package/dist/esm/index.mjs +24507 -2898
- package/dist/esm/linked-list.mjs +4363 -0
- package/dist/esm/matrix.mjs +1038 -0
- package/dist/esm/priority-queue.mjs +1310 -0
- package/dist/esm/queue.mjs +4086 -0
- package/dist/esm/stack.mjs +859 -0
- package/dist/esm/trie.mjs +1170 -0
- package/dist/esm-legacy/binary-tree.mjs +23715 -0
- package/dist/esm-legacy/graph.mjs +5221 -0
- package/dist/esm-legacy/hash.mjs +1259 -0
- package/dist/esm-legacy/heap.mjs +1531 -0
- package/dist/esm-legacy/index.mjs +32553 -10935
- package/dist/esm-legacy/linked-list.mjs +4369 -0
- package/dist/esm-legacy/matrix.mjs +1041 -0
- package/dist/esm-legacy/priority-queue.mjs +1308 -0
- package/dist/esm-legacy/queue.mjs +4084 -0
- package/dist/esm-legacy/stack.mjs +859 -0
- package/dist/esm-legacy/trie.mjs +1169 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +368 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +473 -147
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +931 -80
- package/dist/types/data-structures/binary-tree/bst.d.ts +792 -29
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +592 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +320 -135
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3662 -6
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3487 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2778 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3414 -6
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +419 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +384 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +462 -89
- package/dist/types/data-structures/heap/heap.d.ts +567 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +631 -49
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +581 -68
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +775 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +491 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +578 -71
- package/dist/types/data-structures/queue/queue.d.ts +451 -42
- package/dist/types/data-structures/stack/stack.d.ts +374 -32
- package/dist/types/data-structures/trie/trie.d.ts +458 -48
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/data-structure-typed.js +32432 -10808
- package/dist/umd/data-structure-typed.min.js +10 -4
- package/docs-site-docusaurus/README.md +41 -0
- package/docs-site-docusaurus/docs/api/README.md +52 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
- package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
- package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
- package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
- package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
- package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
- package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
- package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
- package/docs-site-docusaurus/docs/guide/guides.md +611 -0
- package/docs-site-docusaurus/docs/guide/installation.md +60 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
- package/docs-site-docusaurus/docs/guide/overview.md +638 -0
- package/docs-site-docusaurus/docs/guide/performance.md +833 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
- package/docs-site-docusaurus/docusaurus.config.ts +159 -0
- package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
- package/docs-site-docusaurus/package-lock.json +18667 -0
- package/docs-site-docusaurus/package.json +50 -0
- package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
- package/docs-site-docusaurus/sidebars.ts +23 -0
- package/docs-site-docusaurus/sort-protected.mjs +87 -0
- package/docs-site-docusaurus/src/css/custom.css +96 -0
- package/docs-site-docusaurus/src/pages/index.module.css +13 -0
- package/docs-site-docusaurus/src/pages/index.tsx +71 -0
- package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
- package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
- package/docs-site-docusaurus/static/.nojekyll +0 -0
- package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
- package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
- package/docs-site-docusaurus/static/img/favicon.ico +0 -0
- package/docs-site-docusaurus/static/img/favicon.png +0 -0
- package/docs-site-docusaurus/static/img/logo-180.png +0 -0
- package/docs-site-docusaurus/static/img/logo.jpg +0 -0
- package/docs-site-docusaurus/static/img/logo.png +0 -0
- package/docs-site-docusaurus/static/img/logo.svg +1 -0
- package/docs-site-docusaurus/static/img/og-image.png +0 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
- package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
- package/docs-site-docusaurus/static/robots.txt +4 -0
- package/docs-site-docusaurus/typedoc.json +23 -0
- package/package.json +109 -12
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +386 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
- package/src/data-structures/binary-tree/binary-tree.ts +956 -81
- package/src/data-structures/binary-tree/bst.ts +840 -35
- package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
- package/src/data-structures/binary-tree/segment-tree.ts +498 -249
- package/src/data-structures/binary-tree/tree-map.ts +3784 -7
- package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
- package/src/data-structures/binary-tree/tree-set.ts +3531 -10
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +429 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +393 -59
- package/src/data-structures/hash/hash-map.ts +476 -92
- package/src/data-structures/heap/heap.ts +581 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
- package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
- package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
- package/src/data-structures/matrix/matrix.ts +584 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +592 -70
- package/src/data-structures/queue/queue.ts +463 -42
- package/src/data-structures/stack/stack.ts +384 -32
- package/src/data-structures/trie/trie.ts +470 -48
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
- package/vercel.json +6 -0
- package/dist/leetcode/avl-tree-counter.mjs +0 -2957
- package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
- package/dist/leetcode/avl-tree.mjs +0 -2720
- package/dist/leetcode/binary-tree.mjs +0 -1594
- package/dist/leetcode/bst.mjs +0 -2398
- package/dist/leetcode/deque.mjs +0 -683
- package/dist/leetcode/directed-graph.mjs +0 -1733
- package/dist/leetcode/doubly-linked-list.mjs +0 -709
- package/dist/leetcode/hash-map.mjs +0 -493
- package/dist/leetcode/heap.mjs +0 -542
- package/dist/leetcode/max-heap.mjs +0 -375
- package/dist/leetcode/max-priority-queue.mjs +0 -383
- package/dist/leetcode/min-heap.mjs +0 -363
- package/dist/leetcode/min-priority-queue.mjs +0 -371
- package/dist/leetcode/priority-queue.mjs +0 -363
- package/dist/leetcode/queue.mjs +0 -943
- package/dist/leetcode/red-black-tree.mjs +0 -2765
- package/dist/leetcode/singly-linked-list.mjs +0 -754
- package/dist/leetcode/stack.mjs +0 -217
- package/dist/leetcode/tree-counter.mjs +0 -3039
- package/dist/leetcode/tree-multi-map.mjs +0 -2913
- package/dist/leetcode/trie.mjs +0 -413
- package/dist/leetcode/undirected-graph.mjs +0 -1650
|
@@ -0,0 +1,1117 @@
|
|
|
1
|
+
[**data-structure-typed**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[data-structure-typed](../README.md) / TreeSet
|
|
6
|
+
|
|
7
|
+
# Class: TreeSet\<K, R\>
|
|
8
|
+
|
|
9
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:26](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L26)
|
|
10
|
+
|
|
11
|
+
An ordered Set backed by a red-black tree.
|
|
12
|
+
|
|
13
|
+
- Iteration order is ascending by key.
|
|
14
|
+
- No node exposure: all APIs use keys only.
|
|
15
|
+
|
|
16
|
+
## Example
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// Set multiple key-value pairs
|
|
20
|
+
const ts = new TreeSet<number, string>();
|
|
21
|
+
ts.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
|
|
22
|
+
console.log(ts.size); // 3;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Type Parameters
|
|
26
|
+
|
|
27
|
+
### K
|
|
28
|
+
|
|
29
|
+
`K` = `any`
|
|
30
|
+
|
|
31
|
+
### R
|
|
32
|
+
|
|
33
|
+
`R` = `K`
|
|
34
|
+
|
|
35
|
+
## Implements
|
|
36
|
+
|
|
37
|
+
- `Iterable`\<`K`\>
|
|
38
|
+
|
|
39
|
+
## Constructors
|
|
40
|
+
|
|
41
|
+
### Constructor
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
new TreeSet<K, R>(elements?, options?): TreeSet<K, R>;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:46](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L46)
|
|
48
|
+
|
|
49
|
+
Create a TreeSet from an iterable of keys or raw elements.
|
|
50
|
+
|
|
51
|
+
#### Parameters
|
|
52
|
+
|
|
53
|
+
##### elements?
|
|
54
|
+
|
|
55
|
+
`Iterable`\<`K`, `any`, `any`\> \| `Iterable`\<`R`, `any`, `any`\>
|
|
56
|
+
|
|
57
|
+
Iterable of keys, or raw elements if `toElementFn` is provided.
|
|
58
|
+
|
|
59
|
+
##### options?
|
|
60
|
+
|
|
61
|
+
`TreeSetOptions`\<`K`, `R`\> = `{}`
|
|
62
|
+
|
|
63
|
+
Configuration options including optional `toElementFn` to transform raw elements.
|
|
64
|
+
|
|
65
|
+
#### Returns
|
|
66
|
+
|
|
67
|
+
`TreeSet`\<`K`, `R`\>
|
|
68
|
+
|
|
69
|
+
#### Throws
|
|
70
|
+
|
|
71
|
+
When using the default comparator and encountering unsupported key types,
|
|
72
|
+
or invalid keys (e.g. `NaN`, invalid `Date`).
|
|
73
|
+
|
|
74
|
+
#### Example
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// Standard usage with keys
|
|
78
|
+
const set = new TreeSet([3, 1, 2]);
|
|
79
|
+
|
|
80
|
+
// Using toElementFn to transform raw objects
|
|
81
|
+
const users = [{ id: 3, name: 'Alice' }, { id: 1, name: 'Bob' }];
|
|
82
|
+
const set = new TreeSet<number, User>(users, { toElementFn: u => u.id });
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Accessors
|
|
86
|
+
|
|
87
|
+
### size
|
|
88
|
+
|
|
89
|
+
#### Get Signature
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
get size(): number;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:101](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L101)
|
|
96
|
+
|
|
97
|
+
Number of elements in the set.
|
|
98
|
+
|
|
99
|
+
##### Returns
|
|
100
|
+
|
|
101
|
+
`number`
|
|
102
|
+
|
|
103
|
+
## Methods
|
|
104
|
+
|
|
105
|
+
### add()
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
add(key): this;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:398](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L398)
|
|
112
|
+
|
|
113
|
+
Add a key to the set (no-op if already present).
|
|
114
|
+
|
|
115
|
+
#### Parameters
|
|
116
|
+
|
|
117
|
+
##### key
|
|
118
|
+
|
|
119
|
+
`K`
|
|
120
|
+
|
|
121
|
+
#### Returns
|
|
122
|
+
|
|
123
|
+
`this`
|
|
124
|
+
|
|
125
|
+
#### Remarks
|
|
126
|
+
|
|
127
|
+
Expected time O(log n)
|
|
128
|
+
|
|
129
|
+
*
|
|
130
|
+
|
|
131
|
+
#### Example
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
// Unique tags with sorted order
|
|
135
|
+
const tags = new TreeSet<string>(['javascript', 'typescript', 'react', 'typescript', 'node']);
|
|
136
|
+
|
|
137
|
+
// Duplicates removed, sorted alphabetically
|
|
138
|
+
console.log([...tags]); // ['javascript', 'node', 'react', 'typescript'];
|
|
139
|
+
console.log(tags.size); // 4;
|
|
140
|
+
|
|
141
|
+
tags.add('angular');
|
|
142
|
+
console.log(tags.first()); // 'angular';
|
|
143
|
+
console.log(tags.last()); // 'typescript';
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
***
|
|
147
|
+
|
|
148
|
+
### ceiling()
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
ceiling(key): K | undefined;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2832](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2832)
|
|
155
|
+
|
|
156
|
+
Smallest key that is >= the given key.
|
|
157
|
+
|
|
158
|
+
*
|
|
159
|
+
|
|
160
|
+
#### Parameters
|
|
161
|
+
|
|
162
|
+
##### key
|
|
163
|
+
|
|
164
|
+
`K`
|
|
165
|
+
|
|
166
|
+
#### Returns
|
|
167
|
+
|
|
168
|
+
`K` \| `undefined`
|
|
169
|
+
|
|
170
|
+
#### Example
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
// Finding nearest available time slot
|
|
174
|
+
// Available appointment times (minutes from midnight)
|
|
175
|
+
const slots = new TreeSet<number>([540, 600, 660, 720, 840, 900]);
|
|
176
|
+
|
|
177
|
+
// Customer wants something around 10:30 (630 min)
|
|
178
|
+
const nearest = slots.ceiling(630);
|
|
179
|
+
console.log(nearest); // 660; // 11:00 AM
|
|
180
|
+
|
|
181
|
+
// What's the latest slot before 2:00 PM (840)?
|
|
182
|
+
const before2pm = slots.lower(840);
|
|
183
|
+
console.log(before2pm); // 720; // 12:00 PM
|
|
184
|
+
|
|
185
|
+
// Book the 11:00 slot
|
|
186
|
+
slots.delete(660);
|
|
187
|
+
console.log(slots.ceiling(630)); // 720;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
***
|
|
191
|
+
|
|
192
|
+
### clear()
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
clear(): void;
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:837](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L837)
|
|
199
|
+
|
|
200
|
+
Remove all keys.
|
|
201
|
+
|
|
202
|
+
*
|
|
203
|
+
|
|
204
|
+
#### Returns
|
|
205
|
+
|
|
206
|
+
`void`
|
|
207
|
+
|
|
208
|
+
#### Example
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
// Remove all
|
|
212
|
+
const ts = new TreeSet<number>([1, 2]);
|
|
213
|
+
ts.clear();
|
|
214
|
+
console.log(ts.isEmpty()); // true;
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
***
|
|
218
|
+
|
|
219
|
+
### clone()
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
clone(): TreeSet<K>;
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3483](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L3483)
|
|
226
|
+
|
|
227
|
+
Creates a shallow clone of this set.
|
|
228
|
+
|
|
229
|
+
#### Returns
|
|
230
|
+
|
|
231
|
+
`TreeSet`\<`K`\>
|
|
232
|
+
|
|
233
|
+
#### Remarks
|
|
234
|
+
|
|
235
|
+
Time O(n log n), Space O(n)
|
|
236
|
+
|
|
237
|
+
*
|
|
238
|
+
|
|
239
|
+
#### Example
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
// Deep clone
|
|
243
|
+
const ts = new TreeSet<number>([1, 2, 3]);
|
|
244
|
+
const copy = ts.clone();
|
|
245
|
+
copy.delete(1);
|
|
246
|
+
console.log(ts.has(1)); // true;
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
***
|
|
250
|
+
|
|
251
|
+
### delete()
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
delete(key): boolean;
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:700](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L700)
|
|
258
|
+
|
|
259
|
+
Delete a key.
|
|
260
|
+
|
|
261
|
+
#### Parameters
|
|
262
|
+
|
|
263
|
+
##### key
|
|
264
|
+
|
|
265
|
+
`K`
|
|
266
|
+
|
|
267
|
+
#### Returns
|
|
268
|
+
|
|
269
|
+
`boolean`
|
|
270
|
+
|
|
271
|
+
`true` if the key existed; otherwise `false`.
|
|
272
|
+
|
|
273
|
+
#### Remarks
|
|
274
|
+
|
|
275
|
+
Expected time O(log n)
|
|
276
|
+
|
|
277
|
+
*
|
|
278
|
+
|
|
279
|
+
#### Example
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
// Removing elements while maintaining order
|
|
283
|
+
const nums = new TreeSet<number>([1, 3, 5, 7, 9]);
|
|
284
|
+
|
|
285
|
+
console.log(nums.delete(5)); // true;
|
|
286
|
+
console.log(nums.delete(5)); // false; // already gone
|
|
287
|
+
console.log([...nums]); // [1, 3, 7, 9];
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
***
|
|
291
|
+
|
|
292
|
+
### entries()
|
|
293
|
+
|
|
294
|
+
```ts
|
|
295
|
+
entries(): IterableIterator<[K, K]>;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1243](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1243)
|
|
299
|
+
|
|
300
|
+
Iterate over `[value, value]` pairs (native Set convention).
|
|
301
|
+
|
|
302
|
+
Note: TreeSet stores only keys internally; `[k, k]` is created on-the-fly during iteration.
|
|
303
|
+
|
|
304
|
+
*
|
|
305
|
+
|
|
306
|
+
#### Returns
|
|
307
|
+
|
|
308
|
+
`IterableIterator`\<\[`K`, `K`\]\>
|
|
309
|
+
|
|
310
|
+
#### Example
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
// Iterate entries
|
|
314
|
+
const ts = new TreeSet<number>([3, 1, 2]);
|
|
315
|
+
console.log([...ts.entries()].map(([k]) => k)); // [1, 2, 3];
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
***
|
|
319
|
+
|
|
320
|
+
### every()
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
every(callbackfn, thisArg?): boolean;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1951](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1951)
|
|
327
|
+
|
|
328
|
+
Test whether all values satisfy a predicate.
|
|
329
|
+
|
|
330
|
+
#### Parameters
|
|
331
|
+
|
|
332
|
+
##### callbackfn
|
|
333
|
+
|
|
334
|
+
`TreeSetElementCallback`\<`K`, `boolean`, `TreeSet`\<`K`, `K`\>\>
|
|
335
|
+
|
|
336
|
+
##### thisArg?
|
|
337
|
+
|
|
338
|
+
`unknown`
|
|
339
|
+
|
|
340
|
+
#### Returns
|
|
341
|
+
|
|
342
|
+
`boolean`
|
|
343
|
+
|
|
344
|
+
#### Remarks
|
|
345
|
+
|
|
346
|
+
Time O(n), Space O(1)
|
|
347
|
+
|
|
348
|
+
*
|
|
349
|
+
|
|
350
|
+
#### Example
|
|
351
|
+
|
|
352
|
+
```ts
|
|
353
|
+
// Test all
|
|
354
|
+
const ts = new TreeSet<number>([2, 4, 6]);
|
|
355
|
+
console.log(ts.every(k => k > 0)); // true;
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
***
|
|
359
|
+
|
|
360
|
+
### filter()
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
filter(callbackfn, thisArg?): TreeSet<K>;
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1671](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1671)
|
|
367
|
+
|
|
368
|
+
Create a new TreeSet containing only values that satisfy the predicate.
|
|
369
|
+
|
|
370
|
+
#### Parameters
|
|
371
|
+
|
|
372
|
+
##### callbackfn
|
|
373
|
+
|
|
374
|
+
`TreeSetElementCallback`\<`K`, `boolean`, `TreeSet`\<`K`, `K`\>\>
|
|
375
|
+
|
|
376
|
+
##### thisArg?
|
|
377
|
+
|
|
378
|
+
`unknown`
|
|
379
|
+
|
|
380
|
+
#### Returns
|
|
381
|
+
|
|
382
|
+
`TreeSet`\<`K`\>
|
|
383
|
+
|
|
384
|
+
#### Remarks
|
|
385
|
+
|
|
386
|
+
Time O(n log n) expected, Space O(n)
|
|
387
|
+
|
|
388
|
+
*
|
|
389
|
+
|
|
390
|
+
#### Example
|
|
391
|
+
|
|
392
|
+
```ts
|
|
393
|
+
// Filter
|
|
394
|
+
const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
395
|
+
const evens = ts.filter(k => k % 2 === 0);
|
|
396
|
+
console.log([...evens]); // [2, 4];
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
***
|
|
400
|
+
|
|
401
|
+
### find()
|
|
402
|
+
|
|
403
|
+
```ts
|
|
404
|
+
find(callbackfn, thisArg?): K | undefined;
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2232](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2232)
|
|
408
|
+
|
|
409
|
+
Find the first value that satisfies a predicate.
|
|
410
|
+
|
|
411
|
+
#### Parameters
|
|
412
|
+
|
|
413
|
+
##### callbackfn
|
|
414
|
+
|
|
415
|
+
`TreeSetElementCallback`\<`K`, `boolean`, `TreeSet`\<`K`, `K`\>\>
|
|
416
|
+
|
|
417
|
+
##### thisArg?
|
|
418
|
+
|
|
419
|
+
`unknown`
|
|
420
|
+
|
|
421
|
+
#### Returns
|
|
422
|
+
|
|
423
|
+
`K` \| `undefined`
|
|
424
|
+
|
|
425
|
+
#### Remarks
|
|
426
|
+
|
|
427
|
+
Time O(n), Space O(1)
|
|
428
|
+
|
|
429
|
+
*
|
|
430
|
+
|
|
431
|
+
#### Example
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
// Find entry
|
|
435
|
+
const ts = new TreeSet<number>([1, 2, 3]);
|
|
436
|
+
const found = ts.find(k => k === 2);
|
|
437
|
+
console.log(found); // 2;
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
***
|
|
441
|
+
|
|
442
|
+
### first()
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
first(): K | undefined;
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2574](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2574)
|
|
449
|
+
|
|
450
|
+
Smallest key in the set.
|
|
451
|
+
|
|
452
|
+
*
|
|
453
|
+
|
|
454
|
+
#### Returns
|
|
455
|
+
|
|
456
|
+
`K` \| `undefined`
|
|
457
|
+
|
|
458
|
+
#### Example
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
// Student grade ranking with custom comparator
|
|
462
|
+
interface Student {
|
|
463
|
+
name: string;
|
|
464
|
+
gpa: number;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const ranking = new TreeSet<Student>(
|
|
468
|
+
[
|
|
469
|
+
{ name: 'Alice', gpa: 3.8 },
|
|
470
|
+
{ name: 'Bob', gpa: 3.5 },
|
|
471
|
+
{ name: 'Charlie', gpa: 3.9 },
|
|
472
|
+
{ name: 'Diana', gpa: 3.5 }
|
|
473
|
+
],
|
|
474
|
+
{ comparator: (a, b) => b.gpa - a.gpa || a.name.localeCompare(b.name) }
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
// Sorted by GPA descending, then name ascending
|
|
478
|
+
const names = [...ranking].map(s => s.name);
|
|
479
|
+
console.log(names); // ['Charlie', 'Alice', 'Bob', 'Diana'];
|
|
480
|
+
|
|
481
|
+
// Top student
|
|
482
|
+
console.log(ranking.first()?.name); // 'Charlie';
|
|
483
|
+
|
|
484
|
+
// Filter students with GPA >= 3.8
|
|
485
|
+
const honors = ranking.filter(s => s.gpa >= 3.8);
|
|
486
|
+
console.log(honors.toArray().map(s => s.name)); // ['Charlie', 'Alice'];
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
***
|
|
490
|
+
|
|
491
|
+
### floor()
|
|
492
|
+
|
|
493
|
+
```ts
|
|
494
|
+
floor(key): K | undefined;
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2954](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2954)
|
|
498
|
+
|
|
499
|
+
Largest key that is <= the given key.
|
|
500
|
+
|
|
501
|
+
*
|
|
502
|
+
|
|
503
|
+
#### Parameters
|
|
504
|
+
|
|
505
|
+
##### key
|
|
506
|
+
|
|
507
|
+
`K`
|
|
508
|
+
|
|
509
|
+
#### Returns
|
|
510
|
+
|
|
511
|
+
`K` \| `undefined`
|
|
512
|
+
|
|
513
|
+
#### Example
|
|
514
|
+
|
|
515
|
+
```ts
|
|
516
|
+
// Largest element ≤ target
|
|
517
|
+
const breakpoints = new TreeSet<number>([320, 768, 1024, 1280, 1920]);
|
|
518
|
+
|
|
519
|
+
// Current width is 800 → which breakpoint applies?
|
|
520
|
+
console.log(breakpoints.floor(800)); // 768;
|
|
521
|
+
console.log(breakpoints.floor(1024)); // 1024; // exact match
|
|
522
|
+
console.log(breakpoints.floor(100)); // undefined;
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
***
|
|
526
|
+
|
|
527
|
+
### forEach()
|
|
528
|
+
|
|
529
|
+
```ts
|
|
530
|
+
forEach(cb, thisArg?): void;
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1385](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1385)
|
|
534
|
+
|
|
535
|
+
Visit each value in ascending order.
|
|
536
|
+
|
|
537
|
+
Callback follows native Set convention: `(value, value2, set)`.
|
|
538
|
+
|
|
539
|
+
*
|
|
540
|
+
|
|
541
|
+
#### Parameters
|
|
542
|
+
|
|
543
|
+
##### cb
|
|
544
|
+
|
|
545
|
+
(`value`, `value2`, `set`) => `void`
|
|
546
|
+
|
|
547
|
+
##### thisArg?
|
|
548
|
+
|
|
549
|
+
`any`
|
|
550
|
+
|
|
551
|
+
#### Returns
|
|
552
|
+
|
|
553
|
+
`void`
|
|
554
|
+
|
|
555
|
+
#### Example
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
// Execute for each
|
|
559
|
+
const ts = new TreeSet<number>([3, 1, 2]);
|
|
560
|
+
const keys: number[] = [];
|
|
561
|
+
ts.forEach(k => keys.push(k));
|
|
562
|
+
console.log(keys); // [1, 2, 3];
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
***
|
|
566
|
+
|
|
567
|
+
### has()
|
|
568
|
+
|
|
569
|
+
```ts
|
|
570
|
+
has(key): boolean;
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:549](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L549)
|
|
574
|
+
|
|
575
|
+
Test whether a key exists.
|
|
576
|
+
|
|
577
|
+
#### Parameters
|
|
578
|
+
|
|
579
|
+
##### key
|
|
580
|
+
|
|
581
|
+
`K`
|
|
582
|
+
|
|
583
|
+
#### Returns
|
|
584
|
+
|
|
585
|
+
`boolean`
|
|
586
|
+
|
|
587
|
+
#### Remarks
|
|
588
|
+
|
|
589
|
+
Expected time O(log n)
|
|
590
|
+
|
|
591
|
+
*
|
|
592
|
+
|
|
593
|
+
#### Example
|
|
594
|
+
|
|
595
|
+
```ts
|
|
596
|
+
// Checking membership in a sorted collection
|
|
597
|
+
const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
|
|
598
|
+
|
|
599
|
+
console.log(allowed.has('admin')); // true;
|
|
600
|
+
console.log(allowed.has('guest')); // false;
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
***
|
|
604
|
+
|
|
605
|
+
### higher()
|
|
606
|
+
|
|
607
|
+
```ts
|
|
608
|
+
higher(key): K | undefined;
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3074](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L3074)
|
|
612
|
+
|
|
613
|
+
Smallest key that is > the given key.
|
|
614
|
+
|
|
615
|
+
*
|
|
616
|
+
|
|
617
|
+
#### Parameters
|
|
618
|
+
|
|
619
|
+
##### key
|
|
620
|
+
|
|
621
|
+
`K`
|
|
622
|
+
|
|
623
|
+
#### Returns
|
|
624
|
+
|
|
625
|
+
`K` \| `undefined`
|
|
626
|
+
|
|
627
|
+
#### Example
|
|
628
|
+
|
|
629
|
+
```ts
|
|
630
|
+
// Smallest element strictly > target
|
|
631
|
+
const levels = new TreeSet<number>([1, 5, 10, 25, 50, 100]);
|
|
632
|
+
|
|
633
|
+
console.log(levels.higher(10)); // 25;
|
|
634
|
+
console.log(levels.higher(100)); // undefined;
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
***
|
|
638
|
+
|
|
639
|
+
### isEmpty()
|
|
640
|
+
|
|
641
|
+
```ts
|
|
642
|
+
isEmpty(): boolean;
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:234](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L234)
|
|
646
|
+
|
|
647
|
+
Whether the set is empty.
|
|
648
|
+
|
|
649
|
+
*
|
|
650
|
+
|
|
651
|
+
#### Returns
|
|
652
|
+
|
|
653
|
+
`boolean`
|
|
654
|
+
|
|
655
|
+
#### Example
|
|
656
|
+
|
|
657
|
+
```ts
|
|
658
|
+
// Check empty
|
|
659
|
+
console.log(new TreeSet().isEmpty()); // true;
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
***
|
|
663
|
+
|
|
664
|
+
### keys()
|
|
665
|
+
|
|
666
|
+
```ts
|
|
667
|
+
keys(): IterableIterator<K>;
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:971](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L971)
|
|
671
|
+
|
|
672
|
+
Iterate over keys in ascending order.
|
|
673
|
+
|
|
674
|
+
*
|
|
675
|
+
|
|
676
|
+
#### Returns
|
|
677
|
+
|
|
678
|
+
`IterableIterator`\<`K`\>
|
|
679
|
+
|
|
680
|
+
#### Example
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
// Get sorted keys
|
|
684
|
+
const ts = new TreeSet<number>([30, 10, 20]);
|
|
685
|
+
console.log([...ts.keys()]); // [10, 20, 30];
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
***
|
|
689
|
+
|
|
690
|
+
### last()
|
|
691
|
+
|
|
692
|
+
```ts
|
|
693
|
+
last(): K | undefined;
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2614](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2614)
|
|
697
|
+
|
|
698
|
+
Largest key in the set.
|
|
699
|
+
|
|
700
|
+
*
|
|
701
|
+
|
|
702
|
+
#### Returns
|
|
703
|
+
|
|
704
|
+
`K` \| `undefined`
|
|
705
|
+
|
|
706
|
+
#### Example
|
|
707
|
+
|
|
708
|
+
```ts
|
|
709
|
+
// Get the maximum element
|
|
710
|
+
const temps = new TreeSet<number>([18, 22, 15, 30, 25]);
|
|
711
|
+
console.log(temps.last()); // 30;
|
|
712
|
+
console.log(temps.first()); // 15;
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
***
|
|
716
|
+
|
|
717
|
+
### lower()
|
|
718
|
+
|
|
719
|
+
```ts
|
|
720
|
+
lower(key): K | undefined;
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3194](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L3194)
|
|
724
|
+
|
|
725
|
+
Largest key that is < the given key.
|
|
726
|
+
|
|
727
|
+
*
|
|
728
|
+
|
|
729
|
+
#### Parameters
|
|
730
|
+
|
|
731
|
+
##### key
|
|
732
|
+
|
|
733
|
+
`K`
|
|
734
|
+
|
|
735
|
+
#### Returns
|
|
736
|
+
|
|
737
|
+
`K` \| `undefined`
|
|
738
|
+
|
|
739
|
+
#### Example
|
|
740
|
+
|
|
741
|
+
```ts
|
|
742
|
+
// Largest element strictly < target
|
|
743
|
+
const tiers = new TreeSet<number>([100, 200, 500, 1000]);
|
|
744
|
+
|
|
745
|
+
console.log(tiers.lower(500)); // 200;
|
|
746
|
+
console.log(tiers.lower(100)); // undefined;
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
***
|
|
750
|
+
|
|
751
|
+
### map()
|
|
752
|
+
|
|
753
|
+
```ts
|
|
754
|
+
map<MK>(
|
|
755
|
+
callbackfn,
|
|
756
|
+
options?,
|
|
757
|
+
thisArg?): TreeSet<MK>;
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1523](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1523)
|
|
761
|
+
|
|
762
|
+
Create a new TreeSet by mapping each value to a new key.
|
|
763
|
+
|
|
764
|
+
This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
|
|
765
|
+
|
|
766
|
+
#### Type Parameters
|
|
767
|
+
|
|
768
|
+
##### MK
|
|
769
|
+
|
|
770
|
+
`MK`
|
|
771
|
+
|
|
772
|
+
#### Parameters
|
|
773
|
+
|
|
774
|
+
##### callbackfn
|
|
775
|
+
|
|
776
|
+
`TreeSetElementCallback`\<`K`, `MK`, `TreeSet`\<`K`, `K`\>\>
|
|
777
|
+
|
|
778
|
+
##### options?
|
|
779
|
+
|
|
780
|
+
`Omit`\<`TreeSetOptions`\<`MK`, `MK`\>, `"toElementFn"`\> & `object` = `{}`
|
|
781
|
+
|
|
782
|
+
##### thisArg?
|
|
783
|
+
|
|
784
|
+
`unknown`
|
|
785
|
+
|
|
786
|
+
#### Returns
|
|
787
|
+
|
|
788
|
+
`TreeSet`\<`MK`\>
|
|
789
|
+
|
|
790
|
+
#### Remarks
|
|
791
|
+
|
|
792
|
+
Time O(n log n) expected, Space O(n)
|
|
793
|
+
|
|
794
|
+
*
|
|
795
|
+
|
|
796
|
+
#### Example
|
|
797
|
+
|
|
798
|
+
```ts
|
|
799
|
+
// Transform
|
|
800
|
+
const ts = new TreeSet<number>([1, 2, 3]);
|
|
801
|
+
const doubled = ts.map(k => k * 2);
|
|
802
|
+
console.log([...doubled]); // [2, 4, 6];
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
***
|
|
806
|
+
|
|
807
|
+
### pollFirst()
|
|
808
|
+
|
|
809
|
+
```ts
|
|
810
|
+
pollFirst(): K | undefined;
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2656](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2656)
|
|
814
|
+
|
|
815
|
+
Remove and return the smallest key.
|
|
816
|
+
|
|
817
|
+
*
|
|
818
|
+
|
|
819
|
+
#### Returns
|
|
820
|
+
|
|
821
|
+
`K` \| `undefined`
|
|
822
|
+
|
|
823
|
+
#### Example
|
|
824
|
+
|
|
825
|
+
```ts
|
|
826
|
+
// Remove and return minimum
|
|
827
|
+
const queue = new TreeSet<number>([5, 1, 8, 3]);
|
|
828
|
+
|
|
829
|
+
console.log(queue.pollFirst()); // 1;
|
|
830
|
+
console.log(queue.pollFirst()); // 3;
|
|
831
|
+
console.log(queue.size); // 2;
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
***
|
|
835
|
+
|
|
836
|
+
### pollLast()
|
|
837
|
+
|
|
838
|
+
```ts
|
|
839
|
+
pollLast(): K | undefined;
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2700](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2700)
|
|
843
|
+
|
|
844
|
+
Remove and return the largest key.
|
|
845
|
+
|
|
846
|
+
*
|
|
847
|
+
|
|
848
|
+
#### Returns
|
|
849
|
+
|
|
850
|
+
`K` \| `undefined`
|
|
851
|
+
|
|
852
|
+
#### Example
|
|
853
|
+
|
|
854
|
+
```ts
|
|
855
|
+
// Remove and return maximum
|
|
856
|
+
const stack = new TreeSet<number>([10, 20, 30]);
|
|
857
|
+
|
|
858
|
+
console.log(stack.pollLast()); // 30;
|
|
859
|
+
console.log(stack.size); // 2;
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
***
|
|
863
|
+
|
|
864
|
+
### print()
|
|
865
|
+
|
|
866
|
+
```ts
|
|
867
|
+
print(): void;
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2509](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2509)
|
|
871
|
+
|
|
872
|
+
Print a human-friendly representation.
|
|
873
|
+
|
|
874
|
+
#### Returns
|
|
875
|
+
|
|
876
|
+
`void`
|
|
877
|
+
|
|
878
|
+
#### Remarks
|
|
879
|
+
|
|
880
|
+
Time O(n), Space O(n)
|
|
881
|
+
|
|
882
|
+
*
|
|
883
|
+
|
|
884
|
+
#### Example
|
|
885
|
+
|
|
886
|
+
```ts
|
|
887
|
+
// Display tree
|
|
888
|
+
const ts = new TreeSet<number>([1, 2, 3]);
|
|
889
|
+
expect(() => ts.print()).not.toThrow();
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
***
|
|
893
|
+
|
|
894
|
+
### rangeSearch()
|
|
895
|
+
|
|
896
|
+
```ts
|
|
897
|
+
rangeSearch(range, options?): K[];
|
|
898
|
+
```
|
|
899
|
+
|
|
900
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:3328](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L3328)
|
|
901
|
+
|
|
902
|
+
Return all keys in a given range.
|
|
903
|
+
|
|
904
|
+
#### Parameters
|
|
905
|
+
|
|
906
|
+
##### range
|
|
907
|
+
|
|
908
|
+
\[`K`, `K`\]
|
|
909
|
+
|
|
910
|
+
`[low, high]`
|
|
911
|
+
|
|
912
|
+
##### options?
|
|
913
|
+
|
|
914
|
+
`TreeSetRangeOptions` = `{}`
|
|
915
|
+
|
|
916
|
+
Inclusive/exclusive bounds (defaults to inclusive).
|
|
917
|
+
|
|
918
|
+
*
|
|
919
|
+
|
|
920
|
+
#### Returns
|
|
921
|
+
|
|
922
|
+
`K`[]
|
|
923
|
+
|
|
924
|
+
#### Example
|
|
925
|
+
|
|
926
|
+
```ts
|
|
927
|
+
// IP address blocklist with range checking
|
|
928
|
+
// Simplified: use numeric IP representation
|
|
929
|
+
const blocklist = new TreeSet<number>([
|
|
930
|
+
167772160, // 10.0.0.0
|
|
931
|
+
167772416, // 10.0.1.0
|
|
932
|
+
167772672, // 10.0.2.0
|
|
933
|
+
167773184 // 10.0.4.0
|
|
934
|
+
]);
|
|
935
|
+
|
|
936
|
+
// Check if any blocked IP is in range 10.0.1.0 - 10.0.3.0
|
|
937
|
+
const inRange = blocklist.rangeSearch([167772416, 167772928]);
|
|
938
|
+
console.log(inRange); // [167772416, 167772672];
|
|
939
|
+
|
|
940
|
+
// Quick membership check
|
|
941
|
+
console.log(blocklist.has(167772416)); // true;
|
|
942
|
+
console.log(blocklist.has(167772800)); // false;
|
|
943
|
+
```
|
|
944
|
+
|
|
945
|
+
***
|
|
946
|
+
|
|
947
|
+
### reduce()
|
|
948
|
+
|
|
949
|
+
```ts
|
|
950
|
+
reduce<A>(callbackfn, initialValue): A;
|
|
951
|
+
```
|
|
952
|
+
|
|
953
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1815](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1815)
|
|
954
|
+
|
|
955
|
+
Reduce values into a single accumulator.
|
|
956
|
+
|
|
957
|
+
#### Type Parameters
|
|
958
|
+
|
|
959
|
+
##### A
|
|
960
|
+
|
|
961
|
+
`A`
|
|
962
|
+
|
|
963
|
+
#### Parameters
|
|
964
|
+
|
|
965
|
+
##### callbackfn
|
|
966
|
+
|
|
967
|
+
`TreeSetReduceCallback`\<`K`, `A`, `TreeSet`\<`K`, `K`\>\>
|
|
968
|
+
|
|
969
|
+
##### initialValue
|
|
970
|
+
|
|
971
|
+
`A`
|
|
972
|
+
|
|
973
|
+
#### Returns
|
|
974
|
+
|
|
975
|
+
`A`
|
|
976
|
+
|
|
977
|
+
#### Remarks
|
|
978
|
+
|
|
979
|
+
Time O(n), Space O(1)
|
|
980
|
+
|
|
981
|
+
*
|
|
982
|
+
|
|
983
|
+
#### Example
|
|
984
|
+
|
|
985
|
+
```ts
|
|
986
|
+
// Aggregate
|
|
987
|
+
const ts = new TreeSet<number>([1, 2, 3]);
|
|
988
|
+
const sum = ts.reduce((acc, k) => acc + k, 0);
|
|
989
|
+
console.log(sum); // 6;
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
***
|
|
993
|
+
|
|
994
|
+
### some()
|
|
995
|
+
|
|
996
|
+
```ts
|
|
997
|
+
some(callbackfn, thisArg?): boolean;
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2091](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2091)
|
|
1001
|
+
|
|
1002
|
+
Test whether any value satisfies a predicate.
|
|
1003
|
+
|
|
1004
|
+
#### Parameters
|
|
1005
|
+
|
|
1006
|
+
##### callbackfn
|
|
1007
|
+
|
|
1008
|
+
`TreeSetElementCallback`\<`K`, `boolean`, `TreeSet`\<`K`, `K`\>\>
|
|
1009
|
+
|
|
1010
|
+
##### thisArg?
|
|
1011
|
+
|
|
1012
|
+
`unknown`
|
|
1013
|
+
|
|
1014
|
+
#### Returns
|
|
1015
|
+
|
|
1016
|
+
`boolean`
|
|
1017
|
+
|
|
1018
|
+
#### Remarks
|
|
1019
|
+
|
|
1020
|
+
Time O(n), Space O(1)
|
|
1021
|
+
|
|
1022
|
+
*
|
|
1023
|
+
|
|
1024
|
+
#### Example
|
|
1025
|
+
|
|
1026
|
+
```ts
|
|
1027
|
+
// Test any
|
|
1028
|
+
const ts = new TreeSet<number>([1, 3, 5]);
|
|
1029
|
+
console.log(ts.some(k => k === 3)); // true;
|
|
1030
|
+
```
|
|
1031
|
+
|
|
1032
|
+
***
|
|
1033
|
+
|
|
1034
|
+
### toArray()
|
|
1035
|
+
|
|
1036
|
+
```ts
|
|
1037
|
+
toArray(): K[];
|
|
1038
|
+
```
|
|
1039
|
+
|
|
1040
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:2374](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L2374)
|
|
1041
|
+
|
|
1042
|
+
Materialize the set into an array of keys.
|
|
1043
|
+
|
|
1044
|
+
#### Returns
|
|
1045
|
+
|
|
1046
|
+
`K`[]
|
|
1047
|
+
|
|
1048
|
+
#### Remarks
|
|
1049
|
+
|
|
1050
|
+
Time O(n), Space O(n)
|
|
1051
|
+
|
|
1052
|
+
*
|
|
1053
|
+
|
|
1054
|
+
#### Example
|
|
1055
|
+
|
|
1056
|
+
```ts
|
|
1057
|
+
// Convert to array
|
|
1058
|
+
const ts = new TreeSet<number>([3, 1, 2]);
|
|
1059
|
+
console.log(ts.toArray()); // [1, 2, 3];
|
|
1060
|
+
```
|
|
1061
|
+
|
|
1062
|
+
***
|
|
1063
|
+
|
|
1064
|
+
### values()
|
|
1065
|
+
|
|
1066
|
+
```ts
|
|
1067
|
+
values(): IterableIterator<K>;
|
|
1068
|
+
```
|
|
1069
|
+
|
|
1070
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:1107](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L1107)
|
|
1071
|
+
|
|
1072
|
+
Iterate over values in ascending order.
|
|
1073
|
+
|
|
1074
|
+
Note: for Set-like containers, `values()` is the same as `keys()`.
|
|
1075
|
+
|
|
1076
|
+
*
|
|
1077
|
+
|
|
1078
|
+
#### Returns
|
|
1079
|
+
|
|
1080
|
+
`IterableIterator`\<`K`\>
|
|
1081
|
+
|
|
1082
|
+
#### Example
|
|
1083
|
+
|
|
1084
|
+
```ts
|
|
1085
|
+
// Get values (same as keys for Set)
|
|
1086
|
+
const ts = new TreeSet<number>([2, 1, 3]);
|
|
1087
|
+
console.log([...ts.values()]); // [1, 2, 3];
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
***
|
|
1091
|
+
|
|
1092
|
+
### createDefaultComparator()
|
|
1093
|
+
|
|
1094
|
+
```ts
|
|
1095
|
+
static createDefaultComparator<K>(): Comparator<K>;
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
Defined in: [data-structures/binary-tree/tree-set.ts:71](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-set.ts#L71)
|
|
1099
|
+
|
|
1100
|
+
Create the strict default comparator.
|
|
1101
|
+
|
|
1102
|
+
Supports:
|
|
1103
|
+
- `number` (rejects `NaN`; treats `-0` and `0` as equal)
|
|
1104
|
+
- `string`
|
|
1105
|
+
- `Date` (orders by `getTime()`, rejects invalid dates)
|
|
1106
|
+
|
|
1107
|
+
For other key types, a custom comparator must be provided.
|
|
1108
|
+
|
|
1109
|
+
#### Type Parameters
|
|
1110
|
+
|
|
1111
|
+
##### K
|
|
1112
|
+
|
|
1113
|
+
`K`
|
|
1114
|
+
|
|
1115
|
+
#### Returns
|
|
1116
|
+
|
|
1117
|
+
`Comparator`\<`K`\>
|