min-heap-typed 1.40.0-rc → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/.dependency-cruiser.js +422 -422
  2. package/.eslintrc.js +59 -59
  3. package/.prettierrc.js +14 -14
  4. package/README.md +20 -3
  5. package/coverage/clover.xml +11 -7
  6. package/coverage/coverage-final.json +95 -1
  7. package/coverage/coverage-summary.json +59 -2
  8. package/coverage/lcov-report/base.css +278 -99
  9. package/coverage/lcov-report/index.html +69 -65
  10. package/coverage/lcov-report/index.ts.html +36 -35
  11. package/coverage/lcov-report/sorter.js +15 -5
  12. package/dist/data-structures/binary-tree/avl-tree.d.ts +106 -0
  13. package/dist/data-structures/binary-tree/avl-tree.js +347 -0
  14. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +149 -0
  15. package/dist/data-structures/binary-tree/binary-indexed-tree.js +269 -0
  16. package/dist/data-structures/binary-tree/binary-tree.d.ts +363 -0
  17. package/dist/data-structures/binary-tree/binary-tree.js +1135 -0
  18. package/dist/data-structures/binary-tree/bst.d.ts +167 -0
  19. package/dist/data-structures/binary-tree/bst.js +512 -0
  20. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  21. package/dist/data-structures/binary-tree/index.js +23 -0
  22. package/dist/data-structures/binary-tree/rb-tree.d.ts +97 -0
  23. package/dist/data-structures/binary-tree/rb-tree.js +388 -0
  24. package/dist/data-structures/binary-tree/segment-tree.d.ts +67 -0
  25. package/dist/data-structures/binary-tree/segment-tree.js +180 -0
  26. package/dist/data-structures/binary-tree/tree-multiset.d.ts +126 -0
  27. package/dist/data-structures/binary-tree/tree-multiset.js +355 -0
  28. package/dist/data-structures/graph/abstract-graph.d.ts +313 -0
  29. package/dist/data-structures/graph/abstract-graph.js +884 -0
  30. package/dist/data-structures/graph/directed-graph.d.ts +194 -0
  31. package/dist/data-structures/graph/directed-graph.js +404 -0
  32. package/dist/data-structures/graph/index.d.ts +4 -0
  33. package/dist/data-structures/graph/index.js +20 -0
  34. package/dist/data-structures/graph/map-graph.d.ts +73 -0
  35. package/dist/data-structures/graph/map-graph.js +93 -0
  36. package/dist/data-structures/graph/undirected-graph.d.ts +120 -0
  37. package/dist/data-structures/graph/undirected-graph.js +239 -0
  38. package/dist/data-structures/hash/coordinate-map.d.ts +44 -0
  39. package/dist/data-structures/hash/coordinate-map.js +62 -0
  40. package/dist/data-structures/hash/coordinate-set.d.ts +36 -0
  41. package/dist/data-structures/hash/coordinate-set.js +52 -0
  42. package/dist/data-structures/hash/hash-map.d.ts +50 -0
  43. package/dist/data-structures/hash/hash-map.js +153 -0
  44. package/dist/data-structures/hash/hash-table.d.ts +103 -0
  45. package/dist/data-structures/hash/hash-table.js +236 -0
  46. package/dist/data-structures/hash/index.d.ts +6 -0
  47. package/dist/data-structures/hash/index.js +22 -0
  48. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  49. package/dist/data-structures/hash/tree-map.js +6 -0
  50. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  51. package/dist/data-structures/hash/tree-set.js +6 -0
  52. package/dist/data-structures/heap/heap.d.ts +235 -0
  53. package/dist/data-structures/heap/heap.js +515 -0
  54. package/dist/data-structures/heap/index.d.ts +3 -0
  55. package/dist/data-structures/heap/index.js +19 -0
  56. package/dist/data-structures/heap/max-heap.d.ts +15 -0
  57. package/dist/data-structures/heap/max-heap.js +26 -0
  58. package/dist/data-structures/heap/min-heap.d.ts +15 -0
  59. package/dist/data-structures/heap/min-heap.js +26 -0
  60. package/dist/data-structures/index.d.ts +11 -0
  61. package/dist/data-structures/index.js +27 -0
  62. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +253 -0
  63. package/dist/data-structures/linked-list/doubly-linked-list.js +569 -0
  64. package/dist/data-structures/linked-list/index.d.ts +3 -0
  65. package/dist/data-structures/linked-list/index.js +19 -0
  66. package/dist/data-structures/linked-list/singly-linked-list.d.ts +232 -0
  67. package/dist/data-structures/linked-list/singly-linked-list.js +533 -0
  68. package/dist/data-structures/linked-list/skip-linked-list.d.ts +80 -0
  69. package/dist/data-structures/linked-list/skip-linked-list.js +187 -0
  70. package/dist/data-structures/matrix/index.d.ts +4 -0
  71. package/dist/data-structures/matrix/index.js +20 -0
  72. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  73. package/dist/data-structures/matrix/matrix.js +28 -0
  74. package/dist/data-structures/matrix/matrix2d.d.ts +107 -0
  75. package/dist/data-structures/matrix/matrix2d.js +199 -0
  76. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  77. package/dist/data-structures/matrix/navigator.js +106 -0
  78. package/dist/data-structures/matrix/vector2d.d.ts +200 -0
  79. package/dist/data-structures/matrix/vector2d.js +290 -0
  80. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  81. package/dist/data-structures/priority-queue/index.js +19 -0
  82. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +15 -0
  83. package/dist/data-structures/priority-queue/max-priority-queue.js +26 -0
  84. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +15 -0
  85. package/dist/data-structures/priority-queue/min-priority-queue.js +26 -0
  86. package/dist/data-structures/priority-queue/priority-queue.d.ts +15 -0
  87. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  88. package/dist/data-structures/queue/deque.d.ts +161 -0
  89. package/dist/data-structures/queue/deque.js +264 -0
  90. package/dist/data-structures/queue/index.d.ts +2 -0
  91. package/dist/data-structures/queue/index.js +18 -0
  92. package/dist/data-structures/queue/queue.d.ts +122 -0
  93. package/dist/data-structures/queue/queue.js +187 -0
  94. package/dist/data-structures/stack/index.d.ts +1 -0
  95. package/dist/data-structures/stack/index.js +17 -0
  96. package/dist/data-structures/stack/stack.d.ts +64 -0
  97. package/dist/data-structures/stack/stack.js +94 -0
  98. package/dist/data-structures/tree/index.d.ts +1 -0
  99. package/dist/data-structures/tree/index.js +17 -0
  100. package/dist/data-structures/tree/tree.d.ts +8 -0
  101. package/dist/data-structures/tree/tree.js +40 -0
  102. package/dist/data-structures/trie/index.d.ts +1 -0
  103. package/dist/data-structures/trie/index.js +17 -0
  104. package/dist/data-structures/trie/trie.d.ts +79 -0
  105. package/dist/data-structures/trie/trie.js +251 -0
  106. package/dist/index.d.ts +3 -1
  107. package/dist/index.js +18 -4
  108. package/dist/interfaces/binary-tree.d.ts +7 -0
  109. package/dist/interfaces/binary-tree.js +2 -0
  110. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  111. package/dist/interfaces/doubly-linked-list.js +2 -0
  112. package/dist/interfaces/graph.d.ts +5 -0
  113. package/dist/interfaces/graph.js +2 -0
  114. package/dist/interfaces/heap.d.ts +1 -0
  115. package/dist/interfaces/heap.js +2 -0
  116. package/dist/interfaces/index.d.ts +8 -0
  117. package/dist/interfaces/index.js +24 -0
  118. package/dist/interfaces/navigator.d.ts +1 -0
  119. package/dist/interfaces/navigator.js +2 -0
  120. package/dist/interfaces/priority-queue.d.ts +1 -0
  121. package/dist/interfaces/priority-queue.js +2 -0
  122. package/dist/interfaces/segment-tree.d.ts +1 -0
  123. package/dist/interfaces/segment-tree.js +2 -0
  124. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  125. package/dist/interfaces/singly-linked-list.js +2 -0
  126. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  127. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  128. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  129. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  130. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  131. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  132. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
  133. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  134. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  135. package/dist/types/data-structures/binary-tree/index.js +22 -0
  136. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +4 -0
  137. package/dist/types/data-structures/binary-tree/rb-tree.js +13 -0
  138. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  139. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  140. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  141. package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
  142. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  143. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  144. package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
  145. package/dist/types/data-structures/graph/directed-graph.js +9 -0
  146. package/dist/types/data-structures/graph/index.d.ts +3 -0
  147. package/dist/types/data-structures/graph/index.js +19 -0
  148. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  149. package/dist/types/data-structures/graph/map-graph.js +2 -0
  150. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  151. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  152. package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
  153. package/dist/types/data-structures/hash/coordinate-map.js +2 -0
  154. package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
  155. package/dist/types/data-structures/hash/coordinate-set.js +2 -0
  156. package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
  157. package/dist/types/data-structures/hash/hash-map.js +2 -0
  158. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  159. package/dist/types/data-structures/hash/hash-table.js +2 -0
  160. package/dist/types/data-structures/hash/index.d.ts +1 -0
  161. package/dist/types/data-structures/hash/index.js +2 -0
  162. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  163. package/dist/types/data-structures/hash/tree-map.js +2 -0
  164. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  165. package/dist/types/data-structures/hash/tree-set.js +2 -0
  166. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  167. package/dist/types/data-structures/heap/heap.js +2 -0
  168. package/dist/types/data-structures/heap/index.d.ts +1 -0
  169. package/dist/types/data-structures/heap/index.js +17 -0
  170. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  171. package/dist/types/data-structures/heap/max-heap.js +2 -0
  172. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  173. package/dist/types/data-structures/heap/min-heap.js +2 -0
  174. package/dist/types/data-structures/index.d.ts +11 -0
  175. package/dist/types/data-structures/index.js +27 -0
  176. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  177. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  178. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  179. package/dist/types/data-structures/linked-list/index.js +18 -0
  180. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  181. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  182. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  183. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  184. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  185. package/dist/types/data-structures/matrix/index.js +17 -0
  186. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  187. package/dist/types/data-structures/matrix/matrix.js +2 -0
  188. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  189. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  190. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  191. package/dist/types/data-structures/matrix/navigator.js +2 -0
  192. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  193. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  194. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  195. package/dist/types/data-structures/priority-queue/index.js +19 -0
  196. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  199. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  200. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  201. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  202. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  203. package/dist/types/data-structures/queue/deque.js +2 -0
  204. package/dist/types/data-structures/queue/index.d.ts +2 -0
  205. package/dist/types/data-structures/queue/index.js +18 -0
  206. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  207. package/dist/types/data-structures/queue/queue.js +2 -0
  208. package/dist/types/data-structures/stack/index.d.ts +1 -0
  209. package/dist/types/data-structures/stack/index.js +17 -0
  210. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  211. package/dist/types/data-structures/stack/stack.js +2 -0
  212. package/dist/types/data-structures/tree/index.d.ts +1 -0
  213. package/dist/types/data-structures/tree/index.js +17 -0
  214. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  215. package/dist/types/data-structures/tree/tree.js +2 -0
  216. package/dist/types/data-structures/trie/index.d.ts +1 -0
  217. package/dist/types/data-structures/trie/index.js +17 -0
  218. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  219. package/dist/types/data-structures/trie/trie.js +2 -0
  220. package/dist/types/helpers.d.ts +8 -0
  221. package/dist/types/helpers.js +9 -0
  222. package/dist/types/index.d.ts +3 -0
  223. package/dist/types/index.js +19 -0
  224. package/dist/types/utils/index.d.ts +2 -0
  225. package/dist/types/utils/index.js +18 -0
  226. package/dist/types/utils/utils.d.ts +7 -0
  227. package/dist/types/utils/utils.js +2 -0
  228. package/dist/types/utils/validate-type.d.ts +19 -0
  229. package/dist/types/utils/validate-type.js +2 -0
  230. package/dist/utils/index.d.ts +1 -0
  231. package/dist/utils/index.js +17 -0
  232. package/dist/utils/utils.d.ts +20 -0
  233. package/dist/utils/utils.js +73 -0
  234. package/jest.config.js +6 -6
  235. package/package.json +2 -2
  236. package/src/data-structures/binary-tree/avl-tree.ts +350 -0
  237. package/src/data-structures/binary-tree/binary-indexed-tree.ts +306 -0
  238. package/src/data-structures/binary-tree/binary-tree.ts +1284 -0
  239. package/src/data-structures/binary-tree/bst.ts +522 -0
  240. package/src/data-structures/binary-tree/index.ts +7 -0
  241. package/src/data-structures/binary-tree/rb-tree.ts +426 -0
  242. package/src/data-structures/binary-tree/segment-tree.ts +190 -0
  243. package/src/data-structures/binary-tree/tree-multiset.ts +379 -0
  244. package/src/data-structures/graph/abstract-graph.ts +1000 -0
  245. package/src/data-structures/graph/directed-graph.ts +449 -0
  246. package/src/data-structures/graph/index.ts +4 -0
  247. package/src/data-structures/graph/map-graph.ts +106 -0
  248. package/src/data-structures/graph/undirected-graph.ts +259 -0
  249. package/src/data-structures/hash/coordinate-map.ts +63 -0
  250. package/src/data-structures/hash/coordinate-set.ts +52 -0
  251. package/src/data-structures/hash/hash-map.ts +185 -0
  252. package/src/data-structures/hash/hash-table.ts +268 -0
  253. package/src/data-structures/hash/index.ts +6 -0
  254. package/src/data-structures/hash/tree-map.ts +2 -0
  255. package/src/data-structures/hash/tree-set.ts +2 -0
  256. package/src/data-structures/heap/heap.ts +589 -0
  257. package/src/data-structures/heap/index.ts +3 -0
  258. package/src/data-structures/heap/max-heap.ts +26 -0
  259. package/src/data-structures/heap/min-heap.ts +26 -0
  260. package/src/data-structures/index.ts +11 -0
  261. package/src/data-structures/linked-list/doubly-linked-list.ts +605 -0
  262. package/src/data-structures/linked-list/index.ts +3 -0
  263. package/src/data-structures/linked-list/singly-linked-list.ts +576 -0
  264. package/src/data-structures/linked-list/skip-linked-list.ts +221 -0
  265. package/src/data-structures/matrix/index.ts +4 -0
  266. package/src/data-structures/matrix/matrix.ts +27 -0
  267. package/src/data-structures/matrix/matrix2d.ts +211 -0
  268. package/src/data-structures/matrix/navigator.ts +121 -0
  269. package/src/data-structures/matrix/vector2d.ts +315 -0
  270. package/src/data-structures/priority-queue/index.ts +3 -0
  271. package/src/data-structures/priority-queue/max-priority-queue.ts +25 -0
  272. package/src/data-structures/priority-queue/min-priority-queue.ts +25 -0
  273. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  274. package/src/data-structures/queue/deque.ts +282 -0
  275. package/src/data-structures/queue/index.ts +2 -0
  276. package/src/data-structures/queue/queue.ts +209 -0
  277. package/src/data-structures/stack/index.ts +1 -0
  278. package/src/data-structures/stack/stack.ts +102 -0
  279. package/src/data-structures/tree/index.ts +1 -0
  280. package/src/data-structures/tree/tree.ts +41 -0
  281. package/src/data-structures/trie/index.ts +1 -0
  282. package/src/data-structures/trie/trie.ts +262 -0
  283. package/src/index.ts +4 -1
  284. package/src/interfaces/binary-tree.ts +10 -0
  285. package/src/interfaces/doubly-linked-list.ts +1 -0
  286. package/src/interfaces/graph.ts +7 -0
  287. package/src/interfaces/heap.ts +1 -0
  288. package/src/interfaces/index.ts +8 -0
  289. package/src/interfaces/navigator.ts +1 -0
  290. package/src/interfaces/priority-queue.ts +1 -0
  291. package/src/interfaces/segment-tree.ts +1 -0
  292. package/src/interfaces/singly-linked-list.ts +1 -0
  293. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  294. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  295. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  296. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  297. package/src/types/data-structures/binary-tree/index.ts +6 -0
  298. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  299. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  300. package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
  301. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  302. package/src/types/data-structures/graph/directed-graph.ts +8 -0
  303. package/src/types/data-structures/graph/index.ts +3 -0
  304. package/src/types/data-structures/graph/map-graph.ts +1 -0
  305. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  306. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  307. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  308. package/src/types/data-structures/hash/hash-map.ts +1 -0
  309. package/src/types/data-structures/hash/hash-table.ts +1 -0
  310. package/src/types/data-structures/hash/index.ts +1 -0
  311. package/src/types/data-structures/hash/tree-map.ts +1 -0
  312. package/src/types/data-structures/hash/tree-set.ts +1 -0
  313. package/src/types/data-structures/heap/heap.ts +1 -0
  314. package/src/types/data-structures/heap/index.ts +1 -0
  315. package/src/types/data-structures/heap/max-heap.ts +1 -0
  316. package/src/types/data-structures/heap/min-heap.ts +1 -0
  317. package/src/types/data-structures/index.ts +11 -0
  318. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  319. package/src/types/data-structures/linked-list/index.ts +2 -0
  320. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  321. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  322. package/src/types/data-structures/matrix/index.ts +1 -0
  323. package/src/types/data-structures/matrix/matrix.ts +1 -0
  324. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  325. package/src/types/data-structures/matrix/navigator.ts +14 -0
  326. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  327. package/src/types/data-structures/priority-queue/index.ts +3 -0
  328. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  329. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  330. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  331. package/src/types/data-structures/queue/deque.ts +1 -0
  332. package/src/types/data-structures/queue/index.ts +2 -0
  333. package/src/types/data-structures/queue/queue.ts +1 -0
  334. package/src/types/data-structures/stack/index.ts +1 -0
  335. package/src/types/data-structures/stack/stack.ts +1 -0
  336. package/src/types/data-structures/tree/index.ts +1 -0
  337. package/src/types/data-structures/tree/tree.ts +1 -0
  338. package/src/types/data-structures/trie/index.ts +1 -0
  339. package/src/types/data-structures/trie/trie.ts +1 -0
  340. package/src/types/helpers.ts +11 -0
  341. package/src/types/index.ts +3 -0
  342. package/src/types/utils/index.ts +2 -0
  343. package/src/types/utils/utils.ts +6 -0
  344. package/src/types/utils/validate-type.ts +35 -0
  345. package/src/utils/index.ts +1 -0
  346. package/src/utils/utils.ts +86 -0
  347. package/tsconfig.json +1 -2
