data-structure-typed 2.0.5 → 2.1.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 (260) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/COMMANDS.md +17 -0
  3. package/benchmark/report.html +13 -77
  4. package/benchmark/report.json +145 -177
  5. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  6. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  7. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  9. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  12. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  13. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  27. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  28. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  42. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  45. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  46. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  48. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  49. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  50. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  51. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  52. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  54. package/dist/cjs/data-structures/heap/heap.js +340 -349
  55. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  56. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  57. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  58. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  59. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  60. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  61. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  62. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  65. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  68. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  71. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  74. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  77. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  80. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  81. package/dist/cjs/data-structures/queue/deque.js +309 -348
  82. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  83. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  84. package/dist/cjs/data-structures/queue/queue.js +265 -248
  85. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  86. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  87. package/dist/cjs/data-structures/stack/stack.js +181 -125
  88. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  89. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  90. package/dist/cjs/data-structures/trie/trie.js +189 -172
  91. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  92. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  93. package/dist/cjs/interfaces/graph.d.ts +16 -0
  94. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  95. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  96. package/dist/cjs/types/utils/utils.d.ts +1 -0
  97. package/dist/cjs/utils/utils.d.ts +1 -1
  98. package/dist/cjs/utils/utils.js +2 -1
  99. package/dist/cjs/utils/utils.js.map +1 -1
  100. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  101. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  102. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  103. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  104. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  105. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  106. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  107. package/dist/esm/data-structures/base/linear-base.js +137 -274
  108. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  109. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  112. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  115. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  116. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  118. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  119. package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  121. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  122. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  123. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  124. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  127. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  128. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  130. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  133. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  134. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  135. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  136. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  137. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  138. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  139. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  140. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  141. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  142. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  143. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  144. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  145. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  146. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  147. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  148. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  149. package/dist/esm/data-structures/heap/heap.js +329 -349
  150. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  151. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  152. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  153. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  154. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  155. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  156. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  157. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  160. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  163. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  166. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  169. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  172. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  173. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  175. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  176. package/dist/esm/data-structures/queue/deque.js +313 -348
  177. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  178. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  179. package/dist/esm/data-structures/queue/queue.js +263 -248
  180. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  181. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  182. package/dist/esm/data-structures/stack/stack.js +181 -125
  183. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  184. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  185. package/dist/esm/data-structures/trie/trie.js +193 -172
  186. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  187. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  188. package/dist/esm/interfaces/graph.d.ts +16 -0
  189. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  190. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  191. package/dist/esm/types/utils/utils.d.ts +1 -0
  192. package/dist/esm/utils/utils.d.ts +1 -1
  193. package/dist/esm/utils/utils.js +2 -1
  194. package/dist/esm/utils/utils.js.map +1 -1
  195. package/dist/umd/data-structure-typed.js +4685 -6477
  196. package/dist/umd/data-structure-typed.min.js +8 -6
  197. package/dist/umd/data-structure-typed.min.js.map +1 -1
  198. package/package.json +3 -4
  199. package/src/data-structures/base/iterable-element-base.ts +238 -115
  200. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  201. package/src/data-structures/base/linear-base.ts +271 -277
  202. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  203. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  204. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  205. package/src/data-structures/binary-tree/binary-tree.ts +660 -889
  206. package/src/data-structures/binary-tree/bst.ts +568 -570
  207. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  208. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  209. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  210. package/src/data-structures/graph/abstract-graph.ts +339 -264
  211. package/src/data-structures/graph/directed-graph.ts +146 -236
  212. package/src/data-structures/graph/map-graph.ts +63 -60
  213. package/src/data-structures/graph/undirected-graph.ts +129 -152
  214. package/src/data-structures/hash/hash-map.ts +274 -496
  215. package/src/data-structures/heap/heap.ts +389 -402
  216. package/src/data-structures/heap/max-heap.ts +12 -76
  217. package/src/data-structures/heap/min-heap.ts +13 -76
  218. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  219. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  220. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  223. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  224. package/src/data-structures/queue/deque.ts +381 -357
  225. package/src/data-structures/queue/queue.ts +310 -264
  226. package/src/data-structures/stack/stack.ts +217 -131
  227. package/src/data-structures/trie/trie.ts +240 -175
  228. package/src/interfaces/binary-tree.ts +240 -6
  229. package/src/interfaces/graph.ts +37 -0
  230. package/src/types/data-structures/base/base.ts +5 -5
  231. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  232. package/src/types/utils/utils.ts +2 -0
  233. package/src/utils/utils.ts +9 -14
  234. package/test/integration/index.html +1 -1
  235. package/test/performance/benchmark-runner.ts +528 -0
  236. package/test/performance/reportor.mjs +43 -43
  237. package/test/performance/runner-config.json +39 -0
  238. package/test/performance/single-suite-runner.ts +69 -0
  239. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  240. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  241. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  242. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  243. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  244. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  245. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  246. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  247. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  248. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  249. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  250. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  251. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  252. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  253. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  254. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  255. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  256. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  258. package/test/unit/utils/utils.test.ts +0 -1
  259. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  260. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -5,208 +5,186 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BinaryTreeOptions, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
