min-heap-typed 1.38.0 → 1.38.1

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 (334) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +100 -0
  2. package/dist/data-structures/binary-tree/avl-tree.js +341 -0
  3. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +144 -0
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.js +261 -0
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +409 -0
  6. package/dist/data-structures/binary-tree/binary-tree.js +1065 -0
  7. package/dist/data-structures/binary-tree/bst.d.ts +167 -0
  8. package/dist/data-structures/binary-tree/bst.js +512 -0
  9. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  10. package/dist/data-structures/binary-tree/index.js +23 -0
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  12. package/dist/data-structures/binary-tree/rb-tree.js +27 -0
  13. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  14. package/dist/data-structures/binary-tree/segment-tree.js +228 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.d.ts +122 -0
  16. package/dist/data-structures/binary-tree/tree-multiset.js +351 -0
  17. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  18. package/dist/data-structures/graph/abstract-graph.js +923 -0
  19. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  20. package/dist/data-structures/graph/directed-graph.js +422 -0
  21. package/dist/data-structures/graph/index.d.ts +4 -0
  22. package/dist/data-structures/graph/index.js +20 -0
  23. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  24. package/dist/data-structures/graph/map-graph.js +111 -0
  25. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  26. package/dist/data-structures/graph/undirected-graph.js +252 -0
  27. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  28. package/dist/data-structures/hash/coordinate-map.js +65 -0
  29. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  30. package/dist/data-structures/hash/coordinate-set.js +55 -0
  31. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  32. package/dist/data-structures/hash/hash-map.js +171 -0
  33. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  34. package/dist/data-structures/hash/hash-table.js +245 -0
  35. package/dist/data-structures/hash/index.d.ts +6 -0
  36. package/dist/data-structures/hash/index.js +22 -0
  37. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  38. package/dist/data-structures/hash/tree-map.js +6 -0
  39. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  40. package/dist/data-structures/hash/tree-set.js +6 -0
  41. package/dist/data-structures/heap/heap.d.ts +224 -0
  42. package/dist/data-structures/heap/heap.js +497 -0
  43. package/dist/data-structures/heap/index.d.ts +3 -0
  44. package/dist/data-structures/heap/index.js +19 -0
  45. package/dist/data-structures/heap/max-heap.d.ts +12 -0
  46. package/dist/data-structures/heap/max-heap.js +24 -0
  47. package/dist/data-structures/heap/min-heap.d.ts +12 -0
  48. package/dist/data-structures/heap/min-heap.js +24 -0
  49. package/dist/data-structures/index.d.ts +11 -0
  50. package/dist/data-structures/index.js +27 -0
  51. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  52. package/dist/data-structures/linked-list/doubly-linked-list.js +583 -0
  53. package/dist/data-structures/linked-list/index.d.ts +3 -0
  54. package/dist/data-structures/linked-list/index.js +19 -0
  55. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  56. package/dist/data-structures/linked-list/singly-linked-list.js +448 -0
  57. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  58. package/dist/data-structures/linked-list/skip-linked-list.js +142 -0
  59. package/dist/data-structures/matrix/index.d.ts +4 -0
  60. package/dist/data-structures/matrix/index.js +20 -0
  61. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  62. package/dist/data-structures/matrix/matrix.js +28 -0
  63. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  64. package/dist/data-structures/matrix/matrix2d.js +203 -0
  65. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  66. package/dist/data-structures/matrix/navigator.js +106 -0
  67. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  68. package/dist/data-structures/matrix/vector2d.js +291 -0
  69. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  70. package/dist/data-structures/priority-queue/index.js +19 -0
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +24 -0
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +24 -0
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
  76. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  77. package/dist/data-structures/queue/deque.d.ts +165 -0
  78. package/dist/data-structures/queue/deque.js +276 -0
  79. package/dist/data-structures/queue/index.d.ts +2 -0
  80. package/dist/data-structures/queue/index.js +18 -0
  81. package/dist/data-structures/queue/queue.d.ts +107 -0
  82. package/dist/data-structures/queue/queue.js +170 -0
  83. package/dist/data-structures/stack/index.d.ts +1 -0
  84. package/dist/data-structures/stack/index.js +17 -0
  85. package/dist/data-structures/stack/stack.d.ts +63 -0
  86. package/dist/data-structures/stack/stack.js +91 -0
  87. package/dist/data-structures/tree/index.d.ts +1 -0
  88. package/dist/data-structures/tree/index.js +17 -0
  89. package/dist/data-structures/tree/tree.d.ts +14 -0
  90. package/dist/data-structures/tree/tree.js +58 -0
  91. package/dist/data-structures/trie/index.d.ts +1 -0
  92. package/dist/data-structures/trie/index.js +17 -0
  93. package/dist/data-structures/trie/trie.d.ts +84 -0
  94. package/dist/data-structures/trie/trie.js +268 -0
  95. package/dist/index.d.ts +3 -3
  96. package/dist/index.js +3 -3
  97. package/dist/interfaces/binary-tree.d.ts +7 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  100. package/dist/interfaces/doubly-linked-list.js +2 -0
  101. package/dist/interfaces/graph.d.ts +5 -0
  102. package/dist/interfaces/graph.js +2 -0
  103. package/dist/interfaces/heap.d.ts +1 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +8 -0
  106. package/dist/interfaces/index.js +24 -0
  107. package/dist/interfaces/navigator.d.ts +1 -0
  108. package/dist/interfaces/navigator.js +2 -0
  109. package/dist/interfaces/priority-queue.d.ts +1 -0
  110. package/dist/interfaces/priority-queue.js +2 -0
  111. package/dist/interfaces/segment-tree.d.ts +1 -0
  112. package/dist/interfaces/segment-tree.js +2 -0
  113. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  114. package/dist/interfaces/singly-linked-list.js +2 -0
  115. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  116. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  117. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  118. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  119. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +31 -0
  120. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  121. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
  122. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  123. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  124. package/dist/types/data-structures/binary-tree/index.js +22 -0
  125. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
  126. package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
  127. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  128. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  129. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  130. package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
  131. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  132. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  133. package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
  134. package/dist/types/data-structures/graph/directed-graph.js +9 -0
  135. package/dist/types/data-structures/graph/index.d.ts +3 -0
  136. package/dist/types/data-structures/graph/index.js +19 -0
  137. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  138. package/dist/types/data-structures/graph/map-graph.js +2 -0
  139. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  140. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  141. package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
  142. package/dist/types/data-structures/hash/coordinate-map.js +2 -0
  143. package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
  144. package/dist/types/data-structures/hash/coordinate-set.js +2 -0
  145. package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
  146. package/dist/types/data-structures/hash/hash-map.js +2 -0
  147. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  148. package/dist/types/data-structures/hash/hash-table.js +2 -0
  149. package/dist/types/data-structures/hash/index.d.ts +1 -0
  150. package/dist/types/data-structures/hash/index.js +2 -0
  151. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  152. package/dist/types/data-structures/hash/tree-map.js +2 -0
  153. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  154. package/dist/types/data-structures/hash/tree-set.js +2 -0
  155. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  156. package/dist/types/data-structures/heap/heap.js +2 -0
  157. package/dist/types/data-structures/heap/index.d.ts +1 -0
  158. package/dist/types/data-structures/heap/index.js +17 -0
  159. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  160. package/dist/types/data-structures/heap/max-heap.js +2 -0
  161. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  162. package/dist/types/data-structures/heap/min-heap.js +2 -0
  163. package/dist/types/data-structures/index.d.ts +11 -0
  164. package/dist/types/data-structures/index.js +27 -0
  165. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  166. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  167. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  168. package/dist/types/data-structures/linked-list/index.js +18 -0
  169. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  170. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  171. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  172. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  173. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  174. package/dist/types/data-structures/matrix/index.js +17 -0
  175. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  176. package/dist/types/data-structures/matrix/matrix.js +2 -0
  177. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  178. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  179. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  180. package/dist/types/data-structures/matrix/navigator.js +2 -0
  181. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  182. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  183. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  184. package/dist/types/data-structures/priority-queue/index.js +19 -0
  185. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  186. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  187. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  188. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  189. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  190. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  191. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  192. package/dist/types/data-structures/queue/deque.js +2 -0
  193. package/dist/types/data-structures/queue/index.d.ts +2 -0
  194. package/dist/types/data-structures/queue/index.js +18 -0
  195. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  196. package/dist/types/data-structures/queue/queue.js +2 -0
  197. package/dist/types/data-structures/stack/index.d.ts +1 -0
  198. package/dist/types/data-structures/stack/index.js +17 -0
  199. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  200. package/dist/types/data-structures/stack/stack.js +2 -0
  201. package/dist/types/data-structures/tree/index.d.ts +1 -0
  202. package/dist/types/data-structures/tree/index.js +17 -0
  203. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  204. package/dist/types/data-structures/tree/tree.js +2 -0
  205. package/dist/types/data-structures/trie/index.d.ts +1 -0
  206. package/dist/types/data-structures/trie/index.js +17 -0
  207. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  208. package/dist/types/data-structures/trie/trie.js +2 -0
  209. package/dist/types/helpers.d.ts +9 -0
  210. package/dist/types/helpers.js +9 -0
  211. package/dist/types/index.d.ts +3 -0
  212. package/dist/types/index.js +19 -0
  213. package/dist/types/utils/index.d.ts +2 -0
  214. package/dist/types/utils/index.js +18 -0
  215. package/dist/types/utils/utils.d.ts +7 -0
  216. package/dist/types/utils/utils.js +2 -0
  217. package/dist/types/utils/validate-type.d.ts +19 -0
  218. package/dist/types/utils/validate-type.js +2 -0
  219. package/dist/utils/index.d.ts +1 -0
  220. package/dist/utils/index.js +17 -0
  221. package/dist/utils/utils.d.ts +20 -0
  222. package/dist/utils/utils.js +73 -0
  223. package/package.json +1 -4
  224. package/src/data-structures/binary-tree/avl-tree.ts +342 -0
  225. package/src/data-structures/binary-tree/binary-indexed-tree.ts +298 -0
  226. package/src/data-structures/binary-tree/binary-tree.ts +1141 -0
  227. package/src/data-structures/binary-tree/bst.ts +529 -0
  228. package/src/data-structures/binary-tree/index.ts +7 -0
  229. package/src/data-structures/binary-tree/rb-tree.ts +366 -0
  230. package/src/data-structures/binary-tree/segment-tree.ts +257 -0
  231. package/src/data-structures/binary-tree/tree-multiset.ts +375 -0
  232. package/src/data-structures/graph/abstract-graph.ts +1044 -0
  233. package/src/data-structures/graph/directed-graph.ts +470 -0
  234. package/src/data-structures/graph/index.ts +4 -0
  235. package/src/data-structures/graph/map-graph.ts +134 -0
  236. package/src/data-structures/graph/undirected-graph.ts +274 -0
  237. package/src/data-structures/hash/coordinate-map.ts +67 -0
  238. package/src/data-structures/hash/coordinate-set.ts +56 -0
  239. package/src/data-structures/hash/hash-map.ts +209 -0
  240. package/src/data-structures/hash/hash-table.ts +280 -0
  241. package/src/data-structures/hash/index.ts +6 -0
  242. package/src/data-structures/hash/tree-map.ts +1 -0
  243. package/src/data-structures/hash/tree-set.ts +1 -0
  244. package/src/data-structures/heap/heap.ts +561 -0
  245. package/src/data-structures/heap/index.ts +3 -0
  246. package/src/data-structures/heap/max-heap.ts +24 -0
  247. package/src/data-structures/heap/min-heap.ts +24 -0
  248. package/src/data-structures/index.ts +11 -0
  249. package/src/data-structures/linked-list/doubly-linked-list.ts +636 -0
  250. package/src/data-structures/linked-list/index.ts +3 -0
  251. package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
  252. package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
  253. package/src/data-structures/matrix/index.ts +4 -0
  254. package/src/data-structures/matrix/matrix.ts +27 -0
  255. package/src/data-structures/matrix/matrix2d.ts +213 -0
  256. package/src/data-structures/matrix/navigator.ts +121 -0
  257. package/src/data-structures/matrix/vector2d.ts +316 -0
  258. package/src/data-structures/priority-queue/index.ts +3 -0
  259. package/src/data-structures/priority-queue/max-priority-queue.ts +23 -0
  260. package/src/data-structures/priority-queue/min-priority-queue.ts +23 -0
  261. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  262. package/src/data-structures/queue/deque.ts +297 -0
  263. package/src/data-structures/queue/index.ts +2 -0
  264. package/src/data-structures/queue/queue.ts +191 -0
  265. package/src/data-structures/stack/index.ts +1 -0
  266. package/src/data-structures/stack/stack.ts +98 -0
  267. package/src/data-structures/tree/index.ts +1 -0
  268. package/src/data-structures/tree/tree.ts +67 -0
  269. package/src/data-structures/trie/index.ts +1 -0
  270. package/src/data-structures/trie/trie.ts +286 -0
  271. package/src/index.ts +3 -3
  272. package/src/interfaces/binary-tree.ts +10 -0
  273. package/src/interfaces/doubly-linked-list.ts +1 -0
  274. package/src/interfaces/graph.ts +7 -0
  275. package/src/interfaces/heap.ts +1 -0
  276. package/src/interfaces/index.ts +8 -0
  277. package/src/interfaces/navigator.ts +1 -0
  278. package/src/interfaces/priority-queue.ts +1 -0
  279. package/src/interfaces/segment-tree.ts +1 -0
  280. package/src/interfaces/singly-linked-list.ts +1 -0
  281. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  282. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  283. package/src/types/data-structures/binary-tree/binary-tree.ts +35 -0
  284. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  285. package/src/types/data-structures/binary-tree/index.ts +6 -0
  286. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  287. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  288. package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
  289. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  290. package/src/types/data-structures/graph/directed-graph.ts +8 -0
  291. package/src/types/data-structures/graph/index.ts +3 -0
  292. package/src/types/data-structures/graph/map-graph.ts +1 -0
  293. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  294. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  295. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  296. package/src/types/data-structures/hash/hash-map.ts +1 -0
  297. package/src/types/data-structures/hash/hash-table.ts +1 -0
  298. package/src/types/data-structures/hash/index.ts +1 -0
  299. package/src/types/data-structures/hash/tree-map.ts +1 -0
  300. package/src/types/data-structures/hash/tree-set.ts +1 -0
  301. package/src/types/data-structures/heap/heap.ts +1 -0
  302. package/src/types/data-structures/heap/index.ts +1 -0
  303. package/src/types/data-structures/heap/max-heap.ts +1 -0
  304. package/src/types/data-structures/heap/min-heap.ts +1 -0
  305. package/src/types/data-structures/index.ts +11 -0
  306. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  307. package/src/types/data-structures/linked-list/index.ts +2 -0
  308. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  309. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  310. package/src/types/data-structures/matrix/index.ts +1 -0
  311. package/src/types/data-structures/matrix/matrix.ts +1 -0
  312. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  313. package/src/types/data-structures/matrix/navigator.ts +14 -0
  314. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  315. package/src/types/data-structures/priority-queue/index.ts +3 -0
  316. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  317. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  318. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  319. package/src/types/data-structures/queue/deque.ts +1 -0
  320. package/src/types/data-structures/queue/index.ts +2 -0
  321. package/src/types/data-structures/queue/queue.ts +1 -0
  322. package/src/types/data-structures/stack/index.ts +1 -0
  323. package/src/types/data-structures/stack/stack.ts +1 -0
  324. package/src/types/data-structures/tree/index.ts +1 -0
  325. package/src/types/data-structures/tree/tree.ts +1 -0
  326. package/src/types/data-structures/trie/index.ts +1 -0
  327. package/src/types/data-structures/trie/trie.ts +1 -0
  328. package/src/types/helpers.ts +13 -0
  329. package/src/types/index.ts +3 -0
  330. package/src/types/utils/index.ts +2 -0
  331. package/src/types/utils/utils.ts +6 -0
  332. package/src/types/utils/validate-type.ts +35 -0
  333. package/src/utils/index.ts +1 -0
  334. package/src/utils/utils.ts +86 -0
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BinaryIndexedTree = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ const utils_1 = require("../../utils");
12
+ class BinaryIndexedTree {
13
+ /**
14
+ * The constructor initializes the properties of an object, including default frequency, maximum
15
+ * value, a freqMap data structure, the most significant bit, and the count of negative frequencies.
16
+ * @param - - `frequency`: The default frequency value. It is optional and has a default
17
+ * value of 0.
18
+ */
19
+ constructor({ frequency = 0, max }) {
20
+ this._freq = frequency;
21
+ this._max = max;
22
+ this._freqMap = { 0: 0 };
23
+ this._msb = (0, utils_1.getMSB)(max);
24
+ this._negativeCount = frequency < 0 ? max : 0;
25
+ }
26
+ get freqMap() {
27
+ return this._freqMap;
28
+ }
29
+ set freqMap(value) {
30
+ this._freqMap = value;
31
+ }
32
+ get msb() {
33
+ return this._msb;
34
+ }
35
+ set msb(value) {
36
+ this._msb = value;
37
+ }
38
+ get negativeCount() {
39
+ return this._negativeCount;
40
+ }
41
+ set negativeCount(value) {
42
+ this._negativeCount = value;
43
+ }
44
+ get freq() {
45
+ return this._freq;
46
+ }
47
+ get max() {
48
+ return this._max;
49
+ }
50
+ /**
51
+ * The function "readSingle" reads a single number from a specified index.
52
+ * @param {number} index - The `index` parameter is a number that represents the index of an element in a
53
+ * collection or array.
54
+ * @returns a number.
55
+ */
56
+ readSingle(index) {
57
+ this._checkIndex(index);
58
+ return this._readSingle(index);
59
+ }
60
+ /**
61
+ * The "update" function updates the value at a given index by adding a delta and triggers a callback
62
+ * to notify of the change.
63
+ * @param {number} position - The `index` parameter represents the index of the element that needs to be
64
+ * updated in the data structure.
65
+ * @param {number} change - The "delta" parameter represents the change in value that needs to be
66
+ * applied to the frequency at the specified index.
67
+ */
68
+ update(position, change) {
69
+ this._checkIndex(position);
70
+ const freqCur = this._readSingle(position);
71
+ this._update(position, change);
72
+ this._updateNegativeCount(freqCur, freqCur + change);
73
+ }
74
+ /**
75
+ * The function "writeSingle" checks the index and writes a single value with a given frequency.
76
+ * @param {number} index - The `index` parameter is a number that represents the index of an element. It
77
+ * is used to identify the specific element that needs to be written.
78
+ * @param {number} freq - The `freq` parameter represents the frequency value that needs to be
79
+ * written.
80
+ */
81
+ writeSingle(index, freq) {
82
+ this._checkIndex(index);
83
+ this._writeSingle(index, freq);
84
+ }
85
+ /**
86
+ * The read function takes a count parameter, checks if it is an integer, and returns the result of
87
+ * calling the _read function with the count parameter clamped between 0 and the maximum value.
88
+ * @param {number} count - The `count` parameter is a number that represents the number of items to
89
+ * read.
90
+ * @returns a number.
91
+ */
92
+ read(count) {
93
+ if (!Number.isInteger(count)) {
94
+ throw new Error('Invalid count');
95
+ }
96
+ return this._read(Math.max(Math.min(count, this.max), 0));
97
+ }
98
+ /**
99
+ * The function returns the lower bound of a non-descending sequence that sums up to a given number.
100
+ * @param {number} sum - The `sum` parameter is a number that represents the target sum that we want
101
+ * to find in the sequence.
102
+ * @returns The lowerBound function is returning a number.
103
+ */
104
+ lowerBound(sum) {
105
+ if (this.negativeCount > 0) {
106
+ throw new Error('Sequence is not non-descending');
107
+ }
108
+ return this._binarySearch(sum, (x, y) => x < y);
109
+ }
110
+ /**
111
+ * The upperBound function returns the index of the first element in a sequence that is greater than
112
+ * or equal to a given sum.
113
+ * @param {number} sum - The "sum" parameter is a number that represents the target sum that we want
114
+ * to find in the sequence.
115
+ * @returns The upperBound function is returning a number.
116
+ */
117
+ upperBound(sum) {
118
+ if (this.negativeCount > 0) {
119
+ throw new Error('Must not be descending');
120
+ }
121
+ return this._binarySearch(sum, (x, y) => x <= y);
122
+ }
123
+ /**
124
+ * The function returns the value of a specific index in a freqMap data structure, or a default value if
125
+ * the index is not found.
126
+ * @param {number} index - The `index` parameter is a number that represents the index of a node in a
127
+ * freqMap data structure.
128
+ * @returns a number.
129
+ */
130
+ _getFrequency(index) {
131
+ if (index in this.freqMap) {
132
+ return this.freqMap[index];
133
+ }
134
+ return this.freq * (index & -index);
135
+ }
136
+ /**
137
+ * The function _updateFrequency adds a delta value to the element at the specified index in the freqMap array.
138
+ * @param {number} index - The index parameter is a number that represents the index of the freqMap
139
+ * element that needs to be updated.
140
+ * @param {number} delta - The `delta` parameter represents the change in value that needs to be
141
+ * added to the freqMap at the specified `index`.
142
+ */
143
+ _updateFrequency(index, delta) {
144
+ this.freqMap[index] = this._getFrequency(index) + delta;
145
+ }
146
+ /**
147
+ * The function checks if the given index is valid and within the range.
148
+ * @param {number} index - The parameter "index" is of type number and represents the index value
149
+ * that needs to be checked.
150
+ */
151
+ _checkIndex(index) {
152
+ if (!Number.isInteger(index)) {
153
+ throw new Error('Invalid index: Index must be an integer.');
154
+ }
155
+ if (index < 0 || index >= this.max) {
156
+ throw new Error('Index out of range: Index must be within the range [0, this.max).');
157
+ }
158
+ }
159
+ /**
160
+ * The function calculates the sum of elements in an array up to a given index using a binary indexed
161
+ * freqMap.
162
+ * @param {number} index - The `index` parameter is a number that represents the index of an element in a
163
+ * data structure.
164
+ * @returns a number.
165
+ */
166
+ _readSingle(index) {
167
+ index = index + 1;
168
+ let sum = this._getFrequency(index);
169
+ const z = index - (index & -index);
170
+ index--;
171
+ while (index !== z) {
172
+ sum -= this._getFrequency(index);
173
+ index -= index & -index;
174
+ }
175
+ return sum;
176
+ }
177
+ /**
178
+ * The function `_updateNegativeCount` updates a counter based on changes in frequency values.
179
+ * @param {number} freqCur - The current frequency value.
180
+ * @param {number} freqNew - The freqNew parameter represents the new frequency value.
181
+ */
182
+ _updateNegativeCount(freqCur, freqNew) {
183
+ if (freqCur < 0 && freqNew >= 0) {
184
+ this.negativeCount--;
185
+ }
186
+ else if (freqCur >= 0 && freqNew < 0) {
187
+ this.negativeCount++;
188
+ }
189
+ }
190
+ /**
191
+ * The `_update` function updates the values in a binary indexed freqMap starting from a given index and
192
+ * propagating the changes to its parent nodes.
193
+ * @param {number} index - The `index` parameter is a number that represents the index of the element in
194
+ * the data structure that needs to be updated.
195
+ * @param {number} delta - The `delta` parameter represents the change in value that needs to be
196
+ * applied to the elements in the data structure.
197
+ */
198
+ _update(index, delta) {
199
+ index = index + 1;
200
+ while (index <= this.max) {
201
+ this._updateFrequency(index, delta);
202
+ index += index & -index;
203
+ }
204
+ }
205
+ /**
206
+ * The `_writeSingle` function updates the frequency at a specific index and triggers a callback if
207
+ * the frequency has changed.
208
+ * @param {number} index - The `index` parameter is a number that represents the index of the element
209
+ * being modified or accessed.
210
+ * @param {number} freq - The `freq` parameter represents the new frequency value that needs to be
211
+ * written to the specified index `index`.
212
+ */
213
+ _writeSingle(index, freq) {
214
+ const freqCur = this._readSingle(index);
215
+ this._update(index, freq - freqCur);
216
+ this._updateNegativeCount(freqCur, freq);
217
+ }
218
+ /**
219
+ * The `_read` function calculates the sum of values in a binary freqMap up to a given count.
220
+ * @param {number} count - The `count` parameter is a number that represents the number of elements
221
+ * to read from the freqMap.
222
+ * @returns the sum of the values obtained from calling the `_getFrequency` method for each index in the
223
+ * range from `count` to 1.
224
+ */
225
+ _read(count) {
226
+ let index = count;
227
+ let sum = 0;
228
+ while (index) {
229
+ sum += this._getFrequency(index);
230
+ index -= index & -index;
231
+ }
232
+ return sum;
233
+ }
234
+ /**
235
+ * The function `_binarySearch` performs a binary search to find the largest number that satisfies a given
236
+ * condition.
237
+ * @param {number} sum - The sum parameter is a number that represents the target sum value.
238
+ * @param before - The `before` parameter is a function that takes two numbers `x` and `y` as
239
+ * arguments and returns a boolean value. It is used to determine if `x` is less than or equal to
240
+ * `y`. The purpose of this function is to compare two numbers and determine their order.
241
+ * @returns the value of the variable "left".
242
+ */
243
+ _binarySearch(sum, before) {
244
+ let left = 0;
245
+ let right = this.msb << 1;
246
+ let sumT = sum;
247
+ while (right > left + 1) {
248
+ const middle = (left + right) >> 1;
249
+ const sumM = this._getFrequency(middle);
250
+ if (middle <= this.max && before(sumM, sumT)) {
251
+ sumT -= sumM;
252
+ left = middle;
253
+ }
254
+ else {
255
+ right = middle;
256
+ }
257
+ }
258
+ return left;
259
+ }
260
+ }
261
+ exports.BinaryIndexedTree = BinaryIndexedTree;
@@ -0,0 +1,409 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { BFSCallback, BFSCallbackReturn, BinaryTreeNodeKey, BinaryTreeNodeNested, BinaryTreeOptions, MapCallback, MapCallbackReturn } from '../../types';
9
+ import { BinaryTreeDeletedResult, DFSOrderPattern, FamilyPosition, IterationType } from '../../types';
10
+ import { IBinaryTree } from '../../interfaces';
11
+ /**
12
+ * Represents a node in a binary tree.
13
+ * @template V - The type of data stored in the node.
14
+ * @template FAMILY - The type of the family relationship in the binary tree.
15
+ */
16
+ export declare class BinaryTreeNode<V = any, FAMILY extends BinaryTreeNode<V, FAMILY> = BinaryTreeNodeNested<V>> {
17
+ /**
18
+ * The key associated with the node.
19
+ */
20
+ key: BinaryTreeNodeKey;
21
+ /**
22
+ * The value stored in the node.
23
+ */
24
+ val: V | undefined;
25
+ /**
26
+ * The parent node of the current node.
27
+ */
28
+ parent: FAMILY | null | undefined;
29
+ /**
30
+ * Creates a new instance of BinaryTreeNode.
31
+ * @param {BinaryTreeNodeKey} key - The key associated with the node.
32
+ * @param {V} val - The value stored in the node.
33
+ */
34
+ constructor(key: BinaryTreeNodeKey, val?: V);
35
+ private _left;
36
+ /**
37
+ * Get the left child node.
38
+ */
39
+ get left(): FAMILY | null | undefined;
40
+ /**
41
+ * Set the left child node.
42
+ * @param {FAMILY | null | undefined} v - The left child node.
43
+ */
44
+ set left(v: FAMILY | null | undefined);
45
+ private _right;
46
+ /**
47
+ * Get the right child node.
48
+ */
49
+ get right(): FAMILY | null | undefined;
50
+ /**
51
+ * Set the right child node.
52
+ * @param {FAMILY | null | undefined} v - The right child node.
53
+ */
54
+ set right(v: FAMILY | null | undefined);
55
+ /**
56
+ * Get the position of the node within its family.
57
+ * @returns {FamilyPosition} - The family position of the node.
58
+ */
59
+ get familyPosition(): FamilyPosition;
60
+ }
61
+ /**
62
+ * Represents a binary tree data structure.
63
+ * @template N - The type of the binary tree's nodes.
64
+ */
65
+ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> implements IBinaryTree<N> {
66
+ private _loopType;
67
+ /**
68
+ * Creates a new instance of BinaryTree.
69
+ * @param {BinaryTreeOptions} [options] - The options for the binary tree.
70
+ */
71
+ constructor(options?: BinaryTreeOptions);
72
+ private _root;
73
+ /**
74
+ * Get the root node of the binary tree.
75
+ */
76
+ get root(): N | null;
77
+ private _size;
78
+ /**
79
+ * Get the number of nodes in the binary tree.
80
+ */
81
+ get size(): number;
82
+ /**
83
+ * Get the iteration type used in the binary tree.
84
+ */
85
+ get iterationType(): IterationType;
86
+ /**
87
+ * Set the iteration type for the binary tree.
88
+ * @param {IterationType} v - The new iteration type to set.
89
+ */
90
+ set iterationType(v: IterationType);
91
+ /**
92
+ * Creates a new instance of BinaryTreeNode with the given key and value.
93
+ * @param {BinaryTreeNodeKey} key - The key for the new node.
94
+ * @param {N['val']} val - The value for the new node.
95
+ * @returns {N} - The newly created BinaryTreeNode.
96
+ */
97
+ createNode(key: BinaryTreeNodeKey, val?: N['val']): N;
98
+ /**
99
+ * Clear the binary tree, removing all nodes.
100
+ */
101
+ clear(): void;
102
+ /**
103
+ * Check if the binary tree is empty.
104
+ * @returns {boolean} - True if the binary tree is empty, false otherwise.
105
+ */
106
+ isEmpty(): boolean;
107
+ /**
108
+ * Add a node with the given key and value to the binary tree.
109
+ * @param {BinaryTreeNodeKey | N | null} keyOrNode - The key or node to add to the binary tree.
110
+ * @param {N['val']} val - The value for the new node (optional).
111
+ * @returns {N | null | undefined} - The inserted node, or null if nothing was inserted, or undefined if the operation failed.
112
+ */
113
+ add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined;
114
+ /**
115
+ * The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
116
+ * values, and adds them to the binary tree.
117
+ * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} keysOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode
118
+ * objects, or null values.
119
+ * @param {N['val'][]} [values] - The `values` parameter is an optional array of values (`N['val'][]`) that corresponds to
120
+ * the nodes or node IDs being added. It is used to set the value of each node being added. If `values` is not provided,
121
+ * the value of the nodes will be `undefined`.
122
+ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
123
+ */
124
+ addMany(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], values?: N['val'][]): (N | null | undefined)[];
125
+ /**
126
+ * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
127
+ * @param {(BinaryTreeNodeKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
128
+ * `BinaryTreeNodeKey` or `N` values.
129
+ * @param {N[] | Array<N['val']>} [data] - The `data` parameter is an optional array of values that will be assigned to
130
+ * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
131
+ * array. Each value in the `data` array will be assigned to the
132
+ * @returns The method is returning a boolean value.
133
+ */
134
+ refill(keysOrNodes: (BinaryTreeNodeKey | null)[] | (N | null)[], data?: N[] | Array<N['val']>): boolean;
135
+ /**
136
+ * The `delete` function removes a node from a binary search tree and returns the deleted node along
137
+ * with the parent node that needs to be balanced.
138
+ * @param {N | BinaryTreeNodeKey} nodeOrKey - The `nodeOrKey` parameter can be either a node (`N`) or
139
+ * a key (`BinaryTreeNodeKey`). If it is a key, the function will find the corresponding node in the
140
+ * binary tree.
141
+ * @returns an array of `BinaryTreeDeletedResult<N>` objects.
142
+ */
143
+ delete(nodeOrKey: N | BinaryTreeNodeKey): BinaryTreeDeletedResult<N>[];
144
+ /**
145
+ * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
146
+ * specified root node.
147
+ * @param {N | BinaryTreeNodeKey | null} distNode - The `distNode` parameter represents the node
148
+ * whose depth we want to find in the binary tree. It can be either a node object (`N`), a key value
149
+ * of the node (`BinaryTreeNodeKey`), or `null`.
150
+ * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter represents the
151
+ * starting node from which we want to calculate the depth. It can be either a node object or the key
152
+ * of a node in the binary tree. If no value is provided for `beginRoot`, it defaults to the root
153
+ * node of the binary tree.
154
+ * @returns the depth of the `distNode` relative to the `beginRoot`.
155
+ */
156
+ getDepth(distNode: N | BinaryTreeNodeKey | null, beginRoot?: N | BinaryTreeNodeKey | null): number;
157
+ /**
158
+ * The `getHeight` function calculates the maximum height of a binary tree using either recursive or
159
+ * iterative approach.
160
+ * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter represents the
161
+ * starting node from which the height of the binary tree is calculated. It can be either a node
162
+ * object (`N`), a key value of a node in the tree (`BinaryTreeNodeKey`), or `null` if no starting
163
+ * node is specified. If `
164
+ * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
165
+ * height of the binary tree using a recursive approach or an iterative approach. It can have two
166
+ * possible values:
167
+ * @returns the height of the binary tree.
168
+ */
169
+ getHeight(beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): number;
170
+ /**
171
+ * The `getMinHeight` function calculates the minimum height of a binary tree using either a
172
+ * recursive or iterative approach.
173
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which we want to
174
+ * calculate the minimum height of the tree. It is optional and defaults to the root of the tree if
175
+ * not provided.
176
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
177
+ * to calculate the minimum height of a binary tree. It can have two possible values:
178
+ * @returns The function `getMinHeight` returns the minimum height of a binary tree.
179
+ */
180
+ getMinHeight(beginRoot?: N | null, iterationType?: IterationType): number;
181
+ /**
182
+ * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
183
+ * height of the tree.
184
+ * @param {N | null} beginRoot - The parameter `beginRoot` is of type `N | null`, which means it can
185
+ * either be of type `N` (representing a node in a tree) or `null` (representing an empty tree).
186
+ * @returns The method is returning a boolean value.
187
+ */
188
+ isPerfectlyBalanced(beginRoot?: N | null): boolean;
189
+ /**
190
+ * The function `getNodes` returns an array of nodes that match a given node property, using either
191
+ * recursive or iterative traversal.
192
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is either a
193
+ * `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
194
+ * searching for. It can be a specific key value or any other property of the node.
195
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
196
+ * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
197
+ * included in the result. The `callback` parameter has a default value of
198
+ * `this._defaultCallbackByKey`, which
199
+ * @param [onlyOne=false] - A boolean value indicating whether to stop searching after finding the
200
+ * first node that matches the nodeProperty. If set to true, the function will return an array with
201
+ * only one element (or an empty array if no matching node is found). If set to false (default), the
202
+ * function will continue searching for all
203
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which the
204
+ * traversal of the binary tree will begin. It is optional and defaults to the root of the binary
205
+ * tree.
206
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
207
+ * traverse the binary tree. It can have two possible values:
208
+ * @returns The function `getNodes` returns an array of nodes (`N[]`).
209
+ */
210
+ getNodes(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
211
+ /**
212
+ * The function checks if a binary tree has a node with a given property or key.
213
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
214
+ * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or a
215
+ * generic type `N`.
216
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
217
+ * matches the desired criteria. It takes a node as input and returns a boolean value indicating
218
+ * whether the node matches the criteria or not. The default callback function
219
+ * `this._defaultCallbackByKey` is used if no callback function is
220
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
221
+ * the node from which the search should begin. By default, it is set to `this.root`, which means the
222
+ * search will start from the root node of the binary tree. However, you can provide a different node
223
+ * as
224
+ * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
225
+ * performed when searching for nodes in the binary tree. It can have one of the following values:
226
+ * @returns a boolean value.
227
+ */
228
+ has(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>, beginRoot?: N | null, iterationType?: IterationType): boolean;
229
+ /**
230
+ * The function `get` returns the first node in a binary tree that matches the given property or key.
231
+ * @param {BinaryTreeNodeKey | N} nodeProperty - The `nodeProperty` parameter is the key or value of
232
+ * the node that you want to find in the binary tree. It can be either a `BinaryTreeNodeKey` or `N`
233
+ * type.
234
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
235
+ * matches the desired criteria. It takes a node as input and returns a boolean value indicating
236
+ * whether the node matches the criteria or not. The default callback function
237
+ * (`this._defaultCallbackByKey`) is used if no callback function is
238
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
239
+ * the root node from which the search should begin.
240
+ * @param iterationType - The `iterationType` parameter specifies the type of iteration to be
241
+ * performed when searching for a node in the binary tree. It can have one of the following values:
242
+ * @returns either the found node (of type N) or null if no node is found.
243
+ */
244
+ get(nodeProperty: BinaryTreeNodeKey | N, callback?: MapCallback<N>, beginRoot?: N | null, iterationType?: IterationType): N | null;
245
+ /**
246
+ * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
247
+ * up to the root node, with the option to reverse the order of the nodes.
248
+ * @param {N} beginRoot - The `beginRoot` parameter represents the starting node from which you want
249
+ * to find the path to the root node.
250
+ * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
251
+ * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
252
+ * reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
253
+ * @returns The function `getPathToRoot` returns an array of type `N[]`.
254
+ */
255
+ getPathToRoot(beginRoot: N, isReverse?: boolean): N[];
256
+ /**
257
+ * The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
258
+ * iterative traversal.
259
+ * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter is the starting point
260
+ * for finding the leftmost node in a binary tree. It can be either a node object (`N`), a key value
261
+ * of a node (`BinaryTreeNodeKey`), or `null` if the tree is empty.
262
+ * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
263
+ * be performed when finding the leftmost node in a binary tree. It can have two possible values:
264
+ * @returns The function `getLeftMost` returns the leftmost node (`N`) in a binary tree. If there is
265
+ * no leftmost node, it returns `null`.
266
+ */
267
+ getLeftMost(beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): N | null;
268
+ /**
269
+ * The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
270
+ * iteratively.
271
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which we want to
272
+ * find the rightmost node. It is of type `N | null`, which means it can either be a node of type `N`
273
+ * or `null`. If it is `null`, it means there is no starting node
274
+ * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
275
+ * be performed when finding the rightmost node in a binary tree. It can have two possible values:
276
+ * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If the
277
+ * `beginRoot` parameter is `null`, it returns `null`.
278
+ */
279
+ getRightMost(beginRoot?: N | null, iterationType?: IterationType): N | null;
280
+ /**
281
+ * The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
282
+ * @param {N} beginRoot - The `beginRoot` parameter is the root node of the binary tree that you want
283
+ * to check if it is a binary search tree (BST) subtree.
284
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
285
+ * type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
286
+ * possible values:
287
+ * @returns The function `isSubtreeBST` returns a boolean value.
288
+ */
289
+ isSubtreeBST(beginRoot: N, iterationType?: IterationType): boolean;
290
+ /**
291
+ * The function checks if a binary tree is a binary search tree.
292
+ * @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
293
+ * be used when checking if the binary tree is a binary search tree (BST). It is an optional
294
+ * parameter with a default value of "this.iterationType". The value of "this.iterationType" is not
295
+ * provided in
296
+ * @returns a boolean value.
297
+ */
298
+ isBST(iterationType?: IterationType): boolean;
299
+ /**
300
+ * The function `subTreeTraverse` traverses a binary tree and applies a callback function to each
301
+ * node, either recursively or iteratively.
302
+ * @param callback - The `callback` parameter is a function that will be called on each node in the
303
+ * subtree traversal. It takes a single argument, which is the current node being traversed, and
304
+ * returns a value. The return values from each callback invocation will be collected and returned as
305
+ * an array.
306
+ * @param {N | BinaryTreeNodeKey | null} beginRoot - The `beginRoot` parameter is the starting point
307
+ * for traversing the subtree. It can be either a node object, a key value of a node, or `null` to
308
+ * start from the root of the tree.
309
+ * @param iterationType - The `iterationType` parameter determines the type of traversal to be
310
+ * performed on the binary tree. It can have two possible values:
311
+ * @returns The function `subTreeTraverse` returns an array of `MapCallbackReturn<N>`.
312
+ */
313
+ subTreeTraverse(callback?: MapCallback<N>, beginRoot?: N | BinaryTreeNodeKey | null, iterationType?: IterationType): MapCallbackReturn<N>[];
314
+ /**
315
+ * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
316
+ * function on each node according to a specified order pattern.
317
+ * @param callback - The `callback` parameter is a function that will be called on each node during
318
+ * the depth-first search traversal. It takes a node as input and returns a value. The default value
319
+ * is `this._defaultCallbackByKey`, which is a callback function defined elsewhere in the code.
320
+ * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
321
+ * nodes are visited during the depth-first search. There are three possible values for `pattern`:
322
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
323
+ * search. It determines where the search will begin in the tree or graph structure. If `beginRoot`
324
+ * is `null`, an empty array will be returned.
325
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
326
+ * iteration used in the depth-first search algorithm. It can have two possible values:
327
+ * @returns The function `dfs` returns an array of `MapCallbackReturn<N>` values.
328
+ */
329
+ dfs(callback?: MapCallback<N>, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): MapCallbackReturn<N>[];
330
+ /**
331
+ * The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
332
+ * function on each node.
333
+ * @param callback - The `callback` parameter is a function that will be called for each node in the
334
+ * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
335
+ * `BFSCallbackReturn<N>`. The default value for this parameter is `this._defaultCallbackByKey
336
+ * @param {boolean} [withLevel=false] - The `withLevel` parameter is a boolean flag that determines
337
+ * whether or not to include the level of each node in the callback function. If `withLevel` is set
338
+ * to `true`, the level of each node will be passed as an argument to the callback function. If
339
+ * `withLevel` is
340
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
341
+ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
342
+ * will not be performed and an empty array will be returned.
343
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
344
+ * in the breadth-first search (BFS) algorithm. It can have two possible values:
345
+ * @returns The function `bfs` returns an array of `BFSCallbackReturn<N>[]`.
346
+ */
347
+ bfs(callback?: BFSCallback<N>, withLevel?: boolean, beginRoot?: N | null, iterationType?: IterationType): BFSCallbackReturn<N>[];
348
+ /**
349
+ * The function returns the predecessor node of a given node in a binary tree.
350
+ * @param {N} node - The parameter "node" represents a node in a binary tree.
351
+ * @returns The function `getPredecessor` returns the predecessor node of the given node `node`.
352
+ */
353
+ getPredecessor(node: N): N;
354
+ /**
355
+ * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
356
+ * algorithm and returns an array of values obtained by applying a callback function to each node.
357
+ * @param callback - The `callback` parameter is a function that will be called on each node in the
358
+ * tree. It takes a node of type `N` as input and returns a value of type `MapCallbackReturn<N>`. The
359
+ * default value for this parameter is `this._defaultCallbackByKey`.
360
+ * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
361
+ * determines the order in which the nodes of a binary tree are traversed. It can have one of the
362
+ * following values:
363
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
364
+ * traversal. It specifies the root node of the tree from which the traversal should begin. If
365
+ * `beginRoot` is `null`, an empty array will be returned.
366
+ * @returns The `morris` function returns an array of `MapCallbackReturn<N>` values.
367
+ */
368
+ morris(callback?: MapCallback<N>, pattern?: DFSOrderPattern, beginRoot?: N | null): MapCallbackReturn<N>[];
369
+ /**
370
+ * Swap the data of two nodes in the binary tree.
371
+ * @param {N} srcNode - The source node to swap.
372
+ * @param {N} destNode - The destination node to swap.
373
+ * @returns {N} - The destination node after the swap.
374
+ */
375
+ protected _swap(srcNode: N, destNode: N): N;
376
+ /**
377
+ * Time complexity is O(n)
378
+ * Space complexity of Iterative dfs equals to recursive dfs which is O(n) because of the stack
379
+ * The Morris algorithm only modifies the tree's structure during traversal; once the traversal is complete,
380
+ * the tree's structure should be restored to its original state to maintain the tree's integrity.
381
+ * This is because the purpose of the Morris algorithm is to save space rather than permanently alter the tree's shape.
382
+ */
383
+ protected _defaultCallbackByKey: MapCallback<N>;
384
+ /**
385
+ * The function `_addTo` adds a new node to a binary tree if there is an available position.
386
+ * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
387
+ * the binary tree. It can be either a node object or `null`.
388
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
389
+ * be added as a child.
390
+ * @returns either the left or right child node of the parent node, depending on which child is
391
+ * available for adding the new node. If a new node is added, the function also updates the size of
392
+ * the binary tree. If neither the left nor right child is available, the function returns undefined.
393
+ * If the parent node is null, the function also returns undefined.
394
+ */
395
+ protected _addTo(newNode: N | null, parent: N): N | null | undefined;
396
+ /**
397
+ * The function sets the root property of an object to a given value, and if the value is not null,
398
+ * it also sets the parent property of the value to undefined.
399
+ * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of
400
+ * type `N` or `null`.
401
+ */
402
+ protected _setRoot(v: N | null): void;
403
+ /**
404
+ * The function sets the value of the protected property "_size" to the given number.
405
+ * @param {number} v - The parameter "v" is a number that represents the size value that we want to
406
+ * set.
407
+ */
408
+ protected _setSize(v: number): void;
409
+ }