data-structure-typed 2.5.0 → 2.5.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.
Files changed (246) hide show
  1. package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +12984 -0
  2. package/.vitepress/cache/deps_temp_51f5f1b0/package.json +3 -0
  3. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +4505 -0
  4. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +9731 -0
  5. package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +347 -0
  6. package/CHANGELOG.md +5 -1
  7. package/README.md +124 -29
  8. package/dist/cjs/binary-tree.cjs +26282 -0
  9. package/dist/cjs/graph.cjs +5422 -0
  10. package/dist/cjs/hash.cjs +1310 -0
  11. package/dist/cjs/heap.cjs +1602 -0
  12. package/dist/cjs/index.cjs +31257 -14673
  13. package/dist/cjs/linked-list.cjs +4576 -0
  14. package/dist/cjs/matrix.cjs +1080 -0
  15. package/dist/cjs/priority-queue.cjs +1376 -0
  16. package/dist/cjs/queue.cjs +4264 -0
  17. package/dist/cjs/stack.cjs +907 -0
  18. package/dist/cjs/trie.cjs +1223 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +26319 -0
  20. package/dist/cjs-legacy/graph.cjs +5420 -0
  21. package/dist/cjs-legacy/hash.cjs +1310 -0
  22. package/dist/cjs-legacy/heap.cjs +1599 -0
  23. package/dist/cjs-legacy/index.cjs +31268 -14679
  24. package/dist/cjs-legacy/linked-list.cjs +4582 -0
  25. package/dist/cjs-legacy/matrix.cjs +1083 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +1374 -0
  27. package/dist/cjs-legacy/queue.cjs +4262 -0
  28. package/dist/cjs-legacy/stack.cjs +907 -0
  29. package/dist/cjs-legacy/trie.cjs +1222 -0
  30. package/dist/esm/binary-tree.mjs +26267 -0
  31. package/dist/esm/graph.mjs +5409 -0
  32. package/dist/esm/hash.mjs +1307 -0
  33. package/dist/esm/heap.mjs +1596 -0
  34. package/dist/esm/index.mjs +31254 -14674
  35. package/dist/esm/linked-list.mjs +4569 -0
  36. package/dist/esm/matrix.mjs +1076 -0
  37. package/dist/esm/priority-queue.mjs +1372 -0
  38. package/dist/esm/queue.mjs +4260 -0
  39. package/dist/esm/stack.mjs +905 -0
  40. package/dist/esm/trie.mjs +1220 -0
  41. package/dist/esm-legacy/binary-tree.mjs +26304 -0
  42. package/dist/esm-legacy/graph.mjs +5407 -0
  43. package/dist/esm-legacy/hash.mjs +1307 -0
  44. package/dist/esm-legacy/heap.mjs +1593 -0
  45. package/dist/esm-legacy/index.mjs +31265 -14680
  46. package/dist/esm-legacy/linked-list.mjs +4575 -0
  47. package/dist/esm-legacy/matrix.mjs +1079 -0
  48. package/dist/esm-legacy/priority-queue.mjs +1370 -0
  49. package/dist/esm-legacy/queue.mjs +4258 -0
  50. package/dist/esm-legacy/stack.mjs +905 -0
  51. package/dist/esm-legacy/trie.mjs +1219 -0
  52. package/dist/types/common/error.d.ts +9 -0
  53. package/dist/types/common/index.d.ts +1 -1
  54. package/dist/types/data-structures/base/index.d.ts +1 -0
  55. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  56. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  57. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
  58. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  59. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  60. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  61. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  62. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  63. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  64. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  65. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  66. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  67. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  68. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  69. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  70. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  71. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  72. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  73. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  74. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  75. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  76. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  77. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  78. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  79. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  80. package/dist/types/interfaces/graph.d.ts +1 -1
  81. package/dist/types/types/common.d.ts +2 -2
  82. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  83. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  84. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  85. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  86. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  87. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  88. package/dist/types/types/utils/validate-type.d.ts +4 -4
  89. package/dist/umd/data-structure-typed.js +31196 -14608
  90. package/dist/umd/data-structure-typed.min.js +11 -5
  91. package/docs-site-docusaurus/README.md +41 -0
  92. package/docs-site-docusaurus/docs/api/README.md +52 -0
  93. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6644 -0
  94. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
  95. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
  96. package/docs-site-docusaurus/docs/api/classes/BST.md +6293 -0
  97. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
  98. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
  99. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
  100. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
  101. package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
  102. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
  103. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
  104. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
  105. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
  106. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
  107. package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
  108. package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
  109. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
  110. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
  111. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
  112. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
  113. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
  114. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
  115. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
  116. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
  117. package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
  118. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
  119. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
  120. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
  121. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
  122. package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
  123. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
  124. package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
  125. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6888 -0
  126. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
  127. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
  128. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
  129. package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
  130. package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
  131. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1389 -0
  132. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1591 -0
  133. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1246 -0
  134. package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
  135. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
  136. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
  137. package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
  138. package/docs-site-docusaurus/docs/guide/architecture.md +615 -0
  139. package/docs-site-docusaurus/docs/guide/concepts.md +451 -0
  140. package/docs-site-docusaurus/docs/guide/faq.md +180 -0
  141. package/docs-site-docusaurus/docs/guide/guides.md +597 -0
  142. package/docs-site-docusaurus/docs/guide/installation.md +62 -0
  143. package/docs-site-docusaurus/docs/guide/integrations.md +825 -0
  144. package/docs-site-docusaurus/docs/guide/overview.md +645 -0
  145. package/docs-site-docusaurus/docs/guide/performance.md +835 -0
  146. package/docs-site-docusaurus/docs/guide/quick-start.md +104 -0
  147. package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
  148. package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
  149. package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
  150. package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
  151. package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
  152. package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
  153. package/docs-site-docusaurus/docusaurus.config.ts +159 -0
  154. package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
  155. package/docs-site-docusaurus/package-lock.json +18667 -0
  156. package/docs-site-docusaurus/package.json +50 -0
  157. package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
  158. package/docs-site-docusaurus/sidebars.ts +23 -0
  159. package/docs-site-docusaurus/sort-protected.mjs +87 -0
  160. package/docs-site-docusaurus/src/css/custom.css +96 -0
  161. package/docs-site-docusaurus/src/pages/index.module.css +13 -0
  162. package/docs-site-docusaurus/src/pages/index.tsx +120 -0
  163. package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
  164. package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
  165. package/docs-site-docusaurus/static/.nojekyll +0 -0
  166. package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
  167. package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
  168. package/docs-site-docusaurus/static/img/favicon.ico +0 -0
  169. package/docs-site-docusaurus/static/img/favicon.png +0 -0
  170. package/docs-site-docusaurus/static/img/logo-180.png +0 -0
  171. package/docs-site-docusaurus/static/img/logo.jpg +0 -0
  172. package/docs-site-docusaurus/static/img/logo.png +0 -0
  173. package/docs-site-docusaurus/static/img/logo.svg +1 -0
  174. package/docs-site-docusaurus/static/img/og-image.png +0 -0
  175. package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
  176. package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
  177. package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
  178. package/docs-site-docusaurus/static/llms.txt +37 -0
  179. package/docs-site-docusaurus/static/robots.txt +4 -0
  180. package/docs-site-docusaurus/typedoc.json +23 -0
  181. package/llms.txt +37 -0
  182. package/package.json +159 -55
  183. package/src/common/error.ts +19 -1
  184. package/src/common/index.ts +1 -1
  185. package/src/data-structures/base/index.ts +1 -0
  186. package/src/data-structures/base/iterable-element-base.ts +3 -2
  187. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  188. package/src/data-structures/base/linear-base.ts +3 -3
  189. package/src/data-structures/binary-tree/avl-tree.ts +287 -0
  190. package/src/data-structures/binary-tree/binary-indexed-tree.ts +327 -5
  191. package/src/data-structures/binary-tree/binary-tree.ts +581 -6
  192. package/src/data-structures/binary-tree/bst.ts +922 -7
  193. package/src/data-structures/binary-tree/red-black-tree.ts +453 -0
  194. package/src/data-structures/binary-tree/segment-tree.ts +139 -2
  195. package/src/data-structures/binary-tree/tree-map.ts +3300 -495
  196. package/src/data-structures/binary-tree/tree-multi-map.ts +3384 -563
  197. package/src/data-structures/binary-tree/tree-multi-set.ts +2757 -493
  198. package/src/data-structures/binary-tree/tree-set.ts +3122 -440
  199. package/src/data-structures/graph/abstract-graph.ts +6 -6
  200. package/src/data-structures/graph/directed-graph.ts +230 -0
  201. package/src/data-structures/graph/undirected-graph.ts +207 -0
  202. package/src/data-structures/hash/hash-map.ts +270 -19
  203. package/src/data-structures/heap/heap.ts +326 -4
  204. package/src/data-structures/heap/max-heap.ts +2 -2
  205. package/src/data-structures/linked-list/doubly-linked-list.ts +394 -3
  206. package/src/data-structures/linked-list/singly-linked-list.ts +348 -3
  207. package/src/data-structures/linked-list/skip-linked-list.ts +421 -7
  208. package/src/data-structures/matrix/matrix.ts +194 -10
  209. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  210. package/src/data-structures/queue/deque.ts +350 -5
  211. package/src/data-structures/queue/queue.ts +276 -0
  212. package/src/data-structures/stack/stack.ts +230 -0
  213. package/src/data-structures/trie/trie.ts +283 -7
  214. package/src/interfaces/graph.ts +1 -1
  215. package/src/types/common.ts +2 -2
  216. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  217. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  218. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  219. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  220. package/src/types/data-structures/heap/heap.ts +1 -0
  221. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  222. package/src/types/utils/validate-type.ts +4 -4
  223. package/vercel.json +6 -0
  224. package/dist/leetcode/avl-tree-counter.mjs +0 -2957
  225. package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
  226. package/dist/leetcode/avl-tree.mjs +0 -2720
  227. package/dist/leetcode/binary-tree.mjs +0 -1594
  228. package/dist/leetcode/bst.mjs +0 -2398
  229. package/dist/leetcode/deque.mjs +0 -683
  230. package/dist/leetcode/directed-graph.mjs +0 -1733
  231. package/dist/leetcode/doubly-linked-list.mjs +0 -709
  232. package/dist/leetcode/hash-map.mjs +0 -493
  233. package/dist/leetcode/heap.mjs +0 -542
  234. package/dist/leetcode/max-heap.mjs +0 -375
  235. package/dist/leetcode/max-priority-queue.mjs +0 -383
  236. package/dist/leetcode/min-heap.mjs +0 -363
  237. package/dist/leetcode/min-priority-queue.mjs +0 -371
  238. package/dist/leetcode/priority-queue.mjs +0 -363
  239. package/dist/leetcode/queue.mjs +0 -943
  240. package/dist/leetcode/red-black-tree.mjs +0 -2765
  241. package/dist/leetcode/singly-linked-list.mjs +0 -754
  242. package/dist/leetcode/stack.mjs +0 -217
  243. package/dist/leetcode/tree-counter.mjs +0 -3039
  244. package/dist/leetcode/tree-multi-map.mjs +0 -2913
  245. package/dist/leetcode/trie.mjs +0 -413
  246. package/dist/leetcode/undirected-graph.mjs +0 -1650
