data-structure-typed 2.5.0 → 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.
Files changed (222) 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 +3 -1
  7. package/README.md +63 -26
  8. package/dist/cjs/binary-tree.cjs +23698 -0
  9. package/dist/cjs/graph.cjs +5236 -0
  10. package/dist/cjs/hash.cjs +1262 -0
  11. package/dist/cjs/heap.cjs +1540 -0
  12. package/dist/cjs/index.cjs +28244 -14795
  13. package/dist/cjs/linked-list.cjs +4370 -0
  14. package/dist/cjs/matrix.cjs +1042 -0
  15. package/dist/cjs/priority-queue.cjs +1314 -0
  16. package/dist/cjs/queue.cjs +4090 -0
  17. package/dist/cjs/stack.cjs +861 -0
  18. package/dist/cjs/trie.cjs +1173 -0
  19. package/dist/cjs-legacy/binary-tree.cjs +23730 -0
  20. package/dist/cjs-legacy/graph.cjs +5234 -0
  21. package/dist/cjs-legacy/hash.cjs +1262 -0
  22. package/dist/cjs-legacy/heap.cjs +1537 -0
  23. package/dist/cjs-legacy/index.cjs +28239 -14790
  24. package/dist/cjs-legacy/linked-list.cjs +4376 -0
  25. package/dist/cjs-legacy/matrix.cjs +1045 -0
  26. package/dist/cjs-legacy/priority-queue.cjs +1312 -0
  27. package/dist/cjs-legacy/queue.cjs +4088 -0
  28. package/dist/cjs-legacy/stack.cjs +861 -0
  29. package/dist/cjs-legacy/trie.cjs +1172 -0
  30. package/dist/esm/binary-tree.mjs +23683 -0
  31. package/dist/esm/graph.mjs +5223 -0
  32. package/dist/esm/hash.mjs +1259 -0
  33. package/dist/esm/heap.mjs +1534 -0
  34. package/dist/esm/index.mjs +28242 -14796
  35. package/dist/esm/linked-list.mjs +4363 -0
  36. package/dist/esm/matrix.mjs +1038 -0
  37. package/dist/esm/priority-queue.mjs +1310 -0
  38. package/dist/esm/queue.mjs +4086 -0
  39. package/dist/esm/stack.mjs +859 -0
  40. package/dist/esm/trie.mjs +1170 -0
  41. package/dist/esm-legacy/binary-tree.mjs +23715 -0
  42. package/dist/esm-legacy/graph.mjs +5221 -0
  43. package/dist/esm-legacy/hash.mjs +1259 -0
  44. package/dist/esm-legacy/heap.mjs +1531 -0
  45. package/dist/esm-legacy/index.mjs +28237 -14791
  46. package/dist/esm-legacy/linked-list.mjs +4369 -0
  47. package/dist/esm-legacy/matrix.mjs +1041 -0
  48. package/dist/esm-legacy/priority-queue.mjs +1308 -0
  49. package/dist/esm-legacy/queue.mjs +4084 -0
  50. package/dist/esm-legacy/stack.mjs +859 -0
  51. package/dist/esm-legacy/trie.mjs +1169 -0
  52. package/dist/types/data-structures/base/index.d.ts +1 -0
  53. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  54. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  55. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +240 -0
  56. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +280 -0
  57. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +502 -2
  58. package/dist/types/data-structures/binary-tree/bst.d.ts +481 -1
  59. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +380 -0
  60. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +120 -1
  61. package/dist/types/data-structures/binary-tree/tree-map.d.ts +2764 -384
  62. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2753 -353
  63. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2241 -321
  64. package/dist/types/data-structures/binary-tree/tree-set.d.ts +2554 -274
  65. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  66. package/dist/types/data-structures/graph/directed-graph.d.ts +200 -0
  67. package/dist/types/data-structures/graph/undirected-graph.d.ts +180 -0
  68. package/dist/types/data-structures/hash/hash-map.d.ts +230 -10
  69. package/dist/types/data-structures/heap/heap.d.ts +280 -0
  70. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +343 -3
  71. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +303 -3
  72. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +362 -2
  73. package/dist/types/data-structures/matrix/matrix.d.ts +160 -0
  74. package/dist/types/data-structures/queue/deque.d.ts +304 -4
  75. package/dist/types/data-structures/queue/queue.d.ts +240 -0
  76. package/dist/types/data-structures/stack/stack.d.ts +200 -0
  77. package/dist/types/data-structures/trie/trie.d.ts +244 -4
  78. package/dist/types/interfaces/graph.d.ts +1 -1
  79. package/dist/types/types/common.d.ts +2 -2
  80. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  81. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  82. package/dist/types/types/utils/validate-type.d.ts +4 -4
  83. package/dist/umd/data-structure-typed.js +28022 -14573
  84. package/dist/umd/data-structure-typed.min.js +9 -3
  85. package/docs-site-docusaurus/README.md +41 -0
  86. package/docs-site-docusaurus/docs/api/README.md +52 -0
  87. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +6130 -0
  88. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +282 -0
  89. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +2266 -0
  90. package/docs-site-docusaurus/docs/api/classes/BST.md +5831 -0
  91. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +333 -0
  92. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +455 -0
  93. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +4647 -0
  94. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +331 -0
  95. package/docs-site-docusaurus/docs/api/classes/Deque.md +2767 -0
  96. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +2999 -0
  97. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +2685 -0
  98. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +221 -0
  99. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +253 -0
  100. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +21 -0
  101. package/docs-site-docusaurus/docs/api/classes/HashMap.md +1333 -0
  102. package/docs-site-docusaurus/docs/api/classes/Heap.md +1881 -0
  103. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +800 -0
  104. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +644 -0
  105. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +1632 -0
  106. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +1853 -0
  107. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +1108 -0
  108. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +156 -0
  109. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +2824 -0
  110. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +2929 -0
  111. package/docs-site-docusaurus/docs/api/classes/Matrix.md +1026 -0
  112. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +1866 -0
  113. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +1883 -0
  114. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +1879 -0
  115. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +1882 -0
  116. package/docs-site-docusaurus/docs/api/classes/Navigator.md +109 -0
  117. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +1839 -0
  118. package/docs-site-docusaurus/docs/api/classes/Queue.md +2244 -0
  119. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +6374 -0
  120. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +372 -0
  121. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +2897 -0
  122. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +169 -0
  123. package/docs-site-docusaurus/docs/api/classes/SkipList.md +1229 -0
  124. package/docs-site-docusaurus/docs/api/classes/Stack.md +1573 -0
  125. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +1257 -0
  126. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +1475 -0
  127. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +1117 -0
  128. package/docs-site-docusaurus/docs/api/classes/Trie.md +1708 -0
  129. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +199 -0
  130. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +2979 -0
  131. package/docs-site-docusaurus/docs/guide/_category_.json +6 -0
  132. package/docs-site-docusaurus/docs/guide/architecture.md +613 -0
  133. package/docs-site-docusaurus/docs/guide/concepts.md +420 -0
  134. package/docs-site-docusaurus/docs/guide/guides.md +611 -0
  135. package/docs-site-docusaurus/docs/guide/installation.md +60 -0
  136. package/docs-site-docusaurus/docs/guide/integrations.md +823 -0
  137. package/docs-site-docusaurus/docs/guide/overview.md +638 -0
  138. package/docs-site-docusaurus/docs/guide/performance.md +833 -0
  139. package/docs-site-docusaurus/docs/guide/quick-start.md +73 -0
  140. package/docs-site-docusaurus/docusaurus.config.ts +159 -0
  141. package/docs-site-docusaurus/fix-mdx-generics.mjs +75 -0
  142. package/docs-site-docusaurus/package-lock.json +18667 -0
  143. package/docs-site-docusaurus/package.json +50 -0
  144. package/docs-site-docusaurus/prefix-class-to-methods.mjs +48 -0
  145. package/docs-site-docusaurus/sidebars.ts +23 -0
  146. package/docs-site-docusaurus/sort-protected.mjs +87 -0
  147. package/docs-site-docusaurus/src/css/custom.css +96 -0
  148. package/docs-site-docusaurus/src/pages/index.module.css +13 -0
  149. package/docs-site-docusaurus/src/pages/index.tsx +71 -0
  150. package/docs-site-docusaurus/src/pages/markdown-page.md +7 -0
  151. package/docs-site-docusaurus/src/theme/TOCItems/index.tsx +34 -0
  152. package/docs-site-docusaurus/static/.nojekyll +0 -0
  153. package/docs-site-docusaurus/static/img/docusaurus-social-card.jpg +0 -0
  154. package/docs-site-docusaurus/static/img/docusaurus.png +0 -0
  155. package/docs-site-docusaurus/static/img/favicon.ico +0 -0
  156. package/docs-site-docusaurus/static/img/favicon.png +0 -0
  157. package/docs-site-docusaurus/static/img/logo-180.png +0 -0
  158. package/docs-site-docusaurus/static/img/logo.jpg +0 -0
  159. package/docs-site-docusaurus/static/img/logo.png +0 -0
  160. package/docs-site-docusaurus/static/img/logo.svg +1 -0
  161. package/docs-site-docusaurus/static/img/og-image.png +0 -0
  162. package/docs-site-docusaurus/static/img/undraw_docusaurus_mountain.svg +171 -0
  163. package/docs-site-docusaurus/static/img/undraw_docusaurus_react.svg +170 -0
  164. package/docs-site-docusaurus/static/img/undraw_docusaurus_tree.svg +40 -0
  165. package/docs-site-docusaurus/static/robots.txt +4 -0
  166. package/docs-site-docusaurus/typedoc.json +23 -0
  167. package/package.json +106 -10
  168. package/src/data-structures/base/index.ts +1 -0
  169. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  170. package/src/data-structures/base/linear-base.ts +3 -3
  171. package/src/data-structures/binary-tree/avl-tree.ts +240 -0
  172. package/src/data-structures/binary-tree/binary-indexed-tree.ts +281 -1
  173. package/src/data-structures/binary-tree/binary-tree.ts +502 -2
  174. package/src/data-structures/binary-tree/bst.ts +481 -1
  175. package/src/data-structures/binary-tree/red-black-tree.ts +380 -0
  176. package/src/data-structures/binary-tree/segment-tree.ts +121 -2
  177. package/src/data-structures/binary-tree/tree-map.ts +2862 -482
  178. package/src/data-structures/binary-tree/tree-multi-map.ts +2963 -563
  179. package/src/data-structures/binary-tree/tree-multi-set.ts +2399 -479
  180. package/src/data-structures/binary-tree/tree-set.ts +2685 -405
  181. package/src/data-structures/graph/abstract-graph.ts +4 -4
  182. package/src/data-structures/graph/directed-graph.ts +200 -0
  183. package/src/data-structures/graph/undirected-graph.ts +180 -0
  184. package/src/data-structures/hash/hash-map.ts +235 -15
  185. package/src/data-structures/heap/heap.ts +280 -0
  186. package/src/data-structures/linked-list/doubly-linked-list.ts +343 -3
  187. package/src/data-structures/linked-list/singly-linked-list.ts +303 -3
  188. package/src/data-structures/linked-list/skip-linked-list.ts +362 -2
  189. package/src/data-structures/matrix/matrix.ts +161 -1
  190. package/src/data-structures/queue/deque.ts +305 -5
  191. package/src/data-structures/queue/queue.ts +240 -0
  192. package/src/data-structures/stack/stack.ts +200 -0
  193. package/src/data-structures/trie/trie.ts +245 -5
  194. package/src/interfaces/graph.ts +1 -1
  195. package/src/types/common.ts +2 -2
  196. package/src/types/data-structures/heap/heap.ts +1 -0
  197. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  198. package/src/types/utils/validate-type.ts +4 -4
  199. package/vercel.json +6 -0
  200. package/dist/leetcode/avl-tree-counter.mjs +0 -2957
  201. package/dist/leetcode/avl-tree-multi-map.mjs +0 -2889
  202. package/dist/leetcode/avl-tree.mjs +0 -2720
  203. package/dist/leetcode/binary-tree.mjs +0 -1594
  204. package/dist/leetcode/bst.mjs +0 -2398
  205. package/dist/leetcode/deque.mjs +0 -683
  206. package/dist/leetcode/directed-graph.mjs +0 -1733
  207. package/dist/leetcode/doubly-linked-list.mjs +0 -709
  208. package/dist/leetcode/hash-map.mjs +0 -493
  209. package/dist/leetcode/heap.mjs +0 -542
  210. package/dist/leetcode/max-heap.mjs +0 -375
  211. package/dist/leetcode/max-priority-queue.mjs +0 -383
  212. package/dist/leetcode/min-heap.mjs +0 -363
  213. package/dist/leetcode/min-priority-queue.mjs +0 -371
  214. package/dist/leetcode/priority-queue.mjs +0 -363
  215. package/dist/leetcode/queue.mjs +0 -943
  216. package/dist/leetcode/red-black-tree.mjs +0 -2765
  217. package/dist/leetcode/singly-linked-list.mjs +0 -754
  218. package/dist/leetcode/stack.mjs +0 -217
  219. package/dist/leetcode/tree-counter.mjs +0 -3039
  220. package/dist/leetcode/tree-multi-map.mjs +0 -2913
  221. package/dist/leetcode/trie.mjs +0 -413
  222. package/dist/leetcode/undirected-graph.mjs +0 -1650
