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
@@ -12,17 +12,25 @@ import { DFSOperation, Range } from '../../common';
12
12
  /**
13
13
  * Represents a node in a binary tree.
14
14
  * @template V - The type of data stored in the node.
15
- * @template NODE - The type of the family relationship in the binary tree.
15
+ * @template BinaryTreeNode<K, V> - The type of the family relationship in the binary tree.
16
16
  */
17
17
  export class BinaryTreeNode {
18
- key;
19
- value;
20
- parent;
18
+ /**
19
+ * The constructor function initializes an object with a key and an optional value in TypeScript.
20
+ * @param {K} key - The `key` parameter in the constructor function is used to store the key value
21
+ * for the key-value pair.
22
+ * @param {V} [value] - The `value` parameter in the constructor is optional, meaning it does not
23
+ * have to be provided when creating an instance of the class. If a `value` is not provided, it will
24
+ * default to `undefined`.
25
+ */
21
26
  constructor(key, value) {
22
27
  this.key = key;
23
28
  this.value = value;
24
29
  }
25
- _left;
30
+ key;
31
+ value;
32
+ parent = undefined;
33
+ _left = undefined;
26
34
  get left() {
27
35
  return this._left;
28
36
  }
@@ -32,7 +40,7 @@ export class BinaryTreeNode {
32
40
  }
33
41
  this._left = v;
34
42
  }
35
- _right;
43
+ _right = undefined;
36
44
  get right() {
37
45
  return this._right;
38
46
  }
@@ -64,14 +72,13 @@ export class BinaryTreeNode {
64
72
  this._count = value;
65
73
  }