9
+ import { BSTOptions } from '../../types';
10
+ import { BSTNode } from './bst';
9
11
  import { IBinaryTree } from '../../interfaces';
10
12
  import { RedBlackTree, RedBlackTreeNode } 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
+ */
11
19
  export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
12
20
  parent?: TreeCounterNode<K, V>;
13
21
  /**
14
- * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
15
- * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
16
- * used to identify and locate the node within the tree.
17
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
18
- * associated with the key in the Red-Black Tree node. It is not required and can be omitted when
19
- * creating a new node.
20
- * @param [count=1] - The `count` parameter represents the number of occurrences of a particular key
21
- * in the Red-Black Tree. It is an optional parameter with a default value of 1.
22
- * @param {RBTNColor} [color=BLACK] - The `color` parameter is used to specify the color of the node
23
- * in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
22
+ * Create a tree counter node.
23
+ * @remarks Time O(1), Space O(1)
24
+ * @param key - Key of the node.
25
+ * @param [value] - Value associated with the key (ignored in map mode).
26
+ * @param [count] - Initial count for this node (default 1).
27
+ * @param color - Initial color ('RED' or 'BLACK').
28
+ * @returns New TreeCounterNode instance.
24
29
  */
25
30
  constructor(key: K, value?: V, count?: number, color?: RBTNColor);
26
31
  _left?: TreeCounterNode<K, V> | null | undefined;
32
+ /**
33
+ * Get the left child pointer.
34
+ * @remarks Time O(1), Space O(1)
35
+ * @returns Left child node, or null/undefined.
36
+ */
27
37
  get left(): TreeCounterNode<K, V> | null | undefined;
38
+ /**
39
+ * Set the left child and update its parent pointer.
40
+ * @remarks Time O(1), Space O(1)
41
+ * @param v - New left child node, or null/undefined.
42
+ * @returns void
43
+ */
28
44
  set left(v: TreeCounterNode<K, V> | null | undefined);
29
45
  _right?: TreeCounterNode<K, V> | null | undefined;
46
+ /**
47
+ * Get the right child pointer.
48
+ * @remarks Time O(1), Space O(1)
49
+ * @returns Right child node, or null/undefined.
50
+ */
30
51
  get right(): TreeCounterNode<K, V> | null | undefined;
52
+ /**
53
+ * Set the right child and update its parent pointer.
54
+ * @remarks Time O(1), Space O(1)
55
+ * @param v - New right child node, or null/undefined.
56
+ * @returns void
57
+ */
31
58
  set right(v: TreeCounterNode<K, V> | null | undefined);
32
59
  }
33
60
  /**
34
- *
61
+ * Red-Black Tree–based counter map (key → value with per-node count). Supports O(log N) updates and map-like mode.
62
+ * @remarks Time O(1), Space O(1)
63
+ * @template K
64
+ * @template V
65
+ * @template R
35
66
  */