@@ -0,0 +1,512 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BST = exports.BSTNode = void 0;
4
+ const types_1 = require("../../types");
5
+ const binary_tree_1 = require("./binary-tree");
6
+ const queue_1 = require("../queue");
7
+ class BSTNode extends binary_tree_1.BinaryTreeNode {
8
+ constructor(key, value) {
9
+ super(key, value);
10
+ }
11
+ }
12
+ exports.BSTNode = BSTNode;
13
+ class BST extends binary_tree_1.BinaryTree {
14
+ /**
15
+ * The constructor function initializes a binary search tree object with an optional comparator
16
+ * function.
17
+ * @param {BSTOptions} [options] - An optional object that contains configuration options for the
18
+ * binary search tree.
19
+ */
20
+ constructor(options) {
21
+ super(options);
22
+ this._comparator = (a, b) => a - b;
23
+ if (options !== undefined) {
24
+ const { comparator } = options;
25
+ if (comparator !== undefined) {
26
+ this._comparator = comparator;
27
+ }
28
+ }
29
+ }
30
+ /**
31
+ * The function creates a new binary search tree node with the given key and value.
32
+ * @param {BTNKey} key - The key parameter is the key value that will be associated with
33
+ * the new node. It is used to determine the position of the node in the binary search tree.
34
+ * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It
35
+ * represents the value associated with the node in a binary search tree.
36
+ * @returns a new instance of the BSTNode class with the specified key and value.
37
+ */
38
+ createNode(key, value) {
39
+ return new BSTNode(key, value);
40
+ }
41
+ /**
42
+ * The `add` function in a binary search tree class inserts a new node with a given key and value
43
+ * into the tree.
44
+ * @param {BTNKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a
45
+ * `BTNKey` (which can be a number or a string), a `BSTNode` object, or `null`.
46
+ * @param [value] - The `value` parameter is the value to be assigned to the new node being added to the
47
+ * binary search tree.
48
+ * @returns the inserted node (N) if it was successfully added to the binary search tree. If the node
49
+ * was not added or if the parameters were invalid, it returns null or undefined.
50
+ */
51
+ add(keyOrNode, value) {
52
+ // TODO support node as a parameter
53
+ let inserted = null;
54
+ let newNode = null;
55
+ if (keyOrNode instanceof BSTNode) {
56
+ newNode = keyOrNode;
57
+ }
58
+ else if (typeof keyOrNode === 'number') {
59
+ newNode = this.createNode(keyOrNode, value);
60
+ }
61
+ else if (keyOrNode === null) {
62
+ newNode = null;
63
+ }
64
+ if (this.root === null) {
65
+ this._setRoot(newNode);
66
+ this._size = this.size + 1;
67
+ inserted = this.root;
68
+ }
69
+ else {
70
+ let cur = this.root;
71
+ let traversing = true;
72
+ while (traversing) {
73
+ if (cur !== null && newNode !== null) {
74
+ if (this._compare(cur.key, newNode.key) === types_1.CP.eq) {
75
+ if (newNode) {
76
+ cur.value = newNode.value;
77
+ }
78
+ //Duplicates are not accepted.
79
+ traversing = false;
80
+ inserted = cur;
81
+ }
82
+ else if (this._compare(cur.key, newNode.key) === types_1.CP.gt) {
83
+ // Traverse left of the node
84
+ if (cur.left === undefined) {
85
+ if (newNode) {
86
+ newNode.parent = cur;
87
+ }
88
+ //Add to the left of the current node
89
+ cur.left = newNode;
90
+ this._size = this.size + 1;
91
+ traversing = false;
92
+ inserted = cur.left;
93
+ }
94
+ else {
95
+ //Traverse the left of the current node
96
+ if (cur.left)
97
+ cur = cur.left;
98
+ }
99
+ }
100
+ else if (this._compare(cur.key, newNode.key) === types_1.CP.lt) {
101
+ // Traverse right of the node
102
+ if (cur.right === undefined) {
103
+ if (newNode) {
104
+ newNode.parent = cur;
105
+ }
106
+ //Add to the right of the current node
107
+ cur.right = newNode;
108
+ this._size = this.size + 1;
109
+ traversing = false;
110
+ inserted = cur.right;
111
+ }
112
+ else {
113
+ //Traverse the left of the current node
114
+ if (cur.right)
115
+ cur = cur.right;
116
+ }
117
+ }
118
+ }
119
+ else {
120
+ traversing = false;
121
+ }
122
+ }
123
+ }
124
+ return inserted;
125
+ }
126
+ /**
127
+ * The `addMany` function is used to efficiently add multiple nodes to a binary search tree while
128
+ * maintaining balance.
129
+ * @param {[BTNKey | N, V][]} keysOrNodes - The `arr` parameter in the `addMany` function
130
+ * represents an array of keys or nodes that need to be added to the binary search tree. It can be an
131
+ * array of `BTNKey` or `N` (which represents the node type in the binary search tree) or
132
+ * `null
133
+ * @param {V[]} data - The values of tree nodes
134
+ * @param {boolean} isBalanceAdd - If true the nodes will be balance inserted in binary search method.
135
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used.
136
+ * It can have two possible values:
137
+ * @returns The `addMany` function returns an array of `N`, `null`, or `undefined` values.
138
+ */
139
+ addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.iterationType) {
140
+ // TODO this addMany function is inefficient, it should be optimized
141
+ function hasNoNull(arr) {
142
+ return arr.indexOf(null) === -1;
143
+ }
144
+ if (!isBalanceAdd || !hasNoNull(keysOrNodes)) {
145
+ return super.addMany(keysOrNodes, data);
146
+ }
147
+ const inserted = [];
148
+ const combinedArr = keysOrNodes.map((value, index) => [value, data === null || data === void 0 ? void 0 : data[index]]);
149
+ let sorted = [];
150
+ function isNodeOrNullTuple(arr) {
151
+ for (const [keyOrNode] of arr)
152
+ if (keyOrNode instanceof BSTNode)
153
+ return true;
154
+ return false;
155
+ }
156
+ function isBinaryTreeKeyOrNullTuple(arr) {
157
+ for (const [keyOrNode] of arr)
158
+ if (typeof keyOrNode === 'number')
159
+ return true;
160
+ return false;
161
+ }
162
+ let sortedKeysOrNodes = [], sortedData = [];
163
+ if (isNodeOrNullTuple(combinedArr)) {
164
+ sorted = combinedArr.sort((a, b) => a[0].key - b[0].key);
165
+ }
166
+ else if (isBinaryTreeKeyOrNullTuple(combinedArr)) {
167
+ sorted = combinedArr.sort((a, b) => a[0] - b[0]);
168
+ }
169
+ else {
170
+ throw new Error('Invalid input keysOrNodes');
171
+ }
172
+ sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode);
173
+ sortedData = sorted.map(([, value]) => value);
174
+ const recursive = (arr, data) => {
175
+ if (arr.length === 0)
176
+ return;
177
+ const mid = Math.floor((arr.length - 1) / 2);
178
+ const newNode = this.add(arr[mid], data === null || data === void 0 ? void 0 : data[mid]);
179
+ inserted.push(newNode);
180
+ recursive(arr.slice(0, mid), data === null || data === void 0 ? void 0 : data.slice(0, mid));
181
+ recursive(arr.slice(mid + 1), data === null || data === void 0 ? void 0 : data.slice(mid + 1));
182
+ };
183
+ const iterative = () => {
184
+ const n = sorted.length;
185
+ const stack = [[0, n - 1]];
186
+ while (stack.length > 0) {
187
+ const popped = stack.pop();
188
+ if (popped) {
189
+ const [l, r] = popped;
190
+ if (l <= r) {
191
+ const m = l + Math.floor((r - l) / 2);
192
+ const newNode = this.add(sortedKeysOrNodes[m], sortedData === null || sortedData === void 0 ? void 0 : sortedData[m]);
193
+ inserted.push(newNode);
194
+ stack.push([m + 1, r]);
195
+ stack.push([l, m - 1]);
196
+ }
197
+ }
198
+ }
199
+ };
200
+ if (iterationType === types_1.IterationType.RECURSIVE) {
201
+ recursive(sortedKeysOrNodes, sortedData);
202
+ }
203
+ else {
204
+ iterative();
205
+ }
206
+ return inserted;
207
+ }
208
+ /**
209
+ * The function returns the first node in the binary tree that matches the given node property and
210
+ * callback.
211
+ * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
212
+ * property of the binary tree node that you want to search for. It can be either a specific key
213
+ * value (`BTNKey`) or a custom callback function (`BTNCallback<N>`) that determines
214
+ * whether a node matches the desired property.
215
+ * @param callback - The `callback` parameter is a function that is used to determine whether a node
216
+ * matches the desired property. It takes a node as input and returns a boolean value indicating
217
+ * whether the node matches the property or not. If no callback function is provided, the default
218
+ * callback function `_defaultCallbackByKey` is used
219
+ * @param beginRoot - The `beginRoot` parameter is the starting point for the search. It specifies
220
+ * the root node from which the search should begin.
221
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
222
+ * be performed when searching for nodes in the binary tree. It can have one of the following values:
223
+ * @returns either the first node that matches the given nodeProperty and callback, or null if no
224
+ * matching node is found.
225
+ */
226
+ get(identifier, callback = ((node) => node.key), beginRoot = this.root, iterationType = this.iterationType) {
227
+ var _a;
228
+ return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : null;
229
+ }
230
+ /**
231
+ * The function `lastKey` returns the key of the rightmost node if the comparison result is less
232
+ * than, the key of the leftmost node if the comparison result is greater than, and the key of the
233
+ * rightmost node otherwise.
234
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting point for finding the last
235
+ * key in a binary tree. It represents the root node of the subtree from which the search for the
236
+ * last key should begin. If no specific `beginRoot` is provided, the search will start from the root
237
+ * of the entire binary
238
+ * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
239
+ * be performed when finding the last key. It determines whether the iteration should be performed in
240
+ * pre-order, in-order, or post-order.
241
+ * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
242
+ * the key of the leftmost node if the comparison result is greater than, and the key of the
243
+ * rightmost node otherwise. If no node is found, it returns 0.
244
+ */
245
+ lastKey(beginRoot = this.root, iterationType = this.iterationType) {
246
+ var _a, _b, _c, _d, _e, _f;
247
+ if (this._compare(0, 1) === types_1.CP.lt)
248
+ return (_b = (_a = this.getRightMost(beginRoot, iterationType)) === null || _a === void 0 ? void 0 : _a.key) !== null && _b !== void 0 ? _b : 0;
249
+ else if (this._compare(0, 1) === types_1.CP.gt)
250
+ return (_d = (_c = this.getLeftMost(beginRoot, iterationType)) === null || _c === void 0 ? void 0 : _c.key) !== null && _d !== void 0 ? _d : 0;
251
+ else
252
+ return (_f = (_e = this.getRightMost(beginRoot, iterationType)) === null || _e === void 0 ? void 0 : _e.key) !== null && _f !== void 0 ? _f : 0;
253
+ }
254
+ /**
255
+ * The function `getNodes` retrieves nodes from a binary tree based on a given node property or key,
256
+ * using either recursive or iterative traversal.
257
+ * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter represents the property
258
+ * of the binary tree node that you want to search for. It can be either a `BTNKey` or a
259
+ * generic type `N`.
260
+ * @param callback - The `callback` parameter is a function that takes a node as input and returns a
261
+ * value. This value is compared with the `nodeProperty` parameter to determine if the node should be
262
+ * included in the result. The default value for `callback` is `((node: N) => node.key)`, which is
263
+ * a
264
+ * @param [onlyOne=false] - A boolean value indicating whether to stop the traversal after finding
265
+ * the first node that matches the nodeProperty. If set to true, the function will return an array
266
+ * containing only that node. If set to false (default), the function will continue the traversal and
267
+ * return an array containing all nodes that match the node
268
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the traversal. It
269
+ * specifies the root node of the binary tree from which the traversal should begin. If `beginRoot`
270
+ * is `null`, an empty array will be returned.
271
+ * @param iterationType - The `iterationType` parameter determines the type of iteration used to
272
+ * traverse the binary tree. It can have one of the following values:
273
+ * @returns an array of nodes (N[]).
274
+ */
275
+ getNodes(identifier, callback = ((node) => node.key), onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
276
+ if (!beginRoot)
277
+ return [];
278
+ const ans = [];
279
+ if (iterationType === types_1.IterationType.RECURSIVE) {
280
+ const _traverse = (cur) => {
281
+ const callbackResult = callback(cur);
282
+ if (callbackResult === identifier) {
283
+ ans.push(cur);
284
+ if (onlyOne)
285
+ return;
286
+ }
287
+ if (!cur.left && !cur.right)
288
+ return;
289
+ // TODO potential bug
290
+ if (callback === ((node) => node.key)) {
291
+ if (this._compare(cur.key, identifier) === types_1.CP.gt)
292
+ cur.left && _traverse(cur.left);
293
+ if (this._compare(cur.key, identifier) === types_1.CP.lt)
294
+ cur.right && _traverse(cur.right);
295
+ }
296
+ else {
297
+ cur.left && _traverse(cur.left);
298
+ cur.right && _traverse(cur.right);
299
+ }
300
+ };
301
+ _traverse(beginRoot);
302
+ }
303
+ else {
304
+ const queue = new queue_1.Queue([beginRoot]);
305
+ while (queue.size > 0) {
306
+ const cur = queue.shift();
307
+ if (cur) {
308
+ const callbackResult = callback(cur);
309
+ if (callbackResult === identifier) {
310
+ ans.push(cur);
311
+ if (onlyOne)
312
+ return ans;
313
+ }
314
+ // TODO potential bug
315
+ if (callback === ((node) => node.key)) {
316
+ if (this._compare(cur.key, identifier) === types_1.CP.gt)
317
+ cur.left && queue.push(cur.left);
318
+ if (this._compare(cur.key, identifier) === types_1.CP.lt)
319
+ cur.right && queue.push(cur.right);
320
+ }
321
+ else {
322
+ cur.left && queue.push(cur.left);
323
+ cur.right && queue.push(cur.right);
324
+ }
325
+ }
326
+ }
327
+ }
328
+ return ans;
329
+ }
330
+ // --- start additional functions
331
+ /**
332
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
333
+ * nodes that have a key value lesser or greater than a target key value.
334
+ * @param callback - The `callback` parameter is a function that will be called for each node that
335
+ * meets the condition specified by the `lesserOrGreater` parameter. It takes a node as an argument
336
+ * and returns a value.
337
+ * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
338
+ * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It can take one
339
+ * of the following values:
340
+ * @param {BTNKey | N | null} targetNode - The `targetNode` parameter in the
341
+ * `lesserOrGreaterTraverse` function is used to specify the node from which the traversal should
342
+ * start. It can be either a reference to a specific node (`N`), the key of a node
343
+ * (`BTNKey`), or `null` to
344
+ * @param iterationType - The `iterationType` parameter determines whether the traversal should be
345
+ * done recursively or iteratively. It can have two possible values:
346
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
347
+ */
348
+ lesserOrGreaterTraverse(callback = ((node) => node.key), lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
349
+ if (typeof targetNode === 'number')
350
+ targetNode = this.get(targetNode);
351
+ const ans = [];
352
+ if (!targetNode)
353
+ return ans;
354
+ const targetKey = targetNode.key;
355
+ if (!this.root)
356
+ return ans;
357
+ if (iterationType === types_1.IterationType.RECURSIVE) {
358
+ const _traverse = (cur) => {
359
+ const compared = this._compare(cur.key, targetKey);
360
+ if (compared === lesserOrGreater)
361
+ ans.push(callback(cur));
362
+ if (!cur.left && !cur.right)
363
+ return;
364
+ if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater)
365
+ _traverse(cur.left);
366
+ if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater)
367
+ _traverse(cur.right);
368
+ };
369
+ _traverse(this.root);
370
+ return ans;
371
+ }
372
+ else {
373
+ const queue = new queue_1.Queue([this.root]);
374
+ while (queue.size > 0) {
375
+ const cur = queue.shift();
376
+ if (cur) {
377
+ const compared = this._compare(cur.key, targetKey);
378
+ if (compared === lesserOrGreater)
379
+ ans.push(callback(cur));
380
+ if (cur.left && this._compare(cur.left.key, targetKey) === lesserOrGreater)
381
+ queue.push(cur.left);
382
+ if (cur.right && this._compare(cur.right.key, targetKey) === lesserOrGreater)
383
+ queue.push(cur.right);
384
+ }
385
+ }
386
+ return ans;
387
+ }
388
+ }
389
+ /**
390
+ * Balancing Adjustment:
391
+ * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
392
+ * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
393
+ *
394
+ * Use Cases and Efficiency:
395
+ * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
396
+ * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
397
+ */
398
+ /**
399
+ * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
400
+ * ensures the tree is perfectly balanced.
401
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
402
+ * type of iteration to use when building a balanced binary search tree. It can have two possible
403
+ * values:
404
+ * @returns The function `perfectlyBalance` returns a boolean value.
405
+ */
406
+ perfectlyBalance(iterationType = this.iterationType) {
407
+ const sorted = this.dfs(node => node, 'in'), n = sorted.length;
408
+ this.clear();
409
+ if (sorted.length < 1)
410
+ return false;
411
+ if (iterationType === types_1.IterationType.RECURSIVE) {
412
+ const buildBalanceBST = (l, r) => {
413
+ if (l > r)
414
+ return;
415
+ const m = l + Math.floor((r - l) / 2);
416
+ const midNode = sorted[m];
417
+ this.add(midNode.key, midNode.value);
418
+ buildBalanceBST(l, m - 1);
419
+ buildBalanceBST(m + 1, r);
420
+ };
421
+ buildBalanceBST(0, n - 1);
422
+ return true;
423
+ }
424
+ else {
425
+ const stack = [[0, n - 1]];
426
+ while (stack.length > 0) {
427
+ const popped = stack.pop();
428
+ if (popped) {
429
+ const [l, r] = popped;
430
+ if (l <= r) {
431
+ const m = l + Math.floor((r - l) / 2);
432
+ const midNode = sorted[m];
433
+ this.add(midNode.key, midNode.value);
434
+ stack.push([m + 1, r]);
435
+ stack.push([l, m - 1]);
436
+ }
437
+ }
438
+ }
439
+ return true;
440
+ }
441
+ }
442
+ /**
443
+ * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
444
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
445
+ * to check if the AVL tree is balanced. It can have two possible values:
446
+ * @returns a boolean value.
447
+ */
448
+ isAVLBalanced(iterationType = this.iterationType) {
449
+ var _a, _b;
450
+ if (!this.root)
451
+ return true;
452
+ let balanced = true;
453
+ if (iterationType === types_1.IterationType.RECURSIVE) {
454
+ const _height = (cur) => {
455
+ if (!cur)
456
+ return 0;
457
+ const leftHeight = _height(cur.left), rightHeight = _height(cur.right);
458
+ if (Math.abs(leftHeight - rightHeight) > 1)
459
+ balanced = false;
460
+ return Math.max(leftHeight, rightHeight) + 1;
461
+ };
462
+ _height(this.root);
463
+ }
464
+ else {
465
+ const stack = [];
466
+ let node = this.root, last = null;
467
+ const depths = new Map();
468
+ while (stack.length > 0 || node) {
469
+ if (node) {
470
+ stack.push(node);
471
+ node = node.left;
472
+ }
473
+ else {
474
+ node = stack[stack.length - 1];
475
+ if (!node.right || last === node.right) {
476
+ node = stack.pop();
477
+ if (node) {
478
+ const left = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
479
+ const right = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
480
+ if (Math.abs(left - right) > 1)
481
+ return false;
482
+ depths.set(node, 1 + Math.max(left, right));
483
+ last = node;
484
+ node = null;
485
+ }
486
+ }
487
+ else
488
+ node = node.right;
489
+ }
490
+ }
491
+ }
492
+ return balanced;
493
+ }
494
+ /**
495
+ * The function compares two values using a comparator function and returns whether the first value
496
+ * is greater than, less than, or equal to the second value.
497
+ * @param {BTNKey} a - The parameter "a" is of type BTNKey.
498
+ * @param {BTNKey} b - The parameter "b" in the above code represents a BTNKey.
499
+ * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
500
+ * than), CP.lt (less than), or CP.eq (equal).
501
+ */
502
+ _compare(a, b) {
503
+ const compared = this._comparator(a, b);
504
+ if (compared > 0)
505
+ return types_1.CP.gt;
506
+ else if (compared < 0)
507
+ return types_1.CP.lt;
508
+ else
509
+ return types_1.CP.eq;
510
+ }
511
+ }
512
+ exports.BST = BST;
@@ -0,0 +1,7 @@
1
+ export * from './binary-tree';
2
+ export * from './bst';
3
+ export * from './binary-indexed-tree';
4
+ export * from './segment-tree';
5
+ export * from './avl-tree';
6
+ export * from './rb-tree';
7
+ export * from './tree-multiset';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./binary-tree"), exports);
18
+ __exportStar(require("./bst"), exports);
19
+ __exportStar(require("./binary-indexed-tree"), exports);
20
+ __exportStar(require("./segment-tree"), exports);
21
+ __exportStar(require("./avl-tree"), exports);
22
+ __exportStar(require("./rb-tree"), exports);
23
+ __exportStar(require("./tree-multiset"), exports);
@@ -0,0 +1,97 @@
1
+ export declare class RBTreeNode {
2
+ key: number;
3
+ parent: RBTreeNode;
4
+ left: RBTreeNode;
5
+ right: RBTreeNode;
6
+ color: number;
7
+ constructor();
8
+ }
9
+ export declare class RedBlackTree {
10
+ constructor();
11
+ protected _root: RBTreeNode;
12
+ get root(): RBTreeNode;
13
+ protected _NIL: RBTreeNode;
14
+ get NIL(): RBTreeNode;
15
+ /**
16
+ * The `insert` function inserts a new node with a given key into a red-black tree and fixes any
17
+ * violations of the red-black tree properties.
18
+ * @param {number} key - The key parameter is a number that represents the value to be inserted into
19
+ * the RBTree.
20
+ * @returns The function does not explicitly return anything.
21
+ */
22
+ insert(key: number): void;
23
+ /**
24
+ * The `delete` function in TypeScript is used to remove a node with a specific key from a red-black
25
+ * tree.
26
+ * @param {RBTreeNode} node - The `node` parameter is of type `RBTreeNode` and represents the current
27
+ * node being processed in the delete operation.
28
+ * @returns The `delete` function does not return anything. It has a return type of `void`.
29
+ */
30
+ delete(key: number): void;
31
+ /**
32
+ * The function `getNode` is a recursive depth-first search algorithm that searches for a node with a
33
+ * given key in a red-black tree.
34
+ * @param {number} key - The key parameter is a number that represents the value we are searching for
35
+ * in the RBTree.
36
+ * @param beginRoot - The `beginRoot` parameter is an optional parameter that represents the starting
37
+ * point for the search in the binary search tree. If no value is provided for `beginRoot`, it
38
+ * defaults to the root of the binary search tree (`this.root`).
39
+ * @returns a RBTreeNode.
40
+ */
41
+ getNode(key: number, beginRoot?: RBTreeNode): RBTreeNode;
42
+ /**
43
+ * The function returns the leftmost node in a red-black tree.
44
+ * @param {RBTreeNode} node - The parameter "node" is of type RBTreeNode, which represents a node in
45
+ * a Red-Black Tree.
46
+ * @returns The leftmost node in the given RBTreeNode.
47
+ */
48
+ getLeftMost(node: RBTreeNode): RBTreeNode;
49
+ /**
50
+ * The function returns the rightmost node in a red-black tree.
51
+ * @param {RBTreeNode} node - The parameter "node" is of type RBTreeNode.
52
+ * @returns the rightmost node in a red-black tree.
53
+ */
54
+ getRightMost(node: RBTreeNode): RBTreeNode;
55
+ /**
56
+ * The function returns the successor of a given node in a red-black tree.
57
+ * @param {RBTreeNode} x - RBTreeNode - The node for which we want to find the successor.
58
+ * @returns the successor of the given RBTreeNode.
59
+ */
60
+ getSuccessor(x: RBTreeNode): RBTreeNode;
61
+ /**
62
+ * The function returns the predecessor of a given node in a red-black tree.
63
+ * @param {RBTreeNode} x - The parameter `x` is of type `RBTreeNode`, which represents a node in a
64
+ * Red-Black Tree.
65
+ * @returns the predecessor of the given RBTreeNode 'x'.
66
+ */
67
+ getPredecessor(x: RBTreeNode): RBTreeNode;
68
+ /**
69
+ * The function performs a left rotation on a red-black tree node.
70
+ * @param {RBTreeNode} x - The parameter `x` is a RBTreeNode object.
71
+ */
72
+ protected _leftRotate(x: RBTreeNode): void;
73
+ /**
74
+ * The function performs a right rotation on a red-black tree node.
75
+ * @param {RBTreeNode} x - x is a RBTreeNode, which represents the node that needs to be right
76
+ * rotated.
77
+ */
78
+ protected _rightRotate(x: RBTreeNode): void;
79
+ /**
80
+ * The _fixDelete function is used to rebalance the Red-Black Tree after a node deletion.
81
+ * @param {RBTreeNode} x - The parameter `x` is of type `RBTreeNode`, which represents a node in a
82
+ * red-black tree.
83
+ */
84
+ protected _fixDelete(x: RBTreeNode): void;
85
+ /**
86
+ * The function `_rbTransplant` replaces one node in a red-black tree with another node.
87
+ * @param {RBTreeNode} u - The parameter "u" represents a RBTreeNode object.
88
+ * @param {RBTreeNode} v - The parameter "v" is a RBTreeNode object.
89
+ */
90
+ protected _rbTransplant(u: RBTreeNode, v: RBTreeNode): void;
91
+ /**
92
+ * The `_fixInsert` function is used to fix the red-black tree after an insertion operation.
93
+ * @param {RBTreeNode} k - The parameter `k` is a RBTreeNode object, which represents a node in a
94
+ * red-black tree.
95
+ */
96
+ protected _fixInsert(k: RBTreeNode): void;
97
+ }