data-structure-typed 1.54.0 → 1.54.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 (498) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -0
  3. package/benchmark/report.html +1 -28
  4. package/benchmark/report.json +17 -326
  5. package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts → cjs/data-structures/binary-tree/avl-tree-counter.d.ts} +54 -47
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +408 -0
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
  8. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +71 -177
  9. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -340
  10. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +102 -57
  12. package/dist/cjs/data-structures/binary-tree/avl-tree.js +110 -47
  13. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  15. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  16. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +240 -190
  18. package/dist/cjs/data-structures/binary-tree/binary-tree.js +269 -240
  19. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/bst.d.ts +145 -112
  21. package/dist/cjs/data-structures/binary-tree/bst.js +180 -129
  22. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/index.d.ts +2 -0
  24. package/dist/cjs/data-structures/binary-tree/index.js +2 -0
  25. package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +100 -82
  27. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +115 -79
  28. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  29. package/dist/{mjs/data-structures/binary-tree/tree-multi-map.d.ts → cjs/data-structures/binary-tree/tree-counter.d.ts} +74 -64
  30. package/dist/cjs/data-structures/binary-tree/tree-counter.js +445 -0
  31. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -0
  32. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +78 -174
  33. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +142 -377
  34. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  35. package/dist/cjs/data-structures/graph/directed-graph.d.ts +3 -0
  36. package/dist/cjs/data-structures/graph/directed-graph.js +3 -0
  37. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/map-graph.d.ts +3 -0
  39. package/dist/cjs/data-structures/graph/map-graph.js +3 -0
  40. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +3 -0
  42. package/dist/cjs/data-structures/graph/undirected-graph.js +3 -0
  43. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +3 -0
  45. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +3 -0
  46. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  48. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +3 -0
  49. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/matrix/matrix.d.ts +3 -0
  51. package/dist/cjs/data-structures/matrix/matrix.js +3 -0
  52. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  53. package/dist/cjs/data-structures/matrix/navigator.d.ts +3 -0
  54. package/dist/cjs/data-structures/matrix/navigator.js +3 -0
  55. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  56. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  57. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +3 -0
  58. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  59. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  60. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +3 -0
  61. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  62. package/dist/cjs/data-structures/trie/trie.d.ts +0 -4
  63. package/dist/cjs/data-structures/trie/trie.js +0 -4
  64. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  65. package/dist/cjs/interfaces/binary-tree.d.ts +8 -8
  66. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  67. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +3 -0
  68. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
  69. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -4
  70. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -3
  71. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
  72. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
  73. package/dist/cjs/types/data-structures/binary-tree/index.d.ts +3 -1
  74. package/dist/cjs/types/data-structures/binary-tree/index.js +3 -1
  75. package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
  76. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  77. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +3 -0
  78. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +1 -0
  79. package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  80. package/dist/cjs/types/data-structures/binary-tree/{rb-tree.js → tree-counter.js} +1 -1
  81. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +1 -0
  82. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -5
  83. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +213 -0
  84. package/dist/{mjs/data-structures/binary-tree/avl-tree-multi-map.js → esm/data-structures/binary-tree/avl-tree-counter.js} +73 -60
  85. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
  86. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -0
  87. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +191 -0
  88. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -0
  89. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +234 -0
  90. package/dist/{mjs → esm}/data-structures/binary-tree/avl-tree.js +110 -47
  91. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -0
  92. package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -0
  93. package/dist/{mjs → esm}/data-structures/binary-tree/binary-indexed-tree.js +3 -0
  94. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  95. package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.d.ts +240 -190
  96. package/dist/{mjs → esm}/data-structures/binary-tree/binary-tree.js +272 -245
  97. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -0
  98. package/dist/{mjs → esm}/data-structures/binary-tree/bst.d.ts +145 -112
  99. package/dist/{mjs → esm}/data-structures/binary-tree/bst.js +201 -155
  100. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -0
  101. package/dist/{mjs → esm}/data-structures/binary-tree/index.d.ts +2 -0
  102. package/dist/{mjs/types/data-structures/binary-tree/index.d.ts → esm/data-structures/binary-tree/index.js} +6 -2
  103. package/dist/{mjs → esm}/data-structures/binary-tree/index.js.map +1 -1
  104. package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.d.ts +100 -82
  105. package/dist/{mjs → esm}/data-structures/binary-tree/red-black-tree.js +115 -79
  106. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -0
  107. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +212 -0
  108. package/dist/{mjs/data-structures/binary-tree/tree-multi-map.js → esm/data-structures/binary-tree/tree-counter.js} +111 -96
  109. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -0
  110. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +106 -0
  111. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +196 -0
  112. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -0
  113. package/dist/{mjs → esm}/data-structures/graph/directed-graph.d.ts +3 -0
  114. package/dist/{mjs → esm}/data-structures/graph/directed-graph.js +3 -0
  115. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -0
  116. package/dist/{mjs → esm}/data-structures/graph/map-graph.d.ts +3 -0
  117. package/dist/{mjs → esm}/data-structures/graph/map-graph.js +3 -0
  118. package/dist/esm/data-structures/graph/map-graph.js.map +1 -0
  119. package/dist/{mjs → esm}/data-structures/graph/undirected-graph.d.ts +3 -0
  120. package/dist/{mjs → esm}/data-structures/graph/undirected-graph.js +3 -0
  121. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -0
  122. package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.d.ts +3 -0
  123. package/dist/{mjs → esm}/data-structures/linked-list/singly-linked-list.js +3 -0
  124. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -0
  125. package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.d.ts +3 -0
  126. package/dist/{mjs → esm}/data-structures/linked-list/skip-linked-list.js +3 -0
  127. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -0
  128. package/dist/{mjs → esm}/data-structures/matrix/matrix.d.ts +3 -0
  129. package/dist/{mjs → esm}/data-structures/matrix/matrix.js +3 -0
  130. package/dist/esm/data-structures/matrix/matrix.js.map +1 -0
  131. package/dist/{mjs → esm}/data-structures/matrix/navigator.d.ts +3 -0
  132. package/dist/{mjs → esm}/data-structures/matrix/navigator.js +3 -0
  133. package/dist/esm/data-structures/matrix/navigator.js.map +1 -0
  134. package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.d.ts +3 -0
  135. package/dist/{mjs → esm}/data-structures/priority-queue/max-priority-queue.js +3 -0
  136. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  137. package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.d.ts +3 -0
  138. package/dist/{mjs → esm}/data-structures/priority-queue/min-priority-queue.js +3 -0
  139. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  140. package/dist/{mjs → esm}/data-structures/trie/trie.d.ts +0 -4
  141. package/dist/{mjs → esm}/data-structures/trie/trie.js +0 -4
  142. package/dist/esm/data-structures/trie/trie.js.map +1 -0
  143. package/dist/esm/interfaces/binary-tree.d.ts +9 -0
  144. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  145. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +2 -0
  146. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +1 -0
  147. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  148. package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  149. package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.d.ts +0 -3
  150. package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.d.ts +3 -3
  151. package/dist/{mjs/data-structures/binary-tree/index.js → esm/types/data-structures/binary-tree/index.d.ts} +4 -4
  152. package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js +3 -1
  153. package/dist/{mjs → esm}/types/data-structures/binary-tree/index.js.map +1 -1
  154. package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  155. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +2 -0
  156. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +1 -0
  157. package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  158. package/dist/esm/types/data-structures/binary-tree/tree-counter.js +2 -0
  159. package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +1 -0
  160. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  161. package/dist/umd/data-structure-typed.js +1464 -895
  162. package/dist/umd/data-structure-typed.min.js +5 -5
  163. package/dist/umd/data-structure-typed.min.js.map +1 -1
  164. package/package.json +14 -19
  165. package/src/data-structures/binary-tree/avl-tree-counter.ts +463 -0
  166. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +155 -393
  167. package/src/data-structures/binary-tree/avl-tree.ts +144 -93
  168. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -0
  169. package/src/data-structures/binary-tree/binary-tree.ts +433 -405
  170. package/src/data-structures/binary-tree/bst.ts +261 -239
  171. package/src/data-structures/binary-tree/index.ts +2 -0
  172. package/src/data-structures/binary-tree/red-black-tree.ts +163 -134
  173. package/src/data-structures/binary-tree/tree-counter.ts +504 -0
  174. package/src/data-structures/binary-tree/tree-multi-map.ts +161 -429
  175. package/src/data-structures/graph/directed-graph.ts +3 -0
  176. package/src/data-structures/graph/map-graph.ts +3 -0
  177. package/src/data-structures/graph/undirected-graph.ts +3 -0
  178. package/src/data-structures/linked-list/singly-linked-list.ts +3 -0
  179. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  180. package/src/data-structures/matrix/matrix.ts +3 -0
  181. package/src/data-structures/matrix/navigator.ts +3 -0
  182. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -0
  183. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -0
  184. package/src/data-structures/trie/trie.ts +0 -4
  185. package/src/interfaces/binary-tree.ts +10 -24
  186. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  187. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -6
  188. package/src/types/data-structures/binary-tree/avl-tree.ts +0 -5
  189. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -5
  190. package/src/types/data-structures/binary-tree/bst.ts +5 -5
  191. package/src/types/data-structures/binary-tree/index.ts +3 -1
  192. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  193. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  194. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -7
  195. package/test/integration/all-in-one.test.ts +1 -1
  196. package/test/integration/avl-tree.test.ts +1 -1
  197. package/test/integration/bst.test.ts +2 -2
  198. package/test/integration/compile.js +144 -0
  199. package/test/integration/compile.mjs +135 -0
  200. package/test/integration/compile.ts +171 -0
  201. package/test/integration/index.html +48 -48
  202. package/test/performance/data-structures/binary-tree/avl-tree.test.js +45 -0
  203. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
  204. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -4
  205. package/test/performance/data-structures/comparison/comparison.test.ts +2 -2
  206. package/test/performance/reportor.js +249 -0
  207. package/test/performance/reportor.ts +5 -3
  208. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +877 -0
  209. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +459 -761
  210. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +223 -223
  211. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +474 -492
  212. package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
  213. package/test/unit/data-structures/binary-tree/overall.test.ts +0 -3
  214. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +87 -90
  215. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +975 -0
  216. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +729 -857
  217. package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
  218. package/{tsconfig-mjs.json → tsconfig-esm.json} +1 -1
  219. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
  220. package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +0 -1
  221. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  222. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -189
  223. package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +0 -1
  224. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  225. package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +0 -1
  226. package/dist/mjs/data-structures/binary-tree/bst.js.map +0 -1
  227. package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
  228. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  229. package/dist/mjs/data-structures/graph/directed-graph.js.map +0 -1
  230. package/dist/mjs/data-structures/graph/map-graph.js.map +0 -1
  231. package/dist/mjs/data-structures/graph/undirected-graph.js.map +0 -1
  232. package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
  233. package/dist/mjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
  234. package/dist/mjs/data-structures/matrix/matrix.js.map +0 -1
  235. package/dist/mjs/data-structures/matrix/navigator.js.map +0 -1
  236. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  237. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  238. package/dist/mjs/data-structures/trie/trie.js.map +0 -1
  239. package/dist/mjs/interfaces/binary-tree.d.ts +0 -9
  240. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -5
  241. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +0 -5
  242. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +0 -6
  243. package/dist/mjs/types/data-structures/binary-tree/rb-tree.js +0 -2
  244. package/dist/mjs/types/data-structures/binary-tree/rb-tree.js.map +0 -1
  245. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -5
  246. package/src/types/data-structures/binary-tree/rb-tree.ts +0 -10
  247. /package/dist/{mjs → esm}/common/index.d.ts +0 -0
  248. /package/dist/{mjs → esm}/common/index.js +0 -0
  249. /package/dist/{mjs → esm}/common/index.js.map +0 -0
  250. /package/dist/{mjs → esm}/data-structures/base/index.d.ts +0 -0
  251. /package/dist/{mjs → esm}/data-structures/base/index.js +0 -0
  252. /package/dist/{mjs → esm}/data-structures/base/index.js.map +0 -0
  253. /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.d.ts +0 -0
  254. /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js +0 -0
  255. /package/dist/{mjs → esm}/data-structures/base/iterable-element-base.js.map +0 -0
  256. /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.d.ts +0 -0
  257. /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js +0 -0
  258. /package/dist/{mjs → esm}/data-structures/base/iterable-entry-base.js.map +0 -0
  259. /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  260. /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js +0 -0
  261. /package/dist/{mjs → esm}/data-structures/binary-tree/segment-tree.js.map +0 -0
  262. /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.d.ts +0 -0
  263. /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js +0 -0
  264. /package/dist/{mjs → esm}/data-structures/graph/abstract-graph.js.map +0 -0
  265. /package/dist/{mjs → esm}/data-structures/graph/index.d.ts +0 -0
  266. /package/dist/{mjs → esm}/data-structures/graph/index.js +0 -0
  267. /package/dist/{mjs → esm}/data-structures/graph/index.js.map +0 -0
  268. /package/dist/{mjs → esm}/data-structures/hash/hash-map.d.ts +0 -0
  269. /package/dist/{mjs → esm}/data-structures/hash/hash-map.js +0 -0
  270. /package/dist/{mjs → esm}/data-structures/hash/hash-map.js.map +0 -0
  271. /package/dist/{mjs → esm}/data-structures/hash/index.d.ts +0 -0
  272. /package/dist/{mjs → esm}/data-structures/hash/index.js +0 -0
  273. /package/dist/{mjs → esm}/data-structures/hash/index.js.map +0 -0
  274. /package/dist/{mjs → esm}/data-structures/heap/heap.d.ts +0 -0
  275. /package/dist/{mjs → esm}/data-structures/heap/heap.js +0 -0
  276. /package/dist/{mjs → esm}/data-structures/heap/heap.js.map +0 -0
  277. /package/dist/{mjs → esm}/data-structures/heap/index.d.ts +0 -0
  278. /package/dist/{mjs → esm}/data-structures/heap/index.js +0 -0
  279. /package/dist/{mjs → esm}/data-structures/heap/index.js.map +0 -0
  280. /package/dist/{mjs → esm}/data-structures/heap/max-heap.d.ts +0 -0
  281. /package/dist/{mjs → esm}/data-structures/heap/max-heap.js +0 -0
  282. /package/dist/{mjs → esm}/data-structures/heap/max-heap.js.map +0 -0
  283. /package/dist/{mjs → esm}/data-structures/heap/min-heap.d.ts +0 -0
  284. /package/dist/{mjs → esm}/data-structures/heap/min-heap.js +0 -0
  285. /package/dist/{mjs → esm}/data-structures/heap/min-heap.js.map +0 -0
  286. /package/dist/{mjs → esm}/data-structures/index.d.ts +0 -0
  287. /package/dist/{mjs → esm}/data-structures/index.js +0 -0
  288. /package/dist/{mjs → esm}/data-structures/index.js.map +0 -0
  289. /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  290. /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js +0 -0
  291. /package/dist/{mjs → esm}/data-structures/linked-list/doubly-linked-list.js.map +0 -0
  292. /package/dist/{mjs → esm}/data-structures/linked-list/index.d.ts +0 -0
  293. /package/dist/{mjs → esm}/data-structures/linked-list/index.js +0 -0
  294. /package/dist/{mjs → esm}/data-structures/linked-list/index.js.map +0 -0
  295. /package/dist/{mjs → esm}/data-structures/matrix/index.d.ts +0 -0
  296. /package/dist/{mjs → esm}/data-structures/matrix/index.js +0 -0
  297. /package/dist/{mjs → esm}/data-structures/matrix/index.js.map +0 -0
  298. /package/dist/{mjs → esm}/data-structures/priority-queue/index.d.ts +0 -0
  299. /package/dist/{mjs → esm}/data-structures/priority-queue/index.js +0 -0
  300. /package/dist/{mjs → esm}/data-structures/priority-queue/index.js.map +0 -0
  301. /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.d.ts +0 -0
  302. /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js +0 -0
  303. /package/dist/{mjs → esm}/data-structures/priority-queue/priority-queue.js.map +0 -0
  304. /package/dist/{mjs → esm}/data-structures/queue/deque.d.ts +0 -0
  305. /package/dist/{mjs → esm}/data-structures/queue/deque.js +0 -0
  306. /package/dist/{mjs → esm}/data-structures/queue/deque.js.map +0 -0
  307. /package/dist/{mjs → esm}/data-structures/queue/index.d.ts +0 -0
  308. /package/dist/{mjs → esm}/data-structures/queue/index.js +0 -0
  309. /package/dist/{mjs → esm}/data-structures/queue/index.js.map +0 -0
  310. /package/dist/{mjs → esm}/data-structures/queue/queue.d.ts +0 -0
  311. /package/dist/{mjs → esm}/data-structures/queue/queue.js +0 -0
  312. /package/dist/{mjs → esm}/data-structures/queue/queue.js.map +0 -0
  313. /package/dist/{mjs → esm}/data-structures/stack/index.d.ts +0 -0
  314. /package/dist/{mjs → esm}/data-structures/stack/index.js +0 -0
  315. /package/dist/{mjs → esm}/data-structures/stack/index.js.map +0 -0
  316. /package/dist/{mjs → esm}/data-structures/stack/stack.d.ts +0 -0
  317. /package/dist/{mjs → esm}/data-structures/stack/stack.js +0 -0
  318. /package/dist/{mjs → esm}/data-structures/stack/stack.js.map +0 -0
  319. /package/dist/{mjs → esm}/data-structures/tree/index.d.ts +0 -0
  320. /package/dist/{mjs → esm}/data-structures/tree/index.js +0 -0
  321. /package/dist/{mjs → esm}/data-structures/tree/index.js.map +0 -0
  322. /package/dist/{mjs → esm}/data-structures/tree/tree.d.ts +0 -0
  323. /package/dist/{mjs → esm}/data-structures/tree/tree.js +0 -0
  324. /package/dist/{mjs → esm}/data-structures/tree/tree.js.map +0 -0
  325. /package/dist/{mjs → esm}/data-structures/trie/index.d.ts +0 -0
  326. /package/dist/{mjs → esm}/data-structures/trie/index.js +0 -0
  327. /package/dist/{mjs → esm}/data-structures/trie/index.js.map +0 -0
  328. /package/dist/{mjs → esm}/index.d.ts +0 -0
  329. /package/dist/{mjs → esm}/index.js +0 -0
  330. /package/dist/{mjs → esm}/index.js.map +0 -0
  331. /package/dist/{mjs → esm}/interfaces/binary-tree.js +0 -0
  332. /package/dist/{mjs → esm}/interfaces/binary-tree.js.map +0 -0
  333. /package/dist/{mjs → esm}/interfaces/doubly-linked-list.d.ts +0 -0
  334. /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js +0 -0
  335. /package/dist/{mjs → esm}/interfaces/doubly-linked-list.js.map +0 -0
  336. /package/dist/{mjs → esm}/interfaces/graph.d.ts +0 -0
  337. /package/dist/{mjs → esm}/interfaces/graph.js +0 -0
  338. /package/dist/{mjs → esm}/interfaces/graph.js.map +0 -0
  339. /package/dist/{mjs → esm}/interfaces/heap.d.ts +0 -0
  340. /package/dist/{mjs → esm}/interfaces/heap.js +0 -0
  341. /package/dist/{mjs → esm}/interfaces/heap.js.map +0 -0
  342. /package/dist/{mjs → esm}/interfaces/index.d.ts +0 -0
  343. /package/dist/{mjs → esm}/interfaces/index.js +0 -0
  344. /package/dist/{mjs → esm}/interfaces/index.js.map +0 -0
  345. /package/dist/{mjs → esm}/interfaces/navigator.d.ts +0 -0
  346. /package/dist/{mjs → esm}/interfaces/navigator.js +0 -0
  347. /package/dist/{mjs → esm}/interfaces/navigator.js.map +0 -0
  348. /package/dist/{mjs → esm}/interfaces/priority-queue.d.ts +0 -0
  349. /package/dist/{mjs → esm}/interfaces/priority-queue.js +0 -0
  350. /package/dist/{mjs → esm}/interfaces/priority-queue.js.map +0 -0
  351. /package/dist/{mjs → esm}/interfaces/segment-tree.d.ts +0 -0
  352. /package/dist/{mjs → esm}/interfaces/segment-tree.js +0 -0
  353. /package/dist/{mjs → esm}/interfaces/segment-tree.js.map +0 -0
  354. /package/dist/{mjs → esm}/interfaces/singly-linked-list.d.ts +0 -0
  355. /package/dist/{mjs → esm}/interfaces/singly-linked-list.js +0 -0
  356. /package/dist/{mjs → esm}/interfaces/singly-linked-list.js.map +0 -0
  357. /package/dist/{mjs → esm}/types/common.d.ts +0 -0
  358. /package/dist/{mjs → esm}/types/common.js +0 -0
  359. /package/dist/{mjs → esm}/types/common.js.map +0 -0
  360. /package/dist/{mjs → esm}/types/data-structures/base/base.d.ts +0 -0
  361. /package/dist/{mjs → esm}/types/data-structures/base/base.js +0 -0
  362. /package/dist/{mjs → esm}/types/data-structures/base/base.js.map +0 -0
  363. /package/dist/{mjs → esm}/types/data-structures/base/index.d.ts +0 -0
  364. /package/dist/{mjs → esm}/types/data-structures/base/index.js +0 -0
  365. /package/dist/{mjs → esm}/types/data-structures/base/index.js.map +0 -0
  366. /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -0
  367. /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -0
  368. /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js +0 -0
  369. /package/dist/{mjs → esm}/types/data-structures/binary-tree/avl-tree.js.map +0 -0
  370. /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  371. /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js +0 -0
  372. /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -0
  373. /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js +0 -0
  374. /package/dist/{mjs → esm}/types/data-structures/binary-tree/binary-tree.js.map +0 -0
  375. /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js +0 -0
  376. /package/dist/{mjs → esm}/types/data-structures/binary-tree/bst.js.map +0 -0
  377. /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
  378. /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js +0 -0
  379. /package/dist/{mjs → esm}/types/data-structures/binary-tree/segment-tree.js.map +0 -0
  380. /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js +0 -0
  381. /package/dist/{mjs → esm}/types/data-structures/binary-tree/tree-multi-map.js.map +0 -0
  382. /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.d.ts +0 -0
  383. /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js +0 -0
  384. /package/dist/{mjs → esm}/types/data-structures/graph/abstract-graph.js.map +0 -0
  385. /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.d.ts +0 -0
  386. /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js +0 -0
  387. /package/dist/{mjs → esm}/types/data-structures/graph/directed-graph.js.map +0 -0
  388. /package/dist/{mjs → esm}/types/data-structures/graph/index.d.ts +0 -0
  389. /package/dist/{mjs → esm}/types/data-structures/graph/index.js +0 -0
  390. /package/dist/{mjs → esm}/types/data-structures/graph/index.js.map +0 -0
  391. /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.d.ts +0 -0
  392. /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js +0 -0
  393. /package/dist/{mjs → esm}/types/data-structures/graph/map-graph.js.map +0 -0
  394. /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.d.ts +0 -0
  395. /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js +0 -0
  396. /package/dist/{mjs → esm}/types/data-structures/graph/undirected-graph.js.map +0 -0
  397. /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.d.ts +0 -0
  398. /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js +0 -0
  399. /package/dist/{mjs → esm}/types/data-structures/hash/hash-map.js.map +0 -0
  400. /package/dist/{mjs → esm}/types/data-structures/hash/index.d.ts +0 -0
  401. /package/dist/{mjs → esm}/types/data-structures/hash/index.js +0 -0
  402. /package/dist/{mjs → esm}/types/data-structures/hash/index.js.map +0 -0
  403. /package/dist/{mjs → esm}/types/data-structures/heap/heap.d.ts +0 -0
  404. /package/dist/{mjs → esm}/types/data-structures/heap/heap.js +0 -0
  405. /package/dist/{mjs → esm}/types/data-structures/heap/heap.js.map +0 -0
  406. /package/dist/{mjs → esm}/types/data-structures/heap/index.d.ts +0 -0
  407. /package/dist/{mjs → esm}/types/data-structures/heap/index.js +0 -0
  408. /package/dist/{mjs → esm}/types/data-structures/heap/index.js.map +0 -0
  409. /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.d.ts +0 -0
  410. /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js +0 -0
  411. /package/dist/{mjs → esm}/types/data-structures/heap/max-heap.js.map +0 -0
  412. /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.d.ts +0 -0
  413. /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js +0 -0
  414. /package/dist/{mjs → esm}/types/data-structures/heap/min-heap.js.map +0 -0
  415. /package/dist/{mjs → esm}/types/data-structures/index.d.ts +0 -0
  416. /package/dist/{mjs → esm}/types/data-structures/index.js +0 -0
  417. /package/dist/{mjs → esm}/types/data-structures/index.js.map +0 -0
  418. /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  419. /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js +0 -0
  420. /package/dist/{mjs → esm}/types/data-structures/linked-list/doubly-linked-list.js.map +0 -0
  421. /package/dist/{mjs → esm}/types/data-structures/linked-list/index.d.ts +0 -0
  422. /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js +0 -0
  423. /package/dist/{mjs → esm}/types/data-structures/linked-list/index.js.map +0 -0
  424. /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
  425. /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js +0 -0
  426. /package/dist/{mjs → esm}/types/data-structures/linked-list/singly-linked-list.js.map +0 -0
  427. /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  428. /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js +0 -0
  429. /package/dist/{mjs → esm}/types/data-structures/linked-list/skip-linked-list.js.map +0 -0
  430. /package/dist/{mjs → esm}/types/data-structures/matrix/index.d.ts +0 -0
  431. /package/dist/{mjs → esm}/types/data-structures/matrix/index.js +0 -0
  432. /package/dist/{mjs → esm}/types/data-structures/matrix/index.js.map +0 -0
  433. /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.d.ts +0 -0
  434. /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js +0 -0
  435. /package/dist/{mjs → esm}/types/data-structures/matrix/matrix.js.map +0 -0
  436. /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.d.ts +0 -0
  437. /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js +0 -0
  438. /package/dist/{mjs → esm}/types/data-structures/matrix/navigator.js.map +0 -0
  439. /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.d.ts +0 -0
  440. /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js +0 -0
  441. /package/dist/{mjs → esm}/types/data-structures/priority-queue/index.js.map +0 -0
  442. /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  443. /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js +0 -0
  444. /package/dist/{mjs → esm}/types/data-structures/priority-queue/max-priority-queue.js.map +0 -0
  445. /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  446. /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js +0 -0
  447. /package/dist/{mjs → esm}/types/data-structures/priority-queue/min-priority-queue.js.map +0 -0
  448. /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
  449. /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js +0 -0
  450. /package/dist/{mjs → esm}/types/data-structures/priority-queue/priority-queue.js.map +0 -0
  451. /package/dist/{mjs → esm}/types/data-structures/queue/deque.d.ts +0 -0
  452. /package/dist/{mjs → esm}/types/data-structures/queue/deque.js +0 -0
  453. /package/dist/{mjs → esm}/types/data-structures/queue/deque.js.map +0 -0
  454. /package/dist/{mjs → esm}/types/data-structures/queue/index.d.ts +0 -0
  455. /package/dist/{mjs → esm}/types/data-structures/queue/index.js +0 -0
  456. /package/dist/{mjs → esm}/types/data-structures/queue/index.js.map +0 -0
  457. /package/dist/{mjs → esm}/types/data-structures/queue/queue.d.ts +0 -0
  458. /package/dist/{mjs → esm}/types/data-structures/queue/queue.js +0 -0
  459. /package/dist/{mjs → esm}/types/data-structures/queue/queue.js.map +0 -0
  460. /package/dist/{mjs → esm}/types/data-structures/stack/index.d.ts +0 -0
  461. /package/dist/{mjs → esm}/types/data-structures/stack/index.js +0 -0
  462. /package/dist/{mjs → esm}/types/data-structures/stack/index.js.map +0 -0
  463. /package/dist/{mjs → esm}/types/data-structures/stack/stack.d.ts +0 -0
  464. /package/dist/{mjs → esm}/types/data-structures/stack/stack.js +0 -0
  465. /package/dist/{mjs → esm}/types/data-structures/stack/stack.js.map +0 -0
  466. /package/dist/{mjs → esm}/types/data-structures/tree/index.d.ts +0 -0
  467. /package/dist/{mjs → esm}/types/data-structures/tree/index.js +0 -0
  468. /package/dist/{mjs → esm}/types/data-structures/tree/index.js.map +0 -0
  469. /package/dist/{mjs → esm}/types/data-structures/tree/tree.d.ts +0 -0
  470. /package/dist/{mjs → esm}/types/data-structures/tree/tree.js +0 -0
  471. /package/dist/{mjs → esm}/types/data-structures/tree/tree.js.map +0 -0
  472. /package/dist/{mjs → esm}/types/data-structures/trie/index.d.ts +0 -0
  473. /package/dist/{mjs → esm}/types/data-structures/trie/index.js +0 -0
  474. /package/dist/{mjs → esm}/types/data-structures/trie/index.js.map +0 -0
  475. /package/dist/{mjs → esm}/types/data-structures/trie/trie.d.ts +0 -0
  476. /package/dist/{mjs → esm}/types/data-structures/trie/trie.js +0 -0
  477. /package/dist/{mjs → esm}/types/data-structures/trie/trie.js.map +0 -0
  478. /package/dist/{mjs → esm}/types/index.d.ts +0 -0
  479. /package/dist/{mjs → esm}/types/index.js +0 -0
  480. /package/dist/{mjs → esm}/types/index.js.map +0 -0
  481. /package/dist/{mjs → esm}/types/utils/index.d.ts +0 -0
  482. /package/dist/{mjs → esm}/types/utils/index.js +0 -0
  483. /package/dist/{mjs → esm}/types/utils/index.js.map +0 -0
  484. /package/dist/{mjs → esm}/types/utils/utils.d.ts +0 -0
  485. /package/dist/{mjs → esm}/types/utils/utils.js +0 -0
  486. /package/dist/{mjs → esm}/types/utils/utils.js.map +0 -0
  487. /package/dist/{mjs → esm}/types/utils/validate-type.d.ts +0 -0
  488. /package/dist/{mjs → esm}/types/utils/validate-type.js +0 -0
  489. /package/dist/{mjs → esm}/types/utils/validate-type.js.map +0 -0
  490. /package/dist/{mjs → esm}/utils/index.d.ts +0 -0
  491. /package/dist/{mjs → esm}/utils/index.js +0 -0
  492. /package/dist/{mjs → esm}/utils/index.js.map +0 -0
  493. /package/dist/{mjs → esm}/utils/number.d.ts +0 -0
  494. /package/dist/{mjs → esm}/utils/number.js +0 -0
  495. /package/dist/{mjs → esm}/utils/number.js.map +0 -0
  496. /package/dist/{mjs → esm}/utils/utils.d.ts +0 -0
  497. /package/dist/{mjs → esm}/utils/utils.js +0 -0
  498. /package/dist/{mjs → esm}/utils/utils.js.map +0 -0
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var dataStructureTyped = (() => {
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -22,6 +24,7 @@ var dataStructureTyped = (() => {
22
24
  }
23
25
  return a;
24
26
  };
27
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
28
  var __export = (target, all) => {
26
29
  for (var name in all)
27
30
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -93,6 +96,8 @@ var dataStructureTyped = (() => {
93
96
  var src_exports = {};
94
97
  __export(src_exports, {
95
98
  AVLTree: () => AVLTree,
99
+ AVLTreeCounter: () => AVLTreeCounter,
100
+ AVLTreeCounterNode: () => AVLTreeCounterNode,
96
101
  AVLTreeMultiMap: () => AVLTreeMultiMap,
97
102
  AVLTreeMultiMapNode: () => AVLTreeMultiMapNode,
98
103
  AVLTreeNode: () => AVLTreeNode,
@@ -142,6 +147,8 @@ var dataStructureTyped = (() => {
142
147
  SkipListNode: () => SkipListNode,
143
148
  Stack: () => Stack,
144
149
  THUNK_SYMBOL: () => THUNK_SYMBOL,
150
+ TreeCounter: () => TreeCounter,
151
+ TreeCounterNode: () => TreeCounterNode,
145
152
  TreeMultiMap: () => TreeMultiMap,
146
153
  TreeMultiMapNode: () => TreeMultiMapNode,
147
154
  TreeNode: () => TreeNode,
@@ -7383,6 +7390,14 @@ var dataStructureTyped = (() => {
7383
7390
 
7384
7391
  // src/data-structures/binary-tree/binary-tree.ts
7385
7392
  var BinaryTreeNode = class {
7393
+ /**
7394
+ * The constructor function initializes an object with a key and an optional value in TypeScript.
7395
+ * @param {K} key - The `key` parameter in the constructor function is used to store the key value
7396
+ * for the key-value pair.
7397
+ * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
7398
+ * have to be provided when creating an instance of the class. If a `value` is not provided, it will
7399
+ * default to `undefined`.
7400
+ */
7386
7401
  constructor(key, value) {
7387
7402
  __publicField(this, "key");
7388
7403
  __publicField(this, "value");
@@ -7432,13 +7447,12 @@ var dataStructureTyped = (() => {
7432
7447
  this._count = value;
7433
7448
  }
7434
7449
  get familyPosition() {
7435
- const that = this;
7436
7450
  if (!this.parent) {
7437
7451
  return this.left || this.right ? "ROOT" : "ISOLATED";
7438
7452
  }
7439
- if (this.parent.left === that) {
7453
+ if (this.parent.left === this) {
7440
7454
  return this.left || this.right ? "ROOT_LEFT" : "LEFT";
7441
- } else if (this.parent.right === that) {
7455
+ } else if (this.parent.right === this) {
7442
7456
  return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
7443
7457
  }
7444
7458
  return "MAL_NODE";
@@ -7446,13 +7460,13 @@ var dataStructureTyped = (() => {
7446
7460
  };
7447
7461
  var BinaryTree = class _BinaryTree extends IterableEntryBase {
7448
7462
  /**
7449
- * The constructor initializes a binary tree with optional options and adds keys, nodes, entries, or
7450
- * raw data if provided.
7451
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
7452
- * is an iterable that can contain elements of type `BTNRep<K, V, NODE>` or `R`. It is
7453
- * initialized with an empty array `[]` by default.
7454
- * @param [options] - The `options` parameter in the constructor is an object that can contain the
7455
- * following properties:
7463
+ * This TypeScript constructor function initializes a binary tree with optional options and adds
7464
+ * elements based on the provided input.
7465
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
7466
+ * iterable that can contain either objects of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
7467
+ * is used to initialize the binary tree with keys, nodes, entries, or raw data.
7468
+ * @param [options] - The `options` parameter in the constructor is an optional object that can
7469
+ * contain the following properties:
7456
7470
  */
7457
7471
  constructor(keysNodesEntriesOrRaws = [], options) {
7458
7472
  super();
@@ -7501,12 +7515,15 @@ var dataStructureTyped = (() => {
7501
7515
  * not required to be provided when calling the function. If a `value` is provided, it should be of
7502
7516
  * type `V`, which is the type of the value associated with the node.
7503
7517
  * @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
7504
- * as NODE.
7518
+ * as BinaryTreeNode<K, V>.
7505
7519
  */
7506
7520
  createNode(key, value) {
7507
7521
  return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
7508
7522
  }
7509
7523
  /**
7524
+ * Time Complexity: O(1)
7525
+ * Space Complexity: O(1)
7526
+ *
7510
7527
  * The function creates a binary tree with the specified options.
7511
7528
  * @param [options] - The `options` parameter in the `createTree` function is an optional parameter
7512
7529
  * that allows you to provide partial configuration options for creating a binary tree. It is of type
@@ -7521,48 +7538,14 @@ var dataStructureTyped = (() => {
7521
7538
  toEntryFn: this._toEntryFn
7522
7539
  }, options));
7523
7540
  }
7524
- /**
7525
- * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
7526
- * or returns null.
7527
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
7528
- * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
7529
- * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
7530
- * node, an entry
7531
- * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
7532
- * an optional parameter of type `V`. It represents the value associated with the key in the node
7533
- * being created. If a `value` is provided, it will be used when creating the node. If
7534
- * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
7535
- * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
7536
- * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
7537
- * value.
7538
- */
7539
- _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
7540
- if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
7541
- if (keyNodeEntryOrRaw === null) return [null, void 0];
7542
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
7543
- if (this.isEntry(keyNodeEntryOrRaw)) {
7544
- const [key, entryValue] = keyNodeEntryOrRaw;
7545
- if (key === void 0) return [void 0, void 0];
7546
- else if (key === null) return [null, void 0];
7547
- const finalValue = value != null ? value : entryValue;
7548
- return [this.createNode(key, finalValue), finalValue];
7549
- }
7550
- if (this.isRaw(keyNodeEntryOrRaw)) {
7551
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
7552
- const finalValue = value != null ? value : entryValue;
7553
- if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
7554
- }
7555
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
7556
- return [void 0, void 0];
7557
- }
7558
7541
  /**
7559
7542
  * Time Complexity: O(n)
7560
7543
  * Space Complexity: O(log n)
7561
7544
  *
7562
7545
  * The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
7563
7546
  * value and returns the corresponding node or null.
7564
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
7565
- * parameter in the `ensureNode` function can be of type `BTNRep<K, V, NODE>` or `R`. It
7547
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
7548
+ * parameter in the `ensureNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
7566
7549
  * is used to determine whether the input is a key, node, entry, or raw data. The
7567
7550
  * @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
7568
7551
  * is used to specify the type of iteration to be performed. It has a default value of
@@ -7570,41 +7553,42 @@ var dataStructureTyped = (() => {
7570
7553
  * @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
7571
7554
  * conditions specified in the code snippet.
7572
7555
  */
7573
- ensureNode(keyNodeEntryOrRaw, iterationType = this.iterationType) {
7574
- if (keyNodeEntryOrRaw === null) return null;
7575
- if (keyNodeEntryOrRaw === void 0) return;
7576
- if (keyNodeEntryOrRaw === this._NIL) return;
7577
- if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
7578
- if (this.isEntry(keyNodeEntryOrRaw)) {
7579
- const key = keyNodeEntryOrRaw[0];
7556
+ ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
7557
+ if (keyNodeOrEntry === null) return null;
7558
+ if (keyNodeOrEntry === void 0) return;
7559
+ if (keyNodeOrEntry === this._NIL) return;
7560
+ if (this.isNode(keyNodeOrEntry)) return keyNodeOrEntry;
7561
+ if (this.isEntry(keyNodeOrEntry)) {
7562
+ const key = keyNodeOrEntry[0];
7580
7563
  if (key === null) return null;
7581
7564
  if (key === void 0) return;
7582
7565
  return this.getNode(key, this._root, iterationType);
7583
7566
  }
7584
- if (this._toEntryFn) {
7585
- const [key] = this._toEntryFn(keyNodeEntryOrRaw);
7586
- if (this.isKey(key)) return this.getNode(key);
7587
- }
7588
- if (this.isKey(keyNodeEntryOrRaw)) return this.getNode(keyNodeEntryOrRaw, this._root, iterationType);
7589
- return;
7567
+ return this.getNode(keyNodeOrEntry, this._root, iterationType);
7590
7568
  }
7591
7569
  /**
7570
+ * Time Complexity: O(1)
7571
+ * Space Complexity: O(1)
7572
+ *
7592
7573
  * The function isNode checks if the input is an instance of BinaryTreeNode.
7593
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
7594
- * `keyNodeEntryOrRaw` can be either a key, a node, an entry, or raw data. The function is
7574
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
7575
+ * `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
7595
7576
  * checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
7596
7577
  * accordingly.
7597
- * @returns The function `isNode` is checking if the input `keyNodeEntryOrRaw` is an instance of
7578
+ * @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
7598
7579
  * `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
7599
7580
  * it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
7600
7581
  * is not a node.
7601
7582
  */
7602
- isNode(keyNodeEntryOrRaw) {
7603
- return keyNodeEntryOrRaw instanceof BinaryTreeNode;
7583
+ isNode(keyNodeOrEntry) {
7584
+ return keyNodeOrEntry instanceof BinaryTreeNode;
7604
7585
  }
7605
7586
  /**
7587
+ * Time Complexity: O(1)
7588
+ * Space Complexity: O(1)
7589
+ *
7606
7590
  * The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
7607
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V, NODE> | R
7591
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
7608
7592
  * @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
7609
7593
  * checking if it is an object. If the parameter is an object, the function will return `true`,
7610
7594
  * indicating that it is of type `R`.
@@ -7613,85 +7597,114 @@ var dataStructureTyped = (() => {
7613
7597
  return this._toEntryFn !== void 0 && typeof keyNodeEntryOrRaw === "object";
7614
7598
  }
7615
7599
  /**
7600
+ * Time Complexity: O(1)
7601
+ * Space Complexity: O(1)
7602
+ *
7616
7603
  * The function `isRealNode` checks if a given input is a valid node in a binary tree.
7617
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
7618
- * parameter in the `isRealNode` function can be of type `BTNRep<K, V, NODE>` or `R`.
7619
- * The function checks if the input parameter is a `NODE` type by verifying if it is not equal
7620
- * @returns The function `isRealNode` is checking if the input `keyNodeEntryOrRaw` is a valid
7604
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
7605
+ * parameter in the `isRealNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
7606
+ * The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
7607
+ * @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
7621
7608
  * node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
7622
7609
  * values, it then calls the `isNode` method to further determine if the input is a node. The
7623
7610
  * function will return a boolean value indicating whether the
7624
7611
  */
7625
- isRealNode(keyNodeEntryOrRaw) {
7626
- if (keyNodeEntryOrRaw === this._NIL || keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === void 0) return false;
7627
- return this.isNode(keyNodeEntryOrRaw);
7612
+ isRealNode(keyNodeOrEntry) {
7613
+ if (keyNodeOrEntry === this._NIL || keyNodeOrEntry === null || keyNodeOrEntry === void 0) return false;
7614
+ return this.isNode(keyNodeOrEntry);
7628
7615
  }
7629
7616
  /**
7617
+ * Time Complexity: O(1)
7618
+ * Space Complexity: O(1)
7619
+ *
7630
7620
  * The function checks if a given input is a valid node or null.
7631
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
7632
- * `keyNodeEntryOrRaw` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
7633
- * V, NODE>` or `R`. It is a union type that can either be a key, a node, an entry, or
7621
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
7622
+ * `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
7623
+ * V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
7634
7624
  * @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
7635
- * `keyNodeEntryOrRaw` is either `null` or a real node, and returns `true` if it is a node or
7625
+ * `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
7636
7626
  * `null`, and `false` otherwise.
7637
7627
  */
7638
- isRealNodeOrNull(keyNodeEntryOrRaw) {
7639
- return keyNodeEntryOrRaw === null || this.isRealNode(keyNodeEntryOrRaw);
7628
+ isRealNodeOrNull(keyNodeOrEntry) {
7629
+ return keyNodeOrEntry === null || this.isRealNode(keyNodeOrEntry);
7640
7630
  }
7641
7631
  /**
7632
+ * Time Complexity: O(1)
7633
+ * Space Complexity: O(1)
7634
+ *
7642
7635
  * The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
7643
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V,
7644
- * NODE> | R
7645
- * @returns The function is checking if the `keyNodeEntryOrRaw` parameter is equal to the `_NIL`
7636
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - BTNRep<K, V,
7637
+ * BinaryTreeNode<K, V>>
7638
+ * @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
7646
7639
  * property of the current object and returning a boolean value based on that comparison.
7647
7640
  */
7648
- isNIL(keyNodeEntryOrRaw) {
7649
- return keyNodeEntryOrRaw === this._NIL;
7641
+ isNIL(keyNodeOrEntry) {
7642
+ return keyNodeOrEntry === this._NIL;
7650
7643
  }
7651
- isRange(keyNodeEntryRawOrPredicate) {
7652
- return keyNodeEntryRawOrPredicate instanceof Range;
7644
+ /**
7645
+ * Time Complexity: O(1)
7646
+ * Space Complexity: O(1)
7647
+ *
7648
+ * The function `isRange` checks if the input parameter is an instance of the `Range` class.
7649
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>}
7650
+ * keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
7651
+ * of type `BTNRep<K, V, BinaryTreeNode<K, V>>`, `NodePredicate<BinaryTreeNode<K, V>>`, or
7652
+ * `Range<K>`. The function checks if the `keyNodeEntry
7653
+ * @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
7654
+ * instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
7655
+ * indicating that the parameter is a `Range<K>`. If it is not an instance of `Range`, the function
7656
+ * will return `false`.
7657
+ */
7658
+ isRange(keyNodeEntryOrPredicate) {
7659
+ return keyNodeEntryOrPredicate instanceof Range;
7653
7660
  }
7654
7661
  /**
7662
+ * Time Complexity: O(1)
7663
+ * Space Complexity: O(1)
7664
+ *
7655
7665
  * The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
7656
7666
  * tree.
7657
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
7658
- * `keyNodeEntryOrRaw` can be of type `BTNRep<K, V, NODE>` or `R`. It represents a
7667
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
7668
+ * `keyNodeOrEntry` can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It represents a
7659
7669
  * key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
7660
7670
  * provided
7661
7671
  * @returns The function `isLeaf` returns a boolean value indicating whether the input
7662
- * `keyNodeEntryOrRaw` is a leaf node in a binary tree.
7672
+ * `keyNodeOrEntry` is a leaf node in a binary tree.
7663
7673
  */
7664
- isLeaf(keyNodeEntryOrRaw) {
7665
- keyNodeEntryOrRaw = this.ensureNode(keyNodeEntryOrRaw);
7666
- if (keyNodeEntryOrRaw === void 0) return false;
7667
- if (keyNodeEntryOrRaw === null) return true;
7668
- return !this.isRealNode(keyNodeEntryOrRaw.left) && !this.isRealNode(keyNodeEntryOrRaw.right);
7674
+ isLeaf(keyNodeOrEntry) {
7675
+ keyNodeOrEntry = this.ensureNode(keyNodeOrEntry);
7676
+ if (keyNodeOrEntry === void 0) return false;
7677
+ if (keyNodeOrEntry === null) return true;
7678
+ return !this.isRealNode(keyNodeOrEntry.left) && !this.isRealNode(keyNodeOrEntry.right);
7669
7679
  }
7670
7680
  /**
7681
+ * Time Complexity: O(1)
7682
+ * Space Complexity: O(1)
7683
+ *
7671
7684
  * The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
7672
7685
  * with a length of 2.
7673
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
7674
- * parameter in the `isEntry` function can be of type `BTNRep<K, V, NODE>` or type `R`.
7675
- * The function checks if the provided `keyNodeEntryOrRaw` is of type `BTN
7676
- * @returns The `isEntry` function is checking if the `keyNodeEntryOrRaw` parameter is an array
7686
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
7687
+ * parameter in the `isEntry` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or type `R`.
7688
+ * The function checks if the provided `keyNodeOrEntry` is of type `BTN
7689
+ * @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
7677
7690
  * with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
7678
7691
  * `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
7679
7692
  */
7680
- isEntry(keyNodeEntryOrRaw) {
7681
- return Array.isArray(keyNodeEntryOrRaw) && keyNodeEntryOrRaw.length === 2;
7693
+ isEntry(keyNodeOrEntry) {
7694
+ return Array.isArray(keyNodeOrEntry) && keyNodeOrEntry.length === 2;
7682
7695
  }
7683
7696
  /**
7684
7697
  * Time Complexity O(1)
7685
7698
  * Space Complexity O(1)
7686
7699
  *
7687
- * The function `isKey` checks if a given key is comparable.
7700
+ * The function `isValidKey` checks if a given key is comparable.
7688
7701
  * @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
7689
7702
  * TypeScript.
7690
- * @returns The function `isKey` is checking if the `key` parameter is `null` or if it is comparable.
7703
+ * @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
7691
7704
  * If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
7692
7705
  * `isComparable` function, which is not provided in the code snippet.
7693
7706
  */
7694
- isKey(key) {
7707
+ isValidKey(key) {
7695
7708
  if (key === null) return true;
7696
7709
  return isComparable(key);
7697
7710
  }
@@ -7701,8 +7714,8 @@ var dataStructureTyped = (() => {
7701
7714
  *
7702
7715
  * The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
7703
7716
  * and finding the correct insertion position.
7704
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `add` method you provided
7705
- * seems to be for adding a new node to a binary tree structure. The `keyNodeEntryOrRaw`
7717
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `add` method you provided
7718
+ * seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
7706
7719
  * parameter in the method can accept different types of values:
7707
7720
  * @param {V} [value] - The `value` parameter in the `add` method represents the value associated
7708
7721
  * with the key that you want to add to the binary tree. When adding a key-value pair to the binary
@@ -7712,8 +7725,8 @@ var dataStructureTyped = (() => {
7712
7725
  * node was successful, and `false` if the insertion position could not be found or if a duplicate
7713
7726
  * key was found and the node was replaced instead of inserted.
7714
7727
  */
7715
- add(keyNodeEntryOrRaw, value) {
7716
- const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
7728
+ add(keyNodeOrEntry, value) {
7729
+ const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
7717
7730
  if (newNode === void 0) return false;
7718
7731
  if (!this._root) {
7719
7732
  this._setRoot(newNode);
@@ -7755,14 +7768,14 @@ var dataStructureTyped = (() => {
7755
7768
  }
7756
7769
  /**
7757
7770
  * Time Complexity: O(k * n)
7758
- * Space Complexity: O(1)
7771
+ * Space Complexity: O(k)
7759
7772
  *
7760
7773
  * The `addMany` function takes in multiple keys or nodes or entries or raw values along with
7761
7774
  * optional values, and adds them to a data structure while returning an array indicating whether
7762
7775
  * each insertion was successful.
7763
7776
  * @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
7764
7777
  * mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
7765
- * `BTNRep<K, V, NODE>` or `R`.
7778
+ * `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
7766
7779
  * @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
7767
7780
  * accepts an iterable of values. These values correspond to the keys or nodes being added in the
7768
7781
  * `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
@@ -7777,7 +7790,7 @@ var dataStructureTyped = (() => {
7777
7790
  if (values) {
7778
7791
  valuesIterator = values[Symbol.iterator]();
7779
7792
  }
7780
- for (const keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
7793
+ for (let keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
7781
7794
  let value = void 0;
7782
7795
  if (valuesIterator) {
7783
7796
  const valueResult = valuesIterator.next();
@@ -7785,6 +7798,7 @@ var dataStructureTyped = (() => {
7785
7798
  value = valueResult.value;
7786
7799
  }
7787
7800
  }
7801
+ if (this.isRaw(keyNodeEntryOrRaw)) keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
7788
7802
  inserted.push(this.add(keyNodeEntryOrRaw, value));
7789
7803
  }
7790
7804
  return inserted;
@@ -7795,7 +7809,7 @@ var dataStructureTyped = (() => {
7795
7809
  *
7796
7810
  * The `merge` function in TypeScript merges another binary tree into the current tree by adding all
7797
7811
  * elements from the other tree.
7798
- * @param anotherTree - `BinaryTree<K, V, R, NODE, TREE>`
7812
+ * @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
7799
7813
  */
7800
7814
  merge(anotherTree) {
7801
7815
  this.addMany(anotherTree, []);
@@ -7807,7 +7821,7 @@ var dataStructureTyped = (() => {
7807
7821
  * The `refill` function clears the existing data structure and then adds new key-value pairs based
7808
7822
  * on the provided input.
7809
7823
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
7810
- * method can accept an iterable containing a mix of `BTNRep<K, V, NODE>` objects or `R`
7824
+ * method can accept an iterable containing a mix of `BTNRep<K, V, BinaryTreeNode<K, V>>` objects or `R`
7811
7825
  * objects.
7812
7826
  * @param [values] - The `values` parameter in the `refill` method is an optional parameter that
7813
7827
  * accepts an iterable of values of type `V` or `undefined`.
@@ -7822,7 +7836,7 @@ var dataStructureTyped = (() => {
7822
7836
  *
7823
7837
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
7824
7838
  * the deleted node along with information for tree balancing.
7825
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw
7839
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
7826
7840
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
7827
7841
  * node, entry or raw data. The method returns an array of
7828
7842
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
@@ -7831,10 +7845,10 @@ var dataStructureTyped = (() => {
7831
7845
  * the array contains information about the node that was deleted (`deleted`) and the node that may
7832
7846
  * need to be balanced (`needBalanced`).
7833
7847
  */
7834
- delete(keyNodeEntryOrRaw) {
7848
+ delete(keyNodeOrEntry) {
7835
7849
  const deletedResult = [];
7836
7850
  if (!this._root) return deletedResult;
7837
- const curr = this.getNode(keyNodeEntryOrRaw);
7851
+ const curr = this.getNode(keyNodeOrEntry);
7838
7852
  if (!curr) return deletedResult;
7839
7853
  const parent = curr == null ? void 0 : curr.parent;
7840
7854
  let needBalanced;
@@ -7876,15 +7890,15 @@ var dataStructureTyped = (() => {
7876
7890
  *
7877
7891
  * The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
7878
7892
  * structure based on a given predicate or key, with options to return multiple results or just one.
7879
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
7880
- * `keyNodeEntryRawOrPredicate` parameter in the `search` function can accept three types of values:
7893
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
7894
+ * `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
7881
7895
  * @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
7882
7896
  * determines whether the search should stop after finding the first matching node. If `onlyOne` is
7883
7897
  * set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
7884
7898
  * @param {C} callback - The `callback` parameter in the `search` function is a callback function
7885
7899
  * that will be called on each node that matches the search criteria. It is of type `C`, which
7886
- * extends `NodeCallback<NODE>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
7887
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `search` function is
7900
+ * extends `NodeCallback<BinaryTreeNode<K, V>>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
7901
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `search` function is
7888
7902
  * used to specify the node from which the search operation should begin. It represents the starting
7889
7903
  * point in the binary tree where the search will be performed. If no specific `startNode` is
7890
7904
  * provided, the search operation will start from the root
@@ -7894,12 +7908,12 @@ var dataStructureTyped = (() => {
7894
7908
  * @returns The `search` function returns an array of values that match the provided criteria based
7895
7909
  * on the search algorithm implemented within the function.
7896
7910
  */
7897
- search(keyNodeEntryRawOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
7898
- if (keyNodeEntryRawOrPredicate === void 0) return [];
7899
- if (keyNodeEntryRawOrPredicate === null) return [];
7911
+ search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
7912
+ if (keyNodeEntryOrPredicate === void 0) return [];
7913
+ if (keyNodeEntryOrPredicate === null) return [];
7900
7914
  startNode = this.ensureNode(startNode);
7901
7915
  if (!startNode) return [];
7902
- const predicate = this._ensurePredicate(keyNodeEntryRawOrPredicate);
7916
+ const predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
7903
7917
  const ans = [];
7904
7918
  if (iterationType === "RECURSIVE") {
7905
7919
  const dfs = (cur) => {
@@ -7934,12 +7948,12 @@ var dataStructureTyped = (() => {
7934
7948
  *
7935
7949
  * The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
7936
7950
  * or predicate, with options for recursive or iterative traversal.
7937
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7951
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
7938
7952
  * - The `getNodes` function you provided takes several parameters:
7939
7953
  * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
7940
7954
  * determines whether to return only the first node that matches the criteria specified by the
7941
- * `keyNodeEntryRawOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
7942
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7955
+ * `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
7956
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
7943
7957
  * `getNodes` function is used to specify the starting point for traversing the binary tree. It
7944
7958
  * represents the root node of the binary tree or the node from which the traversal should begin. If
7945
7959
  * not provided, the default value is set to `this._root
@@ -7949,19 +7963,19 @@ var dataStructureTyped = (() => {
7949
7963
  * @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
7950
7964
  * based on the input parameters and the iteration type specified.
7951
7965
  */
7952
- getNodes(keyNodeEntryRawOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
7953
- return this.search(keyNodeEntryRawOrPredicate, onlyOne, (node) => node, startNode, iterationType);
7966
+ getNodes(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
7967
+ return this.search(keyNodeEntryOrPredicate, onlyOne, (node) => node, startNode, iterationType);
7954
7968
  }
7955
7969
  /**
7956
7970
  * Time Complexity: O(n)
7957
- * Space Complexity: O(log n).
7971
+ * Space Complexity: O(log n)
7958
7972
  *
7959
7973
  * The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
7960
7974
  * predicate.
7961
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7962
- * - The `keyNodeEntryRawOrPredicate` parameter in the `getNode` function can accept a key,
7975
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
7976
+ * - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
7963
7977
  * node, entry, raw data, or a predicate function.
7964
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
7978
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
7965
7979
  * `getNode` function is used to specify the starting point for searching for a node in a binary
7966
7980
  * tree. If no specific starting point is provided, the default value is set to `this._root`, which
7967
7981
  * is typically the root node of the binary tree.
@@ -7972,9 +7986,8 @@ var dataStructureTyped = (() => {
7972
7986
  * @returns The `getNode` function is returning the first node that matches the specified criteria,
7973
7987
  * or `null` if no matching node is found.
7974
7988
  */
7975
- getNode(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7976
- var _a;
7977
- return (_a = this.search(keyNodeEntryRawOrPredicate, true, (node) => node, startNode, iterationType)[0]) != null ? _a : null;
7989
+ getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
7990
+ return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType)[0];
7978
7991
  }
7979
7992
  /**
7980
7993
  * Time Complexity: O(n)
@@ -7982,10 +7995,10 @@ var dataStructureTyped = (() => {
7982
7995
  *
7983
7996
  * This function overrides the `get` method to retrieve the value associated with a specified key,
7984
7997
  * node, entry, raw data, or predicate in a data structure.
7985
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
7986
- * - The `keyNodeEntryRawOrPredicate` parameter in the `get` method can accept one of the
7998
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
7999
+ * - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
7987
8000
  * following types:
7988
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `get`
8001
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
7989
8002
  * method is used to specify the starting point for searching for a key or node in the binary tree.
7990
8003
  * If no specific starting point is provided, the default starting point is the root of the binary
7991
8004
  * tree (`this._root`).
@@ -7998,14 +8011,14 @@ var dataStructureTyped = (() => {
7998
8011
  * the method returns the corresponding value. If the key or node is not found, it returns
7999
8012
  * `undefined`.
8000
8013
  */
8001
- get(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
8014
+ get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
8002
8015
  var _a;
8003
8016
  if (this._isMapMode) {
8004
- const key = this._extractKey(keyNodeEntryRawOrPredicate);
8017
+ const key = this._extractKey(keyNodeEntryOrPredicate);
8005
8018
  if (key === null || key === void 0) return;
8006
8019
  return this._store.get(key);
8007
8020
  }
8008
- return (_a = this.getNode(keyNodeEntryRawOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
8021
+ return (_a = this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)) == null ? void 0 : _a.value;
8009
8022
  }
8010
8023
  /**
8011
8024
  * Time Complexity: O(n)
@@ -8013,10 +8026,10 @@ var dataStructureTyped = (() => {
8013
8026
  *
8014
8027
  * The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
8015
8028
  * exists in the data structure.
8016
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
8017
- * - The `keyNodeEntryRawOrPredicate` parameter in the `override has` method can accept one of
8029
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
8030
+ * - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
8018
8031
  * the following types:
8019
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8032
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8020
8033
  * `override` method is used to specify the starting point for the search operation within the data
8021
8034
  * structure. It defaults to `this._root` if not provided explicitly.
8022
8035
  * @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
@@ -8028,14 +8041,14 @@ var dataStructureTyped = (() => {
8028
8041
  * are matching nodes, it returns `true`, indicating that the tree contains the specified element.
8029
8042
  * Otherwise, it returns `false`.
8030
8043
  */
8031
- has(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
8032
- return this.search(keyNodeEntryRawOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
8044
+ has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
8045
+ return this.search(keyNodeEntryOrPredicate, true, (node) => node, startNode, iterationType).length > 0;
8033
8046
  }
8034
8047
  /**
8035
8048
  * Time Complexity: O(1)
8036
8049
  * Space Complexity: O(1)
8037
8050
  *
8038
- * The `clear` function resets the root node and size of a data structure to empty.
8051
+ * The clear function removes nodes and values in map mode.
8039
8052
  */
8040
8053
  clear() {
8041
8054
  this._clearNodes();
@@ -8059,7 +8072,7 @@ var dataStructureTyped = (() => {
8059
8072
  *
8060
8073
  * The function checks if a binary tree is perfectly balanced by comparing its minimum height with
8061
8074
  * its height.
8062
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
8075
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
8063
8076
  * point for checking if the binary tree is perfectly balanced. It represents the root node of the
8064
8077
  * binary tree or a specific node from which the balance check should begin.
8065
8078
  * @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
@@ -8073,11 +8086,11 @@ var dataStructureTyped = (() => {
8073
8086
  }
8074
8087
  /**
8075
8088
  * Time Complexity: O(n)
8076
- * Space Complexity: O(1)
8089
+ * Space Complexity: O(log n)
8077
8090
  *
8078
8091
  * The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
8079
8092
  * or iterative methods.
8080
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `isBST`
8093
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
8081
8094
  * function represents the starting point for checking whether a binary search tree (BST) is valid.
8082
8095
  * It can be a node in the BST or a reference to the root of the BST. If no specific node is
8083
8096
  * provided, the function will default to
@@ -8126,13 +8139,13 @@ var dataStructureTyped = (() => {
8126
8139
  }
8127
8140
  /**
8128
8141
  * Time Complexity: O(n)
8129
- * Space Complexity: O(1)
8142
+ * Space Complexity: O(log n)
8130
8143
  *
8131
8144
  * The `getDepth` function calculates the depth between two nodes in a binary tree.
8132
- * @param {BTNRep<K, V, NODE> | R} dist - The `dist` parameter in the `getDepth`
8145
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
8133
8146
  * function represents the node or entry in a binary tree map, or a reference to a node in the tree.
8134
8147
  * It is the target node for which you want to calculate the depth from the `startNode` node.
8135
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8148
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8136
8149
  * `getDepth` function represents the starting point from which you want to calculate the depth of a
8137
8150
  * given node or entry in a binary tree. If no specific starting point is provided, the default value
8138
8151
  * for `startNode` is set to the root of the binary
@@ -8155,11 +8168,11 @@ var dataStructureTyped = (() => {
8155
8168
  }
8156
8169
  /**
8157
8170
  * Time Complexity: O(n)
8158
- * Space Complexity: O(1)
8171
+ * Space Complexity: O(log n)
8159
8172
  *
8160
8173
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
8161
8174
  * or iterative approach in TypeScript.
8162
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
8175
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
8163
8176
  * point from which the height of the binary tree will be calculated. It can be a node in the binary
8164
8177
  * tree or a reference to the root of the tree. If not provided, it defaults to the root of the
8165
8178
  * binary tree data structure.
@@ -8199,7 +8212,7 @@ var dataStructureTyped = (() => {
8199
8212
  *
8200
8213
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
8201
8214
  * recursive or iterative approach in TypeScript.
8202
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8215
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8203
8216
  * `getMinHeight` function represents the starting node from which the minimum height of the binary
8204
8217
  * tree will be calculated. It is either a node in the binary tree or a reference to the root of the
8205
8218
  * tree. If not provided, the default value is the root
@@ -8258,7 +8271,7 @@ var dataStructureTyped = (() => {
8258
8271
  * the path to the root. It is expected to be a function that takes a node as an argument and returns
8259
8272
  * a value based on that node. The return type of the callback function is determined by the generic
8260
8273
  * type `C
8261
- * @param {BTNRep<K, V, NODE> | R} beginNode - The `beginNode` parameter in the
8274
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
8262
8275
  * `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
8263
8276
  * @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
8264
8277
  * whether the resulting path from the given `beginNode` to the root should be in reverse order or
@@ -8281,14 +8294,14 @@ var dataStructureTyped = (() => {
8281
8294
  }
8282
8295
  /**
8283
8296
  * Time Complexity: O(log n)
8284
- * Space Complexity: O(1)
8297
+ * Space Complexity: O(log n)
8285
8298
  *
8286
8299
  * The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
8287
8300
  * tail-recursive iteration.
8288
8301
  * @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
8289
8302
  * node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
8290
8303
  * value of `_DEFAULT_NODE_CALLBACK` if not specified.
8291
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8304
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8292
8305
  * `getLeftMost` function represents the starting point for finding the leftmost node in a binary
8293
8306
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
8294
8307
  * starting point is provided, the function will default
@@ -8320,15 +8333,15 @@ var dataStructureTyped = (() => {
8320
8333
  }
8321
8334
  /**
8322
8335
  * Time Complexity: O(log n)
8323
- * Space Complexity: O(1)
8336
+ * Space Complexity: O(log n)
8324
8337
  *
8325
8338
  * The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
8326
8339
  * or iterative traversal methods.
8327
8340
  * @param {C} callback - The `callback` parameter is a function that will be called with the result
8328
- * of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<NODE>>`,
8341
+ * of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
8329
8342
  * which means it is a callback function that can accept either an optional binary tree node or null
8330
8343
  * as
8331
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8344
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8332
8345
  * `getRightMost` function represents the starting point for finding the rightmost node in a binary
8333
8346
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
8334
8347
  * starting point is provided, the function will default
@@ -8360,14 +8373,14 @@ var dataStructureTyped = (() => {
8360
8373
  }
8361
8374
  /**
8362
8375
  * Time Complexity: O(log n)
8363
- * Space Complexity: O(1)
8376
+ * Space Complexity: O(log n)
8364
8377
  *
8365
8378
  * The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
8366
8379
  * binary tree.
8367
- * @param {NODE} node - The `getPredecessor` function you provided seems to be attempting to find the
8380
+ * @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
8368
8381
  * predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
8369
8382
  * while loop condition that might cause an infinite loop.
8370
- * @returns The `getPredecessor` function returns the predecessor node of the input `NODE` parameter.
8383
+ * @returns The `getPredecessor` function returns the predecessor node of the input `BinaryTreeNode<K, V>` parameter.
8371
8384
  * If the left child of the input node exists, it traverses to the rightmost node of the left subtree
8372
8385
  * to find the predecessor. If the left child does not exist, it returns the input node itself.
8373
8386
  */
@@ -8386,12 +8399,12 @@ var dataStructureTyped = (() => {
8386
8399
  }
8387
8400
  /**
8388
8401
  * Time Complexity: O(log n)
8389
- * Space Complexity: O(1)
8402
+ * Space Complexity: O(log n)
8390
8403
  *
8391
8404
  * The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
8392
8405
  * binary tree.
8393
- * @param {K | NODE | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
8394
- * type `K`, `NODE`, or `null`.
8406
+ * @param {K | BinaryTreeNode<K, V> | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
8407
+ * type `K`, `BinaryTreeNode<K, V>`, or `null`.
8395
8408
  * @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
8396
8409
  * a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
8397
8410
  * have a right child, the function traverses up the parent nodes until it finds a node that is not
@@ -8417,12 +8430,12 @@ var dataStructureTyped = (() => {
8417
8430
  * The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
8418
8431
  * specified parameters.
8419
8432
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends the
8420
- * `NodeCallback` interface with a type parameter of `OptNodeOrNull<NODE>`. It has a default value of
8433
+ * `NodeCallback` interface with a type parameter of `OptNodeOrNull<BinaryTreeNode<K, V>>`. It has a default value of
8421
8434
  * `this._DEFAULT_NODE_CALLBACK as C`.
8422
8435
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
8423
8436
  * order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
8424
8437
  * possible values for the `pattern` parameter are:
8425
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `dfs`
8438
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `dfs`
8426
8439
  * method is used to specify the starting point for the Depth-First Search traversal. It can be
8427
8440
  * either a `BTNRep` object representing a key, node, or entry in the binary tree map,
8428
8441
  * or it can be a
@@ -8449,8 +8462,8 @@ var dataStructureTyped = (() => {
8449
8462
  * tree, executing a specified callback function on each node visited.
8450
8463
  * @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
8451
8464
  * called on each node visited during the breadth-first search traversal. It is a generic type `C`
8452
- * that extends the `NodeCallback` type, which takes a parameter of type `NODE` or `null`.
8453
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `bfs`
8465
+ * that extends the `NodeCallback` type, which takes a parameter of type `BinaryTreeNode<K, V>` or `null`.
8466
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `bfs`
8454
8467
  * function represents the starting point for the breadth-first search traversal in a binary tree. It
8455
8468
  * can be specified as a key, node, or entry in the binary tree structure. If not provided, the
8456
8469
  * default value is the root node of the binary
@@ -8469,7 +8482,9 @@ var dataStructureTyped = (() => {
8469
8482
  if (!startNode) return [];
8470
8483
  const ans = [];
8471
8484
  if (iterationType === "RECURSIVE") {
8472
- const queue = new Queue([startNode]);
8485
+ const queue = new Queue([
8486
+ startNode
8487
+ ]);
8473
8488
  const dfs = (level) => {
8474
8489
  if (queue.size === 0) return;
8475
8490
  const current = queue.shift();
@@ -8511,7 +8526,7 @@ var dataStructureTyped = (() => {
8511
8526
  * structure based on a specified callback and iteration type.
8512
8527
  * @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
8513
8528
  * in the binary tree. It is optional and defaults to a default callback function if not provided.
8514
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `leaves`
8529
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
8515
8530
  * method is used to specify the starting point for finding and processing the leaves of a binary
8516
8531
  * tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
8517
8532
  * explicitly provided, the default value
@@ -8559,7 +8574,7 @@ var dataStructureTyped = (() => {
8559
8574
  * @param {C} callback - The `callback` parameter is a function that will be applied to each node in
8560
8575
  * the binary tree during the traversal. It is used to process each node and determine what
8561
8576
  * information to include in the output for each level of the tree.
8562
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8577
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8563
8578
  * `listLevels` function represents the starting point for traversing the binary tree. It can be
8564
8579
  * either a key, a node, or an entry in the binary tree. If not provided, the default value is the
8565
8580
  * root of the binary tree.
@@ -8617,11 +8632,11 @@ var dataStructureTyped = (() => {
8617
8632
  * Morris Traversal algorithm with different order patterns.
8618
8633
  * @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
8619
8634
  * called on each node in the binary tree during the traversal. It is of type `C`, which extends the
8620
- * `NodeCallback<NODE>` type. The default value for `callback` is `this._DEFAULT
8635
+ * `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
8621
8636
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
8622
8637
  * the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
8623
8638
  * values for the `pattern` parameter are:
8624
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `morris`
8639
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
8625
8640
  * function is the starting point for the Morris traversal algorithm. It represents the root node of
8626
8641
  * the binary tree or the node from which the traversal should begin. It can be provided as either a
8627
8642
  * key, a node, an entry, or a reference
@@ -8722,6 +8737,10 @@ var dataStructureTyped = (() => {
8722
8737
  */
8723
8738
  clone() {
8724
8739
  const cloned = this.createTree();
8740
+ this._clone(cloned);
8741
+ return cloned;
8742
+ }
8743
+ _clone(cloned) {
8725
8744
  this.bfs(
8726
8745
  (node) => {
8727
8746
  if (node === null) cloned.add(null);
@@ -8735,7 +8754,6 @@ var dataStructureTyped = (() => {
8735
8754
  true
8736
8755
  );
8737
8756
  if (this._isMapMode) cloned._store = this._store;
8738
- return cloned;
8739
8757
  }
8740
8758
  /**
8741
8759
  * Time Complexity: O(n)
@@ -8796,7 +8814,7 @@ var dataStructureTyped = (() => {
8796
8814
  *
8797
8815
  * The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
8798
8816
  * customizable options for displaying undefined, null, and sentinel nodes.
8799
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8817
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8800
8818
  * `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
8801
8819
  * It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
8802
8820
  * the default is set to the root
@@ -8820,7 +8838,7 @@ var dataStructureTyped = (() => {
8820
8838
  if (opts.isShowRedBlackNIL) output += `S for Sentinel Node(NIL)
8821
8839
  `;
8822
8840
  const display = (root) => {
8823
- const [lines, ,] = this._displayAux(root, opts);
8841
+ const [lines] = this._displayAux(root, opts);
8824
8842
  let paragraph = "";
8825
8843
  for (const line of lines) {
8826
8844
  paragraph += line + "\n";
@@ -8840,7 +8858,7 @@ var dataStructureTyped = (() => {
8840
8858
  * printing options for the binary tree. It is an optional parameter that allows you to customize how
8841
8859
  * the binary tree is printed, such as choosing between different traversal orders or formatting
8842
8860
  * options.
8843
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
8861
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8844
8862
  * `override print` method is used to specify the starting point for printing the binary tree. It can
8845
8863
  * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
8846
8864
  * provided, the default value is set to
@@ -8848,6 +8866,37 @@ var dataStructureTyped = (() => {
8848
8866
  print(options, startNode = this._root) {
8849
8867
  console.log(this.toVisual(startNode, options));
8850
8868
  }
8869
+ /**
8870
+ * Time Complexity: O(1)
8871
+ * Space Complexity: O(1)
8872
+ *
8873
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
8874
+ * or returns null.
8875
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The
8876
+ * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
8877
+ * can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. This parameter represents either a key, a
8878
+ * node, an entry
8879
+ * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
8880
+ * an optional parameter of type `V`. It represents the value associated with the key in the node
8881
+ * being created. If a `value` is provided, it will be used when creating the node. If
8882
+ * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
8883
+ * (`OptNodeOrNull<BinaryTreeNode<K, V>>`) based on the input parameters provided. The function checks the type of the
8884
+ * input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
8885
+ * value.
8886
+ */
8887
+ _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
8888
+ if (keyNodeOrEntry === void 0) return [void 0, void 0];
8889
+ if (keyNodeOrEntry === null) return [null, void 0];
8890
+ if (this.isNode(keyNodeOrEntry)) return [keyNodeOrEntry, value];
8891
+ if (this.isEntry(keyNodeOrEntry)) {
8892
+ const [key, entryValue] = keyNodeOrEntry;
8893
+ if (key === void 0) return [void 0, void 0];
8894
+ else if (key === null) return [null, void 0];
8895
+ const finalValue = value != null ? value : entryValue;
8896
+ return [this.createNode(key, finalValue), finalValue];
8897
+ }
8898
+ return [this.createNode(keyNodeOrEntry, value), value];
8899
+ }
8851
8900
  /**
8852
8901
  * Time complexity: O(n)
8853
8902
  * Space complexity: O(n)
@@ -8856,11 +8905,11 @@ var dataStructureTyped = (() => {
8856
8905
  * the specified order pattern and callback function.
8857
8906
  * @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
8858
8907
  * called on each node visited during the depth-first search traversal. It is of type `C`, which
8859
- * extends `NodeCallback<OptNodeOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
8908
+ * extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
8860
8909
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
8861
8910
  * order in which the nodes are visited during the Depth-First Search traversal. It can have one of
8862
8911
  * the following values:
8863
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `_dfs`
8912
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
8864
8913
  * method is used to specify the starting point for the depth-first search traversal in a binary
8865
8914
  * tree. It can be provided as either a `BTNRep` object or a reference to the root node
8866
8915
  * of the tree. If no specific
@@ -9070,12 +9119,12 @@ var dataStructureTyped = (() => {
9070
9119
  * Space Complexity: O(1)
9071
9120
  *
9072
9121
  * The _swapProperties function swaps key and value properties between two nodes in a binary tree.
9073
- * @param {BTNRep<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
9122
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
9074
9123
  * `_swapProperties` method can be either a BTNRep object containing key and value
9075
9124
  * properties, or it can be of type R.
9076
- * @param {BTNRep<K, V, NODE> | R} destNode - The `destNode` parameter in the
9125
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
9077
9126
  * `_swapProperties` method represents the node or entry where the properties will be swapped with
9078
- * the `srcNode`. It can be of type `BTNRep<K, V, NODE>` or `R`. The method ensures that
9127
+ * the `srcNode`. It can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. The method ensures that
9079
9128
  * both `srcNode
9080
9129
  * @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
9081
9130
  * with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
@@ -9101,9 +9150,9 @@ var dataStructureTyped = (() => {
9101
9150
  * Space Complexity: O(1)
9102
9151
  *
9103
9152
  * The _replaceNode function replaces an old node with a new node in a binary tree structure.
9104
- * @param {NODE} oldNode - The `oldNode` parameter represents the node that you want to replace in a
9153
+ * @param {BinaryTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that you want to replace in a
9105
9154
  * tree data structure.
9106
- * @param {NODE} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
9155
+ * @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
9107
9156
  * that will replace the `oldNode` in a tree data structure. This function is responsible for
9108
9157
  * updating the parent, left child, right child, and root (if necessary) references when replacing a
9109
9158
  * node in the tree.
@@ -9132,8 +9181,8 @@ var dataStructureTyped = (() => {
9132
9181
  *
9133
9182
  * The function _setRoot sets the root node of a data structure while updating the parent reference
9134
9183
  * of the previous root node.
9135
- * @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<NODE>`, which means
9136
- * it can either be an optional `NODE` type or `null`.
9184
+ * @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<BinaryTreeNode<K, V>>`, which means
9185
+ * it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
9137
9186
  */
9138
9187
  _setRoot(v) {
9139
9188
  if (v) {
@@ -9147,27 +9196,23 @@ var dataStructureTyped = (() => {
9147
9196
  *
9148
9197
  * The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
9149
9198
  * predicate function for a binary tree node.
9150
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
9199
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
9151
9200
  * `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
9152
- * parameter `keyNodeEntryRawOrPredicate` is transformed into a valid predicate function that can be
9201
+ * parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
9153
9202
  * used for filtering nodes in a binary tree.
9154
- * @returns A NodePredicate<NODE> function is being returned.
9203
+ * @returns A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
9155
9204
  */
9156
- _ensurePredicate(keyNodeEntryRawOrPredicate) {
9157
- if (keyNodeEntryRawOrPredicate === null || keyNodeEntryRawOrPredicate === void 0)
9205
+ _ensurePredicate(keyNodeEntryOrPredicate) {
9206
+ if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0)
9158
9207
  return (node) => node ? false : false;
9159
- if (this._isPredicate(keyNodeEntryRawOrPredicate)) return keyNodeEntryRawOrPredicate;
9160
- if (this.isRealNode(keyNodeEntryRawOrPredicate)) return (node) => node === keyNodeEntryRawOrPredicate;
9161
- if (this.isEntry(keyNodeEntryRawOrPredicate)) {
9162
- const [key] = keyNodeEntryRawOrPredicate;
9163
- return (node) => node.key === key;
9164
- }
9165
- if (this.isKey(keyNodeEntryRawOrPredicate)) return (node) => node.key === keyNodeEntryRawOrPredicate;
9166
- if (this._toEntryFn) {
9167
- const [key] = this._toEntryFn(keyNodeEntryRawOrPredicate);
9208
+ if (this._isPredicate(keyNodeEntryOrPredicate)) return keyNodeEntryOrPredicate;
9209
+ if (this.isRealNode(keyNodeEntryOrPredicate))
9210
+ return (node) => node === keyNodeEntryOrPredicate;
9211
+ if (this.isEntry(keyNodeEntryOrPredicate)) {
9212
+ const [key] = keyNodeEntryOrPredicate;
9168
9213
  return (node) => node.key === key;
9169
9214
  }
9170
- return (node) => node.key === keyNodeEntryRawOrPredicate;
9215
+ return (node) => node.key === keyNodeEntryOrPredicate;
9171
9216
  }
9172
9217
  /**
9173
9218
  * Time Complexity: O(1)
@@ -9176,7 +9221,7 @@ var dataStructureTyped = (() => {
9176
9221
  * The function `_isPredicate` checks if a given parameter is a function.
9177
9222
  * @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
9178
9223
  * of value. In this context, the function `_isPredicate` is checking if `p` is a function that
9179
- * satisfies the type `NodePredicate<NODE>`.
9224
+ * satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
9180
9225
  * @returns The function is checking if the input `p` is a function and returning a boolean value
9181
9226
  * based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
9182
9227
  * predicate function for a binary tree node. If `p` is not a function, it will return `false`.
@@ -9190,27 +9235,20 @@ var dataStructureTyped = (() => {
9190
9235
  *
9191
9236
  * The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
9192
9237
  * entry, raw data, or null/undefined.
9193
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `_extractKey` method you provided is a
9194
- * TypeScript method that takes in a parameter `keyNodeEntryOrRaw` of type `BTNRep<K, V, NODE> | R`,
9195
- * where `BTNRep` is a generic type with keys `K`, `V`, and `NODE`, and `
9196
- * @returns The `_extractKey` method returns the key value extracted from the `keyNodeEntryOrRaw`
9238
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `_extractKey` method you provided is a
9239
+ * TypeScript method that takes in a parameter `keyNodeOrEntry` of type `BTNRep<K, V, BinaryTreeNode<K, V>>`,
9240
+ * where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
9241
+ * @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
9197
9242
  * parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
9198
9243
  * the conditions checked in the method.
9199
9244
  */
9200
- _extractKey(keyNodeEntryOrRaw) {
9201
- if (keyNodeEntryOrRaw === null) return null;
9202
- if (keyNodeEntryOrRaw === void 0) return;
9203
- if (keyNodeEntryOrRaw === this._NIL) return;
9204
- if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw.key;
9205
- if (this.isEntry(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw[0];
9206
- if (this.isRaw(keyNodeEntryOrRaw)) {
9207
- if (this._toEntryFn) {
9208
- const [key] = this._toEntryFn(keyNodeEntryOrRaw);
9209
- return key;
9210
- }
9211
- return;
9212
- }
9213
- return keyNodeEntryOrRaw;
9245
+ _extractKey(keyNodeOrEntry) {
9246
+ if (keyNodeOrEntry === null) return null;
9247
+ if (keyNodeOrEntry === void 0) return;
9248
+ if (keyNodeOrEntry === this._NIL) return;
9249
+ if (this.isNode(keyNodeOrEntry)) return keyNodeOrEntry.key;
9250
+ if (this.isEntry(keyNodeOrEntry)) return keyNodeOrEntry[0];
9251
+ return keyNodeOrEntry;
9214
9252
  }
9215
9253
  /**
9216
9254
  * Time Complexity: O(1)
@@ -9254,46 +9292,33 @@ var dataStructureTyped = (() => {
9254
9292
 
9255
9293
  // src/data-structures/binary-tree/bst.ts
9256
9294
  var BSTNode = class extends BinaryTreeNode {
9295
+ /**
9296
+ * This TypeScript constructor function initializes an instance with a key and an optional value.
9297
+ * @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
9298
+ * within a data structure. It serves as a reference or identifier for accessing or manipulating the
9299
+ * associated value.
9300
+ * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
9301
+ * have to be provided when creating an instance of the class. If a value is not provided, it will
9302
+ * default to `undefined`.
9303
+ */
9257
9304
  constructor(key, value) {
9258
9305
  super(key, value);
9259
9306
  __publicField(this, "parent");
9260
9307
  __publicField(this, "_left");
9261
9308
  __publicField(this, "_right");
9262
- this.parent = void 0;
9263
- this._left = void 0;
9264
- this._right = void 0;
9265
9309
  }
9266
- /**
9267
- * The function returns the value of the `_left` property.
9268
- * @returns The `_left` property of the current object is being returned.
9269
- */
9270
9310
  get left() {
9271
9311
  return this._left;
9272
9312
  }
9273
- /**
9274
- * The function sets the left child of a node and updates the parent reference of the child.
9275
- * @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be an
9276
- * instance of the `NODE` class or `undefined`.
9277
- */
9278
9313
  set left(v) {
9279
9314
  if (v) {
9280
9315
  v.parent = this;
9281
9316
  }
9282
9317
  this._left = v;
9283
9318
  }
9284
- /**
9285
- * The function returns the right node of a binary tree or undefined if there is no right node.
9286
- * @returns The method is returning the value of the `_right` property, which is of type `NODE` or
9287
- * `undefined`.
9288
- */
9289
9319
  get right() {
9290
9320
  return this._right;
9291
9321
  }
9292
- /**
9293
- * The function sets the right child of a node and updates the parent reference of the child.
9294
- * @param {OptNode<NODE>} v - The parameter `v` is of type `OptNode<NODE>`. It can either be a
9295
- * `NODE` object or `undefined`.
9296
- */
9297
9322
  set right(v) {
9298
9323
  if (v) {
9299
9324
  v.parent = this;
@@ -9303,12 +9328,13 @@ var dataStructureTyped = (() => {
9303
9328
  };
9304
9329
  var BST = class _BST extends BinaryTree {
9305
9330
  /**
9306
- * This is the constructor function for a Binary Search Tree class in TypeScript.
9307
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
9308
- * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
9309
- * added to the binary search tree during the construction of the object.
9310
- * @param [options] - An optional object that contains additional options for the Binary Search Tree.
9311
- * It can include a comparator function that defines the order of the elements in the tree.
9331
+ * This TypeScript constructor initializes a binary search tree with optional options and adds
9332
+ * elements if provided.
9333
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
9334
+ * iterable that can contain elements of type `BTNRep<K, V, BSTNode<K, V>>` or `R`. It is used to
9335
+ * initialize the binary search tree with keys, nodes, entries, or raw data.
9336
+ * @param [options] - The `options` parameter is an optional object that can contain the following
9337
+ * properties:
9312
9338
  */
9313
9339
  constructor(keysNodesEntriesOrRaws = [], options) {
9314
9340
  super([], options);
@@ -9340,33 +9366,36 @@ var dataStructureTyped = (() => {
9340
9366
  }
9341
9367
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
9342
9368
  }
9343
- /**
9344
- * The function returns the root node of a tree structure.
9345
- * @returns The `_root` property of the object, which is of type `NODE` or `undefined`.
9346
- */
9347
9369
  get root() {
9348
9370
  return this._root;
9349
9371
  }
9350
- /**
9351
- * The above function is a getter method in TypeScript that returns the value of the private property
9352
- * `_isReverse`.
9353
- * @returns The `isReverse` property of the object, which is a boolean value.
9354
- */
9355
9372
  get isReverse() {
9356
9373
  return this._isReverse;
9357
9374
  }
9375
+ get comparator() {
9376
+ return this._comparator;
9377
+ }
9378
+ get specifyComparable() {
9379
+ return this._specifyComparable;
9380
+ }
9358
9381
  /**
9382
+ * Time Complexity: O(1)
9383
+ * Space Complexity: O(1)
9384
+ *
9359
9385
  * The function creates a new BSTNode with the given key and value and returns it.
9360
9386
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
9361
9387
  * being created.
9362
9388
  * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
9363
9389
  * value associated with the key in the node being created.
9364
- * @returns The method is returning a new instance of the BSTNode class, casted as the NODE type.
9390
+ * @returns The method is returning a new instance of the BSTNode class, casted as the BSTNode<K, V> type.
9365
9391
  */
9366
9392
  createNode(key, value) {
9367
9393
  return new BSTNode(key, this._isMapMode ? void 0 : value);
9368
9394
  }
9369
9395
  /**
9396
+ * Time Complexity: O(1)
9397
+ * Space Complexity: O(1)
9398
+ *
9370
9399
  * The function creates a new binary search tree with the specified options.
9371
9400
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
9372
9401
  * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
@@ -9382,28 +9411,14 @@ var dataStructureTyped = (() => {
9382
9411
  isReverse: this._isReverse
9383
9412
  }, options));
9384
9413
  }
9385
- /**
9386
- * The function overrides a method and converts a key, value pair or entry or raw element to a node.
9387
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
9388
- * type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
9389
- * element.
9390
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
9391
- * value associated with a key in a key-value pair.
9392
- * @returns either a NODE object or undefined.
9393
- */
9394
- _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
9395
- const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
9396
- if (node === null) return [void 0, void 0];
9397
- return [node, value != null ? value : entryValue];
9398
- }
9399
9414
  /**
9400
9415
  * Time Complexity: O(log n)
9401
9416
  * Space Complexity: O(log n)
9402
9417
  *
9403
9418
  * The function ensures the existence of a node in a data structure and returns it, or undefined if
9404
9419
  * it doesn't exist.
9405
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
9406
- * `keyNodeEntryOrRaw` can accept a value of type `R`, which represents the key, node,
9420
+ * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
9421
+ * `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
9407
9422
  * entry, or raw element that needs to be ensured in the tree.
9408
9423
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
9409
9424
  * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
@@ -9411,44 +9426,50 @@ var dataStructureTyped = (() => {
9411
9426
  * @returns The method is returning either the node that was ensured or `undefined` if the node could
9412
9427
  * not be ensured.
9413
9428
  */
9414
- ensureNode(keyNodeEntryOrRaw, iterationType = this.iterationType) {
9429
+ ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
9415
9430
  var _a;
9416
- return (_a = super.ensureNode(keyNodeEntryOrRaw, iterationType)) != null ? _a : void 0;
9431
+ return (_a = super.ensureNode(keyNodeOrEntry, iterationType)) != null ? _a : void 0;
9417
9432
  }
9418
9433
  /**
9434
+ * Time Complexity: O(1)
9435
+ * Space Complexity: O(1)
9436
+ *
9419
9437
  * The function checks if the input is an instance of the BSTNode class.
9420
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
9421
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
9422
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
9438
+ * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
9439
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
9440
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
9423
9441
  * an instance of the `BSTNode` class.
9424
9442
  */
9425
- isNode(keyNodeEntryOrRaw) {
9426
- return keyNodeEntryOrRaw instanceof BSTNode;
9443
+ isNode(keyNodeOrEntry) {
9444
+ return keyNodeOrEntry instanceof BSTNode;
9427
9445
  }
9428
9446
  /**
9429
- * The function "override isKey" checks if a key is comparable based on a given comparator.
9447
+ * Time Complexity: O(1)
9448
+ * Space Complexity: O(1)
9449
+ *
9450
+ * The function "override isValidKey" checks if a key is comparable based on a given comparator.
9430
9451
  * @param {any} key - The `key` parameter is a value that will be checked to determine if it is of
9431
9452
  * type `K`.
9432
- * @returns The `override isKey(key: any): key is K` function is returning a boolean value based on
9453
+ * @returns The `override isValidKey(key: any): key is K` function is returning a boolean value based on
9433
9454
  * the result of the `isComparable` function with the condition `this._compare !==
9434
9455
  * this._DEFAULT_COMPARATOR`.
9435
9456
  */
9436
- isKey(key) {
9457
+ isValidKey(key) {
9437
9458
  return isComparable(key, this._specifyComparable !== void 0);
9438
9459
  }
9439
9460
  /**
9440
9461
  * Time Complexity: O(log n)
9441
- * Space Complexity: O(1)
9462
+ * Space Complexity: O(log n)
9442
9463
  *
9443
9464
  * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
9444
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
9445
- * `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
9465
+ * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
9466
+ * `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
9446
9467
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
9447
9468
  * key in the binary search tree. If provided, it will be stored in the node along with the key.
9448
9469
  * @returns a boolean value.
9449
9470
  */
9450
- add(keyNodeEntryOrRaw, value) {
9451
- const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
9471
+ add(keyNodeOrEntry, value) {
9472
+ const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
9452
9473
  if (newNode === void 0) return false;
9453
9474
  if (this._root === void 0) {
9454
9475
  this._setRoot(newNode);
@@ -9510,8 +9531,9 @@ var dataStructureTyped = (() => {
9510
9531
  valuesIterator = values[Symbol.iterator]();
9511
9532
  }
9512
9533
  if (!isBalanceAdd) {
9513
- for (const kve of keysNodesEntriesOrRaws) {
9534
+ for (let kve of keysNodesEntriesOrRaws) {
9514
9535
  const value = valuesIterator == null ? void 0 : valuesIterator.next().value;
9536
+ if (this.isRaw(kve)) kve = this._toEntryFn(kve);
9515
9537
  inserted.push(this.add(kve, value));
9516
9538
  }
9517
9539
  return inserted;
@@ -9525,18 +9547,16 @@ var dataStructureTyped = (() => {
9525
9547
  let sorted = [];
9526
9548
  sorted = realBTNExemplars.sort(({ key: a }, { key: b }) => {
9527
9549
  let keyA, keyB;
9528
- if (this.isEntry(a)) keyA = a[0];
9550
+ if (this.isRaw(a)) keyA = this._toEntryFn(a)[0];
9551
+ else if (this.isEntry(a)) keyA = a[0];
9529
9552
  else if (this.isRealNode(a)) keyA = a.key;
9530
- else if (this._toEntryFn) {
9531
- keyA = this._toEntryFn(a)[0];
9532
- } else {
9553
+ else {
9533
9554
  keyA = a;
9534
9555
  }
9535
- if (this.isEntry(b)) keyB = b[0];
9556
+ if (this.isRaw(b)) keyB = this._toEntryFn(b)[0];
9557
+ else if (this.isEntry(b)) keyB = b[0];
9536
9558
  else if (this.isRealNode(b)) keyB = b.key;
9537
- else if (this._toEntryFn) {
9538
- keyB = this._toEntryFn(b)[0];
9539
- } else {
9559
+ else {
9540
9560
  keyB = b;
9541
9561
  }
9542
9562
  if (keyA !== void 0 && keyA !== null && keyB !== void 0 && keyB !== null) {
@@ -9545,14 +9565,22 @@ var dataStructureTyped = (() => {
9545
9565
  return 0;
9546
9566
  });
9547
9567
  const _dfs = (arr) => {
9568
+ var _a;
9548
9569
  if (arr.length === 0) return;
9549
9570
  const mid = Math.floor((arr.length - 1) / 2);
9550
- const { key, value, orgIndex } = arr[mid];
9571
+ let { key, value } = arr[mid];
9572
+ const { orgIndex } = arr[mid];
9573
+ if (this.isRaw(key)) {
9574
+ const entry = this._toEntryFn(key);
9575
+ key = entry[0];
9576
+ value = (_a = entry[1]) != null ? _a : value;
9577
+ }
9551
9578
  inserted[orgIndex] = this.add(key, value);
9552
9579
  _dfs(arr.slice(0, mid));
9553
9580
  _dfs(arr.slice(mid + 1));
9554
9581
  };
9555
9582
  const _iterate = () => {
9583
+ var _a;
9556
9584
  const n = sorted.length;
9557
9585
  const stack = [[0, n - 1]];
9558
9586
  while (stack.length > 0) {
@@ -9561,7 +9589,13 @@ var dataStructureTyped = (() => {
9561
9589
  const [l, r] = popped;
9562
9590
  if (l <= r) {
9563
9591
  const m = l + Math.floor((r - l) / 2);
9564
- const { key, value, orgIndex } = sorted[m];
9592
+ let { key, value } = sorted[m];
9593
+ const { orgIndex } = sorted[m];
9594
+ if (this.isRaw(key)) {
9595
+ const entry = this._toEntryFn(key);
9596
+ key = entry[0];
9597
+ value = (_a = entry[1]) != null ? _a : value;
9598
+ }
9565
9599
  inserted[orgIndex] = this.add(key, value);
9566
9600
  stack.push([m + 1, r]);
9567
9601
  stack.push([l, m - 1]);
@@ -9582,17 +9616,17 @@ var dataStructureTyped = (() => {
9582
9616
  *
9583
9617
  * The function `search` in TypeScript overrides the search behavior in a binary tree structure based
9584
9618
  * on specified criteria.
9585
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
9586
- * `keyNodeEntryRawOrPredicate` parameter in the `override search` method can accept one of the
9619
+ * @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
9620
+ * `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
9587
9621
  * following types:
9588
9622
  * @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
9589
9623
  * search should stop after finding the first matching node. If `onlyOne` is set to `true`, the
9590
9624
  * search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
9591
9625
  * @param {C} callback - The `callback` parameter in the `override search` function is a function
9592
9626
  * that will be called on each node that matches the search criteria. It is of type `C`, which
9593
- * extends `NodeCallback<NODE>`. The callback function should accept a node of type `NODE` as its
9627
+ * extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
9594
9628
  * argument and
9595
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `override search`
9629
+ * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
9596
9630
  * method represents the node from which the search operation will begin. It is the starting point
9597
9631
  * for searching within the tree data structure. The method ensures that the `startNode` is a valid
9598
9632
  * node before proceeding with the search operation. If the `
@@ -9604,21 +9638,21 @@ var dataStructureTyped = (() => {
9604
9638
  * structure based on the provided key, predicate, and other options. The search results are
9605
9639
  * collected in an array and returned as the output of the method.
9606
9640
  */
9607
- search(keyNodeEntryRawOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
9608
- if (keyNodeEntryRawOrPredicate === void 0) return [];
9609
- if (keyNodeEntryRawOrPredicate === null) return [];
9641
+ search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
9642
+ if (keyNodeEntryOrPredicate === void 0) return [];
9643
+ if (keyNodeEntryOrPredicate === null) return [];
9610
9644
  startNode = this.ensureNode(startNode);
9611
9645
  if (!startNode) return [];
9612
9646
  let predicate;
9613
- const isRange = this.isRange(keyNodeEntryRawOrPredicate);
9647
+ const isRange = this.isRange(keyNodeEntryOrPredicate);
9614
9648
  if (isRange) {
9615
- predicate = (node) => keyNodeEntryRawOrPredicate.isInRange(node.key, this._comparator);
9649
+ predicate = (node) => keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
9616
9650
  } else {
9617
- predicate = this._ensurePredicate(keyNodeEntryRawOrPredicate);
9651
+ predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
9618
9652
  }
9619
9653
  const isToLeftByRange = (cur) => {
9620
9654
  if (isRange) {
9621
- const range = keyNodeEntryRawOrPredicate;
9655
+ const range = keyNodeEntryOrPredicate;
9622
9656
  const leftS = this.isReverse ? range.high : range.low;
9623
9657
  const leftI = this.isReverse ? range.includeHigh : range.includeLow;
9624
9658
  return leftI && this._compare(cur.key, leftS) >= 0 || !leftI && this._compare(cur.key, leftS) > 0;
@@ -9627,7 +9661,7 @@ var dataStructureTyped = (() => {
9627
9661
  };
9628
9662
  const isToRightByRange = (cur) => {
9629
9663
  if (isRange) {
9630
- const range = keyNodeEntryRawOrPredicate;
9664
+ const range = keyNodeEntryOrPredicate;
9631
9665
  const rightS = this.isReverse ? range.low : range.high;
9632
9666
  const rightI = this.isReverse ? range.includeLow : range.includeLow;
9633
9667
  return rightI && this._compare(cur.key, rightS) <= 0 || !rightI && this._compare(cur.key, rightS) < 0;
@@ -9645,8 +9679,8 @@ var dataStructureTyped = (() => {
9645
9679
  if (isRange) {
9646
9680
  if (this.isRealNode(cur.left) && isToLeftByRange(cur)) dfs(cur.left);
9647
9681
  if (this.isRealNode(cur.right) && isToRightByRange(cur)) dfs(cur.right);
9648
- } else if (!this._isPredicate(keyNodeEntryRawOrPredicate)) {
9649
- const benchmarkKey = this._extractKey(keyNodeEntryRawOrPredicate);
9682
+ } else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
9683
+ const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
9650
9684
  if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
9651
9685
  dfs(cur.left);
9652
9686
  if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
@@ -9668,8 +9702,8 @@ var dataStructureTyped = (() => {
9668
9702
  if (isRange) {
9669
9703
  if (this.isRealNode(cur.left) && isToLeftByRange(cur)) stack.push(cur.left);
9670
9704
  if (this.isRealNode(cur.right) && isToRightByRange(cur)) stack.push(cur.right);
9671
- } else if (!this._isPredicate(keyNodeEntryRawOrPredicate)) {
9672
- const benchmarkKey = this._extractKey(keyNodeEntryRawOrPredicate);
9705
+ } else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
9706
+ const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
9673
9707
  if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
9674
9708
  stack.push(cur.right);
9675
9709
  if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
@@ -9684,16 +9718,16 @@ var dataStructureTyped = (() => {
9684
9718
  }
9685
9719
  /**
9686
9720
  * Time Complexity: O(log n)
9687
- * Space Complexity: O(n)
9721
+ * Space Complexity: O(k + log n)
9688
9722
  *
9689
9723
  * The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
9690
9724
  * @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
9691
9725
  * either a `Range` object or an array of two elements representing the range boundaries.
9692
9726
  * @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
9693
9727
  * function that is used to process each node that is found within the specified range during the
9694
- * search operation. It is of type `NodeCallback<NODE>`, where `NODE` is the type of nodes in the
9728
+ * search operation. It is of type `NodeCallback<BSTNode<K, V>>`, where `BSTNode<K, V>` is the type of nodes in the
9695
9729
  * data structure.
9696
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `rangeSearch`
9730
+ * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
9697
9731
  * function represents the node from which the search for nodes within the specified range will
9698
9732
  * begin. It is the starting point for the range search operation.
9699
9733
  * @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
@@ -9709,12 +9743,12 @@ var dataStructureTyped = (() => {
9709
9743
  }
9710
9744
  /**
9711
9745
  * Time Complexity: O(log n)
9712
- * Space Complexity: O(1)
9746
+ * Space Complexity: O(log n)
9713
9747
  *
9714
- * This function retrieves a node based on a given keyNodeEntryRawOrPredicate within a binary search tree structure.
9715
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The `keyNodeEntryRawOrPredicate`
9716
- * parameter can be of type `BTNRep<K, V, NODE>`, `R`, or `NodePredicate<NODE>`.
9717
- * @param {R | BSTNOptKeyOrNode<K, NODE>} startNode - The `startNode` parameter in the `getNode` method
9748
+ * This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
9749
+ * @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
9750
+ * parameter can be of type `BTNRep<K, V, BSTNode<K, V>>`, `R`, or `NodePredicate<BSTNode<K, V>>`.
9751
+ * @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
9718
9752
  * is used to specify the starting point for searching nodes in the binary search tree. If no
9719
9753
  * specific starting point is provided, the default value is set to `this._root`, which is the root
9720
9754
  * node of the binary search tree.
@@ -9722,14 +9756,14 @@ var dataStructureTyped = (() => {
9722
9756
  * parameter that specifies the type of iteration to be used. It has a default value of
9723
9757
  * `this.iterationType`, which means it will use the iteration type defined in the class instance if
9724
9758
  * no value is provided when calling the method.
9725
- * @returns The `getNode` method is returning an optional binary search tree node (`OptNode<NODE>`).
9726
- * It is using the `getNodes` method to find the node based on the provided keyNodeEntryRawOrPredicate, beginning at
9759
+ * @returns The `getNode` method is returning an optional binary search tree node (`OptNode<BSTNode<K, V>>`).
9760
+ * It is using the `getNodes` method to find the node based on the provided keyNodeEntryOrPredicate, beginning at
9727
9761
  * the specified root node (`startNode`) and using the specified iteration type. The method then
9728
9762
  * returns the first node found or `undefined` if no node is found.
9729
9763
  */
9730
- getNode(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
9764
+ getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
9731
9765
  var _a;
9732
- return (_a = this.getNodes(keyNodeEntryRawOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
9766
+ return (_a = this.getNodes(keyNodeEntryOrPredicate, true, startNode, iterationType)[0]) != null ? _a : void 0;
9733
9767
  }
9734
9768
  /**
9735
9769
  * Time complexity: O(n)
@@ -9743,7 +9777,7 @@ var dataStructureTyped = (() => {
9743
9777
  * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
9744
9778
  * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
9745
9779
  * take one of the following values:
9746
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
9780
+ * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
9747
9781
  * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
9748
9782
  * node entry. If not specified, the default value is the root of the tree.
9749
9783
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
@@ -9763,7 +9797,7 @@ var dataStructureTyped = (() => {
9763
9797
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9764
9798
  * visited during the breadth-first search. It should take a single argument, which is the current
9765
9799
  * node being visited, and it can return a value of any type.
9766
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
9800
+ * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
9767
9801
  * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
9768
9802
  * object. If no value is provided, the default value is the root of the tree.
9769
9803
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -9781,9 +9815,9 @@ var dataStructureTyped = (() => {
9781
9815
  * The function overrides the listLevels method from the superclass and returns an array of arrays
9782
9816
  * containing the results of the callback function applied to each level of the tree.
9783
9817
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
9784
- * `NodeCallback<NODE>`. It represents a callback function that will be called for each node in the
9818
+ * `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
9785
9819
  * tree during the iteration process.
9786
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
9820
+ * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
9787
9821
  * point for listing the levels of the binary tree. It can be either a root node of the tree, a
9788
9822
  * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
9789
9823
  * value is provided, the root of
@@ -9807,7 +9841,7 @@ var dataStructureTyped = (() => {
9807
9841
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
9808
9842
  * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
9809
9843
  * 0, or 1, where:
9810
- * @param {BTNRep<K, V, NODE> | R} targetNode - The `targetNode` parameter is the node in
9844
+ * @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
9811
9845
  * the binary tree that you want to start traversing from. It can be specified either by providing
9812
9846
  * the key of the node, the node itself, or an entry containing the key and value of the node. If no
9813
9847
  * `targetNode` is provided,
@@ -9942,24 +9976,69 @@ var dataStructureTyped = (() => {
9942
9976
  return balanced;
9943
9977
  }
9944
9978
  /**
9945
- * The function returns the value of the _comparator property.
9946
- * @returns The `_comparator` property is being returned.
9979
+ * Time complexity: O(n)
9980
+ * Space complexity: O(n)
9981
+ *
9982
+ * The `map` function in TypeScript overrides the default map behavior for a binary search tree by
9983
+ * applying a callback function to each entry and creating a new tree with the results.
9984
+ * @param callback - A function that will be called for each entry in the BST. It takes four
9985
+ * arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
9986
+ * the BST itself.
9987
+ * @param [options] - The `options` parameter in the `override map` method is of type `BSTOptions<MK,
9988
+ * MV, MR>`. It is an optional parameter that allows you to specify additional options for the Binary
9989
+ * Search Tree (BST) being created in the `map` method. These options could include configuration
9990
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` method is used to specify
9991
+ * the value of `this` that should be used when executing the `callback` function. It allows you to
9992
+ * set the context or scope in which the callback function will be called. This can be useful when
9993
+ * you want
9994
+ * @returns The `map` method is returning a new Binary Search Tree (`BST`) instance with the entries
9995
+ * transformed by the provided callback function.
9947
9996
  */
9948
- get comparator() {
9949
- return this._comparator;
9997
+ map(callback, options, thisArg) {
9998
+ const newTree = new _BST([], options);
9999
+ let index = 0;
10000
+ for (const [key, value] of this) {
10001
+ newTree.add(callback.call(thisArg, key, value, index++, this));
10002
+ }
10003
+ return newTree;
9950
10004
  }
9951
10005
  /**
9952
- * This function returns the value of the `_specifyComparable` property.
9953
- * @returns The method `specifyComparable()` is being returned, which is a getter method for the
9954
- * `_specifyComparable` property.
10006
+ * Time complexity: O(n)
10007
+ * Space complexity: O(n)
10008
+ *
10009
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
10010
+ * structure.
10011
+ * @returns The `cloned` object is being returned.
9955
10012
  */
9956
- get specifyComparable() {
9957
- return this._specifyComparable;
10013
+ clone() {
10014
+ const cloned = this.createTree();
10015
+ this._clone(cloned);
10016
+ return cloned;
10017
+ }
10018
+ /**
10019
+ * Time Complexity: O(1)
10020
+ * Space Complexity: O(1)
10021
+ *
10022
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
10023
+ * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - A variable that can be of
10024
+ * type R or BTNRep<K, V, BSTNode<K, V>>. It represents either a key, a node, an entry, or a raw
10025
+ * element.
10026
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
10027
+ * value associated with a key in a key-value pair.
10028
+ * @returns either a BSTNode<K, V> object or undefined.
10029
+ */
10030
+ _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
10031
+ const [node, entryValue] = super._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
10032
+ if (node === null) return [void 0, void 0];
10033
+ return [node, value != null ? value : entryValue];
9958
10034
  }
9959
10035
  /**
10036
+ * Time Complexity: O(1)
10037
+ * Space Complexity: O(1)
10038
+ *
9960
10039
  * The function sets the root of a tree-like structure and updates the parent property of the new
9961
10040
  * root.
9962
- * @param {OptNode<NODE>} v - v is a parameter of type NODE or undefined.
10041
+ * @param {OptNode<BSTNode<K, V>>} v - v is a parameter of type BSTNode<K, V> or undefined.
9963
10042
  */
9964
10043
  _setRoot(v) {
9965
10044
  if (v) {
@@ -9967,17 +10046,23 @@ var dataStructureTyped = (() => {
9967
10046
  }
9968
10047
  this._root = v;
9969
10048
  }
10049
+ /**
10050
+ * Time Complexity: O(1)
10051
+ * Space Complexity: O(1)
10052
+ *
10053
+ * The _compare function compares two values using a specified comparator function and optionally
10054
+ * reverses the result.
10055
+ * @param {K} a - The parameter `a` is of type `K`, which is used as an input for comparison in the
10056
+ * `_compare` method.
10057
+ * @param {K} b - The parameter `b` in the `_compare` function is of type `K`.
10058
+ * @returns The `_compare` method is returning the result of the ternary expression. If `_isReverse`
10059
+ * is true, it returns the negation of the result of calling the `_comparator` function with
10060
+ * arguments `a` and `b`. If `_isReverse` is false, it returns the result of calling the
10061
+ * `_comparator` function with arguments `a` and `b`.
10062
+ */
9970
10063
  _compare(a, b) {
9971
10064
  return this._isReverse ? -this._comparator(a, b) : this._comparator(a, b);
9972
10065
  }
9973
- map(callback, options, thisArg) {
9974
- const newTree = new _BST([], options);
9975
- let index = 0;
9976
- for (const [key, value] of this) {
9977
- newTree.add(callback.call(thisArg, key, value, index++, this));
9978
- }
9979
- return newTree;
9980
- }
9981
10066
  };
9982
10067
 
9983
10068
  // src/data-structures/binary-tree/binary-indexed-tree.ts
@@ -10546,46 +10631,74 @@ var dataStructureTyped = (() => {
10546
10631
  // src/data-structures/binary-tree/avl-tree.ts
10547
10632
  var AVLTreeNode = class extends BSTNode {
10548
10633
  /**
10549
- * The constructor function initializes a new instance of a class with a key and an optional value,
10550
- * and sets the height property to 0.
10551
- * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
10552
- * constructor. It is used to initialize the key property of the object being created.
10553
- * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
10554
- * value associated with the key in the constructor.
10634
+ * This TypeScript constructor function initializes an instance with a key and an optional value.
10635
+ * @param {K} key - The `key` parameter is typically used to uniquely identify an object or element
10636
+ * within a data structure. It serves as a reference or identifier for accessing or manipulating the
10637
+ * associated value or data.
10638
+ * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
10639
+ * have to be provided when creating an instance of the class. If a value is not provided, it will
10640
+ * default to `undefined`.
10555
10641
  */
10556
10642
  constructor(key, value) {
10557
10643
  super(key, value);
10644
+ __publicField(this, "parent");
10645
+ __publicField(this, "_left");
10646
+ __publicField(this, "_right");
10647
+ }
10648
+ get left() {
10649
+ return this._left;
10650
+ }
10651
+ set left(v) {
10652
+ if (v) {
10653
+ v.parent = this;
10654
+ }
10655
+ this._left = v;
10656
+ }
10657
+ get right() {
10658
+ return this._right;
10659
+ }
10660
+ set right(v) {
10661
+ if (v) {
10662
+ v.parent = this;
10663
+ }
10664
+ this._right = v;
10558
10665
  }
10559
10666
  };
10560
10667
  var AVLTree = class _AVLTree extends BST {
10561
10668
  /**
10562
- * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
10563
- * entries, or raw elements.
10564
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
10565
- * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
10566
- * be used to initialize the AVLTree.
10567
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
10568
- * behavior of the AVLTree. It can include properties such as `compareFn` (a function used to compare
10569
- * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
10570
- * `nodeBuilder` (
10669
+ * This TypeScript constructor initializes an AVLTree with keys, nodes, entries, or raw data provided
10670
+ * in an iterable format.
10671
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
10672
+ * iterable that can contain either `BTNRep<K, V, AVLTreeNode<K, V>>` objects or `R` objects. It is
10673
+ * used to initialize the AVLTree with key-value pairs or raw data entries. If provided
10674
+ * @param [options] - The `options` parameter in the constructor is of type `AVLTreeOptions<K, V,
10675
+ * R>`. It is an optional parameter that allows you to specify additional options for configuring the
10676
+ * AVL tree. These options could include things like custom comparators, initial capacity, or any
10677
+ * other configuration settings specific
10571
10678
  */
10572
10679
  constructor(keysNodesEntriesOrRaws = [], options) {
10573
10680
  super([], options);
10574
10681
  if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
10575
10682
  }
10576
10683
  /**
10684
+ * Time Complexity: O(1)
10685
+ * Space Complexity: O(1)
10686
+ *
10577
10687
  * The function creates a new AVL tree node with the given key and value.
10578
10688
  * @param {K} key - The key parameter is of type K, which represents the key of the node being
10579
10689
  * created.
10580
10690
  * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
10581
10691
  * value associated with the key in the node being created.
10582
10692
  * @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
10583
- * type NODE.
10693
+ * type AVLTreeNode<K, V>.
10584
10694
  */
10585
10695
  createNode(key, value) {
10586
10696
  return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
10587
10697
  }
10588
10698
  /**
10699
+ * Time Complexity: O(1)
10700
+ * Space Complexity: O(1)
10701
+ *
10589
10702
  * The function creates a new AVL tree with the specified options and returns it.
10590
10703
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
10591
10704
  * passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
@@ -10602,49 +10715,51 @@ var dataStructureTyped = (() => {
10602
10715
  }, options));
10603
10716
  }
10604
10717
  /**
10718
+ * Time Complexity: O(1)
10719
+ * Space Complexity: O(1)
10720
+ *
10605
10721
  * The function checks if the input is an instance of AVLTreeNode.
10606
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10607
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
10608
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
10722
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
10723
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeNode<K, V>>`.
10724
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
10609
10725
  * an instance of the `AVLTreeNode` class.
10610
10726
  */
10611
- isNode(keyNodeEntryOrRaw) {
10612
- return keyNodeEntryOrRaw instanceof AVLTreeNode;
10727
+ isNode(keyNodeOrEntry) {
10728
+ return keyNodeOrEntry instanceof AVLTreeNode;
10613
10729
  }
10614
10730
  /**
10615
10731
  * Time Complexity: O(log n)
10616
- * Space Complexity: O(1)
10732
+ * Space Complexity: O(log n)
10617
10733
  *
10618
10734
  * The function overrides the add method of a class and inserts a key-value pair into a data
10619
10735
  * structure, then balances the path.
10620
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
10621
- * `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
10622
- * `RawElement`.
10736
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
10737
+ * `keyNodeOrEntry` can accept values of type `R`, `BTNRep<K, V, AVLTreeNode<K, V>>`
10623
10738
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
10624
10739
  * the key or node being added to the data structure.
10625
10740
  * @returns The method is returning a boolean value.
10626
10741
  */
10627
- add(keyNodeEntryOrRaw, value) {
10628
- if (keyNodeEntryOrRaw === null) return false;
10629
- const inserted = super.add(keyNodeEntryOrRaw, value);
10630
- if (inserted) this._balancePath(keyNodeEntryOrRaw);
10742
+ add(keyNodeOrEntry, value) {
10743
+ if (keyNodeOrEntry === null) return false;
10744
+ const inserted = super.add(keyNodeOrEntry, value);
10745
+ if (inserted) this._balancePath(keyNodeOrEntry);
10631
10746
  return inserted;
10632
10747
  }
10633
10748
  /**
10634
10749
  * Time Complexity: O(log n)
10635
- * Space Complexity: O(1)
10750
+ * Space Complexity: O(log n)
10636
10751
  *
10637
10752
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
10638
10753
  * balances the tree if necessary.
10639
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
10754
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
10640
10755
  * parameter in the `override delete` method can be one of the following types:
10641
10756
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
10642
10757
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
10643
10758
  * be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
10644
10759
  * `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
10645
10760
  */
10646
- delete(keyNodeEntryOrRaw) {
10647
- const deletedResults = super.delete(keyNodeEntryOrRaw);
10761
+ delete(keyNodeOrEntry) {
10762
+ const deletedResults = super.delete(keyNodeOrEntry);
10648
10763
  for (const { needBalanced } of deletedResults) {
10649
10764
  if (needBalanced) {
10650
10765
  this._balancePath(needBalanced);
@@ -10652,6 +10767,26 @@ var dataStructureTyped = (() => {
10652
10767
  }
10653
10768
  return deletedResults;
10654
10769
  }
10770
+ /**
10771
+ * Time Complexity: O(n)
10772
+ * Space Complexity: O(n)
10773
+ *
10774
+ * The `map` function in TypeScript overrides the default map behavior of an AVLTree data structure
10775
+ * by applying a callback function to each entry and creating a new AVLTree with the results.
10776
+ * @param callback - A function that will be called for each entry in the AVLTree. It takes four
10777
+ * arguments: the key, the value (which can be undefined), the index of the entry, and a reference to
10778
+ * the AVLTree itself.
10779
+ * @param [options] - The `options` parameter in the `override map` function is of type
10780
+ * `AVLTreeOptions<MK, MV, MR>`. It is an optional parameter that allows you to specify additional
10781
+ * options for the AVL tree being created during the mapping process. These options could include
10782
+ * custom comparators, initial
10783
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
10784
+ * the value of `this` when executing the `callback` function. It allows you to set the context
10785
+ * (value of `this`) within the callback function. This can be useful when you want to access
10786
+ * properties or
10787
+ * @returns The `map` method is returning a new AVLTree instance (`newTree`) with the entries
10788
+ * modified by the provided callback function.
10789
+ */
10655
10790
  map(callback, options, thisArg) {
10656
10791
  const newTree = new _AVLTree([], options);
10657
10792
  let index = 0;
@@ -10661,15 +10796,28 @@ var dataStructureTyped = (() => {
10661
10796
  return newTree;
10662
10797
  }
10663
10798
  /**
10664
- * Time Complexity: O(1)
10665
- * Space Complexity: O(1)
10799
+ * Time Complexity: O(n)
10800
+ * Space Complexity: O(n)
10801
+ *
10802
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
10803
+ * structure.
10804
+ * @returns A cloned tree object is being returned.
10805
+ */
10806
+ clone() {
10807
+ const cloned = this.createTree();
10808
+ this._clone(cloned);
10809
+ return cloned;
10810
+ }
10811
+ /**
10812
+ * Time Complexity: O(1)
10813
+ * Space Complexity: O(1)
10666
10814
  *
10667
10815
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
10668
10816
  * binary search tree.
10669
- * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
10670
- * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
10671
- * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
10672
- * `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
10817
+ * @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} srcNode - The `srcNode` parameter represents either a node
10818
+ * object (`AVLTreeNode<K, V>`) or a key-value pair (`R`) that is being swapped with another node.
10819
+ * @param {BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>} destNode - The `destNode` parameter is either an instance of
10820
+ * `R` or an instance of `BSTNOptKeyOrNode<K, AVLTreeNode<K, V>>`.
10673
10821
  * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
10674
10822
  * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
10675
10823
  */
@@ -10697,7 +10845,7 @@ var dataStructureTyped = (() => {
10697
10845
  * Space Complexity: O(1)
10698
10846
  *
10699
10847
  * The function calculates the balance factor of a node in a binary tree.
10700
- * @param {NODE} node - The parameter "node" is of type "NODE", which likely represents a node in a
10848
+ * @param {AVLTreeNode<K, V>} node - The parameter "node" is of type "AVLTreeNode<K, V>", which likely represents a node in a
10701
10849
  * binary tree data structure.
10702
10850
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
10703
10851
  * height of the left subtree from the height of the right subtree.
@@ -10715,7 +10863,7 @@ var dataStructureTyped = (() => {
10715
10863
  *
10716
10864
  * The function updates the height of a node in a binary tree based on the heights of its left and
10717
10865
  * right children.
10718
- * @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
10866
+ * @param {AVLTreeNode<K, V>} node - The parameter "node" represents a node in a binary tree data structure.
10719
10867
  */
10720
10868
  _updateHeight(node) {
10721
10869
  if (!node.left && !node.right) node.height = 0;
@@ -10730,7 +10878,7 @@ var dataStructureTyped = (() => {
10730
10878
  * Space Complexity: O(1)
10731
10879
  *
10732
10880
  * The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
10733
- * @param {NODE} A - A is a node in a binary tree.
10881
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
10734
10882
  */
10735
10883
  _balanceLL(A) {
10736
10884
  const parentOfA = A.parent;
@@ -10761,7 +10909,7 @@ var dataStructureTyped = (() => {
10761
10909
  * Space Complexity: O(1)
10762
10910
  *
10763
10911
  * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
10764
- * @param {NODE} A - A is a node in a binary tree.
10912
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
10765
10913
  */
10766
10914
  _balanceLR(A) {
10767
10915
  const parentOfA = A.parent;
@@ -10807,7 +10955,7 @@ var dataStructureTyped = (() => {
10807
10955
  * Space Complexity: O(1)
10808
10956
  *
10809
10957
  * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
10810
- * @param {NODE} A - A is a node in a binary tree.
10958
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
10811
10959
  */
10812
10960
  _balanceRR(A) {
10813
10961
  const parentOfA = A.parent;
@@ -10842,7 +10990,7 @@ var dataStructureTyped = (() => {
10842
10990
  * Space Complexity: O(1)
10843
10991
  *
10844
10992
  * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
10845
- * @param {NODE} A - A is a node in a binary tree.
10993
+ * @param {AVLTreeNode<K, V>} A - A is a node in a binary tree.
10846
10994
  */
10847
10995
  _balanceRL(A) {
10848
10996
  const parentOfA = A.parent;
@@ -10887,8 +11035,8 @@ var dataStructureTyped = (() => {
10887
11035
  *
10888
11036
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
10889
11037
  * to restore balance in an AVL tree after inserting a node.
10890
- * @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
10891
- * `BTNRep<K, V, NODE>`.
11038
+ * @param {BTNRep<K, V, AVLTreeNode<K, V>>} node - The `node` parameter can be of type `R` or
11039
+ * `BTNRep<K, V, AVLTreeNode<K, V>>`.
10892
11040
  */
10893
11041
  _balancePath(node) {
10894
11042
  node = this.ensureNode(node);
@@ -10925,9 +11073,9 @@ var dataStructureTyped = (() => {
10925
11073
  *
10926
11074
  * The function replaces an old node with a new node and sets the height of the new node to be the
10927
11075
  * same as the old node.
10928
- * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
11076
+ * @param {AVLTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
10929
11077
  * the data structure.
10930
- * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
11078
+ * @param {AVLTreeNode<K, V>} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
10931
11079
  * the data structure.
10932
11080
  * @returns The method is returning the result of calling the `_replaceNode` method from the
10933
11081
  * superclass, with the `oldNode` and `newNode` as arguments.
@@ -10941,31 +11089,52 @@ var dataStructureTyped = (() => {
10941
11089
  // src/data-structures/binary-tree/red-black-tree.ts
10942
11090
  var RedBlackTreeNode = class extends BSTNode {
10943
11091
  /**
10944
- * The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
10945
- * color.
10946
- * @param {K} key - The key parameter is of type K and represents the key of the node in the
10947
- * Red-Black Tree.
10948
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
10949
- * associated with the key in the Red-Black Tree Node. It is not required and can be omitted when
10950
- * creating a new instance of the Red-Black Tree Node.
10951
- * @param {RBTNColor} color - The `color` parameter is used to specify the color of the Red-Black
10952
- * Tree Node. It is an optional parameter with a default value of `'BLACK'`.
11092
+ * The constructor initializes a node with a key, value, and color for a Red-Black Tree.
11093
+ * @param {K} key - The `key` parameter is a key of type `K` that is used to identify the node in a
11094
+ * Red-Black Tree data structure.
11095
+ * @param {V} [value] - The `value` parameter in the constructor is an optional parameter of type
11096
+ * `V`. It represents the value associated with the key in the data structure being constructed.
11097
+ * @param {RBTNColor} [color=BLACK] - The `color` parameter in the constructor is used to specify the
11098
+ * color of the node in a Red-Black Tree. It has a default value of 'BLACK' if not provided
11099
+ * explicitly.
10953
11100
  */
10954
11101
  constructor(key, value, color = "BLACK") {
10955
11102
  super(key, value);
11103
+ __publicField(this, "parent");
11104
+ __publicField(this, "_left");
11105
+ __publicField(this, "_right");
10956
11106
  this._color = color;
10957
11107
  }
11108
+ get left() {
11109
+ return this._left;
11110
+ }
11111
+ set left(v) {
11112
+ if (v) {
11113
+ v.parent = this;
11114
+ }
11115
+ this._left = v;
11116
+ }
11117
+ get right() {
11118
+ return this._right;
11119
+ }
11120
+ set right(v) {
11121
+ if (v) {
11122
+ v.parent = this;
11123
+ }
11124
+ this._right = v;
11125
+ }
10958
11126
  };
10959
11127
  var RedBlackTree = class _RedBlackTree extends BST {
10960
11128
  /**
10961
- * This is the constructor function for a Red-Black Tree data structure in TypeScript.
10962
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
10963
- * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
10964
- * initialize the RBTree with the provided elements.
10965
- * @param [options] - The `options` parameter is an optional object that can be passed to the
10966
- * constructor. It is of type `RedBlackTreeOptions<K, V, R>`. This object can contain various options for
10967
- * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
10968
- * depend on the implementation
11129
+ * This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
11130
+ * raw data.
11131
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
11132
+ * iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
11133
+ * is used to initialize the Red-Black Tree with keys, nodes, entries, or
11134
+ * @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
11135
+ * V, R>`. It is an optional parameter that allows you to specify additional options for the
11136
+ * RedBlackTree class. These options could include configuration settings, behavior customization, or
11137
+ * any other parameters that are specific to
10969
11138
  */
10970
11139
  constructor(keysNodesEntriesOrRaws = [], options) {
10971
11140
  super([], options);
@@ -10975,14 +11144,13 @@ var dataStructureTyped = (() => {
10975
11144
  this.addMany(keysNodesEntriesOrRaws);
10976
11145
  }
10977
11146
  }
10978
- /**
10979
- * The function returns the root node of a tree or undefined if there is no root.
10980
- * @returns The root node of the tree structure, or undefined if there is no root node.
10981
- */
10982
11147
  get root() {
10983
11148
  return this._root;
10984
11149
  }
10985
11150
  /**
11151
+ * Time Complexity: O(1)
11152
+ * Space Complexity: O(1)
11153
+ *
10986
11154
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
10987
11155
  * @param {K} key - The key parameter represents the key value of the node being created. It is of
10988
11156
  * type K, which is a generic type that can be replaced with any specific type when using the
@@ -11000,6 +11168,9 @@ var dataStructureTyped = (() => {
11000
11168
  return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
11001
11169
  }
11002
11170
  /**
11171
+ * Time Complexity: O(1)
11172
+ * Space Complexity: O(1)
11173
+ *
11003
11174
  * The function creates a new Red-Black Tree with the specified options.
11004
11175
  * @param [options] - The `options` parameter is an optional object that contains additional
11005
11176
  * configuration options for creating the Red-Black Tree. It has the following properties:
@@ -11018,13 +11189,13 @@ var dataStructureTyped = (() => {
11018
11189
  * Space Complexity: O(1)
11019
11190
  *
11020
11191
  * The function checks if the input is an instance of the RedBlackTreeNode class.
11021
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11022
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11023
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
11192
+ * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
11193
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
11194
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
11024
11195
  * an instance of the `RedBlackTreeNode` class.
11025
11196
  */
11026
- isNode(keyNodeEntryOrRaw) {
11027
- return keyNodeEntryOrRaw instanceof RedBlackTreeNode;
11197
+ isNode(keyNodeOrEntry) {
11198
+ return keyNodeOrEntry instanceof RedBlackTreeNode;
11028
11199
  }
11029
11200
  /**
11030
11201
  * Time Complexity: O(1)
@@ -11039,12 +11210,12 @@ var dataStructureTyped = (() => {
11039
11210
  }
11040
11211
  /**
11041
11212
  * Time Complexity: O(log n)
11042
- * Space Complexity: O(1)
11213
+ * Space Complexity: O(log n)
11043
11214
  *
11044
11215
  * The function adds a new node to a binary search tree and returns true if the node was successfully
11045
11216
  * added.
11046
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11047
- * `keyNodeEntryOrRaw` can accept a value of type `R` or `BTNRep<K, V, NODE>`.
11217
+ * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
11218
+ * `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
11048
11219
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
11049
11220
  * the key in the data structure. It represents the value that you want to add or update in the data
11050
11221
  * structure.
@@ -11052,8 +11223,8 @@ var dataStructureTyped = (() => {
11052
11223
  * the method returns true. If the node already exists and its value is updated, the method also
11053
11224
  * returns true. If the node cannot be added or updated, the method returns false.
11054
11225
  */
11055
- add(keyNodeEntryOrRaw, value) {
11056
- const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
11226
+ add(keyNodeOrEntry, value) {
11227
+ const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
11057
11228
  if (!this.isRealNode(newNode)) return false;
11058
11229
  const insertStatus = this._insert(newNode);
11059
11230
  if (insertStatus === "CREATED") {
@@ -11074,24 +11245,24 @@ var dataStructureTyped = (() => {
11074
11245
  }
11075
11246
  /**
11076
11247
  * Time Complexity: O(log n)
11077
- * Space Complexity: O(1)
11248
+ * Space Complexity: O(log n)
11078
11249
  *
11079
11250
  * The function overrides the delete method in a binary tree data structure to remove a node based on
11080
11251
  * a given predicate and maintain the binary search tree properties.
11081
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
11252
+ * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
11082
11253
  * parameter in the `override delete` method is used to specify the condition or key based on which a
11083
11254
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
11084
11255
  * function that determines which node(s) should be deleted.
11085
- * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<NODE>`
11256
+ * @returns The `override delete` method is returning an array of `BinaryTreeDeleteResult<RedBlackTreeNode<K, V>>`
11086
11257
  * objects. Each object in the array contains information about the deleted node and whether
11087
11258
  * balancing is needed.
11088
11259
  */
11089
- delete(keyNodeEntryOrRaw) {
11090
- if (keyNodeEntryOrRaw === null) return [];
11260
+ delete(keyNodeOrEntry) {
11261
+ if (keyNodeOrEntry === null) return [];
11091
11262
  const results = [];
11092
11263
  let nodeToDelete;
11093
- if (this._isPredicate(keyNodeEntryOrRaw)) nodeToDelete = this.getNode(keyNodeEntryOrRaw);
11094
- else nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
11264
+ if (this._isPredicate(keyNodeOrEntry)) nodeToDelete = this.getNode(keyNodeOrEntry);
11265
+ else nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
11095
11266
  if (!nodeToDelete) {
11096
11267
  return results;
11097
11268
  }
@@ -11139,13 +11310,54 @@ var dataStructureTyped = (() => {
11139
11310
  results.push({ deleted: nodeToDelete, needBalanced: void 0 });
11140
11311
  return results;
11141
11312
  }
11313
+ /**
11314
+ * Time Complexity: O(n)
11315
+ * Space Complexity: O(n)
11316
+ *
11317
+ * The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
11318
+ * applying a callback to each entry in the original tree.
11319
+ * @param callback - A function that will be called for each entry in the tree, with parameters
11320
+ * representing the key, value, index, and the tree itself. It should return an entry for the new
11321
+ * tree.
11322
+ * @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
11323
+ * MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
11324
+ * Tree that will be created during the mapping process. These options could include things like
11325
+ * custom comparators
11326
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11327
+ * the value of `this` when executing the `callback` function. It allows you to set the context
11328
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
11329
+ * or
11330
+ * @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
11331
+ * provided callback function.
11332
+ */
11333
+ map(callback, options, thisArg) {
11334
+ const newTree = new _RedBlackTree([], options);
11335
+ let index = 0;
11336
+ for (const [key, value] of this) {
11337
+ newTree.add(callback.call(thisArg, key, value, index++, this));
11338
+ }
11339
+ return newTree;
11340
+ }
11341
+ /**
11342
+ * Time Complexity: O(n)
11343
+ * Space Complexity: O(n)
11344
+ *
11345
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
11346
+ * structure.
11347
+ * @returns The `cloned` object is being returned.
11348
+ */
11349
+ clone() {
11350
+ const cloned = this.createTree();
11351
+ this._clone(cloned);
11352
+ return cloned;
11353
+ }
11142
11354
  /**
11143
11355
  * Time Complexity: O(1)
11144
11356
  * Space Complexity: O(1)
11145
11357
  *
11146
11358
  * The function sets the root of a tree-like structure and updates the parent property of the new
11147
11359
  * root.
11148
- * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
11360
+ * @param {RedBlackTreeNode<K, V> | undefined} v - v is a parameter of type RedBlackTreeNode<K, V> or undefined.
11149
11361
  */
11150
11362
  _setRoot(v) {
11151
11363
  if (v) {
@@ -11158,9 +11370,9 @@ var dataStructureTyped = (() => {
11158
11370
  * Space Complexity: O(1)
11159
11371
  *
11160
11372
  * The function replaces an old node with a new node while preserving the color of the old node.
11161
- * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
11373
+ * @param {RedBlackTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
11162
11374
  * the data structure.
11163
- * @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
11375
+ * @param {RedBlackTreeNode<K, V>} newNode - The `newNode` parameter is of type `RedBlackTreeNode<K, V>`, which represents a node in a
11164
11376
  * data structure.
11165
11377
  * @returns The method is returning the result of calling the `_replaceNode` method from the
11166
11378
  * superclass, with the `oldNode` and `newNode` parameters.
@@ -11171,11 +11383,11 @@ var dataStructureTyped = (() => {
11171
11383
  }
11172
11384
  /**
11173
11385
  * Time Complexity: O(log n)
11174
- * Space Complexity: O(1)
11386
+ * Space Complexity: O(log n)
11175
11387
  *
11176
11388
  * The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
11177
11389
  * maintain the red-black tree properties.
11178
- * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
11390
+ * @param {RedBlackTreeNode<K, V>} node - The `node` parameter represents the node that needs to be inserted into the
11179
11391
  * binary search tree.
11180
11392
  * @returns a string value indicating the result of the insertion operation. It can return either
11181
11393
  * 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
@@ -11216,9 +11428,9 @@ var dataStructureTyped = (() => {
11216
11428
  * Space Complexity: O(1)
11217
11429
  *
11218
11430
  * The function `_transplant` is used to replace a node `u` with another node `v` in a binary tree.
11219
- * @param {NODE} u - The parameter "u" represents a node in a binary tree.
11220
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`, which means it can
11221
- * either be a `NODE` object or `undefined`.
11431
+ * @param {RedBlackTreeNode<K, V>} u - The parameter "u" represents a node in a binary tree.
11432
+ * @param {RedBlackTreeNode<K, V> | undefined} v - The parameter `v` is of type `RedBlackTreeNode<K, V> | undefined`, which means it can
11433
+ * either be a `RedBlackTreeNode<K, V>` object or `undefined`.
11222
11434
  */
11223
11435
  _transplant(u, v) {
11224
11436
  if (!u.parent) {
@@ -11237,7 +11449,7 @@ var dataStructureTyped = (() => {
11237
11449
  * Space Complexity: O(1)
11238
11450
  *
11239
11451
  * The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
11240
- * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
11452
+ * @param {RedBlackTreeNode<K, V> | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
11241
11453
  * structure. It can either be a valid node or `undefined`.
11242
11454
  */
11243
11455
  _insertFixup(z) {
@@ -11289,7 +11501,7 @@ var dataStructureTyped = (() => {
11289
11501
  *
11290
11502
  * The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
11291
11503
  * the colors and performing rotations.
11292
- * @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
11504
+ * @param {RedBlackTreeNode<K, V> | undefined} node - The `node` parameter represents a node in a binary tree. It can
11293
11505
  * be either a valid node object or `undefined`.
11294
11506
  * @returns The function does not return any value. It has a return type of `void`, which means it
11295
11507
  * does not return anything.
@@ -11354,7 +11566,7 @@ var dataStructureTyped = (() => {
11354
11566
  * Space Complexity: O(1)
11355
11567
  *
11356
11568
  * The `_leftRotate` function performs a left rotation on a given node in a binary tree.
11357
- * @param {NODE | undefined} x - The parameter `x` is of type `NODE | undefined`. It represents a
11569
+ * @param {RedBlackTreeNode<K, V> | undefined} x - The parameter `x` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
11358
11570
  * node in a binary tree or `undefined` if there is no node.
11359
11571
  * @returns void, which means it does not return any value.
11360
11572
  */
@@ -11383,7 +11595,7 @@ var dataStructureTyped = (() => {
11383
11595
  * Space Complexity: O(1)
11384
11596
  *
11385
11597
  * The `_rightRotate` function performs a right rotation on a given node in a binary tree.
11386
- * @param {NODE | undefined} y - The parameter `y` is of type `NODE | undefined`. It represents a
11598
+ * @param {RedBlackTreeNode<K, V> | undefined} y - The parameter `y` is of type `RedBlackTreeNode<K, V> | undefined`. It represents a
11387
11599
  * node in a binary tree or `undefined` if there is no node.
11388
11600
  * @returns void, which means it does not return any value.
11389
11601
  */
@@ -11407,221 +11619,606 @@ var dataStructureTyped = (() => {
11407
11619
  x.right = y;
11408
11620
  y.parent = x;
11409
11621
  }
11410
- /**
11411
- * Time Complexity: O(n)
11412
- * Space Complexity: O(n)
11413
- *
11414
- * The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
11415
- * applying a callback to each entry in the original tree.
11416
- * @param callback - A function that will be called for each entry in the tree, with parameters
11417
- * representing the key, value, index, and the tree itself. It should return an entry for the new
11418
- * tree.
11419
- * @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
11420
- * MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
11421
- * Tree that will be created during the mapping process. These options could include things like
11422
- * custom comparators
11423
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11424
- * the value of `this` when executing the `callback` function. It allows you to set the context
11425
- * (value of `this`) for the callback function. This can be useful when you want to access properties
11426
- * or
11427
- * @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
11428
- * provided callback function.
11429
- */
11430
- map(callback, options, thisArg) {
11431
- const newTree = new _RedBlackTree([], options);
11432
- let index = 0;
11433
- for (const [key, value] of this) {
11434
- newTree.add(callback.call(thisArg, key, value, index++, this));
11435
- }
11436
- return newTree;
11437
- }
11438
11622
  };
11439
11623
 
11440
11624
  // src/data-structures/binary-tree/avl-tree-multi-map.ts
11441
11625
  var AVLTreeMultiMapNode = class extends AVLTreeNode {
11442
11626
  /**
11443
- * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
11444
- * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
11445
- * of the binary tree node.
11446
- * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
11447
- * tree node. If no value is provided, it will be `undefined`.
11448
- * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
11449
- * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
11450
- * parameter when creating a new instance of the `BinaryTreeNode` class.
11627
+ * This TypeScript constructor initializes an object with a key of type K and an array of values of
11628
+ * type V.
11629
+ * @param {K} key - The `key` parameter is typically used to store a unique identifier or key for the
11630
+ * data being stored in the data structure. It helps in quickly accessing or retrieving the
11631
+ * associated value in the data structure.
11632
+ * @param {V[]} value - The `value` parameter in the constructor represents an array of values of
11633
+ * type `V`.
11451
11634
  */
11452
- constructor(key, value, count = 1) {
11635
+ constructor(key, value) {
11453
11636
  super(key, value);
11454
- this.count = count;
11637
+ __publicField(this, "parent");
11638
+ __publicField(this, "_left");
11639
+ __publicField(this, "_right");
11640
+ }
11641
+ get left() {
11642
+ return this._left;
11643
+ }
11644
+ set left(v) {
11645
+ if (v) {
11646
+ v.parent = this;
11647
+ }
11648
+ this._left = v;
11649
+ }
11650
+ get right() {
11651
+ return this._right;
11652
+ }
11653
+ set right(v) {
11654
+ if (v) {
11655
+ v.parent = this;
11656
+ }
11657
+ this._right = v;
11455
11658
  }
11456
11659
  };
11457
11660
  var AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11458
11661
  /**
11459
- * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
11460
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
11461
- * iterable object that can contain either keys, nodes, entries, or raw elements.
11462
- * @param [options] - The `options` parameter is an optional object that can be used to customize the
11463
- * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
11464
- * `compareValues` functions to define custom comparison logic for keys and values, respectively.
11662
+ * The constructor initializes an AVLTreeMultiMap with the provided keys, nodes, entries, or raw data
11663
+ * and options.
11664
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
11665
+ * iterable that can contain either key-value pairs represented as `BTNRep<K, V[],
11666
+ * AVLTreeMultiMapNode<K, V>>` or raw data represented as `R`. This parameter is used to initialize
11667
+ * the AVLTreeMulti
11668
+ * @param [options] - The `options` parameter in the constructor is of type
11669
+ * `AVLTreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
11670
+ * additional options for configuring the AVLTreeMultiMap instance.
11465
11671
  */
11466
11672
  constructor(keysNodesEntriesOrRaws = [], options) {
11467
- super([], options);
11468
- __publicField(this, "_count", 0);
11469
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11470
- }
11471
- /**
11472
- * The function calculates the sum of the count property of all nodes in a tree using depth-first
11473
- * search.
11474
- * @returns the sum of the count property of all nodes in the tree.
11475
- */
11476
- get count() {
11477
- return this._count;
11673
+ super([], __spreadProps(__spreadValues({}, options), { isMapMode: true }));
11674
+ if (keysNodesEntriesOrRaws) {
11675
+ this.addMany(keysNodesEntriesOrRaws);
11676
+ }
11478
11677
  }
11479
11678
  /**
11480
- * Time Complexity: O(n)
11679
+ * Time Complexity: O(1)
11481
11680
  * Space Complexity: O(1)
11482
11681
  *
11483
- * The function calculates the sum of the count property of all nodes in a tree using depth-first
11484
- * search.
11485
- * @returns the sum of the count property of all nodes in the tree.
11486
- */
11487
- getComputedCount() {
11488
- let sum = 0;
11489
- this.dfs((node) => sum += node.count);
11490
- return sum;
11491
- }
11492
- /**
11493
- * The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
11494
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
11495
- * which is a generic type that can be replaced with any specific type when using the function.
11496
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11497
- * associated with the key in the node. It is of type `V`, which can be any data type.
11498
- * @param {number} [count] - The `count` parameter represents the number of occurrences of a
11499
- * key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
11500
- * calling the `createNode` method. If provided, it specifies the initial count for the node.
11501
- * @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
11502
- */
11503
- createNode(key, value, count) {
11504
- return new AVLTreeMultiMapNode(key, this._isMapMode ? void 0 : value, count);
11505
- }
11506
- /**
11507
- * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
11508
- * @param [options] - The `options` parameter is an optional object that contains additional
11509
- * configuration options for creating the AVLTreeMultiMap. It can have the following properties:
11510
- * @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
11511
- * object.
11682
+ * The function `createTree` in TypeScript overrides the creation of an AVLTreeMultiMap with
11683
+ * specified options.
11684
+ * @param [options] - The `options` parameter in the `createTree` function is of type
11685
+ * `AVLTreeMultiMapOptions<K, V[], R>`. This means it is an object that can have properties of type
11686
+ * `K`, `V[]`, and `R`. The function creates a new `AVL
11687
+ * @returns The `createTree` method is returning a new instance of `AVLTreeMultiMap` with the
11688
+ * provided options.
11512
11689
  */
11513
11690
  createTree(options) {
11514
11691
  return new _AVLTreeMultiMap([], __spreadValues({
11515
11692
  iterationType: this.iterationType,
11516
- isMapMode: this._isMapMode,
11517
11693
  specifyComparable: this._specifyComparable,
11518
11694
  toEntryFn: this._toEntryFn,
11519
11695
  isReverse: this._isReverse
11520
11696
  }, options));
11521
11697
  }
11522
11698
  /**
11523
- * The function checks if the input is an instance of AVLTreeMultiMapNode.
11524
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11525
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11526
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
11527
- * an instance of the `AVLTreeMultiMapNode` class.
11699
+ * Time Complexity: O(1)
11700
+ * Space Complexity: O(1)
11701
+ *
11702
+ * The function `createNode` overrides the method to create a new AVLTreeMultiMapNode with a
11703
+ * specified key and an empty array of values.
11704
+ * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
11705
+ * that will be created in the AVLTreeMultiMap.
11706
+ * @returns An AVLTreeMultiMapNode object is being returned, initialized with the provided key and an
11707
+ * empty array.
11528
11708
  */
11529
- isNode(keyNodeEntryOrRaw) {
11530
- return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
11709
+ createNode(key) {
11710
+ return new AVLTreeMultiMapNode(key, []);
11531
11711
  }
11532
11712
  /**
11533
11713
  * Time Complexity: O(log n)
11534
- * Space Complexity: O(1)
11714
+ * Space Complexity: O(log n)
11535
11715
  *
11536
- * The function overrides the add method of a TypeScript class to add a new node to a data structure
11537
- * and update the count.
11538
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11539
- * `keyNodeEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
11540
- * can also accept a value of type `BTNRep<K, V, NODE>`, which represents a key, node,
11541
- * entry, or raw element
11542
- * @param {V} [value] - The `value` parameter represents the value associated with the key in the
11543
- * data structure. It is an optional parameter, so it can be omitted if not needed.
11544
- * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
11545
- * be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
11546
- * be added once. However, you can specify a different value for `count` if you want to add
11547
- * @returns a boolean value.
11548
- */
11549
- add(keyNodeEntryOrRaw, value, count = 1) {
11550
- const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11551
- if (newNode === void 0) return false;
11552
- const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
11553
- const inserted = super.add(newNode, newValue);
11554
- if (inserted) {
11555
- this._count += orgNodeCount;
11716
+ * The function `add` in TypeScript overrides the superclass method to add key-value pairs to an AVL
11717
+ * tree multi-map.
11718
+ * @param {BTNRep<K, V[], AVLTreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
11719
+ * parameter in the `override add` method can be either a key-value pair entry or just a key. If it
11720
+ * is a key-value pair entry, it will be in the format `[key, values]`, where `key` is the key and
11721
+ * `values`
11722
+ * @param {V} [value] - The `value` parameter in the `override add` method represents the value that
11723
+ * you want to add to the AVLTreeMultiMap. It can be a single value or an array of values associated
11724
+ * with a specific key.
11725
+ * @returns The `override add` method is returning a boolean value, which indicates whether the
11726
+ * addition operation was successful or not.
11727
+ */
11728
+ add(keyNodeOrEntry, value) {
11729
+ if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11730
+ const _commonAdd = (key, values) => {
11731
+ if (key === void 0 || key === null) return false;
11732
+ const existingValues = this.get(key);
11733
+ if (existingValues !== void 0 && values !== void 0) {
11734
+ for (const value2 of values) existingValues.push(value2);
11735
+ return true;
11736
+ }
11737
+ const existingNode = this.getNode(key);
11738
+ if (this.isRealNode(existingNode)) {
11739
+ if (existingValues === void 0) {
11740
+ super.add(key, values);
11741
+ return true;
11742
+ }
11743
+ if (values !== void 0) {
11744
+ for (const value2 of values) existingValues.push(value2);
11745
+ return true;
11746
+ } else {
11747
+ return false;
11748
+ }
11749
+ } else {
11750
+ return super.add(key, values);
11751
+ }
11752
+ };
11753
+ if (this.isEntry(keyNodeOrEntry)) {
11754
+ const [key, values] = keyNodeOrEntry;
11755
+ return _commonAdd(key, value !== void 0 ? [value] : values);
11556
11756
  }
11557
- return true;
11757
+ return _commonAdd(keyNodeOrEntry, value !== void 0 ? [value] : void 0);
11558
11758
  }
11559
11759
  /**
11560
11760
  * Time Complexity: O(log n)
11561
- * Space Complexity: O(1)
11761
+ * Space Complexity: O(log n)
11562
11762
  *
11563
- * The function overrides the delete method in a binary tree data structure, handling deletion of
11564
- * nodes and maintaining balance in the tree.
11565
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
11566
- * parameter in the `delete` method is used to specify the condition for deleting a node from the
11567
- * binary tree. It can be a key, node, or entry that determines which
11568
- * node(s) should be deleted.
11569
- * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
11570
- * boolean flag that determines whether to ignore the count of the node being deleted. If
11571
- * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
11572
- * `ignoreCount` is set to
11573
- * @returns The `delete` method overrides the default delete behavior in a binary tree data
11574
- * structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
11575
- * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
11576
- * deleted node and whether balancing is needed in the tree.
11763
+ * The function `deleteValue` removes a specific value from a key in an AVLTreeMultiMap data
11764
+ * structure and deletes the entire node if no values are left for that key.
11765
+ * @param {BTNRep<K, V[], AVLTreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
11766
+ * parameter in the `deleteValue` function can be either a `BTNRep` object representing a key-value
11767
+ * pair in the AVLTreeMultiMapNode, or just the key itself.
11768
+ * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
11769
+ * value that you want to delete from the multi-map data structure associated with a particular key.
11770
+ * The function checks if the value exists in the array of values associated with the key, and if
11771
+ * found, removes it from the array.
11772
+ * @returns The `deleteValue` function returns a boolean value. It returns `true` if the specified
11773
+ * `value` was successfully deleted from the array of values associated with the `keyNodeOrEntry`. If
11774
+ * the value was not found in the array, it returns `false`.
11775
+ */
11776
+ deleteValue(keyNodeOrEntry, value) {
11777
+ const values = this.get(keyNodeOrEntry);
11778
+ if (Array.isArray(values)) {
11779
+ const index = values.indexOf(value);
11780
+ if (index === -1) return false;
11781
+ values.splice(index, 1);
11782
+ if (values.length === 0) this.delete(keyNodeOrEntry);
11783
+ return true;
11784
+ }
11785
+ return false;
11786
+ }
11787
+ /**
11788
+ * Time Complexity: O(n)
11789
+ * Space Complexity: O(n)
11790
+ *
11791
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
11792
+ * structure.
11793
+ * @returns A cloned tree object is being returned.
11577
11794
  */
11578
- delete(keyNodeEntryOrRaw, ignoreCount = false) {
11579
- var _a;
11580
- const deletedResult = [];
11581
- if (!this.root) return deletedResult;
11582
- const curr = (_a = this.getNode(keyNodeEntryOrRaw)) != null ? _a : void 0;
11583
- if (!curr) return deletedResult;
11584
- const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
11585
- let needBalanced = void 0, orgCurrent = curr;
11586
- if (curr.count > 1 && !ignoreCount) {
11587
- curr.count--;
11588
- this._count--;
11589
- } else {
11590
- if (!curr.left) {
11591
- if (!parent) {
11592
- if (curr.right !== void 0 && curr.right !== null) this._setRoot(curr.right);
11795
+ clone() {
11796
+ const cloned = this.createTree();
11797
+ this._clone(cloned);
11798
+ return cloned;
11799
+ }
11800
+ };
11801
+
11802
+ // src/data-structures/binary-tree/tree-multi-map.ts
11803
+ var TreeMultiMapNode = class extends RedBlackTreeNode {
11804
+ /**
11805
+ * This TypeScript constructor initializes an object with a key of type K and an array of values of
11806
+ * type V.
11807
+ * @param {K} key - The `key` parameter is typically used to store a unique identifier or key for the
11808
+ * data being stored in the data structure. It helps in quickly accessing or retrieving the
11809
+ * associated value in the data structure.
11810
+ * @param {V[]} value - The `value` parameter in the constructor represents an array of values of
11811
+ * type `V`.
11812
+ */
11813
+ constructor(key, value) {
11814
+ super(key, value);
11815
+ __publicField(this, "parent");
11816
+ __publicField(this, "_left");
11817
+ __publicField(this, "_right");
11818
+ }
11819
+ get left() {
11820
+ return this._left;
11821
+ }
11822
+ set left(v) {
11823
+ if (v) {
11824
+ v.parent = this;
11825
+ }
11826
+ this._left = v;
11827
+ }
11828
+ get right() {
11829
+ return this._right;
11830
+ }
11831
+ set right(v) {
11832
+ if (v) {
11833
+ v.parent = this;
11834
+ }
11835
+ this._right = v;
11836
+ }
11837
+ };
11838
+ var TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
11839
+ /**
11840
+ * The constructor initializes an TreeMultiMap with the provided keys, nodes, entries, or raw data
11841
+ * and options.
11842
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
11843
+ * iterable that can contain either key-value pairs represented as `BTNRep<K, V[],
11844
+ * TreeMultiMapNode<K, V>>` or raw data represented as `R`. This parameter is used to initialize
11845
+ * the RedBlackTreeMulti
11846
+ * @param [options] - The `options` parameter in the constructor is of type
11847
+ * `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
11848
+ * additional options for configuring the TreeMultiMap instance.
11849
+ */
11850
+ constructor(keysNodesEntriesOrRaws = [], options) {
11851
+ super([], __spreadProps(__spreadValues({}, options), { isMapMode: true }));
11852
+ if (keysNodesEntriesOrRaws) {
11853
+ this.addMany(keysNodesEntriesOrRaws);
11854
+ }
11855
+ }
11856
+ /**
11857
+ * Time Complexity: O(1)
11858
+ * Space Complexity: O(1)
11859
+ *
11860
+ * The `createTree` function in TypeScript overrides the default implementation to create a new
11861
+ * TreeMultiMap with specified options.
11862
+ * @param [options] - The `options` parameter in the `createTree` method is of type
11863
+ * `TreeMultiMapOptions<K, V[], R>`. This parameter allows you to pass additional configuration
11864
+ * options when creating a new `TreeMultiMap` instance. It includes properties such as
11865
+ * `iterationType`, `specifyComparable
11866
+ * @returns A new instance of `TreeMultiMap` is being returned, with an empty array as the initial
11867
+ * data and the provided options merged with the existing properties of the current object.
11868
+ */
11869
+ createTree(options) {
11870
+ return new _TreeMultiMap([], __spreadValues({
11871
+ iterationType: this.iterationType,
11872
+ specifyComparable: this._specifyComparable,
11873
+ toEntryFn: this._toEntryFn,
11874
+ isReverse: this._isReverse
11875
+ }, options));
11876
+ }
11877
+ /**
11878
+ * Time Complexity: O(1)
11879
+ * Space Complexity: O(1)
11880
+ *
11881
+ * The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
11882
+ * key and an empty array of values.
11883
+ * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
11884
+ * that will be created in the TreeMultiMap data structure.
11885
+ * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
11886
+ * an empty array as its value.
11887
+ */
11888
+ createNode(key) {
11889
+ return new TreeMultiMapNode(key, []);
11890
+ }
11891
+ /**
11892
+ * Time Complexity: O(log n)
11893
+ * Space Complexity: O(log n)
11894
+ *
11895
+ * The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
11896
+ * TreeMultiMapNode, handling different input types and scenarios.
11897
+ * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
11898
+ * parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
11899
+ * of values, and a `TreeMultiMapNode`, or just a key.
11900
+ * @param {V} [value] - The `value` parameter in the `override add` method represents the value that
11901
+ * you want to add to the TreeMultiMap. If the key is already present in the map, the new value will
11902
+ * be added to the existing list of values associated with that key. If the key is not present,
11903
+ * @returns The `add` method is returning a boolean value, which indicates whether the operation was
11904
+ * successful or not.
11905
+ */
11906
+ add(keyNodeOrEntry, value) {
11907
+ if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11908
+ const _commonAdd = (key, values) => {
11909
+ if (key === void 0 || key === null) return false;
11910
+ const existingValues = this.get(key);
11911
+ if (existingValues !== void 0 && values !== void 0) {
11912
+ for (const value2 of values) existingValues.push(value2);
11913
+ return true;
11914
+ }
11915
+ const existingNode = this.getNode(key);
11916
+ if (this.isRealNode(existingNode)) {
11917
+ if (existingValues === void 0) {
11918
+ super.add(key, values);
11919
+ return true;
11920
+ }
11921
+ if (values !== void 0) {
11922
+ for (const value2 of values) existingValues.push(value2);
11923
+ return true;
11593
11924
  } else {
11594
- const { familyPosition: fp } = curr;
11595
- if (fp === "LEFT" || fp === "ROOT_LEFT") {
11596
- parent.left = curr.right;
11597
- } else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
11598
- parent.right = curr.right;
11599
- }
11600
- needBalanced = parent;
11925
+ return false;
11601
11926
  }
11602
11927
  } else {
11603
- const leftSubTreeRightMost = curr.left ? this.getRightMost((node) => node, curr.left) : void 0;
11604
- if (leftSubTreeRightMost) {
11605
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
11606
- orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
11607
- if (parentOfLeftSubTreeMax) {
11608
- if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
11609
- parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
11610
- } else {
11611
- parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
11928
+ return super.add(key, values);
11929
+ }
11930
+ };
11931
+ if (this.isEntry(keyNodeOrEntry)) {
11932
+ const [key, values] = keyNodeOrEntry;
11933
+ return _commonAdd(key, value !== void 0 ? [value] : values);
11934
+ }
11935
+ return _commonAdd(keyNodeOrEntry, value !== void 0 ? [value] : void 0);
11936
+ }
11937
+ /**
11938
+ * Time Complexity: O(log n)
11939
+ * Space Complexity: O(log n)
11940
+ *
11941
+ * The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
11942
+ * and deletes the entire node if no values are left for that key.
11943
+ * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
11944
+ * parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
11945
+ * array of values, or just a key itself.
11946
+ * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
11947
+ * value that you want to remove from the multi-map data structure associated with a particular key.
11948
+ * The function checks if the value exists in the array of values associated with the key, and if
11949
+ * found, removes it from the array.
11950
+ * @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
11951
+ * successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
11952
+ */
11953
+ deleteValue(keyNodeOrEntry, value) {
11954
+ const values = this.get(keyNodeOrEntry);
11955
+ if (Array.isArray(values)) {
11956
+ const index = values.indexOf(value);
11957
+ if (index === -1) return false;
11958
+ values.splice(index, 1);
11959
+ if (values.length === 0) this.delete(keyNodeOrEntry);
11960
+ return true;
11961
+ }
11962
+ return false;
11963
+ }
11964
+ /**
11965
+ * Time Complexity: O(n)
11966
+ * Space Complexity: O(n)
11967
+ *
11968
+ * The function `clone` overrides the default cloning behavior to create a deep copy of a tree
11969
+ * structure.
11970
+ * @returns The `cloned` object is being returned.
11971
+ */
11972
+ clone() {
11973
+ const cloned = this.createTree();
11974
+ this._clone(cloned);
11975
+ return cloned;
11976
+ }
11977
+ };
11978
+
11979
+ // src/data-structures/binary-tree/tree-counter.ts
11980
+ var TreeCounterNode = class extends RedBlackTreeNode {
11981
+ /**
11982
+ * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
11983
+ * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
11984
+ * used to identify and locate the node within the tree.
11985
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11986
+ * associated with the key in the Red-Black Tree node. It is not required and can be omitted when
11987
+ * creating a new node.
11988
+ * @param [count=1] - The `count` parameter represents the number of occurrences of a particular key
11989
+ * in the Red-Black Tree. It is an optional parameter with a default value of 1.
11990
+ * @param {RBTNColor} [color=BLACK] - The `color` parameter is used to specify the color of the node
11991
+ * in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
11992
+ */
11993
+ constructor(key, value, count = 1, color = "BLACK") {
11994
+ super(key, value, color);
11995
+ __publicField(this, "parent");
11996
+ __publicField(this, "_left");
11997
+ __publicField(this, "_right");
11998
+ this.count = count;
11999
+ }
12000
+ get left() {
12001
+ return this._left;
12002
+ }
12003
+ set left(v) {
12004
+ if (v) {
12005
+ v.parent = this;
12006
+ }
12007
+ this._left = v;
12008
+ }
12009
+ get right() {
12010
+ return this._right;
12011
+ }
12012
+ set right(v) {
12013
+ if (v) {
12014
+ v.parent = this;
12015
+ }
12016
+ this._right = v;
12017
+ }
12018
+ };
12019
+ var TreeCounter = class _TreeCounter extends RedBlackTree {
12020
+ /**
12021
+ * The constructor function initializes a TreeCounter object with optional initial data.
12022
+ * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
12023
+ * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
12024
+ * TreeCounter with initial data.
12025
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
12026
+ * behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
12027
+ * `compareValues`, which are functions used to compare keys and values respectively.
12028
+ */
12029
+ constructor(keysNodesEntriesOrRaws = [], options) {
12030
+ super([], options);
12031
+ __publicField(this, "_count", 0);
12032
+ if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
12033
+ }
12034
+ // TODO the _count is not accurate after nodes count modified
12035
+ /**
12036
+ * The function calculates the sum of the count property of all nodes in a tree structure.
12037
+ * @returns the sum of the count property of all nodes in the tree.
12038
+ */
12039
+ get count() {
12040
+ return this._count;
12041
+ }
12042
+ /**
12043
+ * Time Complexity: O(n)
12044
+ * Space Complexity: O(1)
12045
+ *
12046
+ * The function calculates the sum of the count property of all nodes in a tree using depth-first
12047
+ * search.
12048
+ * @returns the sum of the count property of all nodes in the tree.
12049
+ */
12050
+ getComputedCount() {
12051
+ let sum = 0;
12052
+ this.dfs((node) => sum += node.count);
12053
+ return sum;
12054
+ }
12055
+ /**
12056
+ * The function creates a new TreeCounterNode with the specified key, value, color, and count.
12057
+ * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
12058
+ * which is a generic type representing the type of keys in the tree.
12059
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
12060
+ * associated with the key in the node. It is of type `V`, which can be any data type.
12061
+ * @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
12062
+ * a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
12063
+ * @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
12064
+ * the tree. It is an optional parameter and is used to keep track of the number of values associated
12065
+ * with a key in the tree.
12066
+ * @returns A new instance of the TreeCounterNode class, casted as TreeCounterNode<K, V>.
12067
+ */
12068
+ createNode(key, value, color = "BLACK", count) {
12069
+ return new TreeCounterNode(key, this._isMapMode ? void 0 : value, count, color);
12070
+ }
12071
+ /**
12072
+ * The function creates a new instance of a TreeCounter with the specified options and returns it.
12073
+ * @param [options] - The `options` parameter is an optional object that contains additional
12074
+ * configuration options for creating the `TreeCounter`. It is of type `TreeCounterOptions<K, V,
12075
+ * R>`.
12076
+ * @returns a new instance of the `TreeCounter` class, with the provided options merged with the
12077
+ * existing `iterationType` property. The returned value is casted as `TREE`.
12078
+ */
12079
+ createTree(options) {
12080
+ return new _TreeCounter([], __spreadValues({
12081
+ iterationType: this.iterationType,
12082
+ specifyComparable: this._specifyComparable,
12083
+ isMapMode: this._isMapMode,
12084
+ toEntryFn: this._toEntryFn
12085
+ }, options));
12086
+ }
12087
+ /**
12088
+ * The function checks if the input is an instance of the TreeCounterNode class.
12089
+ * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
12090
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
12091
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
12092
+ * an instance of the `TreeCounterNode` class.
12093
+ */
12094
+ isNode(keyNodeOrEntry) {
12095
+ return keyNodeOrEntry instanceof TreeCounterNode;
12096
+ }
12097
+ /**
12098
+ * Time Complexity: O(log n)
12099
+ * Space Complexity: O(1)
12100
+ *
12101
+ * The function overrides the add method of a class and adds a new node to a data structure, updating
12102
+ * the count and returning a boolean indicating success.
12103
+ * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
12104
+ * `keyNodeOrEntry` parameter can accept one of the following types:
12105
+ * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12106
+ * data structure. It is an optional parameter, so it can be omitted if not needed.
12107
+ * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
12108
+ * be added to the data structure. By default, it is set to 1, meaning that if no value is provided
12109
+ * for `count`, the key-value pair will be added once.
12110
+ * @returns The method is returning a boolean value. It returns true if the addition of the new node
12111
+ * was successful, and false otherwise.
12112
+ */
12113
+ add(keyNodeOrEntry, value, count = 1) {
12114
+ const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12115
+ const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
12116
+ const isSuccessAdded = super.add(newNode, newValue);
12117
+ if (isSuccessAdded) {
12118
+ this._count += orgCount;
12119
+ return true;
12120
+ } else {
12121
+ return false;
12122
+ }
12123
+ }
12124
+ /**
12125
+ * Time Complexity: O(log n)
12126
+ * Space Complexity: O(1)
12127
+ *
12128
+ * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
12129
+ * structure, handling cases where nodes have children and maintaining balance in the tree.
12130
+ * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
12131
+ * parameter in the `delete` method is used to specify the condition or key based on which a node
12132
+ * should be deleted from the binary tree. It can be a key, a node, or an entry.
12133
+ * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
12134
+ * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
12135
+ * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
12136
+ * `ignoreCount` is `false
12137
+ * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
12138
+ */
12139
+ delete(keyNodeOrEntry, ignoreCount = false) {
12140
+ if (keyNodeOrEntry === null) return [];
12141
+ const results = [];
12142
+ let nodeToDelete;
12143
+ if (this._isPredicate(keyNodeOrEntry)) nodeToDelete = this.getNode(keyNodeOrEntry);
12144
+ else nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
12145
+ if (!nodeToDelete) {
12146
+ return results;
12147
+ }
12148
+ let originalColor = nodeToDelete.color;
12149
+ let replacementNode;
12150
+ if (!this.isRealNode(nodeToDelete.left)) {
12151
+ if (nodeToDelete.right !== null) replacementNode = nodeToDelete.right;
12152
+ if (ignoreCount || nodeToDelete.count <= 1) {
12153
+ if (nodeToDelete.right !== null) {
12154
+ this._transplant(nodeToDelete, nodeToDelete.right);
12155
+ this._count -= nodeToDelete.count;
12156
+ }
12157
+ } else {
12158
+ nodeToDelete.count--;
12159
+ this._count--;
12160
+ results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12161
+ return results;
12162
+ }
12163
+ } else if (!this.isRealNode(nodeToDelete.right)) {
12164
+ replacementNode = nodeToDelete.left;
12165
+ if (ignoreCount || nodeToDelete.count <= 1) {
12166
+ this._transplant(nodeToDelete, nodeToDelete.left);
12167
+ this._count -= nodeToDelete.count;
12168
+ } else {
12169
+ nodeToDelete.count--;
12170
+ this._count--;
12171
+ results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12172
+ return results;
12173
+ }
12174
+ } else {
12175
+ const successor = this.getLeftMost((node) => node, nodeToDelete.right);
12176
+ if (successor) {
12177
+ originalColor = successor.color;
12178
+ if (successor.right !== null) replacementNode = successor.right;
12179
+ if (successor.parent === nodeToDelete) {
12180
+ if (this.isRealNode(replacementNode)) {
12181
+ replacementNode.parent = successor;
12182
+ }
12183
+ } else {
12184
+ if (ignoreCount || nodeToDelete.count <= 1) {
12185
+ if (successor.right !== null) {
12186
+ this._transplant(successor, successor.right);
12187
+ this._count -= nodeToDelete.count;
11612
12188
  }
11613
- needBalanced = parentOfLeftSubTreeMax;
12189
+ } else {
12190
+ nodeToDelete.count--;
12191
+ this._count--;
12192
+ results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12193
+ return results;
12194
+ }
12195
+ successor.right = nodeToDelete.right;
12196
+ if (this.isRealNode(successor.right)) {
12197
+ successor.right.parent = successor;
11614
12198
  }
11615
12199
  }
12200
+ if (ignoreCount || nodeToDelete.count <= 1) {
12201
+ this._transplant(nodeToDelete, successor);
12202
+ this._count -= nodeToDelete.count;
12203
+ } else {
12204
+ nodeToDelete.count--;
12205
+ this._count--;
12206
+ results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12207
+ return results;
12208
+ }
12209
+ successor.left = nodeToDelete.left;
12210
+ if (this.isRealNode(successor.left)) {
12211
+ successor.left.parent = successor;
12212
+ }
12213
+ successor.color = nodeToDelete.color;
11616
12214
  }
11617
- this._size = this._size - 1;
11618
- if (orgCurrent) this._count -= orgCurrent.count;
11619
12215
  }
11620
- deletedResult.push({ deleted: orgCurrent, needBalanced });
11621
- if (needBalanced) {
11622
- this._balancePath(needBalanced);
12216
+ this._size--;
12217
+ if (originalColor === "BLACK") {
12218
+ this._deleteFixup(replacementNode);
11623
12219
  }
11624
- return deletedResult;
12220
+ results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12221
+ return results;
11625
12222
  }
11626
12223
  /**
11627
12224
  * Time Complexity: O(1)
@@ -11637,12 +12234,13 @@ var dataStructureTyped = (() => {
11637
12234
  /**
11638
12235
  * Time Complexity: O(n log n)
11639
12236
  * Space Complexity: O(log n)
12237
+ *
11640
12238
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
11641
12239
  * tree using either a recursive or iterative approach.
11642
12240
  * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
11643
12241
  * specifies the type of iteration to use when building the balanced binary search tree. It has a
11644
- * default value of `this.iterationType`, which means it will use the iteration type currently set in
11645
- * the object.
12242
+ * default value of `this.iterationType`, which means it will use the iteration type specified by the
12243
+ * `iterationType` property of the current object.
11646
12244
  * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
11647
12245
  * balancing operation is successful, and `false` if there are no nodes to balance.
11648
12246
  */
@@ -11690,31 +12288,27 @@ var dataStructureTyped = (() => {
11690
12288
  */
11691
12289
  clone() {
11692
12290
  const cloned = this.createTree();
11693
- if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
11694
- else this.bfs((node) => cloned.add(node.key, node.value, node.count));
12291
+ this.bfs((node) => cloned.add(node.key, void 0, node.count));
11695
12292
  if (this._isMapMode) cloned._store = this._store;
11696
12293
  return cloned;
11697
12294
  }
11698
12295
  /**
11699
- * The `map` function in TypeScript overrides the default behavior to create a new AVLTreeMultiMap
11700
- * with modified entries based on a provided callback.
12296
+ * The `map` function in TypeScript overrides the default behavior to create a new TreeCounter with
12297
+ * modified entries based on a provided callback.
11701
12298
  * @param callback - The `callback` parameter is a function that will be called for each entry in the
11702
- * AVLTreeMultiMap. It takes four arguments:
12299
+ * map. It takes four arguments:
11703
12300
  * @param [options] - The `options` parameter in the `override map` function is of type
11704
- * `AVLTreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional
11705
- * configuration options when creating a new `AVLTreeMultiMap` instance within the `map` function.
11706
- * These options
12301
+ * `TreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
12302
+ * options when creating a new `TreeCounter` instance within the `map` function. These options could
12303
+ * include things like
11707
12304
  * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11708
12305
  * the value of `this` when executing the `callback` function. It allows you to set the context
11709
- * (value of `this`) for the callback function. This can be useful when you want to access properties
11710
- * or
11711
- * @returns The `map` method is returning a new `AVLTreeMultiMap` instance with the entries
11712
- * transformed by the provided `callback` function. Each entry in the original tree is passed to the
11713
- * `callback` function along with the index and the original tree itself. The transformed entries are
11714
- * then added to the new `AVLTreeMultiMap` instance, which is returned at the end.
12306
+ * (value of `this`) for the callback function when it is called within the `map` function. This
12307
+ * @returns A new TreeCounter instance is being returned, which is populated with entries generated
12308
+ * by the provided callback function.
11715
12309
  */
11716
12310
  map(callback, options, thisArg) {
11717
- const newTree = new _AVLTreeMultiMap([], options);
12311
+ const newTree = new _TreeCounter([], options);
11718
12312
  let index = 0;
11719
12313
  for (const [key, value] of this) {
11720
12314
  newTree.add(callback.call(thisArg, key, value, index++, this));
@@ -11722,63 +12316,58 @@ var dataStructureTyped = (() => {
11722
12316
  return newTree;
11723
12317
  }
11724
12318
  /**
11725
- * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
11726
- * a node object.
11727
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11728
- * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
11729
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11730
- * `override` function. It represents the value associated with the key in the data structure. If no
11731
- * value is provided, it will default to `undefined`.
12319
+ * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
12320
+ * node based on the input.
12321
+ * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
12322
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
12323
+ * @param {V} [value] - The `value` parameter is an optional value that represents the value
12324
+ * associated with the key in the node. It is used when creating a new node or updating the value of
12325
+ * an existing node.
11732
12326
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11733
12327
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11734
- * @returns either a NODE object or undefined.
12328
+ * @returns either a TreeCounterNode<K, V> object or undefined.
11735
12329
  */
11736
- _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11737
- if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11738
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11739
- if (this.isEntry(keyNodeEntryOrRaw)) {
11740
- const [key, entryValue] = keyNodeEntryOrRaw;
12330
+ _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count = 1) {
12331
+ if (keyNodeOrEntry === void 0 || keyNodeOrEntry === null) return [void 0, void 0];
12332
+ if (this.isNode(keyNodeOrEntry)) return [keyNodeOrEntry, value];
12333
+ if (this.isEntry(keyNodeOrEntry)) {
12334
+ const [key, entryValue] = keyNodeOrEntry;
11741
12335
  if (key === void 0 || key === null) return [void 0, void 0];
11742
12336
  const finalValue = value != null ? value : entryValue;
11743
- return [this.createNode(key, finalValue, count), finalValue];
11744
- }
11745
- if (this.isRaw(keyNodeEntryOrRaw)) {
11746
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11747
- const finalValue = value != null ? value : entryValue;
11748
- if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
12337
+ return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11749
12338
  }
11750
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
11751
- return [void 0, void 0];
12339
+ return [this.createNode(keyNodeOrEntry, value, "BLACK", count), value];
11752
12340
  }
11753
12341
  /**
11754
12342
  * Time Complexity: O(1)
11755
12343
  * Space Complexity: O(1)
11756
12344
  *
11757
- * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
12345
+ * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
11758
12346
  * in a binary search tree.
11759
- * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
11760
- * that will be swapped with the `destNode`.
11761
- * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
12347
+ * @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
12348
+ * that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
12349
+ * instance of the `BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>` class.
12350
+ * @param {R | BSTNOptKeyOrNode<K, TreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
11762
12351
  * node where the properties will be swapped with the source node.
11763
12352
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
11764
- * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
12353
+ * If either `srcNode` or `destNode` is undefined, it returns undefined.
11765
12354
  */
11766
12355
  _swapProperties(srcNode, destNode) {
11767
12356
  srcNode = this.ensureNode(srcNode);
11768
12357
  destNode = this.ensureNode(destNode);
11769
12358
  if (srcNode && destNode) {
11770
- const { key, value, count, height } = destNode;
11771
- const tempNode = this.createNode(key, value, count);
12359
+ const { key, value, count, color } = destNode;
12360
+ const tempNode = this.createNode(key, value, color, count);
11772
12361
  if (tempNode) {
11773
- tempNode.height = height;
12362
+ tempNode.color = color;
11774
12363
  destNode.key = srcNode.key;
11775
12364
  if (!this._isMapMode) destNode.value = srcNode.value;
11776
12365
  destNode.count = srcNode.count;
11777
- destNode.height = srcNode.height;
12366
+ destNode.color = srcNode.color;
11778
12367
  srcNode.key = tempNode.key;
11779
12368
  if (!this._isMapMode) srcNode.value = tempNode.value;
11780
12369
  srcNode.count = tempNode.count;
11781
- srcNode.height = tempNode.height;
12370
+ srcNode.color = tempNode.color;
11782
12371
  }
11783
12372
  return destNode;
11784
12373
  }
@@ -11789,11 +12378,11 @@ var dataStructureTyped = (() => {
11789
12378
  * Space Complexity: O(1)
11790
12379
  *
11791
12380
  * The function replaces an old node with a new node and updates the count property of the new node.
11792
- * @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
11793
- * data structure. It is of type NODE.
11794
- * @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
12381
+ * @param {TreeCounterNode<K, V>} oldNode - The `oldNode` parameter is the node that you want to replace in the data
12382
+ * structure.
12383
+ * @param {TreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `TreeCounterNode<K, V>` class.
11795
12384
  * @returns The method is returning the result of calling the `_replaceNode` method from the
11796
- * superclass, which is of type `NODE`.
12385
+ * superclass, which is of type `TreeCounterNode<K, V>`.
11797
12386
  */
11798
12387
  _replaceNode(oldNode, newNode) {
11799
12388
  newNode.count = oldNode.count + newNode.count;
@@ -11801,43 +12390,61 @@ var dataStructureTyped = (() => {
11801
12390
  }
11802
12391
  };
11803
12392
 
11804
- // src/data-structures/binary-tree/tree-multi-map.ts
11805
- var TreeMultiMapNode = class extends RedBlackTreeNode {
12393
+ // src/data-structures/binary-tree/avl-tree-counter.ts
12394
+ var AVLTreeCounterNode = class extends AVLTreeNode {
11806
12395
  /**
11807
- * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
11808
- * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
11809
- * used to identify and locate the node within the tree.
11810
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11811
- * associated with the key in the Red-Black Tree node. It is not required and can be omitted when
11812
- * creating a new node.
11813
- * @param [count=1] - The `count` parameter represents the number of occurrences of a particular key
11814
- * in the Red-Black Tree. It is an optional parameter with a default value of 1.
11815
- * @param {RBTNColor} [color=BLACK] - The `color` parameter is used to specify the color of the node
11816
- * in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
12396
+ * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
12397
+ * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
12398
+ * of the binary tree node.
12399
+ * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
12400
+ * tree node. If no value is provided, it will be `undefined`.
12401
+ * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
12402
+ * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
12403
+ * parameter when creating a new instance of the `BinaryTreeNode` class.
11817
12404
  */
11818
- constructor(key, value, count = 1, color = "BLACK") {
11819
- super(key, value, color);
12405
+ constructor(key, value, count = 1) {
12406
+ super(key, value);
12407
+ __publicField(this, "parent");
12408
+ __publicField(this, "_left");
12409
+ __publicField(this, "_right");
11820
12410
  this.count = count;
11821
12411
  }
12412
+ get left() {
12413
+ return this._left;
12414
+ }
12415
+ set left(v) {
12416
+ if (v) {
12417
+ v.parent = this;
12418
+ }
12419
+ this._left = v;
12420
+ }
12421
+ get right() {
12422
+ return this._right;
12423
+ }
12424
+ set right(v) {
12425
+ if (v) {
12426
+ v.parent = this;
12427
+ }
12428
+ this._right = v;
12429
+ }
11822
12430
  };
11823
- var TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
12431
+ var AVLTreeCounter = class _AVLTreeCounter extends AVLTree {
11824
12432
  /**
11825
- * The constructor function initializes a TreeMultiMap object with optional initial data.
11826
- * @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
11827
- * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
11828
- * TreeMultiMap with initial data.
12433
+ * The constructor initializes a new AVLTreeCounter object with optional initial elements.
12434
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
12435
+ * iterable object that can contain either keys, nodes, entries, or raw elements.
11829
12436
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
11830
- * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
11831
- * `compareValues`, which are functions used to compare keys and values respectively.
12437
+ * behavior of the AVLTreeCounter. It can include properties such as `compareKeys` and
12438
+ * `compareValues` functions to define custom comparison logic for keys and values, respectively.
11832
12439
  */
11833
12440
  constructor(keysNodesEntriesOrRaws = [], options) {
11834
12441
  super([], options);
11835
12442
  __publicField(this, "_count", 0);
11836
12443
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
11837
12444
  }
11838
- // TODO the _count is not accurate after nodes count modified
11839
12445
  /**
11840
- * The function calculates the sum of the count property of all nodes in a tree structure.
12446
+ * The function calculates the sum of the count property of all nodes in a tree using depth-first
12447
+ * search.
11841
12448
  * @returns the sum of the count property of all nodes in the tree.
11842
12449
  */
11843
12450
  get count() {
@@ -11857,201 +12464,138 @@ var dataStructureTyped = (() => {
11857
12464
  return sum;
11858
12465
  }
11859
12466
  /**
11860
- * The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
11861
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
11862
- * which is a generic type representing the type of keys in the tree.
11863
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11864
- * associated with the key in the node. It is of type `V`, which can be any data type.
11865
- * @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
11866
- * a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
11867
- * @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
11868
- * the tree. It is an optional parameter and is used to keep track of the number of values associated
11869
- * with a key in the tree.
11870
- * @returns A new instance of the TreeMultiMapNode class, casted as NODE.
12467
+ * The function creates a new AVLTreeCounterNode with the specified key, value, and count.
12468
+ * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
12469
+ * which is a generic type that can be replaced with any specific type when using the function.
12470
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
12471
+ * associated with the key in the node. It is of type `V`, which can be any data type.
12472
+ * @param {number} [count] - The `count` parameter represents the number of occurrences of a
12473
+ * key-value pair in the AVLTreeCounterNode. It is an optional parameter, so it can be omitted when
12474
+ * calling the `createNode` method. If provided, it specifies the initial count for the node.
12475
+ * @returns a new instance of the AVLTreeCounterNode class, casted as AVLTreeCounterNode<K, V>.
11871
12476
  */
11872
- createNode(key, value, color = "BLACK", count) {
11873
- return new TreeMultiMapNode(key, this._isMapMode ? void 0 : value, count, color);
12477
+ createNode(key, value, count) {
12478
+ return new AVLTreeCounterNode(key, this._isMapMode ? void 0 : value, count);
11874
12479
  }
11875
12480
  /**
11876
- * The function creates a new instance of a TreeMultiMap with the specified options and returns it.
12481
+ * The function creates a new AVLTreeCounter object with the specified options and returns it.
11877
12482
  * @param [options] - The `options` parameter is an optional object that contains additional
11878
- * configuration options for creating the `TreeMultiMap`. It is of type `TreeMultiMapOptions<K, V,
11879
- * R>`.
11880
- * @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
11881
- * existing `iterationType` property. The returned value is casted as `TREE`.
12483
+ * configuration options for creating the AVLTreeCounter. It can have the following properties:
12484
+ * @returns a new instance of the AVLTreeCounter class, with the specified options, as a TREE
12485
+ * object.
11882
12486
  */
11883
12487
  createTree(options) {
11884
- return new _TreeMultiMap([], __spreadValues({
12488
+ return new _AVLTreeCounter([], __spreadValues({
11885
12489
  iterationType: this.iterationType,
11886
12490
  isMapMode: this._isMapMode,
11887
12491
  specifyComparable: this._specifyComparable,
11888
- toEntryFn: this._toEntryFn
12492
+ toEntryFn: this._toEntryFn,
12493
+ isReverse: this._isReverse
11889
12494
  }, options));
11890
12495
  }
11891
12496
  /**
11892
- * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
11893
- * node based on the input.
11894
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11895
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11896
- * @param {V} [value] - The `value` parameter is an optional value that represents the value
11897
- * associated with the key in the node. It is used when creating a new node or updating the value of
11898
- * an existing node.
11899
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11900
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11901
- * @returns either a NODE object or undefined.
11902
- */
11903
- _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11904
- if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11905
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11906
- if (this.isEntry(keyNodeEntryOrRaw)) {
11907
- const [key, entryValue] = keyNodeEntryOrRaw;
11908
- if (key === void 0 || key === null) return [void 0, void 0];
11909
- const finalValue = value != null ? value : entryValue;
11910
- if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11911
- }
11912
- if (this.isRaw(keyNodeEntryOrRaw)) {
11913
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11914
- const finalValue = value != null ? value : entryValue;
11915
- if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11916
- }
11917
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, "BLACK", count), value];
11918
- return [void 0, void 0];
11919
- }
11920
- /**
11921
- * The function checks if the input is an instance of the TreeMultiMapNode class.
11922
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11923
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11924
- * @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
11925
- * an instance of the `TreeMultiMapNode` class.
12497
+ * The function checks if the input is an instance of AVLTreeCounterNode.
12498
+ * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
12499
+ * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
12500
+ * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
12501
+ * an instance of the `AVLTreeCounterNode` class.
11926
12502
  */
11927
- isNode(keyNodeEntryOrRaw) {
11928
- return keyNodeEntryOrRaw instanceof TreeMultiMapNode;
12503
+ isNode(keyNodeOrEntry) {
12504
+ return keyNodeOrEntry instanceof AVLTreeCounterNode;
11929
12505
  }
11930
12506
  /**
11931
12507
  * Time Complexity: O(log n)
11932
12508
  * Space Complexity: O(1)
11933
12509
  *
11934
- * The function overrides the add method of a class and adds a new node to a data structure, updating
11935
- * the count and returning a boolean indicating success.
11936
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11937
- * `keyNodeEntryOrRaw` parameter can accept one of the following types:
12510
+ * The function overrides the add method of a TypeScript class to add a new node to a data structure
12511
+ * and update the count.
12512
+ * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
12513
+ * `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
12514
+ * can also accept a value of type `BTNRep<K, V, AVLTreeCounterNode<K, V>>`, which represents a key, node,
12515
+ * entry, or raw element
11938
12516
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
11939
12517
  * data structure. It is an optional parameter, so it can be omitted if not needed.
11940
12518
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
11941
- * be added to the data structure. By default, it is set to 1, meaning that if no value is provided
11942
- * for `count`, the key-value pair will be added once.
11943
- * @returns The method is returning a boolean value. It returns true if the addition of the new node
11944
- * was successful, and false otherwise.
12519
+ * be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
12520
+ * be added once. However, you can specify a different value for `count` if you want to add
12521
+ * @returns a boolean value.
11945
12522
  */
11946
- add(keyNodeEntryOrRaw, value, count = 1) {
11947
- const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11948
- const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
11949
- const isSuccessAdded = super.add(newNode, newValue);
11950
- if (isSuccessAdded) {
11951
- this._count += orgCount;
11952
- return true;
11953
- } else {
11954
- return false;
12523
+ add(keyNodeOrEntry, value, count = 1) {
12524
+ const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
12525
+ if (newNode === void 0) return false;
12526
+ const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
12527
+ const inserted = super.add(newNode, newValue);
12528
+ if (inserted) {
12529
+ this._count += orgNodeCount;
11955
12530
  }
12531
+ return true;
11956
12532
  }
11957
12533
  /**
11958
12534
  * Time Complexity: O(log n)
11959
12535
  * Space Complexity: O(1)
11960
12536
  *
11961
- * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
11962
- * structure, handling cases where nodes have children and maintaining balance in the tree.
11963
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
11964
- * parameter in the `delete` method is used to specify the condition or key based on which a node
11965
- * should be deleted from the binary tree. It can be a key, a node, or an entry.
12537
+ * The function overrides the delete method in a binary tree data structure, handling deletion of
12538
+ * nodes and maintaining balance in the tree.
12539
+ * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
12540
+ * parameter in the `delete` method is used to specify the condition for deleting a node from the
12541
+ * binary tree. It can be a key, node, or entry that determines which
12542
+ * node(s) should be deleted.
11966
12543
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
11967
- * boolean flag that determines whether to ignore the count of nodes when performing deletion. If
12544
+ * boolean flag that determines whether to ignore the count of the node being deleted. If
11968
12545
  * `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
11969
- * `ignoreCount` is `false
11970
- * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
12546
+ * `ignoreCount` is set to
12547
+ * @returns The `delete` method overrides the default delete behavior in a binary tree data
12548
+ * structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
12549
+ * method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
12550
+ * deleted node and whether balancing is needed in the tree.
11971
12551
  */
11972
- delete(keyNodeEntryOrRaw, ignoreCount = false) {
11973
- if (keyNodeEntryOrRaw === null) return [];
11974
- const results = [];
11975
- let nodeToDelete;
11976
- if (this._isPredicate(keyNodeEntryOrRaw)) nodeToDelete = this.getNode(keyNodeEntryOrRaw);
11977
- else nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
11978
- if (!nodeToDelete) {
11979
- return results;
11980
- }
11981
- let originalColor = nodeToDelete.color;
11982
- let replacementNode;
11983
- if (!this.isRealNode(nodeToDelete.left)) {
11984
- if (nodeToDelete.right !== null) replacementNode = nodeToDelete.right;
11985
- if (ignoreCount || nodeToDelete.count <= 1) {
11986
- if (nodeToDelete.right !== null) {
11987
- this._transplant(nodeToDelete, nodeToDelete.right);
11988
- this._count -= nodeToDelete.count;
11989
- }
11990
- } else {
11991
- nodeToDelete.count--;
11992
- this._count--;
11993
- results.push({ deleted: nodeToDelete, needBalanced: void 0 });
11994
- return results;
11995
- }
11996
- } else if (!this.isRealNode(nodeToDelete.right)) {
11997
- replacementNode = nodeToDelete.left;
11998
- if (ignoreCount || nodeToDelete.count <= 1) {
11999
- this._transplant(nodeToDelete, nodeToDelete.left);
12000
- this._count -= nodeToDelete.count;
12001
- } else {
12002
- nodeToDelete.count--;
12003
- this._count--;
12004
- results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12005
- return results;
12006
- }
12552
+ delete(keyNodeOrEntry, ignoreCount = false) {
12553
+ var _a;
12554
+ const deletedResult = [];
12555
+ if (!this.root) return deletedResult;
12556
+ const curr = (_a = this.getNode(keyNodeOrEntry)) != null ? _a : void 0;
12557
+ if (!curr) return deletedResult;
12558
+ const parent = (curr == null ? void 0 : curr.parent) ? curr.parent : void 0;
12559
+ let needBalanced = void 0, orgCurrent = curr;
12560
+ if (curr.count > 1 && !ignoreCount) {
12561
+ curr.count--;
12562
+ this._count--;
12007
12563
  } else {
12008
- const successor = this.getLeftMost((node) => node, nodeToDelete.right);
12009
- if (successor) {
12010
- originalColor = successor.color;
12011
- if (successor.right !== null) replacementNode = successor.right;
12012
- if (successor.parent === nodeToDelete) {
12013
- if (this.isRealNode(replacementNode)) {
12014
- replacementNode.parent = successor;
12015
- }
12564
+ if (!curr.left) {
12565
+ if (!parent) {
12566
+ if (curr.right !== void 0 && curr.right !== null) this._setRoot(curr.right);
12016
12567
  } else {
12017
- if (ignoreCount || nodeToDelete.count <= 1) {
12018
- if (successor.right !== null) {
12019
- this._transplant(successor, successor.right);
12020
- this._count -= nodeToDelete.count;
12021
- }
12022
- } else {
12023
- nodeToDelete.count--;
12024
- this._count--;
12025
- results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12026
- return results;
12027
- }
12028
- successor.right = nodeToDelete.right;
12029
- if (this.isRealNode(successor.right)) {
12030
- successor.right.parent = successor;
12568
+ const { familyPosition: fp } = curr;
12569
+ if (fp === "LEFT" || fp === "ROOT_LEFT") {
12570
+ parent.left = curr.right;
12571
+ } else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
12572
+ parent.right = curr.right;
12031
12573
  }
12574
+ needBalanced = parent;
12032
12575
  }
12033
- if (ignoreCount || nodeToDelete.count <= 1) {
12034
- this._transplant(nodeToDelete, successor);
12035
- this._count -= nodeToDelete.count;
12036
- } else {
12037
- nodeToDelete.count--;
12038
- this._count--;
12039
- results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12040
- return results;
12041
- }
12042
- successor.left = nodeToDelete.left;
12043
- if (this.isRealNode(successor.left)) {
12044
- successor.left.parent = successor;
12576
+ } else {
12577
+ const leftSubTreeRightMost = curr.left ? this.getRightMost((node) => node, curr.left) : void 0;
12578
+ if (leftSubTreeRightMost) {
12579
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
12580
+ orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
12581
+ if (parentOfLeftSubTreeMax) {
12582
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
12583
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
12584
+ } else {
12585
+ parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
12586
+ }
12587
+ needBalanced = parentOfLeftSubTreeMax;
12588
+ }
12045
12589
  }
12046
- successor.color = nodeToDelete.color;
12047
12590
  }
12591
+ this._size = this._size - 1;
12592
+ if (orgCurrent) this._count -= orgCurrent.count;
12048
12593
  }
12049
- this._size--;
12050
- if (originalColor === "BLACK") {
12051
- this._deleteFixup(replacementNode);
12594
+ deletedResult.push({ deleted: orgCurrent, needBalanced });
12595
+ if (needBalanced) {
12596
+ this._balancePath(needBalanced);
12052
12597
  }
12053
- results.push({ deleted: nodeToDelete, needBalanced: void 0 });
12054
- return results;
12598
+ return deletedResult;
12055
12599
  }
12056
12600
  /**
12057
12601
  * Time Complexity: O(1)
@@ -12067,13 +12611,12 @@ var dataStructureTyped = (() => {
12067
12611
  /**
12068
12612
  * Time Complexity: O(n log n)
12069
12613
  * Space Complexity: O(log n)
12070
- *
12071
12614
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
12072
12615
  * tree using either a recursive or iterative approach.
12073
12616
  * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
12074
12617
  * specifies the type of iteration to use when building the balanced binary search tree. It has a
12075
- * default value of `this.iterationType`, which means it will use the iteration type specified by the
12076
- * `iterationType` property of the current object.
12618
+ * default value of `this.iterationType`, which means it will use the iteration type currently set in
12619
+ * the object.
12077
12620
  * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
12078
12621
  * balancing operation is successful, and `false` if there are no nodes to balance.
12079
12622
  */
@@ -12121,40 +12664,89 @@ var dataStructureTyped = (() => {
12121
12664
  */
12122
12665
  clone() {
12123
12666
  const cloned = this.createTree();
12124
- this.bfs((node) => cloned.add(node.key, void 0, node.count));
12667
+ if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
12668
+ else this.bfs((node) => cloned.add(node.key, node.value, node.count));
12125
12669
  if (this._isMapMode) cloned._store = this._store;
12126
12670
  return cloned;
12127
12671
  }
12672
+ /**
12673
+ * The `map` function in TypeScript overrides the default behavior to create a new AVLTreeCounter
12674
+ * with modified entries based on a provided callback.
12675
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
12676
+ * AVLTreeCounter. It takes four arguments:
12677
+ * @param [options] - The `options` parameter in the `override map` function is of type
12678
+ * `AVLTreeCounterOptions<MK, MV, MR>`. This parameter allows you to provide additional
12679
+ * configuration options when creating a new `AVLTreeCounter` instance within the `map` function.
12680
+ * These options
12681
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
12682
+ * the value of `this` when executing the `callback` function. It allows you to set the context
12683
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
12684
+ * or
12685
+ * @returns The `map` method is returning a new `AVLTreeCounter` instance with the entries
12686
+ * transformed by the provided `callback` function. Each entry in the original tree is passed to the
12687
+ * `callback` function along with the index and the original tree itself. The transformed entries are
12688
+ * then added to the new `AVLTreeCounter` instance, which is returned at the end.
12689
+ */
12690
+ map(callback, options, thisArg) {
12691
+ const newTree = new _AVLTreeCounter([], options);
12692
+ let index = 0;
12693
+ for (const [key, value] of this) {
12694
+ newTree.add(callback.call(thisArg, key, value, index++, this));
12695
+ }
12696
+ return newTree;
12697
+ }
12698
+ /**
12699
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
12700
+ * a node object.
12701
+ * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
12702
+ * `keyNodeOrEntry` parameter can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
12703
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
12704
+ * `override` function. It represents the value associated with the key in the data structure. If no
12705
+ * value is provided, it will default to `undefined`.
12706
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
12707
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
12708
+ * @returns either a AVLTreeCounterNode<K, V> object or undefined.
12709
+ */
12710
+ _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count = 1) {
12711
+ if (keyNodeOrEntry === void 0 || keyNodeOrEntry === null) return [void 0, void 0];
12712
+ if (this.isNode(keyNodeOrEntry)) return [keyNodeOrEntry, value];
12713
+ if (this.isEntry(keyNodeOrEntry)) {
12714
+ const [key, entryValue] = keyNodeOrEntry;
12715
+ if (key === void 0 || key === null) return [void 0, void 0];
12716
+ const finalValue = value != null ? value : entryValue;
12717
+ return [this.createNode(key, finalValue, count), finalValue];
12718
+ }
12719
+ return [this.createNode(keyNodeOrEntry, value, count), value];
12720
+ }
12128
12721
  /**
12129
12722
  * Time Complexity: O(1)
12130
12723
  * Space Complexity: O(1)
12131
12724
  *
12132
- * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
12725
+ * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
12133
12726
  * in a binary search tree.
12134
- * @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
12135
- * that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
12136
- * instance of the `BSTNOptKeyOrNode<K, NODE>` class.
12137
- * @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
12727
+ * @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} srcNode - The `srcNode` parameter represents the source node
12728
+ * that will be swapped with the `destNode`.
12729
+ * @param {BSTNOptKeyOrNode<K, AVLTreeCounterNode<K, V>>} destNode - The `destNode` parameter represents the destination
12138
12730
  * node where the properties will be swapped with the source node.
12139
12731
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
12140
- * If either `srcNode` or `destNode` is undefined, it returns undefined.
12732
+ * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
12141
12733
  */
12142
12734
  _swapProperties(srcNode, destNode) {
12143
12735
  srcNode = this.ensureNode(srcNode);
12144
12736
  destNode = this.ensureNode(destNode);
12145
12737
  if (srcNode && destNode) {
12146
- const { key, value, count, color } = destNode;
12147
- const tempNode = this.createNode(key, value, color, count);
12738
+ const { key, value, count, height } = destNode;
12739
+ const tempNode = this.createNode(key, value, count);
12148
12740
  if (tempNode) {
12149
- tempNode.color = color;
12741
+ tempNode.height = height;
12150
12742
  destNode.key = srcNode.key;
12151
12743
  if (!this._isMapMode) destNode.value = srcNode.value;
12152
12744
  destNode.count = srcNode.count;
12153
- destNode.color = srcNode.color;
12745
+ destNode.height = srcNode.height;
12154
12746
  srcNode.key = tempNode.key;
12155
12747
  if (!this._isMapMode) srcNode.value = tempNode.value;
12156
12748
  srcNode.count = tempNode.count;
12157
- srcNode.color = tempNode.color;
12749
+ srcNode.height = tempNode.height;
12158
12750
  }
12159
12751
  return destNode;
12160
12752
  }
@@ -12165,39 +12757,16 @@ var dataStructureTyped = (() => {
12165
12757
  * Space Complexity: O(1)
12166
12758
  *
12167
12759
  * The function replaces an old node with a new node and updates the count property of the new node.
12168
- * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace in the data
12169
- * structure.
12170
- * @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
12760
+ * @param {AVLTreeCounterNode<K, V>} oldNode - The oldNode parameter represents the node that needs to be replaced in the
12761
+ * data structure. It is of type AVLTreeCounterNode<K, V>.
12762
+ * @param {AVLTreeCounterNode<K, V>} newNode - The `newNode` parameter is an instance of the `AVLTreeCounterNode<K, V>` class.
12171
12763
  * @returns The method is returning the result of calling the `_replaceNode` method from the
12172
- * superclass, which is of type `NODE`.
12764
+ * superclass, which is of type `AVLTreeCounterNode<K, V>`.
12173
12765
  */
12174
12766
  _replaceNode(oldNode, newNode) {
12175
12767
  newNode.count = oldNode.count + newNode.count;
12176
12768
  return super._replaceNode(oldNode, newNode);
12177
12769
  }
12178
- /**
12179
- * The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
12180
- * modified entries based on a provided callback.
12181
- * @param callback - The `callback` parameter is a function that will be called for each entry in the
12182
- * map. It takes four arguments:
12183
- * @param [options] - The `options` parameter in the `override map` function is of type
12184
- * `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
12185
- * options when creating a new `TreeMultiMap` instance within the `map` function. These options could
12186
- * include things like
12187
- * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
12188
- * the value of `this` when executing the `callback` function. It allows you to set the context
12189
- * (value of `this`) for the callback function when it is called within the `map` function. This
12190
- * @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
12191
- * by the provided callback function.
12192
- */
12193
- map(callback, options, thisArg) {
12194
- const newTree = new _TreeMultiMap([], options);
12195
- let index = 0;
12196
- for (const [key, value] of this) {
12197
- newTree.add(callback.call(thisArg, key, value, index++, this));
12198
- }
12199
- return newTree;
12200
- }
12201
12770
  };
12202
12771
 
12203
12772
  // src/data-structures/priority-queue/priority-queue.ts