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,363 @@
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 { BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNKey } 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 N - The type of the family relationship in the binary tree.
15
+ */
16
+ export declare class BinaryTreeNode<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> {
17
+ /**
18
+ * The key associated with the node.
19
+ */
20
+ key: BTNKey;
21
+ /**
22
+ * The value stored in the node.
23
+ */
24
+ value: V | undefined;
25
+ /**
26
+ * The parent node of the current node.
27
+ */
28
+ parent: N | null | undefined;
29
+ /**
30
+ * Creates a new instance of BinaryTreeNode.
31
+ * @param {BTNKey} key - The key associated with the node.
32
+ * @param {V} value - The value stored in the node.
33
+ */
34
+ constructor(key: BTNKey, value?: V);
35
+ protected _left: N | null | undefined;
36
+ /**
37
+ * Get the left child node.
38
+ */
39
+ get left(): N | null | undefined;
40
+ /**
41
+ * Set the left child node.
42
+ * @param {N | null | undefined} v - The left child node.
43
+ */
44
+ set left(v: N | null | undefined);
45
+ protected _right: N | null | undefined;
46
+ /**
47
+ * Get the right child node.
48
+ */
49
+ get right(): N | null | undefined;
50
+ /**
51
+ * Set the right child node.
52
+ * @param {N | null | undefined} v - The right child node.
53
+ */
54
+ set right(v: N | 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<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode<V, BinaryTreeNodeNested<V>>> implements IBinaryTree<V, N> {
66
+ iterationType: IterationType;
67
+ /**
68
+ * Creates a new instance of BinaryTree.
69
+ * @param {BinaryTreeOptions} [options] - The options for the binary tree.
70
+ */
71
+ constructor(options?: BinaryTreeOptions);
72
+ protected _root: N | null;
73
+ /**
74
+ * Get the root node of the binary tree.
75
+ */
76
+ get root(): N | null;
77
+ protected _size: number;
78
+ /**
79
+ * Get the number of nodes in the binary tree.
80
+ */
81
+ get size(): number;
82
+ /**
83
+ * Creates a new instance of BinaryTreeNode with the given key and value.
84
+ * @param {BTNKey} key - The key for the new node.
85
+ * @param {V} value - The value for the new node.
86
+ * @returns {N} - The newly created BinaryTreeNode.
87
+ */
88
+ createNode(key: BTNKey, value?: V): N;
89
+ /**
90
+ * Clear the binary tree, removing all nodes.
91
+ */
92
+ clear(): void;
93
+ /**
94
+ * Check if the binary tree is empty.
95
+ * @returns {boolean} - True if the binary tree is empty, false otherwise.
96
+ */
97
+ isEmpty(): boolean;
98
+ /**
99
+ * Add a node with the given key and value to the binary tree.
100
+ * @param {BTNKey | N | null} keyOrNode - The key or node to add to the binary tree.
101
+ * @param {V} value - The value for the new node (optional).
102
+ * @returns {N | null | undefined} - The inserted node, or null if nothing was inserted, or undefined if the operation failed.
103
+ */
104
+ add(keyOrNode: BTNKey | N | null, value?: V): N | null | undefined;
105
+ /**
106
+ * The `addMany` function takes an array of binary tree node IDs or nodes, and optionally an array of corresponding data
107
+ * values, and adds them to the binary tree.
108
+ * @param {(BTNKey | null)[] | (N | null)[]} keysOrNodes - An array of BTNKey or BinaryTreeNode
109
+ * objects, or null values.
110
+ * @param {V[]} [values] - The `values` parameter is an optional array of values (`V[]`) that corresponds to
111
+ * the nodes or node IDs being added. It is used to set the value of each node being added. If `values` is not provided,
112
+ * the value of the nodes will be `undefined`.
113
+ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
114
+ */
115
+ addMany(keysOrNodes: (BTNKey | null)[] | (N | null)[], values?: V[]): (N | null | undefined)[];
116
+ /**
117
+ * The `refill` function clears the binary tree and adds multiple nodes with the given IDs or nodes and optional data.
118
+ * @param {(BTNKey | N)[]} keysOrNodes - The `keysOrNodes` parameter is an array that can contain either
119
+ * `BTNKey` or `N` values.
120
+ * @param {N[] | Array<V>} [data] - The `data` parameter is an optional array of values that will be assigned to
121
+ * the nodes being added. If provided, the length of the `data` array should be equal to the length of the `keysOrNodes`
122
+ * array. Each value in the `data` array will be assigned to the
123
+ * @returns The method is returning a boolean value.
124
+ */
125
+ refill(keysOrNodes: (BTNKey | null)[] | (N | null)[], data?: Array<V>): boolean;
126
+ delete<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C): BinaryTreeDeletedResult<N>[];
127
+ delete<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C): BinaryTreeDeletedResult<N>[];
128
+ delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C): BinaryTreeDeletedResult<N>[];
129
+ /**
130
+ * The function `getDepth` calculates the depth of a given node in a binary tree relative to a
131
+ * specified root node.
132
+ * @param {BTNKey | N | null} distNode - The `distNode` parameter represents the node
133
+ * whose depth we want to find in the binary tree. It can be either a node object (`N`), a key value
134
+ * of the node (`BTNKey`), or `null`.
135
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter represents the
136
+ * starting node from which we want to calculate the depth. It can be either a node object or the key
137
+ * of a node in the binary tree. If no value is provided for `beginRoot`, it defaults to the root
138
+ * node of the binary tree.
139
+ * @returns the depth of the `distNode` relative to the `beginRoot`.
140
+ */
141
+ getDepth(distNode: BTNKey | N | null, beginRoot?: BTNKey | N | null): number;
142
+ /**
143
+ * The `getHeight` function calculates the maximum height of a binary tree using either recursive or
144
+ * iterative approach.
145
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter represents the
146
+ * starting node from which the height of the binary tree is calculated. It can be either a node
147
+ * object (`N`), a key value of a node in the tree (`BTNKey`), or `null` if no starting
148
+ * node is specified. If `
149
+ * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
150
+ * height of the binary tree using a recursive approach or an iterative approach. It can have two
151
+ * possible values:
152
+ * @returns the height of the binary tree.
153
+ */
154
+ getHeight(beginRoot?: BTNKey | N | null, iterationType?: IterationType): number;
155
+ /**
156
+ * The `getMinHeight` function calculates the minimum height of a binary tree using either a
157
+ * recursive or iterative approach.
158
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which we want to
159
+ * calculate the minimum height of the tree. It is optional and defaults to the root of the tree if
160
+ * not provided.
161
+ * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
162
+ * to calculate the minimum height of a binary tree. It can have two possible values:
163
+ * @returns The function `getMinHeight` returns the minimum height of a binary tree.
164
+ */
165
+ getMinHeight(beginRoot?: N | null, iterationType?: IterationType): number;
166
+ /**
167
+ * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
168
+ * height of the tree.
169
+ * @param {N | null} beginRoot - The parameter `beginRoot` is of type `N | null`, which means it can
170
+ * either be of type `N` (representing a node in a tree) or `null` (representing an empty tree).
171
+ * @returns The method is returning a boolean value.
172
+ */
173
+ isPerfectlyBalanced(beginRoot?: N | null): boolean;
174
+ getNodes<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
175
+ getNodes<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
176
+ getNodes<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, onlyOne?: boolean, beginRoot?: N | null, iterationType?: IterationType): N[];
177
+ has<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N, iterationType?: IterationType): boolean;
178
+ has<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, beginRoot?: N, iterationType?: IterationType): boolean;
179
+ has<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C, beginRoot?: N, iterationType?: IterationType): boolean;
180
+ get<C extends BTNCallback<N, BTNKey>>(identifier: BTNKey, callback?: C, beginRoot?: N, iterationType?: IterationType): N | null;
181
+ get<C extends BTNCallback<N, N>>(identifier: N | null, callback?: C, beginRoot?: N, iterationType?: IterationType): N | null;
182
+ get<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback: C, beginRoot?: N, iterationType?: IterationType): N | null;
183
+ /**
184
+ * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
185
+ * up to the root node, with the option to reverse the order of the nodes.
186
+ * @param {N} beginRoot - The `beginRoot` parameter represents the starting node from which you want
187
+ * to find the path to the root node.
188
+ * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
189
+ * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
190
+ * reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
191
+ * @returns The function `getPathToRoot` returns an array of type `N[]`.
192
+ */
193
+ getPathToRoot(beginRoot: N, isReverse?: boolean): N[];
194
+ /**
195
+ * The function `getLeftMost` returns the leftmost node in a binary tree, either using recursive or
196
+ * iterative traversal.
197
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
198
+ * for finding the leftmost node in a binary tree. It can be either a node object (`N`), a key value
199
+ * of a node (`BTNKey`), or `null` if the tree is empty.
200
+ * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
201
+ * be performed when finding the leftmost node in a binary tree. It can have two possible values:
202
+ * @returns The function `getLeftMost` returns the leftmost node (`N`) in a binary tree. If there is
203
+ * no leftmost node, it returns `null`.
204
+ */
205
+ getLeftMost(beginRoot?: BTNKey | N | null, iterationType?: IterationType): N | null;
206
+ /**
207
+ * The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
208
+ * iteratively.
209
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node from which we want to
210
+ * find the rightmost node. It is of type `N | null`, which means it can either be a node of type `N`
211
+ * or `null`. If it is `null`, it means there is no starting node
212
+ * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
213
+ * be performed when finding the rightmost node in a binary tree. It can have two possible values:
214
+ * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If the
215
+ * `beginRoot` parameter is `null`, it returns `null`.
216
+ */
217
+ getRightMost(beginRoot?: N | null, iterationType?: IterationType): N | null;
218
+ /**
219
+ * The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
220
+ * @param {N} beginRoot - The `beginRoot` parameter is the root node of the binary tree that you want
221
+ * to check if it is a binary search tree (BST) subtree.
222
+ * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
223
+ * type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
224
+ * possible values:
225
+ * @returns The function `isSubtreeBST` returns a boolean value.
226
+ */
227
+ isSubtreeBST(beginRoot: N | null, iterationType?: IterationType): boolean;
228
+ /**
229
+ * The function checks if a binary tree is a binary search tree.
230
+ * @param iterationType - The parameter "iterationType" is used to specify the type of iteration to
231
+ * be used when checking if the binary tree is a binary search tree (BST). It is an optional
232
+ * parameter with a default value of "this.iterationType". The value of "this.iterationType" is not
233
+ * provided in
234
+ * @returns a boolean value.
235
+ */
236
+ isBST(iterationType?: IterationType): boolean;
237
+ /**
238
+ * The function `subTreeTraverse` traverses a binary tree and applies a callback function to each
239
+ * node, either recursively or iteratively.
240
+ * @param callback - The `callback` parameter is a function that will be called on each node in the
241
+ * subtree traversal. It takes a single argument, which is the current node being traversed, and
242
+ * returns a value. The return values from each callback invocation will be collected and returned as
243
+ * an array.
244
+ * @param {BTNKey | N | null} beginRoot - The `beginRoot` parameter is the starting point
245
+ * for traversing the subtree. It can be either a node object, a key value of a node, or `null` to
246
+ * start from the root of the tree.
247
+ * @param iterationType - The `iterationType` parameter determines the type of traversal to be
248
+ * performed on the binary tree. It can have two possible values:
249
+ * @returns The function `subTreeTraverse` returns an array of `ReturnType<BTNCallback<N>>`.
250
+ */
251
+ subTreeTraverse<C extends BTNCallback<N>>(callback?: C, beginRoot?: BTNKey | N | null, iterationType?: IterationType): ReturnType<C>[];
252
+ /**
253
+ * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
254
+ * function on each node according to a specified order pattern.
255
+ * @param callback - The `callback` parameter is a function that will be called on each node during
256
+ * the depth-first search traversal. It takes a node as input and returns a value. The default value
257
+ * is `((node: N) => node.key)`, which is a callback function defined elsewhere in the code.
258
+ * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
259
+ * nodes are visited during the depth-first search. There are three possible values for `pattern`:
260
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the depth-first
261
+ * search. It determines where the search will begin in the tree or graph structure. If `beginRoot`
262
+ * is `null`, an empty array will be returned.
263
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
264
+ * iteration used in the depth-first search algorithm. It can have two possible values:
265
+ * @returns The function `dfs` returns an array of `ReturnType<BTNCallback<N>>` values.
266
+ */
267
+ dfs<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
268
+ /**
269
+ * The bfs function performs a breadth-first search traversal on a binary tree, executing a callback
270
+ * function on each node.
271
+ * @param callback - The `callback` parameter is a function that will be called for each node in the
272
+ * breadth-first search. It takes a node of type `N` as its argument and returns a value of type
273
+ * `ReturnType<BTNCallback<N>>`. The default value for this parameter is `((node: N) => node.key)
274
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the breadth-first
275
+ * search. It determines from which node the search will begin. If `beginRoot` is `null`, the search
276
+ * will not be performed and an empty array will be returned.
277
+ * @param iterationType - The `iterationType` parameter determines the type of iteration to be used
278
+ * in the breadth-first search (BFS) algorithm. It can have two possible values:
279
+ * @returns The function `bfs` returns an array of `ReturnType<BTNCallback<N>>[]`.
280
+ */
281
+ bfs<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[];
282
+ /**
283
+ * The `listLevels` function takes a binary tree node and a callback function, and returns an array
284
+ * of arrays representing the levels of the tree.
285
+ * @param {C} callback - The `callback` parameter is a function that will be called on each node in
286
+ * the tree. It takes a node as input and returns a value. The return type of the callback function
287
+ * is determined by the generic type `C`.
288
+ * @param {N | null} beginRoot - The `beginRoot` parameter represents the starting node of the binary tree
289
+ * traversal. It can be any node in the binary tree. If no node is provided, the traversal will start
290
+ * from the root node of the binary tree.
291
+ * @param iterationType - The `iterationType` parameter determines whether the tree traversal is done
292
+ * recursively or iteratively. It can have two possible values:
293
+ * @returns The function `listLevels` returns an array of arrays, where each inner array represents a
294
+ * level in a binary tree. Each inner array contains the return type of the provided callback
295
+ * function `C` applied to the nodes at that level.
296
+ */
297
+ listLevels<C extends BTNCallback<N>>(callback?: C, beginRoot?: N | null, iterationType?: IterationType): ReturnType<C>[][];
298
+ /**
299
+ * The function returns the predecessor node of a given node in a binary tree.
300
+ * @param {N} node - The parameter "node" represents a node in a binary tree.
301
+ * @returns The function `getPredecessor` returns the predecessor node of the given node `node`.
302
+ */
303
+ getPredecessor(node: N): N;
304
+ /**
305
+ * The function `getSuccessor` returns the next node in a binary tree given a node `x`, or `null` if
306
+ * `x` is the last node.
307
+ * @param {N} x - N - a node in a binary tree
308
+ * @returns The function `getSuccessor` returns a value of type `N` (the successor node), or `null`
309
+ * if there is no successor, or `undefined` if the input `x` is `undefined`.
310
+ */
311
+ getSuccessor(x: N): N | null | undefined;
312
+ /**
313
+ * The `morris` function performs a depth-first traversal of a binary tree using the Morris traversal
314
+ * algorithm and returns an array of values obtained by applying a callback function to each node.
315
+ * @param callback - The `callback` parameter is a function that will be called on each node in the
316
+ * tree. It takes a node of type `N` as input and returns a value of type `ReturnType<BTNCallback<N>>`. The
317
+ * default value for this parameter is `((node: N) => node.key)`.
318
+ * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
319
+ * determines the order in which the nodes of a binary tree are traversed. It can have one of the
320
+ * following values:
321
+ * @param {N | null} beginRoot - The `beginRoot` parameter is the starting node for the Morris
322
+ * traversal. It specifies the root node of the tree from which the traversal should begin. If
323
+ * `beginRoot` is `null`, an empty array will be returned.
324
+ * @returns The `morris` function returns an array of `ReturnType<BTNCallback<N>>` values.
325
+ */
326
+ morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: N | null): ReturnType<C>[];
327
+ /**
328
+ * The above function is an iterator for a binary tree that can be used to traverse the tree in
329
+ * either an iterative or recursive manner.
330
+ * @param node - The `node` parameter represents the current node in the binary tree from which the
331
+ * iteration starts. It is an optional parameter with a default value of `this.root`, which means
332
+ * that if no node is provided, the iteration will start from the root of the binary tree.
333
+ * @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the
334
+ * binary tree nodes in a specific order.
335
+ */
336
+ [Symbol.iterator](node?: N | null): Generator<BTNKey, void, undefined>;
337
+ /**
338
+ * Swap the data of two nodes in the binary tree.
339
+ * @param {N} srcNode - The source node to swap.
340
+ * @param {N} destNode - The destination node to swap.
341
+ * @returns {N} - The destination node after the swap.
342
+ */
343
+ protected _swap(srcNode: N, destNode: N): N;
344
+ /**
345
+ * The function `_addTo` adds a new node to a binary tree if there is an available position.
346
+ * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to
347
+ * the binary tree. It can be either a node object or `null`.
348
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will
349
+ * be added as a child.
350
+ * @returns either the left or right child node of the parent node, depending on which child is
351
+ * available for adding the new node. If a new node is added, the function also updates the size of
352
+ * the binary tree. If neither the left nor right child is available, the function returns undefined.
353
+ * If the parent node is null, the function also returns undefined.
354
+ */
355
+ protected _addTo(newNode: N | null, parent: N): N | null | undefined;
356
+ /**
357
+ * The function sets the root property of an object to a given value, and if the value is not null,
358
+ * it also sets the parent property of the value to undefined.
359
+ * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of
360
+ * type `N` or `null`.
361
+ */
362
+ protected _setRoot(v: N | null): void;
363
+ }