@@ -0,0 +1,1246 @@
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/8292cb978daf85ebe846186c7c7572aece04fb7b/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/8292cb978daf85ebe846186c7c7572aece04fb7b/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/8292cb978daf85ebe846186c7c7572aece04fb7b/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:468](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L468)
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:3483](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3483)
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:1012](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L1012)
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:4341](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L4341)
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:840](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L840)
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:1523](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L1523)
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:2406](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L2406)
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:2056](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L2056)
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:2757](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L2757)
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:3176](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3176)
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:3633](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3633)
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:1700](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L1700)
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
+ `unknown`
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
+ ### getByRank()
568
+
569
+ ```ts
570
+ getByRank(k): K | undefined;
571
+ ```
572
+
573
+ Defined in: [data-structures/binary-tree/tree-set.ts:4127](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L4127)
574
+
575
+ Returns the element at the k-th position in tree order (0-indexed).
576
+
577
+ #### Parameters
578
+
579
+ ##### k
580
+
581
+ `number`
582
+
583
+ #### Returns
584
+
585
+ `K` \| `undefined`
586
+
587
+ #### Remarks
588
+
589
+ Time O(log n). Requires `enableOrderStatistic: true`.
590
+
591
+ *
592
+
593
+ #### Example
594
+
595
+ ```ts
596
+ // Find k-th element in a TreeSet
597
+ const set = new TreeSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
598
+ console.log(set.getByRank(0)); // 10;
599
+ console.log(set.getByRank(2)); // 30;
600
+ console.log(set.getRank(30)); // 2;
601
+ ```
602
+
603
+ ***
604
+
605
+ ### getRank()
606
+
607
+ ```ts
608
+ getRank(key): number;
609
+ ```
610
+
611
+ Defined in: [data-structures/binary-tree/tree-set.ts:4145](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L4145)
612
+
613
+ Returns the 0-based rank of a key (number of elements that precede it in tree order).
614
+
615
+ #### Parameters
616
+
617
+ ##### key
618
+
619
+ `K`
620
+
621
+ #### Returns
622
+
623
+ `number`
624
+
625
+ #### Remarks
626
+
627
+ Time O(log n). Requires `enableOrderStatistic: true`.
628
+ *
629
+
630
+ #### Example
631
+
632
+ ```ts
633
+ // Get the rank of a key in sorted order
634
+ const tree = new TreeSet<number>(
635
+ [10, 20, 30, 40, 50],
636
+ { enableOrderStatistic: true }
637
+ );
638
+ console.log(tree.getRank(10)); // 0; // smallest → rank 0
639
+ console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
640
+ console.log(tree.getRank(50)); // 4; // largest → rank 4
641
+ console.log(tree.getRank(25)); // 2;
642
+ ```
643
+
644
+ ***
645
+
646
+ ### has()
647
+
648
+ ```ts
649
+ has(key): boolean;
650
+ ```
651
+
652
+ Defined in: [data-structures/binary-tree/tree-set.ts:654](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L654)
653
+
654
+ Test whether a key exists.
655
+
656
+ #### Parameters
657
+
658
+ ##### key
659
+
660
+ `K`
661
+
662
+ #### Returns
663
+
664
+ `boolean`
665
+
666
+ #### Remarks
667
+
668
+ Expected time O(log n)
669
+
670
+ *
671
+
672
+ #### Example
673
+
674
+ ```ts
675
+ // Checking membership in a sorted collection
676
+ const allowed = new TreeSet<string>(['admin', 'editor', 'viewer']);
677
+
678
+ console.log(allowed.has('admin')); // true;
679
+ console.log(allowed.has('guest')); // false;
680
+ ```
681
+
682
+ ***
683
+
684
+ ### higher()
685
+
686
+ ```ts
687
+ higher(key): K | undefined;
688
+ ```
689
+
690
+ Defined in: [data-structures/binary-tree/tree-set.ts:3781](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3781)
691
+
692
+ Smallest key that is > the given key.
693
+
694
+ *
695
+
696
+ #### Parameters
697
+
698
+ ##### key
699
+
700
+ `K`
701
+
702
+ #### Returns
703
+
704
+ `K` \| `undefined`
705
+
706
+ #### Example
707
+
708
+ ```ts
709
+ // Smallest element strictly > target
710
+ const levels = new TreeSet<number>([1, 5, 10, 25, 50, 100]);
711
+
712
+ console.log(levels.higher(10)); // 25;
713
+ console.log(levels.higher(100)); // undefined;
714
+ ```
715
+
716
+ ***
717
+
718
+ ### isEmpty()
719
+
720
+ ```ts
721
+ isEmpty(): boolean;
722
+ ```
723
+
724
+ Defined in: [data-structures/binary-tree/tree-set.ts:269](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L269)
725
+
726
+ Whether the set is empty.
727
+
728
+ *
729
+
730
+ #### Returns
731
+
732
+ `boolean`
733
+
734
+ #### Example
735
+
736
+ ```ts
737
+ // Check empty
738
+ console.log(new TreeSet().isEmpty()); // true;
739
+ ```
740
+
741
+ ***
742
+
743
+ ### keys()
744
+
745
+ ```ts
746
+ keys(): IterableIterator<K>;
747
+ ```
748
+
749
+ Defined in: [data-structures/binary-tree/tree-set.ts:1181](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L1181)
750
+
751
+ Iterate over keys in ascending order.
752
+
753
+ *
754
+
755
+ #### Returns
756
+
757
+ `IterableIterator`\<`K`\>
758
+
759
+ #### Example
760
+
761
+ ```ts
762
+ // Get sorted keys
763
+ const ts = new TreeSet<number>([30, 10, 20]);
764
+ console.log([...ts.keys()]); // [10, 20, 30];
765
+ ```
766
+
767
+ ***
768
+
769
+ ### last()
770
+
771
+ ```ts
772
+ last(): K | undefined;
773
+ ```
774
+
775
+ Defined in: [data-structures/binary-tree/tree-set.ts:3223](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3223)
776
+
777
+ Largest key in the set.
778
+
779
+ *
780
+
781
+ #### Returns
782
+
783
+ `K` \| `undefined`
784
+
785
+ #### Example
786
+
787
+ ```ts
788
+ // Get the maximum element
789
+ const temps = new TreeSet<number>([18, 22, 15, 30, 25]);
790
+ console.log(temps.last()); // 30;
791
+ console.log(temps.first()); // 15;
792
+ ```
793
+
794
+ ***
795
+
796
+ ### lower()
797
+
798
+ ```ts
799
+ lower(key): K | undefined;
800
+ ```
801
+
802
+ Defined in: [data-structures/binary-tree/tree-set.ts:3929](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3929)
803
+
804
+ Largest key that is < the given key.
805
+
806
+ *
807
+
808
+ #### Parameters
809
+
810
+ ##### key
811
+
812
+ `K`
813
+
814
+ #### Returns
815
+
816
+ `K` \| `undefined`
817
+
818
+ #### Example
819
+
820
+ ```ts
821
+ // Largest element strictly < target
822
+ const tiers = new TreeSet<number>([100, 200, 500, 1000]);
823
+
824
+ console.log(tiers.lower(500)); // 200;
825
+ console.log(tiers.lower(100)); // undefined;
826
+ ```
827
+
828
+ ***
829
+
830
+ ### map()
831
+
832
+ ```ts
833
+ map<MK>(
834
+ callbackfn,
835
+ options?,
836
+ thisArg?): TreeSet<MK>;
837
+ ```
838
+
839
+ Defined in: [data-structures/binary-tree/tree-set.ts:1873](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L1873)
840
+
841
+ Create a new TreeSet by mapping each value to a new key.
842
+
843
+ This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
844
+
845
+ #### Type Parameters
846
+
847
+ ##### MK
848
+
849
+ `MK`
850
+
851
+ #### Parameters
852
+
853
+ ##### callbackfn
854
+
855
+ `TreeSetElementCallback`\<`K`, `MK`, `TreeSet`\<`K`, `K`\>\>
856
+
857
+ ##### options?
858
+
859
+ `Omit`\<`TreeSetOptions`\<`MK`, `MK`\>, `"toElementFn"`\> & `object` = `{}`
860
+
861
+ ##### thisArg?
862
+
863
+ `unknown`
864
+
865
+ #### Returns
866
+
867
+ `TreeSet`\<`MK`\>
868
+
869
+ #### Remarks
870
+
871
+ Time O(n log n) expected, Space O(n)
872
+
873
+ *
874
+
875
+ #### Example
876
+
877
+ ```ts
878
+ // Transform
879
+ const ts = new TreeSet<number>([1, 2, 3]);
880
+ const doubled = ts.map(k => k * 2);
881
+ console.log([...doubled]); // [2, 4, 6];
882
+ ```
883
+
884
+ ***
885
+
886
+ ### pollFirst()
887
+
888
+ ```ts
889
+ pollFirst(): K | undefined;
890
+ ```
891
+
892
+ Defined in: [data-structures/binary-tree/tree-set.ts:3272](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3272)
893
+
894
+ Remove and return the smallest key.
895
+
896
+ *
897
+
898
+ #### Returns
899
+
900
+ `K` \| `undefined`
901
+
902
+ #### Example
903
+
904
+ ```ts
905
+ // Remove and return minimum
906
+ const queue = new TreeSet<number>([5, 1, 8, 3]);
907
+
908
+ console.log(queue.pollFirst()); // 1;
909
+ console.log(queue.pollFirst()); // 3;
910
+ console.log(queue.size); // 2;
911
+ ```
912
+
913
+ ***
914
+
915
+ ### pollLast()
916
+
917
+ ```ts
918
+ pollLast(): K | undefined;
919
+ ```
920
+
921
+ Defined in: [data-structures/binary-tree/tree-set.ts:3323](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3323)
922
+
923
+ Remove and return the largest key.
924
+
925
+ *
926
+
927
+ #### Returns
928
+
929
+ `K` \| `undefined`
930
+
931
+ #### Example
932
+
933
+ ```ts
934
+ // Remove and return maximum
935
+ const stack = new TreeSet<number>([10, 20, 30]);
936
+
937
+ console.log(stack.pollLast()); // 30;
938
+ console.log(stack.size); // 2;
939
+ ```
940
+
941
+ ***
942
+
943
+ ### print()
944
+
945
+ ```ts
946
+ print(): void;
947
+ ```
948
+
949
+ Defined in: [data-structures/binary-tree/tree-set.ts:3104](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L3104)
950
+
951
+ Print a human-friendly representation.
952
+
953
+ #### Returns
954
+
955
+ `void`
956
+
957
+ #### Remarks
958
+
959
+ Time O(n), Space O(n)
960
+
961
+ *
962
+
963
+ #### Example
964
+
965
+ ```ts
966
+ // Display tree
967
+ const ts = new TreeSet<number>([1, 2, 3]);
968
+ expect(() => ts.print()).not.toThrow();
969
+ ```
970
+
971
+ ***
972
+
973
+ ### rangeByRank()
974
+
975
+ ```ts
976
+ rangeByRank(start, end): K[];
977
+ ```
978
+
979
+ Defined in: [data-structures/binary-tree/tree-set.ts:4168](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L4168)
980
+
981
+ Returns elements by rank range (0-indexed, inclusive on both ends).
982
+
983
+ #### Parameters
984
+
985
+ ##### start
986
+
987
+ `number`
988
+
989
+ ##### end
990
+
991
+ `number`
992
+
993
+ #### Returns
994
+
995
+ `K`[]
996
+
997
+ #### Remarks
998
+
999
+ Time O(log n + k). Requires `enableOrderStatistic: true`.
1000
+
1001
+ *
1002
+
1003
+ #### Example
1004
+
1005
+ ```ts
1006
+ // Pagination with rangeByRank
1007
+ const tree = new TreeSet<number>(
1008
+ [10, 20, 30, 40, 50, 60, 70, 80, 90],
1009
+ { enableOrderStatistic: true }
1010
+ );
1011
+ const pageSize = 3;
1012
+
1013
+ // Page 1
1014
+ console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
1015
+ // Page 2
1016
+ console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
1017
+ // Page 3
1018
+ console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
1019
+ ```
1020
+
1021
+ ***
1022
+
1023
+ ### rangeSearch()
1024
+
1025
+ ```ts
1026
+ rangeSearch(range, options?): K[];
1027
+ ```
1028
+
1029
+ Defined in: [data-structures/binary-tree/tree-set.ts:4091](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L4091)
1030
+
1031
+ Return all keys in a given range.
1032
+
1033
+ #### Parameters
1034
+
1035
+ ##### range
1036
+
1037
+ \[`K`, `K`\]
1038
+
1039
+ `[low, high]`
1040
+
1041
+ ##### options?
1042
+
1043
+ `TreeSetRangeOptions` = `{}`
1044
+
1045
+ Inclusive/exclusive bounds (defaults to inclusive).
1046
+
1047
+ *
1048
+
1049
+ #### Returns
1050
+
1051
+ `K`[]
1052
+
1053
+ #### Example
1054
+
1055
+ ```ts
1056
+ // IP address blocklist with range checking
1057
+ // Simplified: use numeric IP representation
1058
+ const blocklist = new TreeSet<number>([
1059
+ 167772160, // 10.0.0.0
1060
+ 167772416, // 10.0.1.0
1061
+ 167772672, // 10.0.2.0
1062
+ 167773184 // 10.0.4.0
1063
+ ]);
1064
+
1065
+ // Check if any blocked IP is in range 10.0.1.0 - 10.0.3.0
1066
+ const inRange = blocklist.rangeSearch([167772416, 167772928]);
1067
+ console.log(inRange); // [167772416, 167772672];
1068
+
1069
+ // Quick membership check
1070
+ console.log(blocklist.has(167772416)); // true;
1071
+ console.log(blocklist.has(167772800)); // false;
1072
+ ```
1073
+
1074
+ ***
1075
+
1076
+ ### reduce()
1077
+
1078
+ ```ts
1079
+ reduce<A>(callbackfn, initialValue): A;
1080
+ ```
1081
+
1082
+ Defined in: [data-structures/binary-tree/tree-set.ts:2235](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L2235)
1083
+
1084
+ Reduce values into a single accumulator.
1085
+
1086
+ #### Type Parameters
1087
+
1088
+ ##### A
1089
+
1090
+ `A`
1091
+
1092
+ #### Parameters
1093
+
1094
+ ##### callbackfn
1095
+
1096
+ `TreeSetReduceCallback`\<`K`, `A`, `TreeSet`\<`K`, `K`\>\>
1097
+
1098
+ ##### initialValue
1099
+
1100
+ `A`
1101
+
1102
+ #### Returns
1103
+
1104
+ `A`
1105
+
1106
+ #### Remarks
1107
+
1108
+ Time O(n), Space O(1)
1109
+
1110
+ *
1111
+
1112
+ #### Example
1113
+
1114
+ ```ts
1115
+ // Aggregate
1116
+ const ts = new TreeSet<number>([1, 2, 3]);
1117
+ const sum = ts.reduce((acc, k) => acc + k, 0);
1118
+ console.log(sum); // 6;
1119
+ ```
1120
+
1121
+ ***
1122
+
1123
+ ### some()
1124
+
1125
+ ```ts
1126
+ some(callbackfn, thisArg?): boolean;
1127
+ ```
1128
+
1129
+ Defined in: [data-structures/binary-tree/tree-set.ts:2581](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L2581)
1130
+
1131
+ Test whether any value satisfies a predicate.
1132
+
1133
+ #### Parameters
1134
+
1135
+ ##### callbackfn
1136
+
1137
+ `TreeSetElementCallback`\<`K`, `boolean`, `TreeSet`\<`K`, `K`\>\>
1138
+
1139
+ ##### thisArg?
1140
+
1141
+ `unknown`
1142
+
1143
+ #### Returns
1144
+
1145
+ `boolean`
1146
+
1147
+ #### Remarks
1148
+
1149
+ Time O(n), Space O(1)
1150
+
1151
+ *
1152
+
1153
+ #### Example
1154
+
1155
+ ```ts
1156
+ // Test any
1157
+ const ts = new TreeSet<number>([1, 3, 5]);
1158
+ console.log(ts.some(k => k === 3)); // true;
1159
+ ```
1160
+
1161
+ ***
1162
+
1163
+ ### toArray()
1164
+
1165
+ ```ts
1166
+ toArray(): K[];
1167
+ ```
1168
+
1169
+ Defined in: [data-structures/binary-tree/tree-set.ts:2934](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L2934)
1170
+
1171
+ Materialize the set into an array of keys.
1172
+
1173
+ #### Returns
1174
+
1175
+ `K`[]
1176
+
1177
+ #### Remarks
1178
+
1179
+ Time O(n), Space O(n)
1180
+
1181
+ *
1182
+
1183
+ #### Example
1184
+
1185
+ ```ts
1186
+ // Convert to array
1187
+ const ts = new TreeSet<number>([3, 1, 2]);
1188
+ console.log(ts.toArray()); // [1, 2, 3];
1189
+ ```
1190
+
1191
+ ***
1192
+
1193
+ ### values()
1194
+
1195
+ ```ts
1196
+ values(): IterableIterator<K>;
1197
+ ```
1198
+
1199
+ Defined in: [data-structures/binary-tree/tree-set.ts:1352](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L1352)
1200
+
1201
+ Iterate over values in ascending order.
1202
+
1203
+ Note: for Set-like containers, `values()` is the same as `keys()`.
1204
+
1205
+ *
1206
+
1207
+ #### Returns
1208
+
1209
+ `IterableIterator`\<`K`\>
1210
+
1211
+ #### Example
1212
+
1213
+ ```ts
1214
+ // Get values (same as keys for Set)
1215
+ const ts = new TreeSet<number>([2, 1, 3]);
1216
+ console.log([...ts.values()]); // [1, 2, 3];
1217
+ ```
1218
+
1219
+ ***
1220
+
1221
+ ### createDefaultComparator()
1222
+
1223
+ ```ts
1224
+ static createDefaultComparator<K>(): Comparator<K>;
1225
+ ```
1226
+
1227
+ Defined in: [data-structures/binary-tree/tree-set.ts:71](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-set.ts#L71)
1228
+
1229
+ Create the strict default comparator.
1230
+
1231
+ Supports:
1232
+ - `number` (rejects `NaN`; treats `-0` and `0` as equal)
1233
+ - `string`
1234
+ - `Date` (orders by `getTime()`, rejects invalid dates)
1235
+
1236
+ For other key types, a custom comparator must be provided.
1237
+
1238
+ #### Type Parameters
1239
+
1240
+ ##### K
1241
+
1242
+ `K`
1243
+
1244
+ #### Returns
1245
+
1246
+ `Comparator`\<`K`\>