66
74
  get familyPosition() {
67
- const that = this;
68
75
  if (!this.parent) {
69
76
  return this.left || this.right ? 'ROOT' : 'ISOLATED';
70
77
  }
71
- if (this.parent.left === that) {
78
+ if (this.parent.left === this) {
72
79
  return this.left || this.right ? 'ROOT_LEFT' : 'LEFT';
73
80
  }
74
- else if (this.parent.right === that) {
81
+ else if (this.parent.right === this) {
75
82
  return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
76
83
  }
77
84
  return 'MAL_NODE';
@@ -85,15 +92,14 @@ export class BinaryTreeNode {
85
92
  * 5. Leaf Nodes: Nodes without children are leaves.
86
93
  */
87
94
  export class BinaryTree extends IterableEntryBase {
88
- iterationType = 'ITERATIVE';
89
95
  /**
90
- * The constructor initializes a binary tree with optional options and adds keys, nodes, entries, or
91
- * raw data if provided.
92
- * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor
93
- * is an iterable that can contain elements of type `BTNRep<K, V, NODE>` or `R`. It is
94
- * initialized with an empty array `[]` by default.
95
- * @param [options] - The `options` parameter in the constructor is an object that can contain the
96
- * following properties:
96
+ * This TypeScript constructor function initializes a binary tree with optional options and adds
97
+ * elements based on the provided input.
98
+ * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
99
+ * iterable that can contain either objects of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
100
+ * is used to initialize the binary tree with keys, nodes, entries, or raw data.
101
+ * @param [options] - The `options` parameter in the constructor is an optional object that can
102
+ * contain the following properties:
97
103
  */
98
104
  constructor(keysNodesEntriesOrRaws = [], options) {
99
105
  super();
@@ -111,6 +117,7 @@ export class BinaryTree extends IterableEntryBase {
111
117
  if (keysNodesEntriesOrRaws)
112
118
  this.addMany(keysNodesEntriesOrRaws);
113
119
  }
120
+ iterationType = 'ITERATIVE';
114
121
  _isMapMode = true;
115
122
  get isMapMode() {
116
123
  return this._isMapMode;
@@ -145,12 +152,15 @@ export class BinaryTree extends IterableEntryBase {
145
152
  * not required to be provided when calling the function. If a `value` is provided, it should be of
146
153
  * type `V`, which is the type of the value associated with the node.
147
154
  * @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
148
- * as NODE.
155
+ * as BinaryTreeNode<K, V>.
149
156
  */
150
157
  createNode(key, value) {
151
158
  return new BinaryTreeNode(key, this._isMapMode ? undefined : value);
152
159
  }
153
160
  /**
161
+ * Time Complexity: O(1)
162
+ * Space Complexity: O(1)
163
+ *
154
164
  * The function creates a binary tree with the specified options.
155
165
  * @param [options] - The `options` parameter in the `createTree` function is an optional parameter
156
166
  * that allows you to provide partial configuration options for creating a binary tree. It is of type
@@ -166,55 +176,14 @@ export class BinaryTree extends IterableEntryBase {
166
176
  ...options
167
177
  });
168
178
  }
169
- /**
170
- * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
171
- * or returns null.
172
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
173
- * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
174
- * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
175
- * node, an entry
176
- * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
177
- * an optional parameter of type `V`. It represents the value associated with the key in the node
178
- * being created. If a `value` is provided, it will be used when creating the node. If
179
- * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
180
- * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
181
- * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
182
- * value.
183
- */
184
- _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
185
- if (keyNodeEntryOrRaw === undefined)
186
- return [undefined, undefined];
187
- if (keyNodeEntryOrRaw === null)
188
- return [null, undefined];
189
- if (this.isNode(keyNodeEntryOrRaw))
190
- return [keyNodeEntryOrRaw, value];
191
- if (this.isEntry(keyNodeEntryOrRaw)) {
192
- const [key, entryValue] = keyNodeEntryOrRaw;
193
- if (key === undefined)
194
- return [undefined, undefined];
195
- else if (key === null)
196
- return [null, undefined];
197
- const finalValue = value ?? entryValue;
198
- return [this.createNode(key, finalValue), finalValue];
199
- }
200
- if (this.isRaw(keyNodeEntryOrRaw)) {
201
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
202
- const finalValue = value ?? entryValue;
203
- if (this.isKey(key))
204
- return [this.createNode(key, finalValue), finalValue];
205
- }
206
- if (this.isKey(keyNodeEntryOrRaw))
207
- return [this.createNode(keyNodeEntryOrRaw, value), value];
208
- return [undefined, undefined];
209
- }
210
179
  /**
211
180
  * Time Complexity: O(n)
212
181
  * Space Complexity: O(log n)
213
182
  *
214
183
  * The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
215
184
  * value and returns the corresponding node or null.
216
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
217
- * parameter in the `ensureNode` function can be of type `BTNRep<K, V, NODE>` or `R`. It
185
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
186
+ * parameter in the `ensureNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
218
187
  * is used to determine whether the input is a key, node, entry, or raw data. The
219
188
  * @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
220
189
  * is used to specify the type of iteration to be performed. It has a default value of
@@ -222,49 +191,48 @@ export class BinaryTree extends IterableEntryBase {
222
191
  * @returns The `ensureNode` function returns either a node, `null`, or `undefined` based on the
223
192
  * conditions specified in the code snippet.
224
193
  */
225
- ensureNode(keyNodeEntryOrRaw, iterationType = this.iterationType) {
226
- if (keyNodeEntryOrRaw === null)
194
+ ensureNode(keyNodeOrEntry, iterationType = this.iterationType) {
195
+ if (keyNodeOrEntry === null)
227
196
  return null;
228
- if (keyNodeEntryOrRaw === undefined)
197
+ if (keyNodeOrEntry === undefined)
229
198
  return;
230
- if (keyNodeEntryOrRaw === this._NIL)
199
+ if (keyNodeOrEntry === this._NIL)
231
200
  return;
232
- if (this.isNode(keyNodeEntryOrRaw))
233
- return keyNodeEntryOrRaw;
234
- if (this.isEntry(keyNodeEntryOrRaw)) {
235
- const key = keyNodeEntryOrRaw[0];
201
+ if (this.isNode(keyNodeOrEntry))
202
+ return keyNodeOrEntry;
203
+ if (this.isEntry(keyNodeOrEntry)) {
204
+ const key = keyNodeOrEntry[0];
236
205
  if (key === null)
237
206
  return null;
238
207
  if (key === undefined)
239
208
  return;
240
209
  return this.getNode(key, this._root, iterationType);
241
210
  }
242
- if (this._toEntryFn) {
243
- const [key] = this._toEntryFn(keyNodeEntryOrRaw);
244
- if (this.isKey(key))
245
- return this.getNode(key);
246
- }
247
- if (this.isKey(keyNodeEntryOrRaw))
248
- return this.getNode(keyNodeEntryOrRaw, this._root, iterationType);
249
- return;
211
+ return this.getNode(keyNodeOrEntry, this._root, iterationType);
250
212
  }
251
213
  /**
214
+ * Time Complexity: O(1)
215
+ * Space Complexity: O(1)
216
+ *
252
217
  * The function isNode checks if the input is an instance of BinaryTreeNode.
253
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
254
- * `keyNodeEntryOrRaw` can be either a key, a node, an entry, or raw data. The function is
218
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
219
+ * `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
255
220
  * checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
256
221
  * accordingly.
257
- * @returns The function `isNode` is checking if the input `keyNodeEntryOrRaw` is an instance of
222
+ * @returns The function `isNode` is checking if the input `keyNodeOrEntry` is an instance of
258
223
  * `BinaryTreeNode`. If it is, the function returns `true`, indicating that the input is a node. If
259
224
  * it is not an instance of `BinaryTreeNode`, the function returns `false`, indicating that the input
260
225
  * is not a node.
261
226
  */
262
- isNode(keyNodeEntryOrRaw) {
263
- return keyNodeEntryOrRaw instanceof BinaryTreeNode;
227
+ isNode(keyNodeOrEntry) {
228
+ return keyNodeOrEntry instanceof BinaryTreeNode;
264
229
  }
265
230
  /**
231
+ * Time Complexity: O(1)
232
+ * Space Complexity: O(1)
233
+ *
266
234
  * The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
267
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V, NODE> | R
235
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
268
236
  * @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
269
237
  * checking if it is an object. If the parameter is an object, the function will return `true`,
270
238
  * indicating that it is of type `R`.
@@ -273,88 +241,117 @@ export class BinaryTree extends IterableEntryBase {
273
241
  return this._toEntryFn !== undefined && typeof keyNodeEntryOrRaw === 'object';
274
242
  }
275
243
  /**
244
+ * Time Complexity: O(1)
245
+ * Space Complexity: O(1)
246
+ *
276
247
  * The function `isRealNode` checks if a given input is a valid node in a binary tree.
277
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
278
- * parameter in the `isRealNode` function can be of type `BTNRep<K, V, NODE>` or `R`.
279
- * The function checks if the input parameter is a `NODE` type by verifying if it is not equal
280
- * @returns The function `isRealNode` is checking if the input `keyNodeEntryOrRaw` is a valid
248
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
249
+ * parameter in the `isRealNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
250
+ * The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
251
+ * @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
281
252
  * node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
282
253
  * values, it then calls the `isNode` method to further determine if the input is a node. The
283
254
  * function will return a boolean value indicating whether the
284
255
  */
285
- isRealNode(keyNodeEntryOrRaw) {
286
- if (keyNodeEntryOrRaw === this._NIL || keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === undefined)
256
+ isRealNode(keyNodeOrEntry) {
257
+ if (keyNodeOrEntry === this._NIL || keyNodeOrEntry === null || keyNodeOrEntry === undefined)
287
258
  return false;
288
- return this.isNode(keyNodeEntryOrRaw);
259
+ return this.isNode(keyNodeOrEntry);
289
260
  }
290
261
  /**
262
+ * Time Complexity: O(1)
263
+ * Space Complexity: O(1)
264
+ *
291
265
  * The function checks if a given input is a valid node or null.
292
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
293
- * `keyNodeEntryOrRaw` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
294
- * V, NODE>` or `R`. It is a union type that can either be a key, a node, an entry, or
266
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
267
+ * `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
268
+ * V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
295
269
  * @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
296
- * `keyNodeEntryOrRaw` is either `null` or a real node, and returns `true` if it is a node or
270
+ * `keyNodeOrEntry` is either `null` or a real node, and returns `true` if it is a node or
297
271
  * `null`, and `false` otherwise.
298
272
  */
299
- isRealNodeOrNull(keyNodeEntryOrRaw) {
300
- return keyNodeEntryOrRaw === null || this.isRealNode(keyNodeEntryOrRaw);
273
+ isRealNodeOrNull(keyNodeOrEntry) {
274
+ return keyNodeOrEntry === null || this.isRealNode(keyNodeOrEntry);
301
275
  }
302
276
  /**
277
+ * Time Complexity: O(1)
278
+ * Space Complexity: O(1)
279
+ *
303
280
  * The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
304
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - BTNRep<K, V,
305
- * NODE> | R
306
- * @returns The function is checking if the `keyNodeEntryOrRaw` parameter is equal to the `_NIL`
281
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - BTNRep<K, V,
282
+ * BinaryTreeNode<K, V>>
283
+ * @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
307
284
  * property of the current object and returning a boolean value based on that comparison.
308
285
  */
309
- isNIL(keyNodeEntryOrRaw) {
310
- return keyNodeEntryOrRaw === this._NIL;
286
+ isNIL(keyNodeOrEntry) {
287
+ return keyNodeOrEntry === this._NIL;
311
288
  }
312
- isRange(keyNodeEntryRawOrPredicate) {
313
- return keyNodeEntryRawOrPredicate instanceof Range;
289
+ /**
290
+ * Time Complexity: O(1)
291
+ * Space Complexity: O(1)
292
+ *
293
+ * The function `isRange` checks if the input parameter is an instance of the `Range` class.
294
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>}
295
+ * keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
296
+ * of type `BTNRep<K, V, BinaryTreeNode<K, V>>`, `NodePredicate<BinaryTreeNode<K, V>>`, or
297
+ * `Range<K>`. The function checks if the `keyNodeEntry
298
+ * @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
299
+ * instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
300
+ * indicating that the parameter is a `Range<K>`. If it is not an instance of `Range`, the function
301
+ * will return `false`.
302
+ */
303
+ isRange(keyNodeEntryOrPredicate) {
304
+ return keyNodeEntryOrPredicate instanceof Range;
314
305
  }
315
306
  /**
307
+ * Time Complexity: O(1)
308
+ * Space Complexity: O(1)
309
+ *
316
310
  * The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
317
311
  * tree.
318
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
319
- * `keyNodeEntryOrRaw` can be of type `BTNRep<K, V, NODE>` or `R`. It represents a
312
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
313
+ * `keyNodeOrEntry` can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It represents a
320
314
  * key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
321
315
  * provided
322
316
  * @returns The function `isLeaf` returns a boolean value indicating whether the input
323
- * `keyNodeEntryOrRaw` is a leaf node in a binary tree.
317
+ * `keyNodeOrEntry` is a leaf node in a binary tree.
324
318
  */
325
- isLeaf(keyNodeEntryOrRaw) {
326
- keyNodeEntryOrRaw = this.ensureNode(keyNodeEntryOrRaw);
327
- if (keyNodeEntryOrRaw === undefined)
319
+ isLeaf(keyNodeOrEntry) {
320
+ keyNodeOrEntry = this.ensureNode(keyNodeOrEntry);
321
+ if (keyNodeOrEntry === undefined)
328
322
  return false;
329
- if (keyNodeEntryOrRaw === null)
323
+ if (keyNodeOrEntry === null)
330
324
  return true;
331
- return !this.isRealNode(keyNodeEntryOrRaw.left) && !this.isRealNode(keyNodeEntryOrRaw.right);
325
+ return !this.isRealNode(keyNodeOrEntry.left) && !this.isRealNode(keyNodeOrEntry.right);
332
326
  }
333
327
  /**
328
+ * Time Complexity: O(1)
329
+ * Space Complexity: O(1)
330
+ *
334
331
  * The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
335
332
  * with a length of 2.
336
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
337
- * parameter in the `isEntry` function can be of type `BTNRep<K, V, NODE>` or type `R`.
338
- * The function checks if the provided `keyNodeEntryOrRaw` is of type `BTN
339
- * @returns The `isEntry` function is checking if the `keyNodeEntryOrRaw` parameter is an array
333
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
334
+ * parameter in the `isEntry` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or type `R`.
335
+ * The function checks if the provided `keyNodeOrEntry` is of type `BTN
336
+ * @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
340
337
  * with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
341
338
  * `BTNEntry<K, V>`. If the condition is not met, it returns `false`.
342
339
  */
343
- isEntry(keyNodeEntryOrRaw) {
344
- return Array.isArray(keyNodeEntryOrRaw) && keyNodeEntryOrRaw.length === 2;
340
+ isEntry(keyNodeOrEntry) {
341
+ return Array.isArray(keyNodeOrEntry) && keyNodeOrEntry.length === 2;
345
342
  }
346
343
  /**
347
344
  * Time Complexity O(1)
348
345
  * Space Complexity O(1)
349
346
  *
350
- * The function `isKey` checks if a given key is comparable.
347
+ * The function `isValidKey` checks if a given key is comparable.
351
348
  * @param {any} key - The `key` parameter is of type `any`, which means it can be any data type in
352
349
  * TypeScript.
353
- * @returns The function `isKey` is checking if the `key` parameter is `null` or if it is comparable.
350
+ * @returns The function `isValidKey` is checking if the `key` parameter is `null` or if it is comparable.
354
351
  * If the `key` is `null`, the function returns `true`. Otherwise, it returns the result of the
355
352
  * `isComparable` function, which is not provided in the code snippet.
356
353
  */
357
- isKey(key) {
354
+ isValidKey(key) {
358
355
  if (key === null)
359
356
  return true;
360
357
  return isComparable(key);
@@ -365,8 +362,8 @@ export class BinaryTree extends IterableEntryBase {
365
362
  *
366
363
  * The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
367
364
  * and finding the correct insertion position.
368
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `add` method you provided
369
- * seems to be for adding a new node to a binary tree structure. The `keyNodeEntryOrRaw`
365
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `add` method you provided
366
+ * seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
370
367
  * parameter in the method can accept different types of values:
371
368
  * @param {V} [value] - The `value` parameter in the `add` method represents the value associated
372
369
  * with the key that you want to add to the binary tree. When adding a key-value pair to the binary
@@ -376,8 +373,8 @@ export class BinaryTree extends IterableEntryBase {
376
373
  * node was successful, and `false` if the insertion position could not be found or if a duplicate
377
374
  * key was found and the node was replaced instead of inserted.
378
375
  */
379
- add(keyNodeEntryOrRaw, value) {
380
- const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
376
+ add(keyNodeOrEntry, value) {
377
+ const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
381
378
  if (newNode === undefined)
382
379
  return false;
383
380
  // If the tree is empty, directly set the new node as the root node
@@ -432,14 +429,14 @@ export class BinaryTree extends IterableEntryBase {
432
429
  }
433
430
  /**
434
431
  * Time Complexity: O(k * n)
435
- * Space Complexity: O(1)
432
+ * Space Complexity: O(k)
436
433
  *
437
434
  * The `addMany` function takes in multiple keys or nodes or entries or raw values along with
438
435
  * optional values, and adds them to a data structure while returning an array indicating whether
439
436
  * each insertion was successful.
440
437
  * @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
441
438
  * mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
442
- * `BTNRep<K, V, NODE>` or `R`.
439
+ * `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
443
440
  * @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
444
441
  * accepts an iterable of values. These values correspond to the keys or nodes being added in the
445
442
  * `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
@@ -455,7 +452,7 @@ export class BinaryTree extends IterableEntryBase {
455
452
  if (values) {
456
453
  valuesIterator = values[Symbol.iterator]();
457
454
  }
458
- for (const keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
455
+ for (let keyNodeEntryOrRaw of keysNodesEntriesOrRaws) {
459
456
  let value = undefined;
460
457
  if (valuesIterator) {
461
458
  const valueResult = valuesIterator.next();
@@ -463,6 +460,8 @@ export class BinaryTree extends IterableEntryBase {
463
460
  value = valueResult.value;
464
461
  }
465
462
  }
463
+ if (this.isRaw(keyNodeEntryOrRaw))
464
+ keyNodeEntryOrRaw = this._toEntryFn(keyNodeEntryOrRaw);
466
465
  inserted.push(this.add(keyNodeEntryOrRaw, value));
467
466
  }
468
467
  return inserted;
@@ -473,7 +472,7 @@ export class BinaryTree extends IterableEntryBase {
473
472
  *
474
473
  * The `merge` function in TypeScript merges another binary tree into the current tree by adding all
475
474
  * elements from the other tree.
476
- * @param anotherTree - `BinaryTree<K, V, R, NODE, TREE>`
475
+ * @param anotherTree - BinaryTree<K, V, R, MK, MV, MR>
477
476
  */
478
477
  merge(anotherTree) {
479
478
  this.addMany(anotherTree, []);
@@ -485,7 +484,7 @@ export class BinaryTree extends IterableEntryBase {
485
484
  * The `refill` function clears the existing data structure and then adds new key-value pairs based
486
485
  * on the provided input.
487
486
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
488
- * method can accept an iterable containing a mix of `BTNRep<K, V, NODE>` objects or `R`
487
+ * method can accept an iterable containing a mix of `BTNRep<K, V, BinaryTreeNode<K, V>>` objects or `R`
489
488
  * objects.
490
489
  * @param [values] - The `values` parameter in the `refill` method is an optional parameter that
491
490
  * accepts an iterable of values of type `V` or `undefined`.
@@ -500,7 +499,7 @@ export class BinaryTree extends IterableEntryBase {
500
499
  *
501
500
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
502
501
  * the deleted node along with information for tree balancing.
503
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw
502
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
504
503
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
505
504
  * node, entry or raw data. The method returns an array of
506
505
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
@@ -509,11 +508,11 @@ export class BinaryTree extends IterableEntryBase {
509
508
  * the array contains information about the node that was deleted (`deleted`) and the node that may
510
509
  * need to be balanced (`needBalanced`).
511
510
  */
512
- delete(keyNodeEntryOrRaw) {
511
+ delete(keyNodeOrEntry) {
513
512
  const deletedResult = [];
514
513
  if (!this._root)
515
514
  return deletedResult;
516
- const curr = this.getNode(keyNodeEntryOrRaw);
515
+ const curr = this.getNode(keyNodeOrEntry);
517
516
  if (!curr)
518
517
  return deletedResult;
519
518
  const parent = curr?.parent;
@@ -562,15 +561,15 @@ export class BinaryTree extends IterableEntryBase {
562
561
  *
563
562
  * The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
564
563
  * structure based on a given predicate or key, with options to return multiple results or just one.
565
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
566
- * `keyNodeEntryRawOrPredicate` parameter in the `search` function can accept three types of values:
564
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
565
+ * `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
567
566
  * @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
568
567
  * determines whether the search should stop after finding the first matching node. If `onlyOne` is
569
568
  * set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
570
569
  * @param {C} callback - The `callback` parameter in the `search` function is a callback function
571
570
  * that will be called on each node that matches the search criteria. It is of type `C`, which
572
- * extends `NodeCallback<NODE>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
573
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `search` function is
571
+ * extends `NodeCallback<BinaryTreeNode<K, V>>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
572
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `search` function is
574
573
  * used to specify the node from which the search operation should begin. It represents the starting
575
574
  * point in the binary tree where the search will be performed. If no specific `startNode` is
576
575
  * provided, the search operation will start from the root
@@ -580,15 +579,15 @@ export class BinaryTree extends IterableEntryBase {
580
579
  * @returns The `search` function returns an array of values that match the provided criteria based
581
580
  * on the search algorithm implemented within the function.
582
581
  */
583
- search(keyNodeEntryRawOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
584
- if (keyNodeEntryRawOrPredicate === undefined)
582
+ search(keyNodeEntryOrPredicate, onlyOne = false, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
583
+ if (keyNodeEntryOrPredicate === undefined)
585
584
  return [];
586
- if (keyNodeEntryRawOrPredicate === null)
585
+ if (keyNodeEntryOrPredicate === null)
587
586
  return [];
588
587
  startNode = this.ensureNode(startNode);
589
588
  if (!startNode)
590
589
  return [];
591
- const predicate = this._ensurePredicate(keyNodeEntryRawOrPredicate);
590
+ const predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
592
591
  const ans = [];
593
592
  if (iterationType === 'RECURSIVE') {
594
593
  const dfs = (cur) => {
@@ -631,12 +630,12 @@ export class BinaryTree extends IterableEntryBase {
631
630
  *
632
631
  * The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
633
632
  * or predicate, with options for recursive or iterative traversal.
634
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
633
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
635
634
  * - The `getNodes` function you provided takes several parameters:
636
635
  * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
637
636
  * determines whether to return only the first node that matches the criteria specified by the
638
- * `keyNodeEntryRawOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
639
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
637
+ * `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
638
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
640
639
  * `getNodes` function is used to specify the starting point for traversing the binary tree. It
641
640
  * represents the root node of the binary tree or the node from which the traversal should begin. If
642
641
  * not provided, the default value is set to `this._root
@@ -646,19 +645,19 @@ export class BinaryTree extends IterableEntryBase {
646
645
  * @returns The `getNodes` function returns an array of nodes that satisfy the provided condition
647
646
  * based on the input parameters and the iteration type specified.
648
647
  */
649
- getNodes(keyNodeEntryRawOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
650
- return this.search(keyNodeEntryRawOrPredicate, onlyOne, node => node, startNode, iterationType);
648
+ getNodes(keyNodeEntryOrPredicate, onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
649
+ return this.search(keyNodeEntryOrPredicate, onlyOne, node => node, startNode, iterationType);
651
650
  }
652
651
  /**
653
652
  * Time Complexity: O(n)
654
- * Space Complexity: O(log n).
653
+ * Space Complexity: O(log n)
655
654
  *
656
655
  * The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
657
656
  * predicate.
658
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
659
- * - The `keyNodeEntryRawOrPredicate` parameter in the `getNode` function can accept a key,
657
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
658
+ * - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
660
659
  * node, entry, raw data, or a predicate function.
661
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
660
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
662
661
  * `getNode` function is used to specify the starting point for searching for a node in a binary
663
662
  * tree. If no specific starting point is provided, the default value is set to `this._root`, which
664
663
  * is typically the root node of the binary tree.
@@ -669,8 +668,8 @@ export class BinaryTree extends IterableEntryBase {
669
668
  * @returns The `getNode` function is returning the first node that matches the specified criteria,
670
669
  * or `null` if no matching node is found.
671
670
  */
672
- getNode(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
673
- return this.search(keyNodeEntryRawOrPredicate, true, node => node, startNode, iterationType)[0] ?? null;
671
+ getNode(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
672
+ return this.search(keyNodeEntryOrPredicate, true, node => node, startNode, iterationType)[0];
674
673
  }
675
674
  /**
676
675
  * Time Complexity: O(n)
@@ -678,10 +677,10 @@ export class BinaryTree extends IterableEntryBase {
678
677
  *
679
678
  * This function overrides the `get` method to retrieve the value associated with a specified key,
680
679
  * node, entry, raw data, or predicate in a data structure.
681
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
682
- * - The `keyNodeEntryRawOrPredicate` parameter in the `get` method can accept one of the
680
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
681
+ * - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
683
682
  * following types:
684
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `get`
683
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
685
684
  * method is used to specify the starting point for searching for a key or node in the binary tree.
686
685
  * If no specific starting point is provided, the default starting point is the root of the binary
687
686
  * tree (`this._root`).
@@ -694,14 +693,14 @@ export class BinaryTree extends IterableEntryBase {
694
693
  * the method returns the corresponding value. If the key or node is not found, it returns
695
694
  * `undefined`.
696
695
  */
697
- get(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
696
+ get(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
698
697
  if (this._isMapMode) {
699
- const key = this._extractKey(keyNodeEntryRawOrPredicate);
698
+ const key = this._extractKey(keyNodeEntryOrPredicate);
700
699
  if (key === null || key === undefined)
701
700
  return;
702
701
  return this._store.get(key);
703
702
  }
704
- return this.getNode(keyNodeEntryRawOrPredicate, startNode, iterationType)?.value;
703
+ return this.getNode(keyNodeEntryOrPredicate, startNode, iterationType)?.value;
705
704
  }
706
705
  /**
707
706
  * Time Complexity: O(n)
@@ -709,10 +708,10 @@ export class BinaryTree extends IterableEntryBase {
709
708
  *
710
709
  * The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
711
710
  * exists in the data structure.
712
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate
713
- * - The `keyNodeEntryRawOrPredicate` parameter in the `override has` method can accept one of
711
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
712
+ * - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
714
713
  * the following types:
715
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
714
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
716
715
  * `override` method is used to specify the starting point for the search operation within the data
717
716
  * structure. It defaults to `this._root` if not provided explicitly.
718
717
  * @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
@@ -724,14 +723,14 @@ export class BinaryTree extends IterableEntryBase {
724
723
  * are matching nodes, it returns `true`, indicating that the tree contains the specified element.
725
724
  * Otherwise, it returns `false`.
726
725
  */
727
- has(keyNodeEntryRawOrPredicate, startNode = this._root, iterationType = this.iterationType) {
728
- return this.search(keyNodeEntryRawOrPredicate, true, node => node, startNode, iterationType).length > 0;
726
+ has(keyNodeEntryOrPredicate, startNode = this._root, iterationType = this.iterationType) {
727
+ return this.search(keyNodeEntryOrPredicate, true, node => node, startNode, iterationType).length > 0;
729
728
  }
730
729
  /**
731
730
  * Time Complexity: O(1)
732
731
  * Space Complexity: O(1)
733
732
  *
734
- * The `clear` function resets the root node and size of a data structure to empty.
733
+ * The clear function removes nodes and values in map mode.
735
734
  */
736
735
  clear() {
737
736
  this._clearNodes();
@@ -756,7 +755,7 @@ export class BinaryTree extends IterableEntryBase {
756
755
  *
757
756
  * The function checks if a binary tree is perfectly balanced by comparing its minimum height with
758
757
  * its height.
759
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
758
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
760
759
  * point for checking if the binary tree is perfectly balanced. It represents the root node of the
761
760
  * binary tree or a specific node from which the balance check should begin.
762
761
  * @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
@@ -770,11 +769,11 @@ export class BinaryTree extends IterableEntryBase {
770
769
  }
771
770
  /**
772
771
  * Time Complexity: O(n)
773
- * Space Complexity: O(1)
772
+ * Space Complexity: O(log n)
774
773
  *
775
774
  * The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
776
775
  * or iterative methods.
777
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `isBST`
776
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
778
777
  * function represents the starting point for checking whether a binary search tree (BST) is valid.
779
778
  * It can be a node in the BST or a reference to the root of the BST. If no specific node is
780
779
  * provided, the function will default to
@@ -830,13 +829,13 @@ export class BinaryTree extends IterableEntryBase {
830
829
  }
831
830
  /**
832
831
  * Time Complexity: O(n)
833
- * Space Complexity: O(1)
832
+ * Space Complexity: O(log n)
834
833
  *
835
834
  * The `getDepth` function calculates the depth between two nodes in a binary tree.
836
- * @param {BTNRep<K, V, NODE> | R} dist - The `dist` parameter in the `getDepth`
835
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
837
836
  * function represents the node or entry in a binary tree map, or a reference to a node in the tree.
838
837
  * It is the target node for which you want to calculate the depth from the `startNode` node.
839
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
838
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
840
839
  * `getDepth` function represents the starting point from which you want to calculate the depth of a
841
840
  * given node or entry in a binary tree. If no specific starting point is provided, the default value
842
841
  * for `startNode` is set to the root of the binary
@@ -859,11 +858,11 @@ export class BinaryTree extends IterableEntryBase {
859
858
  }
860
859
  /**
861
860
  * Time Complexity: O(n)
862
- * Space Complexity: O(1)
861
+ * Space Complexity: O(log n)
863
862
  *
864
863
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
865
864
  * or iterative approach in TypeScript.
866
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter is the starting
865
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
867
866
  * point from which the height of the binary tree will be calculated. It can be a node in the binary
868
867
  * tree or a reference to the root of the tree. If not provided, it defaults to the root of the
869
868
  * binary tree data structure.
@@ -908,7 +907,7 @@ export class BinaryTree extends IterableEntryBase {
908
907
  *
909
908
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
910
909
  * recursive or iterative approach in TypeScript.
911
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
910
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
912
911
  * `getMinHeight` function represents the starting node from which the minimum height of the binary
913
912
  * tree will be calculated. It is either a node in the binary tree or a reference to the root of the
914
913
  * tree. If not provided, the default value is the root
@@ -974,7 +973,7 @@ export class BinaryTree extends IterableEntryBase {
974
973
  * the path to the root. It is expected to be a function that takes a node as an argument and returns
975
974
  * a value based on that node. The return type of the callback function is determined by the generic
976
975
  * type `C
977
- * @param {BTNRep<K, V, NODE> | R} beginNode - The `beginNode` parameter in the
976
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
978
977
  * `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
979
978
  * @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
980
979
  * whether the resulting path from the given `beginNode` to the root should be in reverse order or
@@ -999,14 +998,14 @@ export class BinaryTree extends IterableEntryBase {
999
998
  }
1000
999
  /**
1001
1000
  * Time Complexity: O(log n)
1002
- * Space Complexity: O(1)
1001
+ * Space Complexity: O(log n)
1003
1002
  *
1004
1003
  * The function `getLeftMost` retrieves the leftmost node in a binary tree using either recursive or
1005
1004
  * tail-recursive iteration.
1006
1005
  * @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
1007
1006
  * node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
1008
1007
  * value of `_DEFAULT_NODE_CALLBACK` if not specified.
1009
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
1008
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
1010
1009
  * `getLeftMost` function represents the starting point for finding the leftmost node in a binary
1011
1010
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
1012
1011
  * starting point is provided, the function will default
@@ -1044,15 +1043,15 @@ export class BinaryTree extends IterableEntryBase {
1044
1043
  }
1045
1044
  /**
1046
1045
  * Time Complexity: O(log n)
1047
- * Space Complexity: O(1)
1046
+ * Space Complexity: O(log n)
1048
1047
  *
1049
1048
  * The function `getRightMost` retrieves the rightmost node in a binary tree using either recursive
1050
1049
  * or iterative traversal methods.
1051
1050
  * @param {C} callback - The `callback` parameter is a function that will be called with the result
1052
- * of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<NODE>>`,
1051
+ * of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
1053
1052
  * which means it is a callback function that can accept either an optional binary tree node or null
1054
1053
  * as
1055
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
1054
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
1056
1055
  * `getRightMost` function represents the starting point for finding the rightmost node in a binary
1057
1056
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
1058
1057
  * starting point is provided, the function will default
@@ -1090,14 +1089,14 @@ export class BinaryTree extends IterableEntryBase {
1090
1089
  }
1091
1090
  /**
1092
1091
  * Time Complexity: O(log n)
1093
- * Space Complexity: O(1)
1092
+ * Space Complexity: O(log n)
1094
1093
  *
1095
1094
  * The function `getPredecessor` in TypeScript returns the predecessor node of a given node in a
1096
1095
  * binary tree.
1097
- * @param {NODE} node - The `getPredecessor` function you provided seems to be attempting to find the
1096
+ * @param {BinaryTreeNode<K, V>} node - The `getPredecessor` function you provided seems to be attempting to find the
1098
1097
  * predecessor of a given node in a binary tree. However, there seems to be a logical issue in the
1099
1098
  * while loop condition that might cause an infinite loop.
1100
- * @returns The `getPredecessor` function returns the predecessor node of the input `NODE` parameter.
1099
+ * @returns The `getPredecessor` function returns the predecessor node of the input `BinaryTreeNode<K, V>` parameter.
1101
1100
  * If the left child of the input node exists, it traverses to the rightmost node of the left subtree
1102
1101
  * to find the predecessor. If the left child does not exist, it returns the input node itself.
1103
1102
  */
@@ -1117,12 +1116,12 @@ export class BinaryTree extends IterableEntryBase {
1117
1116
  }
1118
1117
  /**
1119
1118
  * Time Complexity: O(log n)
1120
- * Space Complexity: O(1)
1119
+ * Space Complexity: O(log n)
1121
1120
  *
1122
1121
  * The function `getSuccessor` in TypeScript returns the next node in an in-order traversal of a
1123
1122
  * binary tree.
1124
- * @param {K | NODE | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
1125
- * type `K`, `NODE`, or `null`.
1123
+ * @param {K | BinaryTreeNode<K, V> | null} [x] - The `getSuccessor` function takes a parameter `x`, which can be of
1124
+ * type `K`, `BinaryTreeNode<K, V>`, or `null`.
1126
1125
  * @returns The `getSuccessor` function returns the successor node of the input node `x`. If `x` has
1127
1126
  * a right child, the function returns the leftmost node in the right subtree of `x`. If `x` does not
1128
1127
  * have a right child, the function traverses up the parent nodes until it finds a node that is not
@@ -1149,12 +1148,12 @@ export class BinaryTree extends IterableEntryBase {
1149
1148
  * The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
1150
1149
  * specified parameters.
1151
1150
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends the
1152
- * `NodeCallback` interface with a type parameter of `OptNodeOrNull<NODE>`. It has a default value of
1151
+ * `NodeCallback` interface with a type parameter of `OptNodeOrNull<BinaryTreeNode<K, V>>`. It has a default value of
1153
1152
  * `this._DEFAULT_NODE_CALLBACK as C`.
1154
1153
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
1155
1154
  * order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
1156
1155
  * possible values for the `pattern` parameter are:
1157
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `dfs`
1156
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `dfs`
1158
1157
  * method is used to specify the starting point for the Depth-First Search traversal. It can be
1159
1158
  * either a `BTNRep` object representing a key, node, or entry in the binary tree map,
1160
1159
  * or it can be a
@@ -1182,8 +1181,8 @@ export class BinaryTree extends IterableEntryBase {
1182
1181
  * tree, executing a specified callback function on each node visited.
1183
1182
  * @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
1184
1183
  * called on each node visited during the breadth-first search traversal. It is a generic type `C`
1185
- * that extends the `NodeCallback` type, which takes a parameter of type `NODE` or `null`.
1186
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `bfs`
1184
+ * that extends the `NodeCallback` type, which takes a parameter of type `BinaryTreeNode<K, V>` or `null`.
1185
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `bfs`
1187
1186
  * function represents the starting point for the breadth-first search traversal in a binary tree. It
1188
1187
  * can be specified as a key, node, or entry in the binary tree structure. If not provided, the
1189
1188
  * default value is the root node of the binary
@@ -1203,7 +1202,9 @@ export class BinaryTree extends IterableEntryBase {
1203
1202
  return [];
1204
1203
  const ans = [];
1205
1204
  if (iterationType === 'RECURSIVE') {
1206
- const queue = new Queue([startNode]);
1205
+ const queue = new Queue([
1206
+ startNode
1207
+ ]);
1207
1208
  const dfs = (level) => {
1208
1209
  if (queue.size === 0)
1209
1210
  return;
@@ -1257,7 +1258,7 @@ export class BinaryTree extends IterableEntryBase {
1257
1258
  * structure based on a specified callback and iteration type.
1258
1259
  * @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
1259
1260
  * in the binary tree. It is optional and defaults to a default callback function if not provided.
1260
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `leaves`
1261
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
1261
1262
  * method is used to specify the starting point for finding and processing the leaves of a binary
1262
1263
  * tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
1263
1264
  * explicitly provided, the default value
@@ -1312,7 +1313,7 @@ export class BinaryTree extends IterableEntryBase {
1312
1313
  * @param {C} callback - The `callback` parameter is a function that will be applied to each node in
1313
1314
  * the binary tree during the traversal. It is used to process each node and determine what
1314
1315
  * information to include in the output for each level of the tree.
1315
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
1316
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
1316
1317
  * `listLevels` function represents the starting point for traversing the binary tree. It can be
1317
1318
  * either a key, a node, or an entry in the binary tree. If not provided, the default value is the
1318
1319
  * root of the binary tree.
@@ -1384,11 +1385,11 @@ export class BinaryTree extends IterableEntryBase {
1384
1385
  * Morris Traversal algorithm with different order patterns.
1385
1386
  * @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
1386
1387
  * called on each node in the binary tree during the traversal. It is of type `C`, which extends the
1387
- * `NodeCallback<NODE>` type. The default value for `callback` is `this._DEFAULT
1388
+ * `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
1388
1389
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
1389
1390
  * the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
1390
1391
  * values for the `pattern` parameter are:
1391
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `morris`
1392
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
1392
1393
  * function is the starting point for the Morris traversal algorithm. It represents the root node of
1393
1394
  * the binary tree or the node from which the traversal should begin. It can be provided as either a
1394
1395
  * key, a node, an entry, or a reference
@@ -1494,6 +1495,10 @@ export class BinaryTree extends IterableEntryBase {
1494
1495
  */
1495
1496
  clone() {
1496
1497
  const cloned = this.createTree();
1498
+ this._clone(cloned);
1499
+ return cloned;
1500
+ }
1501
+ _clone(cloned) {
1497
1502
  this.bfs(node => {
1498
1503
  if (node === null)
1499
1504
  cloned.add(null);
@@ -1506,7 +1511,6 @@ export class BinaryTree extends IterableEntryBase {
1506
1511
  }, this._root, this.iterationType, true);
1507
1512
  if (this._isMapMode)
1508
1513
  cloned._store = this._store;
1509
- return cloned;
1510
1514
  }
1511
1515
  /**
1512
1516
  * Time Complexity: O(n)
@@ -1567,7 +1571,7 @@ export class BinaryTree extends IterableEntryBase {
1567
1571
  *
1568
1572
  * The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
1569
1573
  * customizable options for displaying undefined, null, and sentinel nodes.
1570
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
1574
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
1571
1575
  * `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
1572
1576
  * It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
1573
1577
  * the default is set to the root
@@ -1592,7 +1596,7 @@ export class BinaryTree extends IterableEntryBase {
1592
1596
  if (opts.isShowRedBlackNIL)
1593
1597
  output += `S for Sentinel Node(NIL)\n`;
1594
1598
  const display = (root) => {
1595
- const [lines, ,] = this._displayAux(root, opts);
1599
+ const [lines] = this._displayAux(root, opts);
1596
1600
  let paragraph = '';
1597
1601
  for (const line of lines) {
1598
1602
  paragraph += line + '\n';
@@ -1612,7 +1616,7 @@ export class BinaryTree extends IterableEntryBase {
1612
1616
  * printing options for the binary tree. It is an optional parameter that allows you to customize how
1613
1617
  * the binary tree is printed, such as choosing between different traversal orders or formatting
1614
1618
  * options.
1615
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the
1619
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
1616
1620
  * `override print` method is used to specify the starting point for printing the binary tree. It can
1617
1621
  * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
1618
1622
  * provided, the default value is set to
@@ -1620,6 +1624,42 @@ export class BinaryTree extends IterableEntryBase {
1620
1624
  print(options, startNode = this._root) {
1621
1625
  console.log(this.toVisual(startNode, options));
1622
1626
  }
1627
+ /**
1628
+ * Time Complexity: O(1)
1629
+ * Space Complexity: O(1)
1630
+ *
1631
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
1632
+ * or returns null.
1633
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The
1634
+ * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
1635
+ * can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. This parameter represents either a key, a
1636
+ * node, an entry
1637
+ * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
1638
+ * an optional parameter of type `V`. It represents the value associated with the key in the node
1639
+ * being created. If a `value` is provided, it will be used when creating the node. If
1640
+ * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
1641
+ * (`OptNodeOrNull<BinaryTreeNode<K, V>>`) based on the input parameters provided. The function checks the type of the
1642
+ * input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
1643
+ * value.
1644
+ */
1645
+ _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value) {
1646
+ if (keyNodeOrEntry === undefined)
1647
+ return [undefined, undefined];
1648
+ if (keyNodeOrEntry === null)
1649
+ return [null, undefined];
1650
+ if (this.isNode(keyNodeOrEntry))
1651
+ return [keyNodeOrEntry, value];
1652
+ if (this.isEntry(keyNodeOrEntry)) {
1653
+ const [key, entryValue] = keyNodeOrEntry;
1654
+ if (key === undefined)
1655
+ return [undefined, undefined];
1656
+ else if (key === null)
1657
+ return [null, undefined];
1658
+ const finalValue = value ?? entryValue;
1659
+ return [this.createNode(key, finalValue), finalValue];
1660
+ }
1661
+ return [this.createNode(keyNodeOrEntry, value), value];
1662
+ }
1623
1663
  /**
1624
1664
  * Time complexity: O(n)
1625
1665
  * Space complexity: O(n)
@@ -1628,11 +1668,11 @@ export class BinaryTree extends IterableEntryBase {
1628
1668
  * the specified order pattern and callback function.
1629
1669
  * @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
1630
1670
  * called on each node visited during the depth-first search traversal. It is of type `C`, which
1631
- * extends `NodeCallback<OptNodeOrNull<NODE>>`. The default value for this parameter is `this._DEFAULT
1671
+ * extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
1632
1672
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
1633
1673
  * order in which the nodes are visited during the Depth-First Search traversal. It can have one of
1634
1674
  * the following values:
1635
- * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `_dfs`
1675
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
1636
1676
  * method is used to specify the starting point for the depth-first search traversal in a binary
1637
1677
  * tree. It can be provided as either a `BTNRep` object or a reference to the root node
1638
1678
  * of the tree. If no specific
@@ -1875,12 +1915,12 @@ export class BinaryTree extends IterableEntryBase {
1875
1915
  * Space Complexity: O(1)
1876
1916
  *
1877
1917
  * The _swapProperties function swaps key and value properties between two nodes in a binary tree.
1878
- * @param {BTNRep<K, V, NODE> | R} srcNode - The `srcNode` parameter in the
1918
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
1879
1919
  * `_swapProperties` method can be either a BTNRep object containing key and value
1880
1920
  * properties, or it can be of type R.
1881
- * @param {BTNRep<K, V, NODE> | R} destNode - The `destNode` parameter in the
1921
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
1882
1922
  * `_swapProperties` method represents the node or entry where the properties will be swapped with
1883
- * the `srcNode`. It can be of type `BTNRep<K, V, NODE>` or `R`. The method ensures that
1923
+ * the `srcNode`. It can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. The method ensures that
1884
1924
  * both `srcNode
1885
1925
  * @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
1886
1926
  * with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
@@ -1908,9 +1948,9 @@ export class BinaryTree extends IterableEntryBase {
1908
1948
  * Space Complexity: O(1)
1909
1949
  *
1910
1950
  * The _replaceNode function replaces an old node with a new node in a binary tree structure.
1911
- * @param {NODE} oldNode - The `oldNode` parameter represents the node that you want to replace in a
1951
+ * @param {BinaryTreeNode<K, V>} oldNode - The `oldNode` parameter represents the node that you want to replace in a
1912
1952
  * tree data structure.
1913
- * @param {NODE} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
1953
+ * @param {BinaryTreeNode<K, V>} newNode - The `newNode` parameter in the `_replaceNode` function represents the node
1914
1954
  * that will replace the `oldNode` in a tree data structure. This function is responsible for
1915
1955
  * updating the parent, left child, right child, and root (if necessary) references when replacing a
1916
1956
  * node in the tree.
@@ -1940,8 +1980,8 @@ export class BinaryTree extends IterableEntryBase {
1940
1980
  *
1941
1981
  * The function _setRoot sets the root node of a data structure while updating the parent reference
1942
1982
  * of the previous root node.
1943
- * @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<NODE>`, which means
1944
- * it can either be an optional `NODE` type or `null`.
1983
+ * @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<BinaryTreeNode<K, V>>`, which means
1984
+ * it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
1945
1985
  */
1946
1986
  _setRoot(v) {
1947
1987
  if (v) {
@@ -1955,30 +1995,24 @@ export class BinaryTree extends IterableEntryBase {
1955
1995
  *
1956
1996
  * The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
1957
1997
  * predicate function for a binary tree node.
1958
- * @param {BTNRep<K, V, NODE> | R | NodePredicate<NODE>} keyNodeEntryRawOrPredicate - The
1998
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
1959
1999
  * `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
1960
- * parameter `keyNodeEntryRawOrPredicate` is transformed into a valid predicate function that can be
2000
+ * parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
1961
2001
  * used for filtering nodes in a binary tree.
1962
- * @returns A NodePredicate<NODE> function is being returned.
2002
+ * @returns A NodePredicate<BinaryTreeNode<K, V>> function is being returned.
1963
2003
  */
1964
- _ensurePredicate(keyNodeEntryRawOrPredicate) {
1965
- if (keyNodeEntryRawOrPredicate === null || keyNodeEntryRawOrPredicate === undefined)
2004
+ _ensurePredicate(keyNodeEntryOrPredicate) {
2005
+ if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === undefined)
1966
2006
  return (node) => (node ? false : false);
1967
- if (this._isPredicate(keyNodeEntryRawOrPredicate))
1968
- return keyNodeEntryRawOrPredicate;
1969
- if (this.isRealNode(keyNodeEntryRawOrPredicate))
1970
- return (node) => node === keyNodeEntryRawOrPredicate;
1971
- if (this.isEntry(keyNodeEntryRawOrPredicate)) {
1972
- const [key] = keyNodeEntryRawOrPredicate;
1973
- return (node) => node.key === key;
1974
- }
1975
- if (this.isKey(keyNodeEntryRawOrPredicate))
1976
- return (node) => node.key === keyNodeEntryRawOrPredicate;
1977
- if (this._toEntryFn) {
1978
- const [key] = this._toEntryFn(keyNodeEntryRawOrPredicate);
2007
+ if (this._isPredicate(keyNodeEntryOrPredicate))
2008
+ return keyNodeEntryOrPredicate;
2009
+ if (this.isRealNode(keyNodeEntryOrPredicate))
2010
+ return (node) => node === keyNodeEntryOrPredicate;
2011
+ if (this.isEntry(keyNodeEntryOrPredicate)) {
2012
+ const [key] = keyNodeEntryOrPredicate;
1979
2013
  return (node) => node.key === key;
1980
2014
  }
1981
- return (node) => node.key === keyNodeEntryRawOrPredicate;
2015
+ return (node) => node.key === keyNodeEntryOrPredicate;
1982
2016
  }
1983
2017
  /**
1984
2018
  * Time Complexity: O(1)
@@ -1987,7 +2021,7 @@ export class BinaryTree extends IterableEntryBase {
1987
2021
  * The function `_isPredicate` checks if a given parameter is a function.
1988
2022
  * @param {any} p - The parameter `p` is a variable of type `any`, which means it can hold any type
1989
2023
  * of value. In this context, the function `_isPredicate` is checking if `p` is a function that
1990
- * satisfies the type `NodePredicate<NODE>`.
2024
+ * satisfies the type `NodePredicate<BinaryTreeNode<K, V>>`.
1991
2025
  * @returns The function is checking if the input `p` is a function and returning a boolean value
1992
2026
  * based on that check. If `p` is a function, it will return `true`, indicating that `p` is a
1993
2027
  * predicate function for a binary tree node. If `p` is not a function, it will return `false`.
@@ -2001,32 +2035,25 @@ export class BinaryTree extends IterableEntryBase {
2001
2035
  *
2002
2036
  * The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
2003
2037
  * entry, raw data, or null/undefined.
2004
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `_extractKey` method you provided is a
2005
- * TypeScript method that takes in a parameter `keyNodeEntryOrRaw` of type `BTNRep<K, V, NODE> | R`,
2006
- * where `BTNRep` is a generic type with keys `K`, `V`, and `NODE`, and `
2007
- * @returns The `_extractKey` method returns the key value extracted from the `keyNodeEntryOrRaw`
2038
+ * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `_extractKey` method you provided is a
2039
+ * TypeScript method that takes in a parameter `keyNodeOrEntry` of type `BTNRep<K, V, BinaryTreeNode<K, V>>`,
2040
+ * where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
2041
+ * @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
2008
2042
  * parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
2009
2043
  * the conditions checked in the method.
2010
2044
  */
2011
- _extractKey(keyNodeEntryOrRaw) {
2012
- if (keyNodeEntryOrRaw === null)
2045
+ _extractKey(keyNodeOrEntry) {
2046
+ if (keyNodeOrEntry === null)
2013
2047
  return null;
2014
- if (keyNodeEntryOrRaw === undefined)
2048
+ if (keyNodeOrEntry === undefined)
2015
2049
  return;
2016
- if (keyNodeEntryOrRaw === this._NIL)
2050
+ if (keyNodeOrEntry === this._NIL)
2017
2051
  return;
2018
- if (this.isNode(keyNodeEntryOrRaw))
2019
- return keyNodeEntryOrRaw.key;
2020
- if (this.isEntry(keyNodeEntryOrRaw))
2021
- return keyNodeEntryOrRaw[0];
2022
- if (this.isRaw(keyNodeEntryOrRaw)) {
2023
- if (this._toEntryFn) {
2024
- const [key] = this._toEntryFn(keyNodeEntryOrRaw);
2025
- return key;
2026
- }
2027
- return;
2028
- }
2029
- return keyNodeEntryOrRaw;
2052
+ if (this.isNode(keyNodeOrEntry))
2053
+ return keyNodeOrEntry.key;
2054
+ if (this.isEntry(keyNodeOrEntry))
2055
+ return keyNodeOrEntry[0];
2056
+ return keyNodeOrEntry;
2030
2057
  }
2031
2058
  /**
2032
2059
  * Time Complexity: O(1)