36
- export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends RedBlackTree<K, V, R, MK, MV, MR> implements IBinaryTree<K, V, R, MK, MV, MR> {
67
+ export declare class TreeCounter<K = any, V = any, R extends object = object> extends RedBlackTree<K, V, R> implements IBinaryTree<K, V, R> {
37
68
  /**
38
- * The constructor function initializes a TreeCounter object with optional initial data.
39
- * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
40
- * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
41
- * TreeCounter with initial data.
42
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
43
- * behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
44
- * `compareValues`, which are functions used to compare keys and values respectively.
69
+ * Create a TreeCounter and optionally bulk-insert items.
70
+ * @remarks Time O(N log N), Space O(N)
71
+ * @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
72
+ * @param [options] - Options for TreeCounter (comparator, reverse, map mode).
73
+ * @returns New TreeCounter instance.
45
74
  */
46
75
  constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: TreeCounterOptions<K, V, R>);
47
76
  protected _count: number;
48
77
  /**
49
- * The function calculates the sum of the count property of all nodes in a tree structure.
50
- * @returns the sum of the count property of all nodes in the tree.
78
+ * Get the total aggregate count across all nodes.
79
+ * @remarks Time O(1), Space O(1)
80
+ * @returns Total count.
51
81
  */
52
82
  get count(): number;
53
83
  /**
54
- * Time Complexity: O(n)
55
- * Space Complexity: O(1)
56
- *
57
- * The function calculates the sum of the count property of all nodes in a tree using depth-first
58
- * search.
59
- * @returns the sum of the count property of all nodes in the tree.
84
+ * Compute the total count by traversing the tree (sums node.count).
85
+ * @remarks Time O(N), Space O(H)
86
+ * @returns Total count recomputed from nodes.
60
87
  */
61
88
  getComputedCount(): number;
89
+ _createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
62
90
  /**
63
- * The function creates a new TreeCounterNode with the specified key, value, color, and count.
64
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
65
- * which is a generic type representing the type of keys in the tree.
66
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
67
- * associated with the key in the node. It is of type `V`, which can be any data type.
68
- * @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
69
- * a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
70
- * @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
71
- * the tree. It is an optional parameter and is used to keep track of the number of values associated
72
- * with a key in the tree.
73
- * @returns A new instance of the TreeCounterNode class, casted as TreeCounterNode<K, V>.
74
- */
75
- createNode(key: K, value?: V, color?: RBTNColor, count?: number): TreeCounterNode<K, V>;
76
- /**
77
- * The function creates a new instance of a TreeCounter with the specified options and returns it.
78
- * @param [options] - The `options` parameter is an optional object that contains additional
79
- * configuration options for creating the `TreeCounter`. It is of type `TreeCounterOptions<K, V,
80
- * R>`.
81
- * @returns a new instance of the `TreeCounter` class, with the provided options merged with the
82
- * existing `iterationType` property. The returned value is casted as `TREE`.
83
- */
84
- createTree(options?: TreeCounterOptions<K, V, R>): TreeCounter<K, V, R, MK, MV, MR>;
85
- /**
86
- * The function checks if the input is an instance of the TreeCounterNode class.
87
- * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
88
- * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
89
- * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
90
- * an instance of the `TreeCounterNode` class.
91
+ * Type guard: check whether the input is a TreeCounterNode.
92
+ * @remarks Time O(1), Space O(1)
93
+ * @returns True if the value is a TreeCounterNode.
91
94
  */
92
95
  isNode(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is TreeCounterNode<K, V>;
93
96
  /**
94
- * Time Complexity: O(log n)
95
- * Space Complexity: O(1)
96
- *
97
- * The function overrides the add method of a class and adds a new node to a data structure, updating
98
- * the count and returning a boolean indicating success.
99
- * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
100
- * `keyNodeOrEntry` parameter can accept one of the following types:
101
- * @param {V} [value] - The `value` parameter represents the value associated with the key in the
102
- * data structure. It is an optional parameter, so it can be omitted if not needed.
103
- * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
104
- * be added to the data structure. By default, it is set to 1, meaning that if no value is provided
105
- * for `count`, the key-value pair will be added once.
106
- * @returns The method is returning a boolean value. It returns true if the addition of the new node
107
- * was successful, and false otherwise.
97
+ * Insert or increment a node and update aggregate count.
98
+ * @remarks Time O(log N), Space O(1)
99
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
100
+ * @param [value] - Value when a bare key is provided (ignored in map mode).
101
+ * @param [count] - How much to increase the node's count (default 1).
102
+ * @returns True if inserted/updated; false if ignored.
108
103
  */
109
104
  add(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
110
105
  /**
111
- * Time Complexity: O(log n)
112
- * Space Complexity: O(1)
113
- *
114
- * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
115
- * structure, handling cases where nodes have children and maintaining balance in the tree.
116
- * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
117
- * parameter in the `delete` method is used to specify the condition or key based on which a node
118
- * should be deleted from the binary tree. It can be a key, a node, or an entry.
119
- * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
120
- * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
121
- * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
122
- * `ignoreCount` is `false
123
- * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
106
+ * Delete a node (or decrement its count) and rebalance if needed.
107
+ * @remarks Time O(log N), Space O(1)
108
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
109
+ * @param [ignoreCount] - If true, remove the node regardless of its count.
110
+ * @returns Array of deletion results including deleted node and a rebalance hint when present.
124
111
  */
125
112
  delete(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
126
113
  /**
127
- * Time Complexity: O(1)
128
- * Space Complexity: O(1)
129
- *
130
- * The "clear" function overrides the parent class's "clear" function and also resets the count to
131
- * zero.
114
+ * Remove all nodes and reset aggregate counters.
115
+ * @remarks Time O(N), Space O(1)
116
+ * @returns void
132
117
  */
133
118
  clear(): void;
134
119
  /**
135
- * Time Complexity: O(n log n)
136
- * Space Complexity: O(log n)
137
- *
138
- * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
139
- * tree using either a recursive or iterative approach.
140
- * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
141
- * specifies the type of iteration to use when building the balanced binary search tree. It has a
142
- * default value of `this.iterationType`, which means it will use the iteration type specified by the
143
- * `iterationType` property of the current object.
144
- * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
145
- * balancing operation is successful, and `false` if there are no nodes to balance.
120
+ * Rebuild the tree into a perfectly balanced form using in-order nodes.
121
+ * @remarks Time O(N), Space O(N)
122
+ * @param [iterationType] - Traversal style to use when constructing the balanced tree.
123
+ * @returns True if rebalancing succeeded (tree not empty).
146
124
  */
147
125
  perfectlyBalance(iterationType?: IterationType): boolean;
148
126
  /**
149
- * Time complexity: O(n)
150
- * Space complexity: O(n)
151
- *
152
- * The function overrides the clone method to create a deep copy of a tree object.
153
- * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
154
- */
155
- clone(): TreeCounter<K, V, R, MK, MV, MR>;
156
- /**
157
- * The `map` function in TypeScript overrides the default behavior to create a new TreeCounter with
158
- * modified entries based on a provided callback.
159
- * @param callback - The `callback` parameter is a function that will be called for each entry in the
160
- * map. It takes four arguments:
161
- * @param [options] - The `options` parameter in the `override map` function is of type
162
- * `TreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
163
- * options when creating a new `TreeCounter` instance within the `map` function. These options could
164
- * include things like
165
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
166
- * the value of `this` when executing the `callback` function. It allows you to set the context
167
- * (value of `this`) for the callback function when it is called within the `map` function. This
168
- * @returns A new TreeCounter instance is being returned, which is populated with entries generated
169
- * by the provided callback function.
170
- */
171
- map(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: TreeCounterOptions<MK, MV, MR>, thisArg?: any): TreeCounter<MK, MV, MR>;
172
- /**
173
- * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
174
- * node based on the input.
175
- * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
176
- * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
177
- * @param {V} [value] - The `value` parameter is an optional value that represents the value
178
- * associated with the key in the node. It is used when creating a new node or updating the value of
179
- * an existing node.
180
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
181
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
182
- * @returns either a TreeCounterNode<K, V> object or undefined.
127
+ * Create a new TreeCounter by mapping each [key, value] entry.
128
+ * @remarks Time O(N log N), Space O(N)
129
+ * @template MK
130
+ * @template MV
131
+ * @template MR
132
+ * @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
133
+ * @param [options] - Options for the output tree.
134
+ * @param [thisArg] - Value for `this` inside the callback.
135
+ * @returns A new TreeCounter with mapped entries.
136
+ */
137
+ map<MK = K, MV = V, MR extends object = object>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): TreeCounter<MK, MV, MR>;
138
+ /**
139
+ * Deep copy this tree, preserving map mode and aggregate counts.
140
+ * @remarks Time O(N), Space O(N)
141
+ * @returns A deep copy of this tree.
142
+ */
143
+ clone(): this;
144
+ /**
145
+ * (Protected) Create an empty instance of the same concrete class.
146
+ * @remarks Time O(1), Space O(1)
147
+ * @template TK
148
+ * @template TV
149
+ * @template TR
150
+ * @param [options] - Optional constructor options for the like-kind instance.
151
+ * @returns An empty like-kind instance.
152
+ */
153
+ protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<BSTOptions<TK, TV, TR>>): this;
154
+ /**
155
+ * (Protected) Create a like-kind instance and seed it from an iterable.
156
+ * @remarks Time O(N log N), Space O(N)
157
+ * @template TK
158
+ * @template TV
159
+ * @template TR
160
+ * @param iter - Iterable used to seed the new tree.
161
+ * @param [options] - Options merged with the current snapshot.
162
+ * @returns A like-kind TreeCounter built from the iterable.
163
+ */
164
+ protected _createLike<TK = K, TV = V, TR extends object = 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>;
165
+ /**
166
+ * (Protected) Normalize input into a node plus its effective value and count.
167
+ * @remarks Time O(1), Space O(1)
168
+ * @param keyNodeOrEntry - Key, node, or [key, value] entry.
169
+ * @param [value] - Value used when a bare key is provided.
170
+ * @param [count] - Count increment to apply (default 1).
171
+ * @returns Tuple [node, value] where node may be undefined.
183
172
  */
184
173
  protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
185
174
  /**
186
- * Time Complexity: O(1)
187
- * Space Complexity: O(1)
188
- *
189
- * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
190
- * in a binary search tree.
191
- * @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
192
- * that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
193
- * instance of the `BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>` class.
194
- * @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
195
- * node where the properties will be swapped with the source node.
196
- * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
197
- * If either `srcNode` or `destNode` is undefined, it returns undefined.
175
+ * (Protected) Swap keys/values/counters between the source and destination nodes.
176
+ * @remarks Time O(1), Space O(1)
177
+ * @param srcNode - Source node (or key) whose properties will be moved.
178
+ * @param destNode - Destination node (or key) to receive properties.
179
+ * @returns Destination node after swap, or undefined.
198
180
  */
199
181
  protected _swapProperties(srcNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>, destNode: BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>): TreeCounterNode<K, V> | undefined;
200
182
  /**
201
- * Time Complexity: O(1)
202
- * Space Complexity: O(1)
203
- *
204
- * The function replaces an old node with a new node and updates the count property of the new node.
205
- * @param {TreeCounterNode<K, V>} oldNode - The `oldNode` parameter is the node that you want to replace in the data
206
- * structure.
207
- * @param {TreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `TreeCounterNode<K, V>` class.
208
- * @returns The method is returning the result of calling the `_replaceNode` method from the
209
- * superclass, which is of type `TreeCounterNode<K, V>`.
183
+ * (Protected) Replace one node by another and adjust counters accordingly.
184
+ * @remarks Time O(1), Space O(1)
185
+ * @param oldNode - Node being replaced.
186
+ * @param newNode - Replacement node.
187
+ * @returns The new node after replacement.
210
188
  */
211
189
  protected _replaceNode(oldNode: TreeCounterNode<K, V>, newNode: TreeCounterNode<K, V>): TreeCounterNode<K, V>;
212
190
  }