@@ -0,0 +1,1257 @@
1
+ [**data-structure-typed**](../README.md)
2
+
3
+ ***
4
+
5
+ [data-structure-typed](../README.md) / TreeMap
6
+
7
+ # Class: TreeMap\<K, V, R\>
8
+
9
+ Defined in: [data-structures/binary-tree/tree-map.ts:26](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L26)
10
+
11
+ An ordered Map backed by a red-black tree.
12
+
13
+ - Iteration order is ascending by key.
14
+ - No node exposure: all APIs use keys/values only.
15
+
16
+ ## Example
17
+
18
+ ```ts
19
+ // Set multiple key-value pairs
20
+ const tm = new TreeMap<number, string>();
21
+ tm.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
22
+ console.log(tm.size); // 3;
23
+ ```
24
+
25
+ ## Type Parameters
26
+
27
+ ### K
28
+
29
+ `K` = `any`
30
+
31
+ ### V
32
+
33
+ `V` = `any`
34
+
35
+ ### R
36
+
37
+ `R` = \[`K`, `V`\]
38
+
39
+ ## Implements
40
+
41
+ - `Iterable`\<\[`K`, `V` \| `undefined`\]\>
42
+
43
+ ## Constructors
44
+
45
+ ### Constructor
46
+
47
+ ```ts
48
+ new TreeMap<K, V, R>(entries?, options?): TreeMap<K, V, R>;
49
+ ```
50
+
51
+ Defined in: [data-structures/binary-tree/tree-map.ts:46](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L46)
52
+
53
+ Create a TreeMap from an iterable of `[key, value]` entries or raw elements.
54
+
55
+ #### Parameters
56
+
57
+ ##### entries?
58
+
59
+ \| `Iterable`\<\[`K`, `V` \| `undefined`\], `any`, `any`\>
60
+ \| `Iterable`\<`R`, `any`, `any`\>
61
+
62
+ Iterable of `[key, value]` tuples, or raw elements if `toEntryFn` is provided.
63
+
64
+ ##### options?
65
+
66
+ `TreeMapOptions`\<`K`, `V`, `R`\> = `{}`
67
+
68
+ Configuration options including optional `toEntryFn` to transform raw elements.
69
+
70
+ #### Returns
71
+
72
+ `TreeMap`\<`K`, `V`, `R`\>
73
+
74
+ #### Throws
75
+
76
+ If any entry is not a 2-tuple-like value (when no toEntryFn), or when using
77
+ the default comparator and encountering unsupported/invalid keys (e.g. `NaN`, invalid `Date`).
78
+
79
+ #### Example
80
+
81
+ ```ts
82
+ // Standard usage with entries
83
+ const map = new TreeMap([['a', 1], ['b', 2]]);
84
+
85
+ // Using toEntryFn to transform raw objects
86
+ const users = [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }];
87
+ const map = new TreeMap<number, User, User>(users, { toEntryFn: u => [u.id, u] });
88
+ ```
89
+
90
+ ## Accessors
91
+
92
+ ### size
93
+
94
+ #### Get Signature
95
+
96
+ ```ts
97
+ get size(): number;
98
+ ```
99
+
100
+ Defined in: [data-structures/binary-tree/tree-map.ts:134](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L134)
101
+
102
+ Number of entries in the map.
103
+
104
+ ##### Returns
105
+
106
+ `number`
107
+
108
+ ## Methods
109
+
110
+ ### ceiling()
111
+
112
+ ```ts
113
+ ceiling(key): [K, V | undefined] | undefined;
114
+ ```
115
+
116
+ Defined in: [data-structures/binary-tree/tree-map.ts:3061](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L3061)
117
+
118
+ Smallest entry whose key is >= the given key.
119
+
120
+ *
121
+
122
+ #### Parameters
123
+
124
+ ##### key
125
+
126
+ `K`
127
+
128
+ #### Returns
129
+
130
+ \[`K`, `V` \| `undefined`\] \| `undefined`
131
+
132
+ #### Example
133
+
134
+ ```ts
135
+ // Event scheduler with time-based lookup
136
+ const events = new TreeMap<Date, string>();
137
+
138
+ const meeting = new Date('2024-01-15T10:00:00Z');
139
+ const lunch = new Date('2024-01-15T12:00:00Z');
140
+ const review = new Date('2024-01-15T15:00:00Z');
141
+ const standup = new Date('2024-01-15T09:00:00Z');
142
+
143
+ events.set(meeting, 'Team Meeting');
144
+ events.set(lunch, 'Lunch Break');
145
+ events.set(review, 'Code Review');
146
+ events.set(standup, 'Daily Standup');
147
+
148
+ // Events are sorted chronologically
149
+ console.log([...events.values()]); // [
150
+ // 'Daily Standup',
151
+ // 'Team Meeting',
152
+ // 'Lunch Break',
153
+ // 'Code Review'
154
+ // ];
155
+
156
+ // Next event after 11:00
157
+ const after11 = new Date('2024-01-15T11:00:00Z');
158
+ console.log(events.ceiling(after11)?.[1]); // 'Lunch Break';
159
+
160
+ // Events between 9:30 and 13:00
161
+ const from = new Date('2024-01-15T09:30:00Z');
162
+ const to = new Date('2024-01-15T13:00:00Z');
163
+ const window = events.rangeSearch([from, to]);
164
+ console.log(window.map(([, v]) => v)); // ['Team Meeting', 'Lunch Break'];
165
+ ```
166
+
167
+ ***
168
+
169
+ ### clear()
170
+
171
+ ```ts
172
+ clear(): void;
173
+ ```
174
+
175
+ Defined in: [data-structures/binary-tree/tree-map.ts:1028](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1028)
176
+
177
+ Remove all entries.
178
+
179
+ *
180
+
181
+ #### Returns
182
+
183
+ `void`
184
+
185
+ #### Example
186
+
187
+ ```ts
188
+ // Remove all
189
+ const tm = new TreeMap<number, string>([[1, 'a']]);
190
+ tm.clear();
191
+ console.log(tm.isEmpty()); // true;
192
+ ```
193
+
194
+ ***
195
+
196
+ ### clone()
197
+
198
+ ```ts
199
+ clone(): TreeMap<K, V>;
200
+ ```
201
+
202
+ Defined in: [data-structures/binary-tree/tree-map.ts:3751](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L3751)
203
+
204
+ Creates a shallow clone of this map.
205
+
206
+ #### Returns
207
+
208
+ `TreeMap`\<`K`, `V`\>
209
+
210
+ #### Remarks
211
+
212
+ Time O(n log n), Space O(n)
213
+
214
+ *
215
+
216
+ #### Example
217
+
218
+ ```ts
219
+ // Deep clone
220
+ const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
221
+ const copy = tm.clone();
222
+ copy.delete(1);
223
+ console.log(tm.has(1)); // true;
224
+ ```
225
+
226
+ ***
227
+
228
+ ### delete()
229
+
230
+ ```ts
231
+ delete(key): boolean;
232
+ ```
233
+
234
+ Defined in: [data-structures/binary-tree/tree-map.ts:891](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L891)
235
+
236
+ Delete a key.
237
+
238
+ #### Parameters
239
+
240
+ ##### key
241
+
242
+ `K`
243
+
244
+ #### Returns
245
+
246
+ `boolean`
247
+
248
+ `true` if the key existed; otherwise `false`.
249
+
250
+ #### Remarks
251
+
252
+ Expected time O(log n)
253
+
254
+ *
255
+
256
+ #### Example
257
+
258
+ ```ts
259
+ // Session management with expiry
260
+ const sessions = new TreeMap<string, number>([
261
+ ['sess_abc', Date.now()],
262
+ ['sess_def', Date.now()],
263
+ ['sess_ghi', Date.now()]
264
+ ]);
265
+
266
+ console.log(sessions.size); // 3;
267
+ sessions.delete('sess_def');
268
+ console.log(sessions.has('sess_def')); // false;
269
+ console.log(sessions.size); // 2;
270
+ ```
271
+
272
+ ***
273
+
274
+ ### entries()
275
+
276
+ ```ts
277
+ entries(): IterableIterator<[K, V | undefined]>;
278
+ ```
279
+
280
+ Defined in: [data-structures/binary-tree/tree-map.ts:1440](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1440)
281
+
282
+ Iterate over `[key, value]` entries in ascending key order.
283
+
284
+ Note: values may be `undefined`.
285
+
286
+ *
287
+
288
+ #### Returns
289
+
290
+ `IterableIterator`\<\[`K`, `V` \| `undefined`\]\>
291
+
292
+ #### Example
293
+
294
+ ```ts
295
+ // Iterate key-value pairs
296
+ const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a'], [2, 'b']]);
297
+ console.log([...tm.entries()]); // [[1, 'a'], [2, 'b'], [3, 'c']];
298
+ ```
299
+
300
+ ***
301
+
302
+ ### every()
303
+
304
+ ```ts
305
+ every(callbackfn, thisArg?): boolean;
306
+ ```
307
+
308
+ Defined in: [data-structures/binary-tree/tree-map.ts:2147](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2147)
309
+
310
+ Test whether all entries satisfy a predicate.
311
+
312
+ #### Parameters
313
+
314
+ ##### callbackfn
315
+
316
+ `TreeMapEntryCallback`\<`K`, `V`, `boolean`, `TreeMap`\<`K`, `V`, \[`K`, `V`\]\>\>
317
+
318
+ ##### thisArg?
319
+
320
+ `unknown`
321
+
322
+ #### Returns
323
+
324
+ `boolean`
325
+
326
+ #### Remarks
327
+
328
+ Time O(n), Space O(1)
329
+
330
+ *
331
+
332
+ #### Example
333
+
334
+ ```ts
335
+ // Test all entries
336
+ const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
337
+ console.log(tm.every((v, k) => k > 0)); // true;
338
+ ```
339
+
340
+ ***
341
+
342
+ ### filter()
343
+
344
+ ```ts
345
+ filter(callbackfn, thisArg?): TreeMap<K, V>;
346
+ ```
347
+
348
+ Defined in: [data-structures/binary-tree/tree-map.ts:1868](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1868)
349
+
350
+ Create a new TreeMap containing only entries that satisfy the predicate.
351
+
352
+ #### Parameters
353
+
354
+ ##### callbackfn
355
+
356
+ `TreeMapEntryCallback`\<`K`, `V`, `boolean`, `TreeMap`\<`K`, `V`, \[`K`, `V`\]\>\>
357
+
358
+ ##### thisArg?
359
+
360
+ `unknown`
361
+
362
+ #### Returns
363
+
364
+ `TreeMap`\<`K`, `V`\>
365
+
366
+ #### Remarks
367
+
368
+ Time O(n log n) expected, Space O(n)
369
+
370
+ *
371
+
372
+ #### Example
373
+
374
+ ```ts
375
+ // Filter entries
376
+ const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
377
+ const filtered = tm.filter((v, k) => k > 1);
378
+ console.log([...filtered.keys()]); // [2, 3];
379
+ ```
380
+
381
+ ***
382
+
383
+ ### find()
384
+
385
+ ```ts
386
+ find(callbackfn, thisArg?): [K, V | undefined] | undefined;
387
+ ```
388
+
389
+ Defined in: [data-structures/binary-tree/tree-map.ts:2428](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2428)
390
+
391
+ Find the first entry that satisfies a predicate.
392
+
393
+ #### Parameters
394
+
395
+ ##### callbackfn
396
+
397
+ `TreeMapEntryCallback`\<`K`, `V`, `boolean`, `TreeMap`\<`K`, `V`, \[`K`, `V`\]\>\>
398
+
399
+ ##### thisArg?
400
+
401
+ `unknown`
402
+
403
+ #### Returns
404
+
405
+ \[`K`, `V` \| `undefined`\] \| `undefined`
406
+
407
+ The first matching `[key, value]` tuple, or `undefined`.
408
+
409
+ #### Remarks
410
+
411
+ Time O(n), Space O(1)
412
+
413
+ *
414
+
415
+ #### Example
416
+
417
+ ```ts
418
+ // Find matching entry
419
+ const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
420
+ console.log(tm.find(v => v === 'b')?.[0]); // 2;
421
+ ```
422
+
423
+ ***
424
+
425
+ ### first()
426
+
427
+ ```ts
428
+ first(): [K, V | undefined] | undefined;
429
+ ```
430
+
431
+ Defined in: [data-structures/binary-tree/tree-map.ts:2770](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2770)
432
+
433
+ Smallest entry by key.
434
+
435
+ *
436
+
437
+ #### Returns
438
+
439
+ \[`K`, `V` \| `undefined`\] \| `undefined`
440
+
441
+ #### Example
442
+
443
+ ```ts
444
+ // Leaderboard with ranked scores
445
+ // Use score as key (descending), player name as value
446
+ const leaderboard = new TreeMap<number, string>([], {
447
+ comparator: (a, b) => b - a // descending
448
+ });
449
+
450
+ leaderboard.set(1500, 'Alice');
451
+ leaderboard.set(2200, 'Bob');
452
+ leaderboard.set(1800, 'Charlie');
453
+ leaderboard.set(2500, 'Diana');
454
+
455
+ // Top 3 players (first 3 in descending order)
456
+ const top3 = [...leaderboard.entries()].slice(0, 3);
457
+ console.log(top3); // [
458
+ // [2500, 'Diana'],
459
+ // [2200, 'Bob'],
460
+ // [1800, 'Charlie']
461
+ // ];
462
+
463
+ // Highest scorer
464
+ console.log(leaderboard.first()); // [2500, 'Diana'];
465
+
466
+ // Remove lowest scorer
467
+ console.log(leaderboard.pollLast()); // [1500, 'Alice'];
468
+ console.log(leaderboard.size); // 3;
469
+ ```
470
+
471
+ ***
472
+
473
+ ### floor()
474
+
475
+ ```ts
476
+ floor(key): [K, V | undefined] | undefined;
477
+ ```
478
+
479
+ Defined in: [data-structures/binary-tree/tree-map.ts:3191](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L3191)
480
+
481
+ Largest entry whose key is <= the given key.
482
+
483
+ *
484
+
485
+ #### Parameters
486
+
487
+ ##### key
488
+
489
+ `K`
490
+
491
+ #### Returns
492
+
493
+ \[`K`, `V` \| `undefined`\] \| `undefined`
494
+
495
+ #### Example
496
+
497
+ ```ts
498
+ // Find the largest key ≤ target
499
+ const versions = new TreeMap<number, string>([
500
+ [1, 'v1.0'],
501
+ [3, 'v3.0'],
502
+ [5, 'v5.0'],
503
+ [7, 'v7.0']
504
+ ]);
505
+
506
+ // Largest version ≤ 4
507
+ console.log(versions.floor(4)); // [3, 'v3.0'];
508
+ // Largest version ≤ 5 (exact match)
509
+ console.log(versions.floor(5)); // [5, 'v5.0'];
510
+ // No version ≤ 0
511
+ console.log(versions.floor(0)); // undefined;
512
+ ```
513
+
514
+ ***
515
+
516
+ ### forEach()
517
+
518
+ ```ts
519
+ forEach(cb, thisArg?): void;
520
+ ```
521
+
522
+ Defined in: [data-structures/binary-tree/tree-map.ts:1582](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1582)
523
+
524
+ Visit each entry in ascending key order.
525
+
526
+ Note: callback value may be `undefined`.
527
+
528
+ *
529
+
530
+ #### Parameters
531
+
532
+ ##### cb
533
+
534
+ (`value`, `key`, `map`) => `void`
535
+
536
+ ##### thisArg?
537
+
538
+ `any`
539
+
540
+ #### Returns
541
+
542
+ `void`
543
+
544
+ #### Example
545
+
546
+ ```ts
547
+ // Execute for each entry
548
+ const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
549
+ const pairs: string[] = [];
550
+ tm.forEach((v, k) => pairs.push(`${k}:${v}`));
551
+ console.log(pairs); // ['1:a', '2:b'];
552
+ ```
553
+
554
+ ***
555
+
556
+ ### get()
557
+
558
+ ```ts
559
+ get(key): V | undefined;
560
+ ```
561
+
562
+ Defined in: [data-structures/binary-tree/tree-map.ts:582](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L582)
563
+
564
+ Get the value under a key.
565
+
566
+ #### Parameters
567
+
568
+ ##### key
569
+
570
+ `K`
571
+
572
+ #### Returns
573
+
574
+ `V` \| `undefined`
575
+
576
+ #### Remarks
577
+
578
+ Expected time O(log n)
579
+
580
+ *
581
+
582
+ #### Example
583
+
584
+ ```ts
585
+ // Configuration registry with typed lookups
586
+ const config = new TreeMap<string, number>([
587
+ ['maxRetries', 3],
588
+ ['timeout', 5000],
589
+ ['poolSize', 10]
590
+ ]);
591
+
592
+ console.log(config.get('timeout')); // 5000;
593
+ console.log(config.get('missing')); // undefined;
594
+ console.log(config.size); // 3;
595
+ ```
596
+
597
+ ***
598
+
599
+ ### has()
600
+
601
+ ```ts
602
+ has(key): boolean;
603
+ ```
604
+
605
+ Defined in: [data-structures/binary-tree/tree-map.ts:735](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L735)
606
+
607
+ Test whether a key exists.
608
+
609
+ #### Parameters
610
+
611
+ ##### key
612
+
613
+ `K`
614
+
615
+ #### Returns
616
+
617
+ `boolean`
618
+
619
+ #### Remarks
620
+
621
+ Expected time O(log n)
622
+
623
+ *
624
+
625
+ #### Example
626
+
627
+ ```ts
628
+ // Feature flag checking
629
+ const flags = new TreeMap<string, boolean>([
630
+ ['darkMode', true],
631
+ ['betaFeature', false],
632
+ ['notifications', true]
633
+ ]);
634
+
635
+ console.log(flags.has('darkMode')); // true;
636
+ console.log(flags.has('unknownFlag')); // false;
637
+ ```
638
+
639
+ ***
640
+
641
+ ### higher()
642
+
643
+ ```ts
644
+ higher(key): [K, V | undefined] | undefined;
645
+ ```
646
+
647
+ Defined in: [data-structures/binary-tree/tree-map.ts:3321](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L3321)
648
+
649
+ Smallest entry whose key is > the given key.
650
+
651
+ *
652
+
653
+ #### Parameters
654
+
655
+ ##### key
656
+
657
+ `K`
658
+
659
+ #### Returns
660
+
661
+ \[`K`, `V` \| `undefined`\] \| `undefined`
662
+
663
+ #### Example
664
+
665
+ ```ts
666
+ // Find the smallest key strictly > target
667
+ const prices = new TreeMap<number, string>([
668
+ [10, 'Basic'],
669
+ [25, 'Standard'],
670
+ [50, 'Premium'],
671
+ [100, 'Enterprise']
672
+ ]);
673
+
674
+ // Next tier above $25
675
+ console.log(prices.higher(25)); // [50, 'Premium'];
676
+ // Next tier above $99
677
+ console.log(prices.higher(99)); // [100, 'Enterprise'];
678
+ // Nothing above $100
679
+ console.log(prices.higher(100)); // undefined;
680
+ ```
681
+
682
+ ***
683
+
684
+ ### isEmpty()
685
+
686
+ ```ts
687
+ isEmpty(): boolean;
688
+ ```
689
+
690
+ Defined in: [data-structures/binary-tree/tree-map.ts:267](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L267)
691
+
692
+ Whether the map is empty.
693
+
694
+ *
695
+
696
+ #### Returns
697
+
698
+ `boolean`
699
+
700
+ #### Example
701
+
702
+ ```ts
703
+ // Check empty
704
+ console.log(new TreeMap().isEmpty()); // true;
705
+ ```
706
+
707
+ ***
708
+
709
+ ### keys()
710
+
711
+ ```ts
712
+ keys(): IterableIterator<K>;
713
+ ```
714
+
715
+ Defined in: [data-structures/binary-tree/tree-map.ts:1162](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1162)
716
+
717
+ Iterate over keys in ascending order.
718
+
719
+ *
720
+
721
+ #### Returns
722
+
723
+ `IterableIterator`\<`K`\>
724
+
725
+ #### Example
726
+
727
+ ```ts
728
+ // Get sorted keys
729
+ const tm = new TreeMap<number, string>([[3, 'c'], [1, 'a']]);
730
+ console.log([...tm.keys()]); // [1, 3];
731
+ ```
732
+
733
+ ***
734
+
735
+ ### last()
736
+
737
+ ```ts
738
+ last(): [K, V | undefined] | undefined;
739
+ ```
740
+
741
+ Defined in: [data-structures/binary-tree/tree-map.ts:2816](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2816)
742
+
743
+ Largest entry by key.
744
+
745
+ *
746
+
747
+ #### Returns
748
+
749
+ \[`K`, `V` \| `undefined`\] \| `undefined`
750
+
751
+ #### Example
752
+
753
+ ```ts
754
+ // Access the maximum entry
755
+ const scores = new TreeMap<number, string>([
756
+ [85, 'Bob'],
757
+ [92, 'Alice'],
758
+ [78, 'Charlie']
759
+ ]);
760
+
761
+ console.log(scores.last()); // [92, 'Alice'];
762
+ console.log(scores.first()); // [78, 'Charlie'];
763
+ ```
764
+
765
+ ***
766
+
767
+ ### lower()
768
+
769
+ ```ts
770
+ lower(key): [K, V | undefined] | undefined;
771
+ ```
772
+
773
+ Defined in: [data-structures/binary-tree/tree-map.ts:3449](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L3449)
774
+
775
+ Largest entry whose key is < the given key.
776
+
777
+ *
778
+
779
+ #### Parameters
780
+
781
+ ##### key
782
+
783
+ `K`
784
+
785
+ #### Returns
786
+
787
+ \[`K`, `V` \| `undefined`\] \| `undefined`
788
+
789
+ #### Example
790
+
791
+ ```ts
792
+ // Find the largest key strictly < target
793
+ const temps = new TreeMap<number, string>([
794
+ [0, 'Freezing'],
795
+ [20, 'Cool'],
796
+ [30, 'Warm'],
797
+ [40, 'Hot']
798
+ ]);
799
+
800
+ // Largest reading below 30
801
+ console.log(temps.lower(30)); // [20, 'Cool'];
802
+ // Nothing below 0
803
+ console.log(temps.lower(0)); // undefined;
804
+ ```
805
+
806
+ ***
807
+
808
+ ### map()
809
+
810
+ ```ts
811
+ map<MK, MV>(
812
+ callbackfn,
813
+ options?,
814
+ thisArg?): TreeMap<MK, MV>;
815
+ ```
816
+
817
+ Defined in: [data-structures/binary-tree/tree-map.ts:1720](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1720)
818
+
819
+ Create a new TreeMap by mapping each entry to a new `[key, value]` entry.
820
+
821
+ This mirrors `RedBlackTree.map`: mapping produces a new ordered container.
822
+
823
+ #### Type Parameters
824
+
825
+ ##### MK
826
+
827
+ `MK`
828
+
829
+ ##### MV
830
+
831
+ `MV`
832
+
833
+ #### Parameters
834
+
835
+ ##### callbackfn
836
+
837
+ `TreeMapEntryCallback`\<`K`, `V`, \[`MK`, `MV`\], `TreeMap`\<`K`, `V`, \[`K`, `V`\]\>\>
838
+
839
+ ##### options?
840
+
841
+ `Omit`\<`TreeMapOptions`\<`MK`, `MV`, \[`MK`, `MV`\]\>, `"toEntryFn"`\> & `object` = `{}`
842
+
843
+ ##### thisArg?
844
+
845
+ `unknown`
846
+
847
+ #### Returns
848
+
849
+ `TreeMap`\<`MK`, `MV`\>
850
+
851
+ #### Remarks
852
+
853
+ Time O(n log n) expected, Space O(n)
854
+
855
+ *
856
+
857
+ #### Example
858
+
859
+ ```ts
860
+ // Transform entries
861
+ const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
862
+ const doubled = tm.map((v, k) => [k, (v ?? 0) * 2] as [number, number]);
863
+ console.log([...doubled.values()]); // [20, 40];
864
+ ```
865
+
866
+ ***
867
+
868
+ ### pollFirst()
869
+
870
+ ```ts
871
+ pollFirst(): [K, V | undefined] | undefined;
872
+ ```
873
+
874
+ Defined in: [data-structures/binary-tree/tree-map.ts:2864](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2864)
875
+
876
+ Remove and return the smallest entry.
877
+
878
+ *
879
+
880
+ #### Returns
881
+
882
+ \[`K`, `V` \| `undefined`\] \| `undefined`
883
+
884
+ #### Example
885
+
886
+ ```ts
887
+ // Process items from lowest priority
888
+ const tasks = new TreeMap<number, string>([
889
+ [3, 'Low'],
890
+ [1, 'Critical'],
891
+ [2, 'Medium']
892
+ ]);
893
+
894
+ // Process lowest priority first
895
+ console.log(tasks.pollFirst()); // [1, 'Critical'];
896
+ console.log(tasks.pollFirst()); // [2, 'Medium'];
897
+ console.log(tasks.size); // 1;
898
+ ```
899
+
900
+ ***
901
+
902
+ ### pollLast()
903
+
904
+ ```ts
905
+ pollLast(): [K, V | undefined] | undefined;
906
+ ```
907
+
908
+ Defined in: [data-structures/binary-tree/tree-map.ts:2914](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2914)
909
+
910
+ Remove and return the largest entry.
911
+
912
+ *
913
+
914
+ #### Returns
915
+
916
+ \[`K`, `V` \| `undefined`\] \| `undefined`
917
+
918
+ #### Example
919
+
920
+ ```ts
921
+ // Remove the maximum entry
922
+ const bids = new TreeMap<number, string>([
923
+ [100, 'Alice'],
924
+ [150, 'Bob'],
925
+ [120, 'Charlie']
926
+ ]);
927
+
928
+ // Remove highest bid
929
+ console.log(bids.pollLast()); // [150, 'Bob'];
930
+ console.log(bids.size); // 2;
931
+ console.log(bids.last()); // [120, 'Charlie'];
932
+ ```
933
+
934
+ ***
935
+
936
+ ### print()
937
+
938
+ ```ts
939
+ print(): void;
940
+ ```
941
+
942
+ Defined in: [data-structures/binary-tree/tree-map.ts:2705](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2705)
943
+
944
+ Print a human-friendly representation.
945
+
946
+ #### Returns
947
+
948
+ `void`
949
+
950
+ #### Remarks
951
+
952
+ Time O(n), Space O(n)
953
+
954
+ *
955
+
956
+ #### Example
957
+
958
+ ```ts
959
+ // Display tree
960
+ const tm = new TreeMap<number, string>([[1, 'a']]);
961
+ expect(() => tm.print()).not.toThrow();
962
+ ```
963
+
964
+ ***
965
+
966
+ ### rangeSearch()
967
+
968
+ ```ts
969
+ rangeSearch(range, options?): [K, V | undefined][];
970
+ ```
971
+
972
+ Defined in: [data-structures/binary-tree/tree-map.ts:3597](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L3597)
973
+
974
+ Return all entries in a given key range.
975
+
976
+ #### Parameters
977
+
978
+ ##### range
979
+
980
+ \[`K`, `K`\]
981
+
982
+ `[low, high]`
983
+
984
+ ##### options?
985
+
986
+ `TreeMapRangeOptions` = `{}`
987
+
988
+ Inclusive/exclusive bounds (defaults to inclusive).
989
+
990
+ *
991
+
992
+ #### Returns
993
+
994
+ \[`K`, `V` \| `undefined`\][]
995
+
996
+ #### Example
997
+
998
+ ```ts
999
+ // Inventory system with price-sorted products
1000
+ interface Product {
1001
+ name: string;
1002
+ price: number;
1003
+ stock: number;
1004
+ }
1005
+
1006
+ const inventory = new TreeMap<string, Product, Product>(
1007
+ [
1008
+ { name: 'Widget', price: 9.99, stock: 100 },
1009
+ { name: 'Gadget', price: 24.99, stock: 50 },
1010
+ { name: 'Doohickey', price: 4.99, stock: 200 }
1011
+ ],
1012
+ { toEntryFn: p => [p.name, p] }
1013
+ );
1014
+
1015
+ // Sorted alphabetically by product name
1016
+ console.log([...inventory.keys()]); // ['Doohickey', 'Gadget', 'Widget'];
1017
+
1018
+ // Filter high-stock items
1019
+ const highStock = inventory.filter(p => (p?.stock ?? 0) > 75);
1020
+ console.log([...highStock.keys()]); // ['Doohickey', 'Widget'];
1021
+
1022
+ // Calculate total inventory value
1023
+ const totalValue = inventory.reduce(
1024
+ (sum, p) => sum + (p ? p.price * p.stock : 0),
1025
+ 0
1026
+ );
1027
+ console.log(totalValue); // toBeCloseTo;
1028
+ ```
1029
+
1030
+ ***
1031
+
1032
+ ### reduce()
1033
+
1034
+ ```ts
1035
+ reduce<A>(callbackfn, initialValue): A;
1036
+ ```
1037
+
1038
+ Defined in: [data-structures/binary-tree/tree-map.ts:2011](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2011)
1039
+
1040
+ Reduce entries into a single accumulator.
1041
+
1042
+ #### Type Parameters
1043
+
1044
+ ##### A
1045
+
1046
+ `A`
1047
+
1048
+ #### Parameters
1049
+
1050
+ ##### callbackfn
1051
+
1052
+ `TreeMapReduceCallback`\<`K`, `V`, `A`, `TreeMap`\<`K`, `V`, \[`K`, `V`\]\>\>
1053
+
1054
+ ##### initialValue
1055
+
1056
+ `A`
1057
+
1058
+ #### Returns
1059
+
1060
+ `A`
1061
+
1062
+ #### Remarks
1063
+
1064
+ Time O(n), Space O(1)
1065
+
1066
+ *
1067
+
1068
+ #### Example
1069
+
1070
+ ```ts
1071
+ // Aggregate values
1072
+ const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
1073
+ console.log(tm.reduce((acc, v) => acc + (v ?? 0), 0)); // 30;
1074
+ ```
1075
+
1076
+ ***
1077
+
1078
+ ### set()
1079
+
1080
+ ```ts
1081
+ set(key, value): this;
1082
+ ```
1083
+
1084
+ Defined in: [data-structures/binary-tree/tree-map.ts:427](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L427)
1085
+
1086
+ Set or overwrite a value for a key.
1087
+
1088
+ #### Parameters
1089
+
1090
+ ##### key
1091
+
1092
+ `K`
1093
+
1094
+ ##### value
1095
+
1096
+ `V` \| `undefined`
1097
+
1098
+ #### Returns
1099
+
1100
+ `this`
1101
+
1102
+ #### Remarks
1103
+
1104
+ Expected time O(log n)
1105
+
1106
+ *
1107
+
1108
+ #### Example
1109
+
1110
+ ```ts
1111
+ // Sorted dictionary for a contact book
1112
+ const contacts = new TreeMap<string, string>([
1113
+ ['Bob', '555-0102'],
1114
+ ['Alice', '555-0101'],
1115
+ ['Charlie', '555-0103']
1116
+ ]);
1117
+
1118
+ // Contacts are automatically sorted by name
1119
+ console.log([...contacts.keys()]); // ['Alice', 'Bob', 'Charlie'];
1120
+ console.log(contacts.get('Bob')); // '555-0102';
1121
+
1122
+ // Find the first contact alphabetically after 'B'
1123
+ console.log(contacts.ceiling('B')); // ['Bob', '555-0102'];
1124
+
1125
+ // Find contacts in range
1126
+ console.log(contacts.rangeSearch(['Alice', 'Bob'])); // [
1127
+ // ['Alice', '555-0101'],
1128
+ // ['Bob', '555-0102']
1129
+ // ];
1130
+ ```
1131
+
1132
+ ***
1133
+
1134
+ ### some()
1135
+
1136
+ ```ts
1137
+ some(callbackfn, thisArg?): boolean;
1138
+ ```
1139
+
1140
+ Defined in: [data-structures/binary-tree/tree-map.ts:2287](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2287)
1141
+
1142
+ Test whether any entry satisfies a predicate.
1143
+
1144
+ #### Parameters
1145
+
1146
+ ##### callbackfn
1147
+
1148
+ `TreeMapEntryCallback`\<`K`, `V`, `boolean`, `TreeMap`\<`K`, `V`, \[`K`, `V`\]\>\>
1149
+
1150
+ ##### thisArg?
1151
+
1152
+ `unknown`
1153
+
1154
+ #### Returns
1155
+
1156
+ `boolean`
1157
+
1158
+ #### Remarks
1159
+
1160
+ Time O(n), Space O(1)
1161
+
1162
+ *
1163
+
1164
+ #### Example
1165
+
1166
+ ```ts
1167
+ // Test any entry
1168
+ const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
1169
+ console.log(tm.some((v, k) => k === 2)); // true;
1170
+ ```
1171
+
1172
+ ***
1173
+
1174
+ ### toArray()
1175
+
1176
+ ```ts
1177
+ toArray(): [K, V | undefined][];
1178
+ ```
1179
+
1180
+ Defined in: [data-structures/binary-tree/tree-map.ts:2570](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L2570)
1181
+
1182
+ Materialize the map into an array of `[key, value]` tuples.
1183
+
1184
+ #### Returns
1185
+
1186
+ \[`K`, `V` \| `undefined`\][]
1187
+
1188
+ #### Remarks
1189
+
1190
+ Time O(n), Space O(n)
1191
+
1192
+ *
1193
+
1194
+ #### Example
1195
+
1196
+ ```ts
1197
+ // Convert to array
1198
+ const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
1199
+ console.log(tm.toArray()); // [[1, 'a'], [2, 'b']];
1200
+ ```
1201
+
1202
+ ***
1203
+
1204
+ ### values()
1205
+
1206
+ ```ts
1207
+ values(): IterableIterator<V | undefined>;
1208
+ ```
1209
+
1210
+ Defined in: [data-structures/binary-tree/tree-map.ts:1304](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L1304)
1211
+
1212
+ Iterate over values in ascending key order.
1213
+
1214
+ Note: values may be `undefined` (TreeMap allows storing `undefined`, like native `Map`).
1215
+
1216
+ *
1217
+
1218
+ #### Returns
1219
+
1220
+ `IterableIterator`\<`V` \| `undefined`\>
1221
+
1222
+ #### Example
1223
+
1224
+ ```ts
1225
+ // Get values in key order
1226
+ const tm = new TreeMap<number, string>([[2, 'b'], [1, 'a']]);
1227
+ console.log([...tm.values()]); // ['a', 'b'];
1228
+ ```
1229
+
1230
+ ***
1231
+
1232
+ ### createDefaultComparator()
1233
+
1234
+ ```ts
1235
+ static createDefaultComparator<K>(): Comparator<K>;
1236
+ ```
1237
+
1238
+ Defined in: [data-structures/binary-tree/tree-map.ts:87](https://github.com/zrwusa/data-structure-typed/blob/2f6ceb3aee852228efc88b111e19c0809753e805/src/data-structures/binary-tree/tree-map.ts#L87)
1239
+
1240
+ Create the strict default comparator.
1241
+
1242
+ Supports:
1243
+ - `number` (rejects `NaN`; treats `-0` and `0` as equal)
1244
+ - `string`
1245
+ - `Date` (orders by `getTime()`, rejects invalid dates)
1246
+
1247
+ For other key types, a custom comparator must be provided.
1248
+
1249
+ #### Type Parameters
1250
+
1251
+ ##### K
1252
+
1253
+ `K`
1254
+
1255
+ #### Returns
1256
+
1257
+ `Comparator`\<`K`\>