trie-typed 2.1.1 → 2.2.0

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 (288) hide show
  1. package/dist/cjs/index.cjs +797 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs-legacy/index.cjs +795 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +792 -0
  6. package/dist/esm/index.mjs.map +1 -0
  7. package/dist/esm-legacy/index.mjs +790 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -0
  9. package/dist/types/data-structures/base/index.d.ts +2 -1
  10. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -2
  11. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -2
  12. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +345 -2
  13. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  14. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  15. package/dist/types/data-structures/binary-tree/bst.d.ts +467 -12
  16. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  17. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +262 -3
  18. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  19. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +244 -2
  20. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +332 -2
  21. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  22. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  23. package/dist/types/data-structures/graph/index.d.ts +2 -1
  24. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  25. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  26. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  27. package/dist/types/data-structures/hash/index.d.ts +0 -1
  28. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  29. package/dist/types/data-structures/heap/index.d.ts +2 -0
  30. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  31. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  32. package/dist/types/data-structures/index.d.ts +7 -7
  33. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  34. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  35. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  36. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  37. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  38. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  39. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  40. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  41. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  42. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  43. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  44. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  45. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  46. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  47. package/dist/types/index.d.ts +11 -2
  48. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  49. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  51. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  52. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  53. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  54. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  55. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  56. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  57. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  58. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  59. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  60. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  61. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  62. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  63. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  64. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  65. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  66. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  67. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  68. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  69. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  70. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  71. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  72. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  73. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  74. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  75. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  76. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  77. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  78. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  79. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  80. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  81. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  82. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  83. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  84. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  85. package/dist/types/types/index.d.ts +3 -0
  86. package/dist/types/types/utils/index.d.ts +2 -0
  87. package/dist/types/types/utils/utils.d.ts +22 -0
  88. package/dist/types/utils/index.d.ts +1 -1
  89. package/dist/types/utils/utils.d.ts +209 -22
  90. package/dist/umd/trie-typed.js +802 -0
  91. package/dist/umd/trie-typed.js.map +1 -0
  92. package/dist/umd/trie-typed.min.js +9 -0
  93. package/dist/umd/trie-typed.min.js.map +1 -0
  94. package/package.json +43 -5
  95. package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
  96. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  97. package/src/data-structures/binary-tree/avl-tree.ts +107 -16
  98. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  99. package/src/data-structures/binary-tree/bst.ts +103 -12
  100. package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
  101. package/src/data-structures/binary-tree/tree-counter.ts +105 -14
  102. package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
  103. package/src/data-structures/graph/abstract-graph.ts +5 -5
  104. package/src/data-structures/graph/directed-graph.ts +5 -5
  105. package/src/data-structures/graph/undirected-graph.ts +5 -5
  106. package/src/data-structures/heap/heap.ts +5 -5
  107. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  108. package/src/interfaces/binary-tree.ts +1 -1
  109. package/tsconfig.base.json +23 -0
  110. package/tsconfig.json +8 -34
  111. package/tsconfig.test.json +8 -0
  112. package/tsconfig.types.json +15 -0
  113. package/tsup.config.js +28 -0
  114. package/tsup.node.config.js +71 -0
  115. package/dist/common/index.js +0 -28
  116. package/dist/constants/index.js +0 -8
  117. package/dist/data-structures/base/index.d.ts +0 -2
  118. package/dist/data-structures/base/index.js +0 -18
  119. package/dist/data-structures/base/iterable-element-base.js +0 -243
  120. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  121. package/dist/data-structures/base/linear-base.js +0 -415
  122. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  123. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  124. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  125. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  126. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  127. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  128. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  129. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  130. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  131. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  132. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  133. package/dist/data-structures/binary-tree/bst.js +0 -903
  134. package/dist/data-structures/binary-tree/index.js +0 -26
  135. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  136. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  137. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  138. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  139. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  140. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  141. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  142. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  143. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  144. package/dist/data-structures/graph/abstract-graph.js +0 -896
  145. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  146. package/dist/data-structures/graph/directed-graph.js +0 -525
  147. package/dist/data-structures/graph/index.js +0 -20
  148. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  149. package/dist/data-structures/graph/map-graph.js +0 -107
  150. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  151. package/dist/data-structures/graph/undirected-graph.js +0 -424
  152. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  153. package/dist/data-structures/hash/hash-map.js +0 -692
  154. package/dist/data-structures/hash/index.d.ts +0 -1
  155. package/dist/data-structures/hash/index.js +0 -17
  156. package/dist/data-structures/heap/heap.d.ts +0 -503
  157. package/dist/data-structures/heap/heap.js +0 -901
  158. package/dist/data-structures/heap/index.d.ts +0 -3
  159. package/dist/data-structures/heap/index.js +0 -19
  160. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  161. package/dist/data-structures/heap/max-heap.js +0 -40
  162. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  163. package/dist/data-structures/heap/min-heap.js +0 -31
  164. package/dist/data-structures/index.js +0 -28
  165. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  166. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  167. package/dist/data-structures/linked-list/index.js +0 -19
  168. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  169. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  170. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  171. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  172. package/dist/data-structures/matrix/index.js +0 -18
  173. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  174. package/dist/data-structures/matrix/matrix.js +0 -448
  175. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  176. package/dist/data-structures/matrix/navigator.js +0 -111
  177. package/dist/data-structures/priority-queue/index.js +0 -19
  178. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  179. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  180. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  181. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  182. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  183. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  184. package/dist/data-structures/queue/deque.d.ts +0 -431
  185. package/dist/data-structures/queue/deque.js +0 -879
  186. package/dist/data-structures/queue/index.js +0 -18
  187. package/dist/data-structures/queue/queue.d.ts +0 -308
  188. package/dist/data-structures/queue/queue.js +0 -473
  189. package/dist/data-structures/stack/index.js +0 -17
  190. package/dist/data-structures/stack/stack.d.ts +0 -306
  191. package/dist/data-structures/stack/stack.js +0 -401
  192. package/dist/data-structures/tree/index.js +0 -17
  193. package/dist/data-structures/tree/tree.d.ts +0 -62
  194. package/dist/data-structures/tree/tree.js +0 -107
  195. package/dist/data-structures/trie/index.js +0 -17
  196. package/dist/data-structures/trie/trie.d.ts +0 -350
  197. package/dist/data-structures/trie/trie.js +0 -610
  198. package/dist/index.d.ts +0 -12
  199. package/dist/index.js +0 -28
  200. package/dist/interfaces/binary-tree.js +0 -2
  201. package/dist/interfaces/doubly-linked-list.js +0 -2
  202. package/dist/interfaces/graph.js +0 -2
  203. package/dist/interfaces/heap.js +0 -2
  204. package/dist/interfaces/index.js +0 -24
  205. package/dist/interfaces/navigator.js +0 -2
  206. package/dist/interfaces/priority-queue.js +0 -2
  207. package/dist/interfaces/segment-tree.js +0 -2
  208. package/dist/interfaces/singly-linked-list.js +0 -2
  209. package/dist/types/common.js +0 -2
  210. package/dist/types/data-structures/base/base.js +0 -2
  211. package/dist/types/data-structures/base/index.js +0 -17
  212. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  213. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  214. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  215. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  216. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  217. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  218. package/dist/types/data-structures/binary-tree/index.js +0 -25
  219. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  220. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  221. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  222. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  223. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  224. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  225. package/dist/types/data-structures/graph/index.js +0 -19
  226. package/dist/types/data-structures/graph/map-graph.js +0 -2
  227. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  228. package/dist/types/data-structures/hash/hash-map.js +0 -2
  229. package/dist/types/data-structures/hash/index.js +0 -17
  230. package/dist/types/data-structures/heap/heap.js +0 -2
  231. package/dist/types/data-structures/heap/index.js +0 -17
  232. package/dist/types/data-structures/heap/max-heap.js +0 -2
  233. package/dist/types/data-structures/heap/min-heap.js +0 -2
  234. package/dist/types/data-structures/index.js +0 -28
  235. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  236. package/dist/types/data-structures/linked-list/index.js +0 -19
  237. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  238. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  239. package/dist/types/data-structures/matrix/index.js +0 -18
  240. package/dist/types/data-structures/matrix/matrix.js +0 -2
  241. package/dist/types/data-structures/matrix/navigator.js +0 -2
  242. package/dist/types/data-structures/priority-queue/index.js +0 -19
  243. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  244. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  245. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  246. package/dist/types/data-structures/queue/deque.js +0 -2
  247. package/dist/types/data-structures/queue/index.js +0 -18
  248. package/dist/types/data-structures/queue/queue.js +0 -2
  249. package/dist/types/data-structures/stack/index.js +0 -17
  250. package/dist/types/data-structures/stack/stack.js +0 -2
  251. package/dist/types/data-structures/tree/index.js +0 -17
  252. package/dist/types/data-structures/tree/tree.js +0 -2
  253. package/dist/types/data-structures/trie/index.js +0 -17
  254. package/dist/types/data-structures/trie/trie.js +0 -2
  255. package/dist/types/index.js +0 -19
  256. package/dist/types/utils/index.js +0 -18
  257. package/dist/types/utils/utils.js +0 -2
  258. package/dist/types/utils/validate-type.js +0 -2
  259. package/dist/utils/index.d.ts +0 -2
  260. package/dist/utils/index.js +0 -18
  261. package/dist/utils/number.js +0 -24
  262. package/dist/utils/utils.d.ts +0 -209
  263. package/dist/utils/utils.js +0 -353
  264. package/dist/{common → types/common}/index.d.ts +0 -0
  265. package/dist/{constants → types/constants}/index.d.ts +0 -0
  266. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  267. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  268. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  270. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  271. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  272. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  273. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  274. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  275. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  276. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  277. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  278. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  279. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  280. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  281. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  282. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  283. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  284. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  285. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  286. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  287. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  288. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,3 +1,262 @@
