min-heap-typed 1.40.0-rc → 1.40.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 +355 -0
  17. package/dist/data-structures/binary-tree/binary-tree.js +1115 -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 +11 -0
  23. package/dist/data-structures/binary-tree/rb-tree.js +21 -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 +8 -0
  137. package/dist/types/data-structures/binary-tree/rb-tree.js +8 -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 +1262 -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 +358 -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,533 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ class SinglyLinkedListNode {
12
+ /**
13
+ * The constructor function initializes an instance of a class with a given value and sets the next property to null.
14
+ * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
15
+ * will be stored in the node of a linked list.
16
+ */
17
+ constructor(value) {
18
+ this.value = value;
19
+ this.next = null;
20
+ }
21
+ }
22
+ exports.SinglyLinkedListNode = SinglyLinkedListNode;
23
+ class SinglyLinkedList {
24
+ /**
25
+ * The constructor initializes the linked list with an empty head, tail, and length.
26
+ */
27
+ constructor() {
28
+ this._head = null;
29
+ this._tail = null;
30
+ this._length = 0;
31
+ }
32
+ get head() {
33
+ return this._head;
34
+ }
35
+ get tail() {
36
+ return this._tail;
37
+ }
38
+ get length() {
39
+ return this._length;
40
+ }
41
+ /**
42
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
43
+ * array.
44
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
45
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
46
+ */
47
+ static fromArray(data) {
48
+ const singlyLinkedList = new SinglyLinkedList();
49
+ for (const item of data) {
50
+ singlyLinkedList.push(item);
51
+ }
52
+ return singlyLinkedList;
53
+ }
54
+ /**
55
+ * The `push` function adds a new node with the given value to the end of a singly linked list.
56
+ * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
57
+ * any type (E) as specified in the generic type declaration of the class or function.
58
+ */
59
+ push(value) {
60
+ const newNode = new SinglyLinkedListNode(value);
61
+ if (!this.head) {
62
+ this._head = newNode;
63
+ this._tail = newNode;
64
+ }
65
+ else {
66
+ this.tail.next = newNode;
67
+ this._tail = newNode;
68
+ }
69
+ this._length++;
70
+ }
71
+ /**
72
+ * The `push` function adds a new node with the given value to the end of a singly linked list.
73
+ * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
74
+ * any type (E) as specified in the generic type declaration of the class or function.
75
+ */
76
+ addLast(value) {
77
+ this.push(value);
78
+ }
79
+ /**
80
+ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
81
+ * pointers accordingly.
82
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
83
+ * the linked list is empty, it returns `null`.
84
+ */
85
+ pop() {
86
+ if (!this.head)
87
+ return undefined;
88
+ if (this.head === this.tail) {
89
+ const value = this.head.value;
90
+ this._head = null;
91
+ this._tail = null;
92
+ this._length--;
93
+ return value;
94
+ }
95
+ let current = this.head;
96
+ while (current.next !== this.tail) {
97
+ current = current.next;
98
+ }
99
+ const value = this.tail.value;
100
+ current.next = null;
101
+ this._tail = current;
102
+ this._length--;
103
+ return value;
104
+ }
105
+ /**
106
+ * The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
107
+ * pointers accordingly.
108
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
109
+ * the linked list is empty, it returns `null`.
110
+ */
111
+ popLast() {
112
+ return this.pop();
113
+ }
114
+ /**
115
+ * The `shift()` function removes and returns the value of the first node in a linked list.
116
+ * @returns The value of the node that is being removed from the beginning of the linked list.
117
+ */
118
+ shift() {
119
+ if (!this.head)
120
+ return undefined;
121
+ const removedNode = this.head;
122
+ this._head = this.head.next;
123
+ this._length--;
124
+ return removedNode.value;
125
+ }
126
+ /**
127
+ * The `popFirst()` function removes and returns the value of the first node in a linked list.
128
+ * @returns The value of the node that is being removed from the beginning of the linked list.
129
+ */
130
+ popFirst() {
131
+ return this.shift();
132
+ }
133
+ /**
134
+ * The unshift function adds a new node with the given value to the beginning of a singly linked list.
135
+ * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
136
+ * linked list.
137
+ */
138
+ unshift(value) {
139
+ const newNode = new SinglyLinkedListNode(value);
140
+ if (!this.head) {
141
+ this._head = newNode;
142
+ this._tail = newNode;
143
+ }
144
+ else {
145
+ newNode.next = this.head;
146
+ this._head = newNode;
147
+ }
148
+ this._length++;
149
+ }
150
+ /**
151
+ * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
152
+ * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
153
+ * linked list.
154
+ */
155
+ addFirst(value) {
156
+ this.unshift(value);
157
+ }
158
+ /**
159
+ * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
160
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
161
+ * retrieve from the list.
162
+ * @returns The method `getAt(index: number): E | null` returns the value at the specified index in the linked list, or
163
+ * `null` if the index is out of bounds.
164
+ */
165
+ getAt(index) {
166
+ if (index < 0 || index >= this.length)
167
+ return undefined;
168
+ let current = this.head;
169
+ for (let i = 0; i < index; i++) {
170
+ current = current.next;
171
+ }
172
+ return current.value;
173
+ }
174
+ /**
175
+ * The function `getNodeAt` returns the node at a given index in a singly linked list.
176
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
177
+ * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
178
+ * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
179
+ * specified index exists, or `null` if the index is out of bounds.
180
+ */
181
+ getNodeAt(index) {
182
+ let current = this.head;
183
+ for (let i = 0; i < index; i++) {
184
+ current = current.next;
185
+ }
186
+ return current;
187
+ }
188
+ /**
189
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
190
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
191
+ * data structure. It is of type number.
192
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
193
+ * bounds.
194
+ */
195
+ deleteAt(index) {
196
+ if (index < 0 || index >= this.length)
197
+ return undefined;
198
+ if (index === 0)
199
+ return this.shift();
200
+ if (index === this.length - 1)
201
+ return this.pop();
202
+ const prevNode = this.getNodeAt(index - 1);
203
+ const removedNode = prevNode.next;
204
+ prevNode.next = removedNode.next;
205
+ this._length--;
206
+ return removedNode.value;
207
+ }
208
+ /**
209
+ * The delete function removes a node with a specific value from a singly linked list.
210
+ * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
211
+ * or a `SinglyLinkedListNode<E>` object.
212
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
213
+ * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
214
+ */
215
+ delete(valueOrNode) {
216
+ if (!valueOrNode)
217
+ return false;
218
+ let value;
219
+ if (valueOrNode instanceof SinglyLinkedListNode) {
220
+ value = valueOrNode.value;
221
+ }
222
+ else {
223
+ value = valueOrNode;
224
+ }
225
+ let current = this.head, prev = null;
226
+ while (current) {
227
+ if (current.value === value) {
228
+ if (prev === null) {
229
+ this._head = current.next;
230
+ if (current === this.tail) {
231
+ this._tail = null;
232
+ }
233
+ }
234
+ else {
235
+ prev.next = current.next;
236
+ if (current === this.tail) {
237
+ this._tail = prev;
238
+ }
239
+ }
240
+ this._length--;
241
+ return true;
242
+ }
243
+ prev = current;
244
+ current = current.next;
245
+ }
246
+ return false;
247
+ }
248
+ /**
249
+ * The `insertAt` function inserts a value at a specified index in a singly linked list.
250
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
251
+ * linked list. It is of type number.
252
+ * @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
253
+ * specified index.
254
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
255
+ * if the index is out of bounds.
256
+ */
257
+ insertAt(index, value) {
258
+ if (index < 0 || index > this.length)
259
+ return false;
260
+ if (index === 0) {
261
+ this.unshift(value);
262
+ return true;
263
+ }
264
+ if (index === this.length) {
265
+ this.push(value);
266
+ return true;
267
+ }
268
+ const newNode = new SinglyLinkedListNode(value);
269
+ const prevNode = this.getNodeAt(index - 1);
270
+ newNode.next = prevNode.next;
271
+ prevNode.next = newNode;
272
+ this._length++;
273
+ return true;
274
+ }
275
+ /**
276
+ * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
277
+ * whether it is empty or not.
278
+ * @returns A boolean value indicating whether the length of the object is equal to 0.
279
+ */
280
+ isEmpty() {
281
+ return this.length === 0;
282
+ }
283
+ /**
284
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
285
+ */
286
+ clear() {
287
+ this._head = null;
288
+ this._tail = null;
289
+ this._length = 0;
290
+ }
291
+ /**
292
+ * The `toArray` function converts a linked list into an array.
293
+ * @returns The `toArray()` method is returning an array of type `E[]`.
294
+ */
295
+ toArray() {
296
+ const array = [];
297
+ let current = this.head;
298
+ while (current) {
299
+ array.push(current.value);
300
+ current = current.next;
301
+ }
302
+ return array;
303
+ }
304
+ /**
305
+ * The `reverse` function reverses the order of the nodes in a singly linked list.
306
+ * @returns The reverse() method does not return anything. It has a return type of void.
307
+ */
308
+ reverse() {
309
+ if (!this.head || this.head === this.tail)
310
+ return;
311
+ let prev = null;
312
+ let current = this.head;
313
+ let next = null;
314
+ while (current) {
315
+ next = current.next;
316
+ current.next = prev;
317
+ prev = current;
318
+ current = next;
319
+ }
320
+ [this._head, this._tail] = [this.tail, this.head];
321
+ }
322
+ /**
323
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
324
+ * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
325
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
326
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
327
+ * the callback function. If no element satisfies the condition, it returns `null`.
328
+ */
329
+ find(callback) {
330
+ let current = this.head;
331
+ while (current) {
332
+ if (callback(current.value)) {
333
+ return current.value;
334
+ }
335
+ current = current.next;
336
+ }
337
+ return null;
338
+ }
339
+ /**
340
+ * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
341
+ * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
342
+ * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
343
+ * value is not found, it returns -1.
344
+ */
345
+ indexOf(value) {
346
+ let index = 0;
347
+ let current = this.head;
348
+ while (current) {
349
+ if (current.value === value) {
350
+ return index;
351
+ }
352
+ index++;
353
+ current = current.next;
354
+ }
355
+ return -1;
356
+ }
357
+ /**
358
+ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
359
+ * null.
360
+ * @param {E} value - The value parameter is the value that we want to search for in the linked list.
361
+ * @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
362
+ * the specified value is found, the function returns `null`.
363
+ */
364
+ getNode(value) {
365
+ let current = this.head;
366
+ while (current) {
367
+ if (current.value === value) {
368
+ return current;
369
+ }
370
+ current = current.next;
371
+ }
372
+ return null;
373
+ }
374
+ /**
375
+ * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
376
+ * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
377
+ * new value before. It can be either the value itself or a node containing the value in the linked list.
378
+ * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
379
+ * @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
380
+ * inserted before the existing value, and `false` otherwise.
381
+ */
382
+ insertBefore(existingValueOrNode, newValue) {
383
+ if (!this.head)
384
+ return false;
385
+ let existingValue;
386
+ if (existingValueOrNode instanceof SinglyLinkedListNode) {
387
+ existingValue = existingValueOrNode.value;
388
+ }
389
+ else {
390
+ existingValue = existingValueOrNode;
391
+ }
392
+ if (this.head.value === existingValue) {
393
+ this.unshift(newValue);
394
+ return true;
395
+ }
396
+ let current = this.head;
397
+ while (current.next) {
398
+ if (current.next.value === existingValue) {
399
+ const newNode = new SinglyLinkedListNode(newValue);
400
+ newNode.next = current.next;
401
+ current.next = newNode;
402
+ this._length++;
403
+ return true;
404
+ }
405
+ current = current.next;
406
+ }
407
+ return false;
408
+ }
409
+ /**
410
+ * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
411
+ * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
412
+ * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
413
+ * @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
414
+ * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
415
+ * existing value or node, and false if the existing value or node was not found in the linked list.
416
+ */
417
+ insertAfter(existingValueOrNode, newValue) {
418
+ let existingNode;
419
+ if (existingValueOrNode instanceof SinglyLinkedListNode) {
420
+ existingNode = existingValueOrNode;
421
+ }
422
+ else {
423
+ existingNode = this.getNode(existingValueOrNode);
424
+ }
425
+ if (existingNode) {
426
+ const newNode = new SinglyLinkedListNode(newValue);
427
+ newNode.next = existingNode.next;
428
+ existingNode.next = newNode;
429
+ if (existingNode === this.tail) {
430
+ this._tail = newNode;
431
+ }
432
+ this._length++;
433
+ return true;
434
+ }
435
+ return false;
436
+ }
437
+ /**
438
+ * The function counts the number of occurrences of a given value in a linked list.
439
+ * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
440
+ * @returns The count of occurrences of the given value in the linked list.
441
+ */
442
+ countOccurrences(value) {
443
+ let count = 0;
444
+ let current = this.head;
445
+ while (current) {
446
+ if (current.value === value) {
447
+ count++;
448
+ }
449
+ current = current.next;
450
+ }
451
+ return count;
452
+ }
453
+ /**
454
+ * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
455
+ * @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
456
+ * represents the value of the current node in the linked list, and the index argument represents the index of the
457
+ * current node in the linked list.
458
+ */
459
+ forEach(callback) {
460
+ let current = this.head;
461
+ let index = 0;
462
+ while (current) {
463
+ callback(current.value, index);
464
+ current = current.next;
465
+ index++;
466
+ }
467
+ }
468
+ /**
469
+ * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
470
+ * SinglyLinkedList with the transformed values.
471
+ * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
472
+ * the original SinglyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
473
+ * SinglyLinkedList).
474
+ * @returns The `map` function is returning a new instance of `SinglyLinkedList<U>` that contains the mapped values.
475
+ */
476
+ map(callback) {
477
+ const mappedList = new SinglyLinkedList();
478
+ let current = this.head;
479
+ while (current) {
480
+ mappedList.push(callback(current.value));
481
+ current = current.next;
482
+ }
483
+ return mappedList;
484
+ }
485
+ /**
486
+ * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
487
+ * elements that satisfy the given callback function.
488
+ * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
489
+ * It is used to determine whether a value should be included in the filtered list or not.
490
+ * @returns The filtered list, which is an instance of the SinglyLinkedList class.
491
+ */
492
+ filter(callback) {
493
+ const filteredList = new SinglyLinkedList();
494
+ let current = this.head;
495
+ while (current) {
496
+ if (callback(current.value)) {
497
+ filteredList.push(current.value);
498
+ }
499
+ current = current.next;
500
+ }
501
+ return filteredList;
502
+ }
503
+ /**
504
+ * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
505
+ * single value.
506
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
507
+ * used to perform a specific operation on each element of the linked list.
508
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
509
+ * point for the reduction operation.
510
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
511
+ * elements in the linked list.
512
+ */
513
+ reduce(callback, initialValue) {
514
+ let accumulator = initialValue;
515
+ let current = this.head;
516
+ while (current) {
517
+ accumulator = callback(accumulator, current.value);
518
+ current = current.next;
519
+ }
520
+ return accumulator;
521
+ }
522
+ /**
523
+ * The function returns an iterator that iterates over the values of a linked list.
524
+ */
525
+ *[Symbol.iterator]() {
526
+ let current = this.head;
527
+ while (current) {
528
+ yield current.value;
529
+ current = current.next;
530
+ }
531
+ }
532
+ }
533
+ exports.SinglyLinkedList = SinglyLinkedList;
@@ -0,0 +1,80 @@
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
+ export declare class SkipListNode<K, V> {
9
+ key: K;
10
+ value: V;
11
+ forward: SkipListNode<K, V>[];
12
+ constructor(key: K, value: V, level: number);
13
+ }
14
+ export declare class SkipList<K, V> {
15
+ /**
16
+ * The constructor initializes a SkipList with a specified maximum level and probability.
17
+ * @param [maxLevel=16] - The `maxLevel` parameter represents the maximum level that a skip list can have. It determines
18
+ * the maximum number of levels that can be created in the skip list.
19
+ * @param [probability=0.5] - The probability parameter represents the probability of a node being promoted to a higher
20
+ * level in the skip list. It is used to determine the height of each node in the skip list.
21
+ */
22
+ constructor(maxLevel?: number, probability?: number);
23
+ protected _head: SkipListNode<K, V>;
24
+ get head(): SkipListNode<K, V>;
25
+ protected _level: number;
26
+ get level(): number;
27
+ protected _maxLevel: number;
28
+ get maxLevel(): number;
29
+ protected _probability: number;
30
+ get probability(): number;
31
+ /**
32
+ * The add function adds a new node with a given key and value to a Skip List data structure.
33
+ * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
34
+ * @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
35
+ * List.
36
+ */
37
+ add(key: K, value: V): void;
38
+ /**
39
+ * The function `get` retrieves the value associated with a given key from a skip list data structure.
40
+ * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
41
+ * @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
42
+ * otherwise it returns `undefined`.
43
+ */
44
+ get(key: K): V | undefined;
45
+ has(key: K): boolean;
46
+ /**
47
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
48
+ * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
49
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
50
+ * skip list, and `false` if the key was not found in the skip list.
51
+ */
52
+ delete(key: K): boolean;
53
+ /**
54
+ * Get the value of the first element (the smallest element) in the Skip List.
55
+ * @returns The value of the first element, or undefined if the Skip List is empty.
56
+ */
57
+ getFirst(): V | undefined;
58
+ /**
59
+ * Get the value of the last element (the largest element) in the Skip List.
60
+ * @returns The value of the last element, or undefined if the Skip List is empty.
61
+ */
62
+ getLast(): V | undefined;
63
+ /**
64
+ * Get the value of the first element in the Skip List that is greater than the given key.
65
+ * @param key - the given key.
66
+ * @returns The value of the first element greater than the given key, or undefined if there is no such element.
67
+ */
68
+ higher(key: K): V | undefined;
69
+ /**
70
+ * Get the value of the last element in the Skip List that is less than the given key.
71
+ * @param key - the given key.
72
+ * @returns The value of the last element less than the given key, or undefined if there is no such element.
73
+ */
74
+ lower(key: K): V | undefined;
75
+ /**
76
+ * The function "_randomLevel" generates a random level based on a given probability and maximum level.
77
+ * @returns the level, which is a number.
78
+ */
79
+ protected _randomLevel(): number;
80
+ }