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,1591 @@
1
+ [**data-structure-typed**](../README.md)
2
+
3
+ ***
4
+
5
+ [data-structure-typed](../README.md) / TreeMultiMap
6
+
7
+ # Class: TreeMultiMap\<K, V, R\>
8
+
9
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:28](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L28)
10
+
11
+ TreeMultiMap (ordered MultiMap) — key → bucket (Array of values).
12
+
13
+ Semantics (RFC):
14
+ - Bucketed design: each key appears once; duplicates live in the bucket.
15
+ - `get(key)` returns a **live** bucket reference.
16
+ - Default iteration yields bucket entries: `[K, V[]]`.
17
+ - Navigable operations (`first/last/ceiling/...`) return entry tuples like TreeMap.
18
+
19
+ ## Example
20
+
21
+ ```ts
22
+ // Morris traversal (O(1) space)
23
+ const tmm = new TreeMultiMap<number>([5, 3, 7]);
24
+ const result = tmm.morris(n => n.key, 'IN');
25
+ console.log(result.length); // > 0;
26
+ ```
27
+
28
+ ## Type Parameters
29
+
30
+ ### K
31
+
32
+ `K` = `any`
33
+
34
+ ### V
35
+
36
+ `V` = `any`
37
+
38
+ ### R
39
+
40
+ `R` = `any`
41
+
42
+ ## Implements
43
+
44
+ - `Iterable`\<\[`K`, `V`[]\]\>
45
+
46
+ ## Constructors
47
+
48
+ ### Constructor
49
+
50
+ ```ts
51
+ new TreeMultiMap<K, V, R>(keysNodesEntriesOrRaws?, options?): TreeMultiMap<K, V, R>;
52
+ ```
53
+
54
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:45](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L45)
55
+
56
+ Creates a new TreeMultiMap.
57
+
58
+ #### Parameters
59
+
60
+ ##### keysNodesEntriesOrRaws?
61
+
62
+ `Iterable`\<
63
+ \| `K`
64
+ \| `R`
65
+ \| \[`K` \| `null` \| `undefined`, `V`[] \| `undefined`\]
66
+ \| `null`
67
+ \| `undefined`\> = `[]`
68
+
69
+ Initial entries, or raw elements if `toEntryFn` is provided.
70
+
71
+ ##### options?
72
+
73
+ `TreeMultiMapOptions`\<`K`, `V`[], `R`\> = `{}`
74
+
75
+ Configuration options including optional `toEntryFn` to transform raw elements.
76
+
77
+ #### Returns
78
+
79
+ `TreeMultiMap`\<`K`, `V`, `R`\>
80
+
81
+ #### Remarks
82
+
83
+ Time O(m log m), Space O(m) where m is the number of initial entries
84
+
85
+ #### Example
86
+
87
+ ```ts
88
+ // Standard usage with entries
89
+ const mmap = new TreeMultiMap([['a', ['x', 'y']], ['b', ['z']]]);
90
+
91
+ // Using toEntryFn to transform raw objects
92
+ const players = [{ score: 100, items: ['sword'] }, { score: 200, items: ['shield', 'bow'] }];
93
+ const mmap = new TreeMultiMap(players, { toEntryFn: p => [p.score, p.items] });
94
+ ```
95
+
96
+ ## Accessors
97
+
98
+ ### comparator
99
+
100
+ #### Get Signature
101
+
102
+ ```ts
103
+ get comparator(): Comparator<K>;
104
+ ```
105
+
106
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4533](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4533)
107
+
108
+ Expose comparator for advanced usage/testing (read-only).
109
+
110
+ ##### Remarks
111
+
112
+ Time O(1), Space O(1)
113
+
114
+ ##### Returns
115
+
116
+ `Comparator`\<`K`\>
117
+
118
+ ***
119
+
120
+ ### size
121
+
122
+ #### Get Signature
123
+
124
+ ```ts
125
+ get size(): number;
126
+ ```
127
+
128
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:109](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L109)
129
+
130
+ Number of distinct keys.
131
+
132
+ ##### Remarks
133
+
134
+ Time O(1), Space O(1)
135
+
136
+ ##### Returns
137
+
138
+ `number`
139
+
140
+ ***
141
+
142
+ ### totalSize
143
+
144
+ #### Get Signature
145
+
146
+ ```ts
147
+ get totalSize(): number;
148
+ ```
149
+
150
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:532](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L532)
151
+
152
+ Total number of values across all buckets (Σ bucket.length).
153
+
154
+ ##### Remarks
155
+
156
+ Time O(n), Space O(1)
157
+
158
+ *
159
+
160
+ ##### Example
161
+
162
+ ```ts
163
+ // Total number of values
164
+ const mm = new TreeMultiMap<number, string>();
165
+ mm.add(1, 'a');
166
+ mm.add(1, 'b');
167
+ mm.add(2, 'c');
168
+ console.log(mm.totalSize); // 3;
169
+ ```
170
+
171
+ ##### Returns
172
+
173
+ `number`
174
+
175
+ ## Methods
176
+
177
+ ### \[iterator\]()
178
+
179
+ ```ts
180
+ iterator: Iterator<[K, V[]]>;
181
+ ```
182
+
183
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1721](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1721)
184
+
185
+ Iterates over all entries as [key, bucket] pairs.
186
+
187
+ #### Returns
188
+
189
+ `Iterator`\<\[`K`, `V`[]\]\>
190
+
191
+ #### Remarks
192
+
193
+ Time O(n), Space O(1)
194
+
195
+ #### Implementation of
196
+
197
+ ```ts
198
+ Iterable.[iterator]
199
+ ```
200
+
201
+ ***
202
+
203
+ ### add()
204
+
205
+ ```ts
206
+ add(key, value): boolean;
207
+ ```
208
+
209
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1123](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1123)
210
+
211
+ Append a single value.
212
+
213
+ #### Parameters
214
+
215
+ ##### key
216
+
217
+ `K`
218
+
219
+ ##### value
220
+
221
+ `V`
222
+
223
+ #### Returns
224
+
225
+ `boolean`
226
+
227
+ #### Remarks
228
+
229
+ Time O(log n), Space O(1)
230
+
231
+ *
232
+
233
+ #### Example
234
+
235
+ ```ts
236
+ // Add key-value pair
237
+ const mm = new TreeMultiMap<number, string>();
238
+ mm.add(1, 'a');
239
+ mm.add(1, 'b');
240
+ mm.add(2, 'c');
241
+ console.log(mm.get(1)); // ['a', 'b'];
242
+ ```
243
+
244
+ ***
245
+
246
+ ### ceiling()
247
+
248
+ ```ts
249
+ ceiling(key): [K, V[]] | undefined;
250
+ ```
251
+
252
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2624](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2624)
253
+
254
+ Returns the entry with the smallest key >= given key.
255
+
256
+ #### Parameters
257
+
258
+ ##### key
259
+
260
+ `K`
261
+
262
+ #### Returns
263
+
264
+ \[`K`, `V`[]\] \| `undefined`
265
+
266
+ #### Remarks
267
+
268
+ Time O(log n), Space O(1)
269
+
270
+ *
271
+
272
+ #### Example
273
+
274
+ ```ts
275
+ // Least key ≥ target
276
+ const mm = new TreeMultiMap<number, string>();
277
+ mm.add(10, 'a');
278
+ mm.add(20, 'b');
279
+ mm.add(30, 'c');
280
+ console.log(mm.ceiling(15)?.[0]); // 20;
281
+ ```
282
+
283
+ ***
284
+
285
+ ### clear()
286
+
287
+ ```ts
288
+ clear(): void;
289
+ ```
290
+
291
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:450](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L450)
292
+
293
+ Removes all entries from the map.
294
+
295
+ #### Returns
296
+
297
+ `void`
298
+
299
+ #### Remarks
300
+
301
+ Time O(1), Space O(1)
302
+
303
+ *
304
+
305
+ #### Example
306
+
307
+ ```ts
308
+ // Remove all entries
309
+ const mm = new TreeMultiMap<number, string>();
310
+ mm.add(1, 'a');
311
+ mm.clear();
312
+ console.log(mm.isEmpty()); // true;
313
+ ```
314
+
315
+ ***
316
+
317
+ ### clone()
318
+
319
+ ```ts
320
+ clone(): TreeMultiMap<K, V, R>;
321
+ ```
322
+
323
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4525](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4525)
324
+
325
+ Deep copy
326
+
327
+ *
328
+
329
+ #### Returns
330
+
331
+ `TreeMultiMap`\<`K`, `V`, `R`\>
332
+
333
+ #### Example
334
+
335
+ ```ts
336
+ // Deep clone
337
+ const mm = new TreeMultiMap<number, string>();
338
+ mm.add(1, 'a');
339
+ const copy = mm.clone();
340
+ copy.delete(1);
341
+ console.log(mm.has(1)); // true;
342
+ ```
343
+
344
+ ***
345
+
346
+ ### count()
347
+
348
+ ```ts
349
+ count(key): number;
350
+ ```
351
+
352
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:490](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L490)
353
+
354
+ Bucket length for a key (missing => 0).
355
+
356
+ #### Parameters
357
+
358
+ ##### key
359
+
360
+ `K`
361
+
362
+ #### Returns
363
+
364
+ `number`
365
+
366
+ #### Remarks
367
+
368
+ Time O(log n), Space O(1)
369
+
370
+ *
371
+
372
+ #### Example
373
+
374
+ ```ts
375
+ // Count values for key
376
+ const mm = new TreeMultiMap<number, string>();
377
+ mm.add(1, 'a');
378
+ mm.add(1, 'b');
379
+ console.log(mm.count(1)); // 2;
380
+ ```
381
+
382
+ ***
383
+
384
+ ### delete()
385
+
386
+ ```ts
387
+ delete(key): boolean;
388
+ ```
389
+
390
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1569](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1569)
391
+
392
+ Deletes a key and its entire bucket.
393
+
394
+ #### Parameters
395
+
396
+ ##### key
397
+
398
+ `K`
399
+
400
+ #### Returns
401
+
402
+ `boolean`
403
+
404
+ #### Remarks
405
+
406
+ Time O(log n), Space O(1)
407
+
408
+ *
409
+
410
+ #### Example
411
+
412
+ ```ts
413
+ // Remove key
414
+ const mm = new TreeMultiMap<number, string>();
415
+ mm.add(1, 'a');
416
+ mm.add(2, 'b');
417
+ mm.delete(1);
418
+ console.log(mm.has(1)); // false;
419
+ ```
420
+
421
+ ***
422
+
423
+ ### deleteValue()
424
+
425
+ ```ts
426
+ deleteValue(
427
+ key,
428
+ value,
429
+ eq?): boolean;
430
+ ```
431
+
432
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1653](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1653)
433
+
434
+ Delete a single occurrence of a value from a key's bucket.
435
+
436
+ #### Parameters
437
+
438
+ ##### key
439
+
440
+ `K`
441
+
442
+ ##### value
443
+
444
+ `V`
445
+
446
+ ##### eq?
447
+
448
+ (`a`, `b`) => `boolean`
449
+
450
+ #### Returns
451
+
452
+ `boolean`
453
+
454
+ #### Remarks
455
+
456
+ Time O(log n + m), Space O(1) where m is bucket size
457
+
458
+ *
459
+
460
+ #### Example
461
+
462
+ ```ts
463
+ // Delete specific value
464
+ const mm = new TreeMultiMap<number, string>();
465
+ mm.add(1, 'a');
466
+ mm.add(1, 'b');
467
+ mm.deleteValue(1, 'a');
468
+ console.log(mm.get(1)); // ['b'];
469
+ ```
470
+
471
+ ***
472
+
473
+ ### deleteValues()
474
+
475
+ ```ts
476
+ deleteValues(
477
+ key,
478
+ value,
479
+ eq?): number;
480
+ ```
481
+
482
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1701](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1701)
483
+
484
+ Delete all occurrences of a value from a key's bucket.
485
+
486
+ #### Parameters
487
+
488
+ ##### key
489
+
490
+ `K`
491
+
492
+ ##### value
493
+
494
+ `V`
495
+
496
+ ##### eq?
497
+
498
+ (`a`, `b`) => `boolean`
499
+
500
+ #### Returns
501
+
502
+ `number`
503
+
504
+ #### Remarks
505
+
506
+ Time O(log n + m), Space O(1) where m is bucket size
507
+
508
+ *
509
+
510
+ #### Example
511
+
512
+ ```ts
513
+ // Delete all matching values
514
+ const mm = new TreeMultiMap<number, string>();
515
+ mm.add(1, 'a');
516
+ mm.add(1, 'a');
517
+ mm.add(1, 'b');
518
+ const count = mm.deleteValues(1, 'a');
519
+ console.log(count); // 2;
520
+ ```
521
+
522
+ ***
523
+
524
+ ### entriesOf()
525
+
526
+ ```ts
527
+ entriesOf(key): IterableIterator<[K, V]>;
528
+ ```
529
+
530
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2110](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2110)
531
+
532
+ Iterates over all entries for a specific key.
533
+
534
+ #### Parameters
535
+
536
+ ##### key
537
+
538
+ `K`
539
+
540
+ #### Returns
541
+
542
+ `IterableIterator`\<\[`K`, `V`\]\>
543
+
544
+ #### Remarks
545
+
546
+ Time O(log n + m), Space O(1) where m is bucket size
547
+
548
+ *
549
+
550
+ #### Example
551
+
552
+ ```ts
553
+ // Get entries for key
554
+ const mm = new TreeMultiMap<number, string>();
555
+ mm.add(1, 'a');
556
+ mm.add(1, 'b');
557
+ console.log([...mm.entriesOf(1)]); // [[1, 'a'], [1, 'b']];
558
+ ```
559
+
560
+ ***
561
+
562
+ ### filter()
563
+
564
+ ```ts
565
+ filter(predicate): TreeMultiMap<K, V, R>;
566
+ ```
567
+
568
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:3619](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L3619)
569
+
570
+ Creates a new map with entries that pass the predicate.
571
+
572
+ #### Parameters
573
+
574
+ ##### predicate
575
+
576
+ (`value`, `key`, `map`) => `boolean`
577
+
578
+ #### Returns
579
+
580
+ `TreeMultiMap`\<`K`, `V`, `R`\>
581
+
582
+ #### Remarks
583
+
584
+ Time O(n), Space O(n)
585
+
586
+ *
587
+
588
+ #### Example
589
+
590
+ ```ts
591
+ // Filter entries
592
+ const mm = new TreeMultiMap<number, string>();
593
+ mm.add(1, 'a');
594
+ mm.add(2, 'b');
595
+ mm.add(3, 'c');
596
+ const filtered = mm.filter((v, k) => k > 1);
597
+ console.log([...filtered.keys()]); // [2, 3];
598
+ ```
599
+
600
+ ***
601
+
602
+ ### first()
603
+
604
+ ```ts
605
+ first(): [K, V[]] | undefined;
606
+ ```
607
+
608
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2275](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2275)
609
+
610
+ Returns the entry with the smallest key.
611
+
612
+ #### Returns
613
+
614
+ \[`K`, `V`[]\] \| `undefined`
615
+
616
+ #### Remarks
617
+
618
+ Time O(log n), Space O(1)
619
+
620
+ *
621
+
622
+ #### Example
623
+
624
+ ```ts
625
+ // First entry
626
+ const mm = new TreeMultiMap<number, string>();
627
+ mm.add(3, 'c');
628
+ mm.add(1, 'a');
629
+ console.log(mm.first()?.[0]); // 1;
630
+ ```
631
+
632
+ ***
633
+
634
+ ### flatEntries()
635
+
636
+ ```ts
637
+ flatEntries(): IterableIterator<[K, V]>;
638
+ ```
639
+
640
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2195](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2195)
641
+
642
+ Iterates over all [key, value] pairs (flattened from buckets).
643
+
644
+ #### Returns
645
+
646
+ `IterableIterator`\<\[`K`, `V`\]\>
647
+
648
+ #### Remarks
649
+
650
+ Time O(T), Space O(1) where T is totalSize
651
+
652
+ *
653
+
654
+ #### Example
655
+
656
+ ```ts
657
+ // All key-value pairs flattened
658
+ const mm = new TreeMultiMap<number, string>();
659
+ mm.add(1, 'a');
660
+ mm.add(1, 'b');
661
+ mm.add(2, 'c');
662
+ console.log([...mm.flatEntries()]); // [[1, 'a'], [1, 'b'], [2, 'c']];
663
+ ```
664
+
665
+ ***
666
+
667
+ ### floor()
668
+
669
+ ```ts
670
+ floor(key): [K, V[]] | undefined;
671
+ ```
672
+
673
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2804](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2804)
674
+
675
+ Returns the entry with the largest key <= given key.
676
+
677
+ #### Parameters
678
+
679
+ ##### key
680
+
681
+ `K`
682
+
683
+ #### Returns
684
+
685
+ \[`K`, `V`[]\] \| `undefined`
686
+
687
+ #### Remarks
688
+
689
+ Time O(log n), Space O(1)
690
+
691
+ *
692
+
693
+ #### Example
694
+
695
+ ```ts
696
+ // Greatest key ≤ target
697
+ const mm = new TreeMultiMap<number, string>();
698
+ mm.add(10, 'a');
699
+ mm.add(20, 'b');
700
+ mm.add(30, 'c');
701
+ console.log(mm.floor(25)?.[0]); // 20;
702
+ ```
703
+
704
+ ***
705
+
706
+ ### forEach()
707
+
708
+ ```ts
709
+ forEach(callback): void;
710
+ ```
711
+
712
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:3443](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L3443)
713
+
714
+ Executes a callback for each entry.
715
+
716
+ #### Parameters
717
+
718
+ ##### callback
719
+
720
+ (`value`, `key`, `map`) => `void`
721
+
722
+ #### Returns
723
+
724
+ `void`
725
+
726
+ #### Remarks
727
+
728
+ Time O(n), Space O(1)
729
+
730
+ *
731
+
732
+ #### Example
733
+
734
+ ```ts
735
+ // Iterate entries
736
+ const mm = new TreeMultiMap<number, string>();
737
+ mm.add(1, 'a');
738
+ mm.add(2, 'b');
739
+ const keys: number[] = [];
740
+ mm.forEach((v, k) => keys.push(k));
741
+ console.log(keys); // [1, 2];
742
+ ```
743
+
744
+ ***
745
+
746
+ ### get()
747
+
748
+ ```ts
749
+ get(key): V[] | undefined;
750
+ ```
751
+
752
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:955](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L955)
753
+
754
+ Live bucket reference (do not auto-delete key if bucket becomes empty via mutation).
755
+
756
+ #### Parameters
757
+
758
+ ##### key
759
+
760
+ `K`
761
+
762
+ #### Returns
763
+
764
+ `V`[] \| `undefined`
765
+
766
+ #### Remarks
767
+
768
+ Time O(log n), Space O(1)
769
+
770
+ *
771
+
772
+ #### Example
773
+
774
+ ```ts
775
+ // Get values for key
776
+ const mm = new TreeMultiMap<number, string>();
777
+ mm.add(1, 'a');
778
+ mm.add(1, 'b');
779
+ console.log(mm.get(1)); // ['a', 'b'];
780
+ ```
781
+
782
+ ***
783
+
784
+ ### getByRank()
785
+
786
+ ```ts
787
+ getByRank(k): [K, V[]] | undefined;
788
+ ```
789
+
790
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4463](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4463)
791
+
792
+ Creates a shallow clone of this map.
793
+
794
+ #### Parameters
795
+
796
+ ##### k
797
+
798
+ `number`
799
+
800
+ #### Returns
801
+
802
+ \[`K`, `V`[]\] \| `undefined`
803
+
804
+ #### Remarks
805
+
806
+ Time O(n log n), Space O(n)
807
+
808
+ *
809
+
810
+ #### Example
811
+
812
+ ```ts
813
+ // Order-statistic on BST
814
+ const tree = new TreeMultiMap<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
815
+ console.log(tree.getByRank(0)); // 10;
816
+ console.log(tree.getByRank(4)); // 50;
817
+ console.log(tree.getRank(30)); // 2;
818
+ ```
819
+
820
+ ***
821
+
822
+ ### getRank()
823
+
824
+ ```ts
825
+ getRank(key): number;
826
+ ```
827
+
828
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4482](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4482)
829
+
830
+ Get the rank of a key in sorted order
831
+
832
+ #### Parameters
833
+
834
+ ##### key
835
+
836
+ `K`
837
+
838
+ #### Returns
839
+
840
+ `number`
841
+
842
+ #### Example
843
+
844
+ ```ts
845
+ // Get the rank of a key in sorted order
846
+ const tree = new TreeMultiMap<number>(
847
+ [10, 20, 30, 40, 50],
848
+ { enableOrderStatistic: true }
849
+ );
850
+ console.log(tree.getRank(10)); // 0; // smallest → rank 0
851
+ console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
852
+ console.log(tree.getRank(50)); // 4; // largest → rank 4
853
+ console.log(tree.getRank(25)); // 2;
854
+ ```
855
+
856
+ ***
857
+
858
+ ### has()
859
+
860
+ ```ts
861
+ has(key): boolean;
862
+ ```
863
+
864
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:744](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L744)
865
+
866
+ Whether the map contains the given key.
867
+
868
+ #### Parameters
869
+
870
+ ##### key
871
+
872
+ `K`
873
+
874
+ #### Returns
875
+
876
+ `boolean`
877
+
878
+ #### Remarks
879
+
880
+ Time O(log n), Space O(1)
881
+
882
+ *
883
+
884
+ #### Example
885
+
886
+ ```ts
887
+ // Check key existence
888
+ const mm = new TreeMultiMap<number, string>();
889
+ mm.add(1, 'a');
890
+ console.log(mm.has(1)); // true;
891
+ console.log(mm.has(2)); // false;
892
+ ```
893
+
894
+ ***
895
+
896
+ ### hasEntry()
897
+
898
+ ```ts
899
+ hasEntry(
900
+ key,
901
+ value,
902
+ eq?): boolean;
903
+ ```
904
+
905
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1610](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1610)
906
+
907
+ Check if a specific value exists in a key's bucket.
908
+
909
+ #### Parameters
910
+
911
+ ##### key
912
+
913
+ `K`
914
+
915
+ ##### value
916
+
917
+ `V`
918
+
919
+ ##### eq?
920
+
921
+ (`a`, `b`) => `boolean`
922
+
923
+ #### Returns
924
+
925
+ `boolean`
926
+
927
+ #### Remarks
928
+
929
+ Time O(log n + m), Space O(1) where m is bucket size
930
+
931
+ *
932
+
933
+ #### Example
934
+
935
+ ```ts
936
+ // Check specific key-value
937
+ const mm = new TreeMultiMap<number, string>();
938
+ mm.add(1, 'a');
939
+ console.log(mm.hasEntry(1, 'a')); // true;
940
+ console.log(mm.hasEntry(1, 'z')); // false;
941
+ ```
942
+
943
+ ***
944
+
945
+ ### higher()
946
+
947
+ ```ts
948
+ higher(key): [K, V[]] | undefined;
949
+ ```
950
+
951
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2948](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2948)
952
+
953
+ Returns the entry with the smallest key > given key.
954
+
955
+ #### Parameters
956
+
957
+ ##### key
958
+
959
+ `K`
960
+
961
+ #### Returns
962
+
963
+ \[`K`, `V`[]\] \| `undefined`
964
+
965
+ #### Remarks
966
+
967
+ Time O(log n), Space O(1)
968
+
969
+ *
970
+
971
+ #### Example
972
+
973
+ ```ts
974
+ // Least key > target
975
+ const mm = new TreeMultiMap<number, string>();
976
+ mm.add(10, 'a');
977
+ mm.add(20, 'b');
978
+ console.log(mm.higher(10)?.[0]); // 20;
979
+ ```
980
+
981
+ ***
982
+
983
+ ### isEmpty()
984
+
985
+ ```ts
986
+ isEmpty(): boolean;
987
+ ```
988
+
989
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:278](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L278)
990
+
991
+ Whether the map is empty.
992
+
993
+ #### Returns
994
+
995
+ `boolean`
996
+
997
+ #### Remarks
998
+
999
+ Time O(1), Space O(1)
1000
+
1001
+ *
1002
+
1003
+ #### Example
1004
+
1005
+ ```ts
1006
+ // Check if empty
1007
+ console.log(new TreeMultiMap().isEmpty()); // true;
1008
+ ```
1009
+
1010
+ ***
1011
+
1012
+ ### keys()
1013
+
1014
+ ```ts
1015
+ keys(): IterableIterator<K>;
1016
+ ```
1017
+
1018
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1896](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1896)
1019
+
1020
+ Iterates over all keys.
1021
+
1022
+ #### Returns
1023
+
1024
+ `IterableIterator`\<`K`\>
1025
+
1026
+ #### Remarks
1027
+
1028
+ Time O(n), Space O(1)
1029
+
1030
+ *
1031
+
1032
+ #### Example
1033
+
1034
+ ```ts
1035
+ // Iterate keys
1036
+ const mm = new TreeMultiMap<number, string>();
1037
+ mm.add(3, 'c');
1038
+ mm.add(1, 'a');
1039
+ console.log([...mm.keys()]); // [1, 3];
1040
+ ```
1041
+
1042
+ ***
1043
+
1044
+ ### last()
1045
+
1046
+ ```ts
1047
+ last(): [K, V[]] | undefined;
1048
+ ```
1049
+
1050
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2354](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2354)
1051
+
1052
+ Returns the entry with the largest key.
1053
+
1054
+ #### Returns
1055
+
1056
+ \[`K`, `V`[]\] \| `undefined`
1057
+
1058
+ #### Remarks
1059
+
1060
+ Time O(log n), Space O(1)
1061
+
1062
+ *
1063
+
1064
+ #### Example
1065
+
1066
+ ```ts
1067
+ // Last entry
1068
+ const mm = new TreeMultiMap<number, string>();
1069
+ mm.add(1, 'a');
1070
+ mm.add(3, 'c');
1071
+ console.log(mm.last()?.[0]); // 3;
1072
+ ```
1073
+
1074
+ ***
1075
+
1076
+ ### lower()
1077
+
1078
+ ```ts
1079
+ lower(key): [K, V[]] | undefined;
1080
+ ```
1081
+
1082
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:3092](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L3092)
1083
+
1084
+ Returns the entry with the largest key < given key.
1085
+
1086
+ #### Parameters
1087
+
1088
+ ##### key
1089
+
1090
+ `K`
1091
+
1092
+ #### Returns
1093
+
1094
+ \[`K`, `V`[]\] \| `undefined`
1095
+
1096
+ #### Remarks
1097
+
1098
+ Time O(log n), Space O(1)
1099
+
1100
+ *
1101
+
1102
+ #### Example
1103
+
1104
+ ```ts
1105
+ // Greatest key < target
1106
+ const mm = new TreeMultiMap<number, string>();
1107
+ mm.add(10, 'a');
1108
+ mm.add(20, 'b');
1109
+ console.log(mm.lower(20)?.[0]); // 10;
1110
+ ```
1111
+
1112
+ ***
1113
+
1114
+ ### map()
1115
+
1116
+ ```ts
1117
+ map<V2>(mapper): TreeMultiMap<K, V2, R>;
1118
+ ```
1119
+
1120
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:3795](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L3795)
1121
+
1122
+ Creates a new map by transforming each entry.
1123
+
1124
+ #### Type Parameters
1125
+
1126
+ ##### V2
1127
+
1128
+ `V2`
1129
+
1130
+ #### Parameters
1131
+
1132
+ ##### mapper
1133
+
1134
+ (`value`, `key`, `map`) => \[`K`, `V2`[]\]
1135
+
1136
+ #### Returns
1137
+
1138
+ `TreeMultiMap`\<`K`, `V2`, `R`\>
1139
+
1140
+ #### Remarks
1141
+
1142
+ Time O(n log n), Space O(n)
1143
+
1144
+ *
1145
+
1146
+ #### Example
1147
+
1148
+ ```ts
1149
+ // Transform values
1150
+ const mm = new TreeMultiMap<number, string>();
1151
+ mm.add(1, 'a');
1152
+ const mapped = mm.map((v, k) => [k, v.map(s => s.toUpperCase())] as [number, string[]]);
1153
+ console.log(mapped.get(1)); // ['A'];
1154
+ ```
1155
+
1156
+ ***
1157
+
1158
+ ### pollFirst()
1159
+
1160
+ ```ts
1161
+ pollFirst(): [K, V[]] | undefined;
1162
+ ```
1163
+
1164
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2400](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2400)
1165
+
1166
+ Removes and returns the entry with the smallest key.
1167
+
1168
+ #### Returns
1169
+
1170
+ \[`K`, `V`[]\] \| `undefined`
1171
+
1172
+ #### Remarks
1173
+
1174
+ Time O(log n), Space O(1)
1175
+
1176
+ *
1177
+
1178
+ #### Example
1179
+
1180
+ ```ts
1181
+ // Remove and return first
1182
+ const mm = new TreeMultiMap<number, string>();
1183
+ mm.add(2, 'b');
1184
+ mm.add(1, 'a');
1185
+ const first = mm.pollFirst();
1186
+ console.log(first?.[0]); // 1;
1187
+ console.log(mm.has(1)); // false;
1188
+ ```
1189
+
1190
+ ***
1191
+
1192
+ ### pollLast()
1193
+
1194
+ ```ts
1195
+ pollLast(): [K, V[]] | undefined;
1196
+ ```
1197
+
1198
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2445](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2445)
1199
+
1200
+ Removes and returns the entry with the largest key.
1201
+
1202
+ #### Returns
1203
+
1204
+ \[`K`, `V`[]\] \| `undefined`
1205
+
1206
+ #### Remarks
1207
+
1208
+ Time O(log n), Space O(1)
1209
+
1210
+ *
1211
+
1212
+ #### Example
1213
+
1214
+ ```ts
1215
+ // Remove and return last
1216
+ const mm = new TreeMultiMap<number, string>();
1217
+ mm.add(1, 'a');
1218
+ mm.add(3, 'c');
1219
+ const last = mm.pollLast();
1220
+ console.log(last?.[0]); // 3;
1221
+ ```
1222
+
1223
+ ***
1224
+
1225
+ ### print()
1226
+
1227
+ ```ts
1228
+ print(): void;
1229
+ ```
1230
+
1231
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:3269](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L3269)
1232
+
1233
+ Prints the internal tree structure (for debugging).
1234
+
1235
+ #### Returns
1236
+
1237
+ `void`
1238
+
1239
+ #### Remarks
1240
+
1241
+ Time O(n), Space O(n)
1242
+
1243
+ *
1244
+
1245
+ #### Example
1246
+
1247
+ ```ts
1248
+ // Display tree
1249
+ const mm = new TreeMultiMap<number, string>();
1250
+ mm.add(1, 'a');
1251
+ expect(() => mm.print()).not.toThrow();
1252
+ ```
1253
+
1254
+ ***
1255
+
1256
+ ### rangeByRank()
1257
+
1258
+ ```ts
1259
+ rangeByRank(start, end): [K, V[]][];
1260
+ ```
1261
+
1262
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4504](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4504)
1263
+
1264
+ Get elements by rank range
1265
+
1266
+ *
1267
+
1268
+ #### Parameters
1269
+
1270
+ ##### start
1271
+
1272
+ `number`
1273
+
1274
+ ##### end
1275
+
1276
+ `number`
1277
+
1278
+ #### Returns
1279
+
1280
+ \[`K`, `V`[]\][]
1281
+
1282
+ #### Example
1283
+
1284
+ ```ts
1285
+ // Pagination with rangeByRank
1286
+ const tree = new TreeMultiMap<number>(
1287
+ [10, 20, 30, 40, 50, 60, 70, 80, 90],
1288
+ { enableOrderStatistic: true }
1289
+ );
1290
+ const pageSize = 3;
1291
+
1292
+ // Page 1
1293
+ console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
1294
+ // Page 2
1295
+ console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
1296
+ // Page 3
1297
+ console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
1298
+ ```
1299
+
1300
+ ***
1301
+
1302
+ ### rangeSearch()
1303
+
1304
+ ```ts
1305
+ rangeSearch<C>(range, callback?): ReturnType<C>[];
1306
+ ```
1307
+
1308
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4288](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4288)
1309
+
1310
+ Searches for entries within a key range.
1311
+
1312
+ #### Type Parameters
1313
+
1314
+ ##### C
1315
+
1316
+ `C` *extends* (`node`) => `unknown`
1317
+
1318
+ #### Parameters
1319
+
1320
+ ##### range
1321
+
1322
+ `Range`\<`K`\> \| \[`K`, `K`\]
1323
+
1324
+ ##### callback?
1325
+
1326
+ `C`
1327
+
1328
+ #### Returns
1329
+
1330
+ `ReturnType`\<`C`\>[]
1331
+
1332
+ #### Remarks
1333
+
1334
+ Time O(log n + k), Space O(k) where k is result size
1335
+
1336
+ *
1337
+
1338
+ #### Example
1339
+
1340
+ ```ts
1341
+ // Find keys in range
1342
+ const mm = new TreeMultiMap<number, string>();
1343
+ mm.add(10, 'a');
1344
+ mm.add(20, 'b');
1345
+ mm.add(30, 'c');
1346
+ const result = mm.rangeSearch([15, 25]);
1347
+ console.log(result.length); // 1;
1348
+ ```
1349
+
1350
+ ***
1351
+
1352
+ ### reduce()
1353
+
1354
+ ```ts
1355
+ reduce<U>(callback, initialValue): U;
1356
+ ```
1357
+
1358
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:3974](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L3974)
1359
+
1360
+ Reduces all entries to a single value.
1361
+
1362
+ #### Type Parameters
1363
+
1364
+ ##### U
1365
+
1366
+ `U`
1367
+
1368
+ #### Parameters
1369
+
1370
+ ##### callback
1371
+
1372
+ (`accumulator`, `value`, `key`, `map`) => `U`
1373
+
1374
+ ##### initialValue
1375
+
1376
+ `U`
1377
+
1378
+ #### Returns
1379
+
1380
+ `U`
1381
+
1382
+ #### Remarks
1383
+
1384
+ Time O(n), Space O(1)
1385
+
1386
+ *
1387
+
1388
+ #### Example
1389
+
1390
+ ```ts
1391
+ // Aggregate
1392
+ const mm = new TreeMultiMap<number, number>();
1393
+ mm.add(1, 10);
1394
+ mm.add(2, 20);
1395
+ const sum = mm.reduce((acc, v) => acc + v.reduce((a, b) => a + b, 0), 0);
1396
+ console.log(sum); // 30;
1397
+ ```
1398
+
1399
+ ***
1400
+
1401
+ ### set()
1402
+
1403
+ #### Call Signature
1404
+
1405
+ ```ts
1406
+ set(entry, value?): boolean;
1407
+ ```
1408
+
1409
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1337](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1337)
1410
+
1411
+ Alias for compatibility with existing TreeMultiMap semantics.
1412
+
1413
+ ##### Parameters
1414
+
1415
+ ###### entry
1416
+
1417
+ \| `K`
1418
+ \| \[`K` \| `null` \| `undefined`, `V`[] \| `undefined`\]
1419
+ \| `null`
1420
+ \| `undefined`
1421
+
1422
+ ###### value?
1423
+
1424
+ `V`
1425
+
1426
+ ##### Returns
1427
+
1428
+ `boolean`
1429
+
1430
+ ##### Remarks
1431
+
1432
+ Time O(log n), Space O(1) for single value; O(log n + m) for bucket append
1433
+
1434
+ *
1435
+
1436
+ ##### Example
1437
+
1438
+ ```ts
1439
+ // Set values for key
1440
+ const mm = new TreeMultiMap<number, string>();
1441
+ mm.set(1, 'a');
1442
+ mm.set(1, 'b');
1443
+ console.log(mm.get(1)); // ['a', 'b'];
1444
+ ```
1445
+
1446
+ #### Call Signature
1447
+
1448
+ ```ts
1449
+ set(key, value): boolean;
1450
+ ```
1451
+
1452
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:1338](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L1338)
1453
+
1454
+ Alias for compatibility with existing TreeMultiMap semantics.
1455
+
1456
+ ##### Parameters
1457
+
1458
+ ###### key
1459
+
1460
+ `K`
1461
+
1462
+ ###### value
1463
+
1464
+ `V`
1465
+
1466
+ ##### Returns
1467
+
1468
+ `boolean`
1469
+
1470
+ ##### Remarks
1471
+
1472
+ Time O(log n), Space O(1) for single value; O(log n + m) for bucket append
1473
+
1474
+ *
1475
+
1476
+ ##### Example
1477
+
1478
+ ```ts
1479
+ // Set values for key
1480
+ const mm = new TreeMultiMap<number, string>();
1481
+ mm.set(1, 'a');
1482
+ mm.set(1, 'b');
1483
+ console.log(mm.get(1)); // ['a', 'b'];
1484
+ ```
1485
+
1486
+ ***
1487
+
1488
+ ### setMany()
1489
+
1490
+ ```ts
1491
+ setMany(keysNodesEntriesOrRaws): boolean[];
1492
+ ```
1493
+
1494
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:4141](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L4141)
1495
+
1496
+ Sets multiple entries at once.
1497
+
1498
+ #### Parameters
1499
+
1500
+ ##### keysNodesEntriesOrRaws
1501
+
1502
+ `Iterable`\<`K` \| \[`K` \| `null` \| `undefined`, `V`[] \| `undefined`\]\>
1503
+
1504
+ #### Returns
1505
+
1506
+ `boolean`[]
1507
+
1508
+ #### Remarks
1509
+
1510
+ Time O(m log n), Space O(m) where m is input size
1511
+
1512
+ *
1513
+
1514
+ #### Example
1515
+
1516
+ ```ts
1517
+ // Set multiple entries
1518
+ const mm = new TreeMultiMap<number, string>();
1519
+ mm.setMany([[1, ['a']], [2, ['b']]]);
1520
+ console.log(mm.size); // 2;
1521
+ ```
1522
+
1523
+ ***
1524
+
1525
+ ### values()
1526
+
1527
+ ```ts
1528
+ values(): IterableIterator<V[]>;
1529
+ ```
1530
+
1531
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2068](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2068)
1532
+
1533
+ Iterates over all buckets.
1534
+
1535
+ #### Returns
1536
+
1537
+ `IterableIterator`\<`V`[]\>
1538
+
1539
+ #### Remarks
1540
+
1541
+ Time O(n), Space O(1)
1542
+
1543
+ *
1544
+
1545
+ #### Example
1546
+
1547
+ ```ts
1548
+ // Iterate value arrays
1549
+ const mm = new TreeMultiMap<number, string>();
1550
+ mm.add(1, 'a');
1551
+ mm.add(1, 'b');
1552
+ console.log([...mm.values()]); // [['a', 'b']];
1553
+ ```
1554
+
1555
+ ***
1556
+
1557
+ ### valuesOf()
1558
+
1559
+ ```ts
1560
+ valuesOf(key): IterableIterator<V>;
1561
+ ```
1562
+
1563
+ Defined in: [data-structures/binary-tree/tree-multi-map.ts:2152](https://github.com/zrwusa/data-structure-typed/blob/8292cb978daf85ebe846186c7c7572aece04fb7b/src/data-structures/binary-tree/tree-multi-map.ts#L2152)
1564
+
1565
+ Iterates over all values for a specific key.
1566
+
1567
+ #### Parameters
1568
+
1569
+ ##### key
1570
+
1571
+ `K`
1572
+
1573
+ #### Returns
1574
+
1575
+ `IterableIterator`\<`V`\>
1576
+
1577
+ #### Remarks
1578
+
1579
+ Time O(log n + m), Space O(1) where m is bucket size
1580
+
1581
+ *
1582
+
1583
+ #### Example
1584
+
1585
+ ```ts
1586
+ // Get flat values for key
1587
+ const mm = new TreeMultiMap<number, string>();
1588
+ mm.add(1, 'a');
1589
+ mm.add(1, 'b');
1590
+ console.log([...mm.valuesOf(1)]); // ['a', 'b'];
1591
+ ```