1
- import type { BSTOptions } from './bst';
2
- export type RBTNColor = 'RED' | 'BLACK';
3
- export type RedBlackTreeOptions<K, V, R> = BSTOptions<K, V, R> & {};
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { BinaryTreeDeleteResult, BinaryTreeOptions, CRUD, EntryCallback, FamilyPosition, RBTNColor, RedBlackTreeOptions } from '../../types';
9
+ import { BST } from './bst';
10
+ import { IBinaryTree } from '../../interfaces';
11
+ export declare class RedBlackTreeNode<K = any, V = any> {
12
+ key: K;
13
+ value?: V;
14
+ parent?: RedBlackTreeNode<K, V>;
15
+ /**
16
+ * Create a Red-Black Tree and optionally bulk-insert items.
17
+ * @remarks Time O(n log n), Space O(n)
18
+ * @param key - See parameter type for details.
19
+ * @param [value]- See parameter type for details.
20
+ * @param color - See parameter type for details.
21
+ * @returns New RedBlackTree instance.
22
+ */
23
+ constructor(key: K, value?: V, color?: RBTNColor);
24
+ _left?: RedBlackTreeNode<K, V> | null | undefined;
25
+ /**
26
+ * Get the left child pointer.
27
+ * @remarks Time O(1), Space O(1)
28
+ * @returns Left child node, or null/undefined.
29
+ */
30
+ get left(): RedBlackTreeNode<K, V> | null | undefined;
31
+ /**
32
+ * Set the left child and update its parent pointer.
33
+ * @remarks Time O(1), Space O(1)
34
+ * @param v - New left node, or null/undefined.
35
+ * @returns void
36
+ */
37
+ set left(v: RedBlackTreeNode<K, V> | null | undefined);
38
+ _right?: RedBlackTreeNode<K, V> | null | undefined;
39
+ /**
40
+ * Get the right child pointer.
41
+ * @remarks Time O(1), Space O(1)
42
+ * @returns Right child node, or null/undefined.
43
+ */
44
+ get right(): RedBlackTreeNode<K, V> | null | undefined;
45
+ /**
46
+ * Set the right child and update its parent pointer.
47
+ * @remarks Time O(1), Space O(1)
48
+ * @param v - New right node, or null/undefined.
49
+ * @returns void
50
+ */
51
+ set right(v: RedBlackTreeNode<K, V> | null | undefined);
52
+ _height: number;
53
+ /**
54
+ * Gets the height of the node (used in self-balancing trees).
55
+ * @remarks Time O(1), Space O(1)
56
+ *
57
+ * @returns The height.
58
+ */
59
+ get height(): number;
60
+ /**
61
+ * Sets the height of the node.
62
+ * @remarks Time O(1), Space O(1)
63
+ *
64
+ * @param value - The new height.
65
+ */
66
+ set height(value: number);
67
+ _color: RBTNColor;
68
+ /**
69
+ * Gets the color of the node (used in Red-Black trees).
70
+ * @remarks Time O(1), Space O(1)
71
+ *
72
+ * @returns The node's color.
73
+ */
74
+ get color(): RBTNColor;
75
+ /**
76
+ * Sets the color of the node.
77
+ * @remarks Time O(1), Space O(1)
78
+ *
79
+ * @param value - The new color.
80
+ */
81
+ set color(value: RBTNColor);
82
+ _count: number;
83
+ /**
84
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
85
+ * @remarks Time O(1), Space O(1)
86
+ *
87
+ * @returns The subtree node count.
88
+ */
89
+ get count(): number;
90
+ /**
91
+ * Sets the count of nodes in the subtree.
92
+ * @remarks Time O(1), Space O(1)
93
+ *
94
+ * @param value - The new count.
95
+ */
96
+ set count(value: number);
97
+ /**
98
+ * Gets the position of the node relative to its parent.
99
+ * @remarks Time O(1), Space O(1)
100
+ *
101
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
102
+ */
103
+ get familyPosition(): FamilyPosition;
104
+ }
105
+ /**
106
+ * Represents a Red-Black Tree (self-balancing BST) supporting map-like mode and stable O(log n) updates.
107
+ * @remarks Time O(1), Space O(1)
108
+ * @template K
109
+ * @template V
110
+ * @template R
111
+ * 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high, but the query efficiency is slightly lower.
112
+ * 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
113
+ * @example
114
+ * // using Red-Black Tree as a price-based index for stock data
115
+ * // Define the structure of individual stock records
116
+ * interface StockRecord {
117
+ * price: number; // Stock price (key for indexing)
118
+ * symbol: string; // Stock ticker symbol
119
+ * volume: number; // Trade volume
120
+ * }
121
+ *
122
+ * // Simulate stock market data as it might come from an external feed
123
+ * const marketStockData: StockRecord[] = [
124
+ * { price: 142.5, symbol: 'AAPL', volume: 1000000 },
125
+ * { price: 335.2, symbol: 'MSFT', volume: 800000 },
126
+ * { price: 3285.04, symbol: 'AMZN', volume: 500000 },
127
+ * { price: 267.98, symbol: 'META', volume: 750000 },
128
+ * { price: 234.57, symbol: 'GOOGL', volume: 900000 }
129
+ * ];
130
+ *
131
+ * // Extend the stock record type to include metadata for database usage
132
+ * type StockTableRecord = StockRecord & { lastUpdated: Date };
133
+ *
134
+ * // Create a Red-Black Tree to index stock records by price
135
+ * // Simulates a database index with stock price as the key for quick lookups
136
+ * const priceIndex = new RedBlackTree<number, StockTableRecord, StockRecord>(marketStockData, {
137
+ * toEntryFn: stockRecord => [
138
+ * stockRecord.price, // Use stock price as the key
139
+ * {
140
+ * ...stockRecord,
141
+ * lastUpdated: new Date() // Add a timestamp for when the record was indexed
142
+ * }
143
+ * ]
144
+ * });
145
+ *
146
+ * // Query the stock with the highest price
147
+ * const highestPricedStock = priceIndex.getRightMost();
148
+ * console.log(priceIndex.get(highestPricedStock)?.symbol); // 'AMZN' // Amazon has the highest price
149
+ *
150
+ * // Query stocks within a specific price range (200 to 400)
151
+ * const stocksInRange = priceIndex.rangeSearch(
152
+ * [200, 400], // Price range
153
+ * node => priceIndex.get(node)?.symbol // Extract stock symbols for the result
154
+ * );
155
+ * console.log(stocksInRange); // ['GOOGL', 'META', 'MSFT']
156
+ */
157
+ export declare class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
158
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: RedBlackTreeOptions<K, V, R>);
159
+ protected _root: RedBlackTreeNode<K, V> | undefined;
160
+ /**
161
+ * Get the current root node.
162
+ * @remarks Time O(1), Space O(1)
163
+ * @returns Root node, or undefined.
164
+ */
165
+ get root(): RedBlackTreeNode<K, V> | undefined;
166
+ /**
167
+ * Create a red-black node for the given key/value (value ignored in map mode).
168
+ * @remarks Time O(1), Space O(1)
169
+ * @param key - See parameter type for details.
170
+ * @param [value] - See parameter type for details.
171
+ * @param color - See parameter type for details.
172
+ * @returns A new RedBlackTreeNode instance.
173
+ */
174
+ createNode(key: K, value?: V, color?: RBTNColor): RedBlackTreeNode<K, V>;
175
+ /**
176
+ * Type guard: check whether the input is a RedBlackTreeNode.
177
+ * @remarks Time O(1), Space O(1)
178
+ * @param keyNodeOrEntry - See parameter type for details.
179
+ * @returns True if the value is a RedBlackTreeNode.
180
+ */
181
+ isNode(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is RedBlackTreeNode<K, V>;
182
+ /**
183
+ * Remove all nodes and clear the key→value store (if in map mode).
184
+ * @remarks Time O(n), Space O(1)
185
+ * @returns void
186
+ */
187
+ clear(): void;
188
+ /**
189
+ * Insert or replace an entry using BST order and red-black fix-up.
190
+ * @remarks Time O(log n), Space O(1)
191
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
192
+ * @param [value]- See parameter type for details.
193
+ * @returns True if inserted or updated; false if ignored.
194
+ */
195
+ add(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
196
+ /**
197
+ * Delete a node by key/node/entry and rebalance as needed.
198
+ * @remarks Time O(log n), Space O(1)
199
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node to delete.
200
+ * @returns Array with deletion metadata (removed node, rebalancing hint if any).
201
+ */
202
+ delete(keyNodeOrEntry: K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>[];
203
+ /**
204
+ * Transform entries into a like-kind red-black tree with possibly different key/value types.
205
+ * @remarks Time O(n), Space O(n)
206
+ * @template MK
207
+ * @template MV
208
+ * @template MR
209
+ * @param callback - Mapping function from (key, value, index, tree) to a new [key, value].
210
+ * @param [options] - See parameter type for details.
211
+ * @param [thisArg] - See parameter type for details.
212
+ * @returns A new RedBlackTree with mapped entries.
213
+ */
214
+ map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): RedBlackTree<MK, MV, MR>;
215
+ protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): this;
216
+ protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | RedBlackTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): RedBlackTree<TK, TV, TR>;
217
+ protected _setRoot(v: RedBlackTreeNode<K, V> | undefined): void;
218
+ protected _replaceNode(oldNode: RedBlackTreeNode<K, V>, newNode: RedBlackTreeNode<K, V>): RedBlackTreeNode<K, V>;
219
+ /**
220
+ * (Protected) Standard BST insert followed by red-black fix-up.
221
+ * @remarks Time O(log n), Space O(1)
222
+ * @param node - Node to insert.
223
+ * @returns Status string: 'CREATED' or 'UPDATED'.
224
+ */
225
+ protected _insert(node: RedBlackTreeNode<K, V>): CRUD;
226
+ /**
227
+ * (Protected) Transplant a subtree in place of another during deletion.
228
+ * @remarks Time O(1), Space O(1)
229
+ * @param u - Node to replace.
230
+ * @param v - Replacement subtree root (may be undefined).
231
+ * @returns void
232
+ */
233
+ protected _transplant(u: RedBlackTreeNode<K, V>, v: RedBlackTreeNode<K, V> | undefined): void;
234
+ /**
235
+ * (Protected) Restore red-black properties after insertion (recolor/rotate).
236
+ * @remarks Time O(log n), Space O(1)
237
+ * @param z - Recently inserted node.
238
+ * @returns void
239
+ */
240
+ protected _insertFixup(z: RedBlackTreeNode<K, V> | undefined): void;
241
+ /**
242
+ * (Protected) Restore red-black properties after deletion (recolor/rotate).
243
+ * @remarks Time O(log n), Space O(1)
244
+ * @param node - Child that replaced the deleted node (may be undefined).
245
+ * @returns void
246
+ */
247
+ protected _deleteFixup(node: RedBlackTreeNode<K, V> | undefined): void;
248
+ /**
249
+ * (Protected) Perform a left rotation around x.
250
+ * @remarks Time O(1), Space O(1)
251
+ * @param x - Pivot node to rotate around.
252
+ * @returns void
253
+ */
254
+ protected _leftRotate(x: RedBlackTreeNode<K, V> | undefined): void;
255
+ /**
256
+ * (Protected) Perform a right rotation around y.
257
+ * @remarks Time O(1), Space O(1)
258
+ * @param y - Pivot node to rotate around.
259
+ * @returns void
260
+ */
261
+ protected _rightRotate(y: RedBlackTreeNode<K, V> | undefined): void;
262
+ }
@@ -1 +1,160 @@
1
- export type SegmentTreeNodeVal = number;
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { SegmentTreeNodeVal } from '../../types';
9
+ export declare class SegmentTreeNode {
10
+ /**
11
+ * The constructor initializes the properties of a SegmentTreeNode object.
12
+ * @param {number} start - The `start` parameter represents the starting index of the segment covered
13
+ * by this node in a segment tree.
14
+ * @param {number} end - The `end` parameter represents the end index of the segment covered by this
15
+ * node in a segment tree.
16
+ * @param {number} sum - The `sum` parameter represents the sum of the values in the range covered by
17
+ * the segment tree node.
18
+ * @param {SegmentTreeNodeVal | undefined} [value] - The `value` parameter is an optional parameter
19
+ * of type `SegmentTreeNodeVal`. It represents the value associated with the segment tree node.
20
+ */
21
+ constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal | undefined);
22
+ protected _start: number;
23
+ /**
24
+ * The function returns the value of the protected variable _start.
25
+ * @returns The start value, which is of type number.
26
+ */
27
+ get start(): number;
28
+ /**
29
+ * The above function sets the value of the "start" property.
30
+ * @param {number} value - The value parameter is of type number.
31
+ */
32
+ set start(value: number);
33
+ protected _end: number;
34
+ /**
35
+ * The function returns the value of the protected variable `_end`.
36
+ * @returns The value of the protected property `_end`.
37
+ */
38
+ get end(): number;
39
+ /**
40
+ * The above function sets the value of the "end" property.
41
+ * @param {number} value - The value parameter is a number that represents the new value for the end
42
+ * property.
43
+ */
44
+ set end(value: number);
45
+ protected _value: SegmentTreeNodeVal | undefined;
46
+ /**
47
+ * The function returns the value of a segment tree node.
48
+ * @returns The value being returned is either a `SegmentTreeNodeVal` object or `undefined`.
49
+ */
50
+ get value(): SegmentTreeNodeVal | undefined;
51
+ /**
52
+ * The function sets the value of a segment tree node.
53
+ * @param {SegmentTreeNodeVal | undefined} value - The `value` parameter is of type
54
+ * `SegmentTreeNodeVal` or `undefined`.
55
+ */
56
+ set value(value: SegmentTreeNodeVal | undefined);
57
+ protected _sum: number;
58
+ /**
59
+ * The function returns the value of the sum property.
60
+ * @returns The method is returning the value of the variable `_sum`.
61
+ */
62
+ get sum(): number;
63
+ /**
64
+ * The above function sets the value of the sum property.
65
+ * @param {number} value - The parameter "value" is of type "number".
66
+ */
67
+ set sum(value: number);
68
+ protected _left: SegmentTreeNode | undefined;
69
+ /**
70
+ * The function returns the left child of a segment tree node.
71
+ * @returns The `left` property of the `SegmentTreeNode` object is being returned. It is of type
72
+ * `SegmentTreeNode` or `undefined`.
73
+ */
74
+ get left(): SegmentTreeNode | undefined;
75
+ /**
76
+ * The function sets the value of the left property of a SegmentTreeNode object.
77
+ * @param {SegmentTreeNode | undefined} value - The value parameter is of type SegmentTreeNode or
78
+ * undefined.
79
+ */
80
+ set left(value: SegmentTreeNode | undefined);
81
+ protected _right: SegmentTreeNode | undefined;
82
+ /**
83
+ * The function returns the right child of a segment tree node.
84
+ * @returns The `getRight()` method is returning a value of type `SegmentTreeNode` or `undefined`.
85
+ */
86
+ get right(): SegmentTreeNode | undefined;
87
+ /**
88
+ * The function sets the right child of a segment tree node.
89
+ * @param {SegmentTreeNode | undefined} value - The `value` parameter is of type `SegmentTreeNode |
90
+ * undefined`. This means that it can accept either a `SegmentTreeNode` object or `undefined` as its
91
+ * value.
92
+ */
93
+ set right(value: SegmentTreeNode | undefined);
94
+ }
95
+ export declare class SegmentTree {
96
+ /**
97
+ * The constructor initializes the values, start, end, and root properties of an object.
98
+ * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
99
+ * @param {number} [start] - The `start` parameter is the index of the first element in the `values` array that should
100
+ * be included in the range. If no value is provided for `start`, it defaults to 0, which means the range starts from
101
+ * the beginning of the array.
102
+ * @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
103
+ * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
104
+ */
105
+ constructor(values: number[], start?: number, end?: number);
106
+ protected _values: number[];
107
+ /**
108
+ * The function returns an array of numbers.
109
+ * @returns An array of numbers is being returned.
110
+ */
111
+ get values(): number[];
112
+ protected _start: number;
113
+ /**
114
+ * The function returns the value of the protected variable _start.
115
+ * @returns The start value, which is of type number.
116
+ */
117
+ get start(): number;
118
+ protected _end: number;
119
+ /**
120
+ * The function returns the value of the protected variable `_end`.
121
+ * @returns The value of the protected property `_end`.
122
+ */
123
+ get end(): number;
124
+ protected _root: SegmentTreeNode | undefined;
125
+ /**
126
+ * The function returns the root node of a segment tree.
127
+ * @returns The `root` property of the class `SegmentTreeNode` or `undefined` if it is not defined.
128
+ */
129
+ get root(): SegmentTreeNode | undefined;
130
+ /**
131
+ * The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
132
+ * the sum of values to each segment.
133
+ * @param {number} start - The `start` parameter represents the starting index of the segment or range for which we are
134
+ * building the segment tree.
135
+ * @param {number} end - The "end" parameter represents the ending index of the segment or range for which we want to
136
+ * build a segment tree.
137
+ * @returns a SegmentTreeNode object.
138
+ */
139
+ build(start: number, end: number): SegmentTreeNode;
140
+ /**
141
+ * The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
142
+ * @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
143
+ * updated.
144
+ * @param {number} sum - The `sum` parameter represents the new value that should be assigned to the `sum` property of
145
+ * the `SegmentTreeNode` at the specified `index`.
146
+ * @param {SegmentTreeNodeVal} [value] - The `value` parameter is an optional value that can be assigned to the `value`
147
+ * property of the `SegmentTreeNode` object. It is not currently used in the code, but you can uncomment the line `//
148
+ * cur.value = value;` and pass a value for `value` in the
149
+ * @returns The function does not return anything.
150
+ */
151
+ updateNode(index: number, sum: number, value?: SegmentTreeNodeVal): void;
152
+ /**
153
+ * The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
154
+ * @param {number} indexA - The starting index of the range for which you want to calculate the sum.
155
+ * @param {number} indexB - The parameter `indexB` represents the ending index of the range for which you want to
156
+ * calculate the sum.
157
+ * @returns The function `querySumByRange` returns a number.
158
+ */
159
+ querySumByRange(indexA: number, indexB: number): number;
160
+ }
@@ -1,2 +1,244 @@
1
- import type { RedBlackTreeOptions } from './red-black-tree';
2
- export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, FamilyPosition, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
9
+ import { BSTOptions } from '../../types';
10
+ import { BSTNode } from './bst';
11
+ import { IBinaryTree } from '../../interfaces';
12
+ import { RedBlackTree } from './red-black-tree';
13
+ /**
14
+ * RB-tree node with an extra 'count' field; keeps parent/child links.
15
+ * @remarks Time O(1), Space O(1)
16
+ * @template K
17
+ * @template V
18
+ */
19
+ export declare class TreeCounterNode<K = any, V = any> {
20
+ key: K;
21
+ value?: V;
22
+ parent?: TreeCounterNode<K, V>;
23
+ /**
24
+ * Create a tree counter node.
25
+ * @remarks Time O(1), Space O(1)
26
+ * @param key - Key of the node.
27
+ * @param [value] - Value associated with the key (ignored in map mode).
28
+ * @param [count] - Initial count for this node (default 1).
29
+ * @param color - Initial color ('RED' or 'BLACK').
30
+ * @returns New TreeCounterNode instance.
31
+ */
32
+ constructor(key: K, value?: V, count?: number, color?: RBTNColor);
33
+ _left?: TreeCounterNode<K, V> | null | undefined;
34
+ /**
35
+ * Get the left child pointer.
36
+ * @remarks Time O(1), Space O(1)
37
+ * @returns Left child node, or null/undefined.
38
+ */
39
+ get left(): TreeCounterNode<K, V> | null | undefined;
40
+ /**
41
+ * Set the left child and update its parent pointer.
42
+ * @remarks Time O(1), Space O(1)
43
+ * @param v - New left child node, or null/undefined.
44
+ * @returns void
45
+ */
46
+ set left(v: TreeCounterNode<K, V> | null | undefined);
47
+ _right?: TreeCounterNode<K, V> | null | undefined;
48
+ /**
49
+ * Get the right child pointer.
50
+ * @remarks Time O(1), Space O(1)
51
+ * @returns Right child node, or null/undefined.
52
+ */
53
+ get right(): TreeCounterNode<K, V> | null | undefined;
54
+ /**
55
+ * Set the right child and update its parent pointer.
56
+ * @remarks Time O(1), Space O(1)
57
+ * @param v - New right child node, or null/undefined.
58
+ * @returns void
59
+ */
60
+ set right(v: TreeCounterNode<K, V> | null | undefined);
61
+ _height: number;
62
+ /**
63
+ * Gets the height of the node (used in self-balancing trees).
64
+ * @remarks Time O(1), Space O(1)
65
+ *
66
+ * @returns The height.
67
+ */
68
+ get height(): number;
69
+ /**
70
+ * Sets the height of the node.
71
+ * @remarks Time O(1), Space O(1)
72
+ *
73
+ * @param value - The new height.
74
+ */
75
+ set height(value: number);
76
+ _color: RBTNColor;
77
+ /**
78
+ * Gets the color of the node (used in Red-Black trees).
79
+ * @remarks Time O(1), Space O(1)
80
+ *
81
+ * @returns The node's color.
82
+ */
83
+ get color(): RBTNColor;
84
+ /**
85
+ * Sets the color of the node.
86
+ * @remarks Time O(1), Space O(1)
87
+ *
88
+ * @param value - The new color.
89
+ */
90
+ set color(value: RBTNColor);
91
+ _count: number;
92
+ /**
93
+ * Gets the count of nodes in the subtree rooted at this node (used in order-statistic trees).
94
+ * @remarks Time O(1), Space O(1)
95
+ *
96
+ * @returns The subtree node count.
97
+ */
98
+ get count(): number;
99
+ /**
100
+ * Sets the count of nodes in the subtree.
101
+ * @remarks Time O(1), Space O(1)
102
+ *
103
+ * @param value - The new count.
104
+ */
105
+ set count(value: number);
106
+ /**
107
+ * Gets the position of the node relative to its parent.
108
+ * @remarks Time O(1), Space O(1)
109
+ *
110
+ * @returns The family position (e.g., 'ROOT', 'LEFT', 'RIGHT').
111
+ */
112
+ get familyPosition(): FamilyPosition;
113
+ }
114
+ /**
115
+ * Red-Black Tree–based counter map (key → value with per-node count). Supports O(log N) updates and map-like mode.
116
+ * @remarks Time O(1), Space O(1)
117
+ * @template K
118
+ * @template V
119
+ * @template R
120
+ */
121
+ export declare class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R> implements IBinaryTree<K, V, R> {
122
+ /**
123
+ * Create a TreeCounter and optionally bulk-insert items.
124
+ * @remarks Time O(N log N), Space O(N)
125
+ * @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
126
+ * @param [options] - Options for TreeCounter (comparator, reverse, map mode).
127
+ * @returns New TreeCounter instance.
128
+ */
129
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: TreeCounterOptions<K, V, R>);
130
+ protected _count: number;
131
+ /**
132
+ * Get the total aggregate count across all nodes.
133
+ * @remarks Time O(1), Space O(1)
134
+ * @returns Total count.
135
+ */
136
+ get count(): number;
137
+ /**
138
+ * Compute the total count by traversing the tree (sums node.count).
139
+ * @remarks Time O(N), Space O(H)
140
+ * @returns Total count recomputed from nodes.
141
+ */
142
+ getComputedCount(): number;
143
+ createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
144
+ /**
145
+ * Type guard: check whether the input is a TreeCounterNode.
146
+ * @remarks Time O(1), Space O(1)
147
+ * @returns True if the value is a TreeCounterNode.
148
+ */
149
+ isNode(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is TreeCounterNode<K, V>;
150
+ /**
151
+ * Insert or increment a node and update aggregate count.
152
+ * @remarks Time O(log N), Space O(1)
153
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
154
+ * @param [value] - Value when a bare key is provided (ignored in map mode).
155
+ * @param [count] - How much to increase the node's count (default 1).
156
+ * @returns True if inserted/updated; false if ignored.
157
+ */
158
+ add(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
159
+ /**
160
+ * Delete a node (or decrement its count) and rebalance if needed.
161
+ * @remarks Time O(log N), Space O(1)
162
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
163
+ * @param [ignoreCount] - If true, remove the node regardless of its count.
164
+ * @returns Array of deletion results including deleted node and a rebalance hint when present.
165
+ */
166
+ delete(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
167
+ /**
168
+ * Remove all nodes and reset aggregate counters.
169
+ * @remarks Time O(N), Space O(1)
170
+ * @returns void
171
+ */
172
+ clear(): void;
173
+ /**
174
+ * Rebuild the tree into a perfectly balanced form using in-order nodes.
175
+ * @remarks Time O(N), Space O(N)
176
+ * @param [iterationType] - Traversal style to use when constructing the balanced tree.
177
+ * @returns True if rebalancing succeeded (tree not empty).
178
+ */
179
+ perfectlyBalance(iterationType?: IterationType): boolean;
180
+ /**
181
+ * Create a new TreeCounter by mapping each [key, value] entry.
182
+ * @remarks Time O(N log N), Space O(N)
183
+ * @template MK
184
+ * @template MV
185
+ * @template MR
186
+ * @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
187
+ * @param [options] - Options for the output tree.
188
+ * @param [thisArg] - Value for `this` inside the callback.
189
+ * @returns A new TreeCounter with mapped entries.
190
+ */
191
+ map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): TreeCounter<MK, MV, MR>;
192
+ /**
193
+ * Deep copy this tree, preserving map mode and aggregate counts.
194
+ * @remarks Time O(N), Space O(N)
195
+ * @returns A deep copy of this tree.
196
+ */
197
+ clone(): this;
198
+ /**
199
+ * (Protected) Create an empty instance of the same concrete class.
200
+ * @remarks Time O(1), Space O(1)
201
+ * @template TK
202
+ * @template TV
203
+ * @template TR
204
+ * @param [options] - Optional constructor options for the like-kind instance.
205
+ * @returns An empty like-kind instance.
206
+ */
207
+ protected _createInstance<TK = K, TV = V, TR = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
208
+ /**
209
+ * (Protected) Create a like-kind instance and seed it from an iterable.
210
+ * @remarks Time O(N log N), Space O(N)
211
+ * @template TK
212
+ * @template TV
213
+ * @template TR
214
+ * @param iter - Iterable used to seed the new tree.
215
+ * @param [options] - Options merged with the current snapshot.
216
+ * @returns A like-kind TreeCounter built from the iterable.
217
+ */
218
+ protected _createLike<TK = K, TV = V, TR = R>(iter?: Iterable<TK | BSTNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<BSTOptions<TK, TV, TR>>): TreeCounter<TK, TV, TR>;
219
+ /**
220
+ * (Protected) Normalize input into a node plus its effective value and count.
221
+ * @remarks Time O(1), Space O(1)
222
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry.
223
+ * @param [value] - Value used when a bare key is provided.
224
+ * @param [count] - Count increment to apply (default 1).
225
+ * @returns Tuple [node, value] where node may be undefined.
226
+ */
227
+ protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
228
+ /**
229
+ * (Protected) Swap keys/values/counters between the source and destination nodes.
230
+ * @remarks Time O(1), Space O(1)
231
+ * @param srcNode - Source node (or key) whose properties will be moved.
232
+ * @param destNode - Destination node (or key) to receive properties.
233
+ * @returns Destination node after swap, or undefined.
234
+ */
235
+ protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>): TreeCounterNode<K, V> | undefined;
236
+ /**
237
+ * (Protected) Replace one node by another and adjust counters accordingly.
238
+ * @remarks Time O(1), Space O(1)
239
+ * @param oldNode - Node being replaced.
240
+ * @param newNode - Replacement node.
241
+ * @returns The new node after replacement.
242
+ */
243
+ protected _replaceNode(oldNode: TreeCounterNode<K, V>, newNode: TreeCounterNode<K, V>): TreeCounterNode<K, V>;
244
+ }