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,36 @@
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 CoordinateSet extends Set<any> {
9
+ constructor(joint?: string);
10
+ protected _joint: string;
11
+ get joint(): string;
12
+ /**
13
+ * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
14
+ * joining its elements with a specified separator.
15
+ * @param {number[]} value - The parameter "value" is an array of numbers.
16
+ * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
17
+ * in the joined value as an argument.
18
+ */
19
+ has(value: number[]): boolean;
20
+ /**
21
+ * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
22
+ * specified delimiter before calling the parent class's "add" function.
23
+ * @param {number[]} value - An array of numbers
24
+ * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
25
+ * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
26
+ */
27
+ add(value: number[]): this;
28
+ /**
29
+ * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
30
+ * array with a specified joint and then calling the delete method of the parent class.
31
+ * @param {number[]} value - An array of numbers
32
+ * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
33
+ * `value` array joined together using the `_joint` property.
34
+ */
35
+ delete(value: number[]): boolean;
36
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoordinateSet = 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 CoordinateSet extends Set {
12
+ constructor(joint) {
13
+ super();
14
+ this._joint = '_';
15
+ if (joint !== undefined)
16
+ this._joint = joint;
17
+ }
18
+ get joint() {
19
+ return this._joint;
20
+ }
21
+ /**
22
+ * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
23
+ * joining its elements with a specified separator.
24
+ * @param {number[]} value - The parameter "value" is an array of numbers.
25
+ * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
26
+ * in the joined value as an argument.
27
+ */
28
+ has(value) {
29
+ return super.has(value.join(this._joint));
30
+ }
31
+ /**
32
+ * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
33
+ * specified delimiter before calling the parent class's "add" function.
34
+ * @param {number[]} value - An array of numbers
35
+ * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
36
+ * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
37
+ */
38
+ add(value) {
39
+ return super.add(value.join(this._joint));
40
+ }
41
+ /**
42
+ * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
43
+ * array with a specified joint and then calling the delete method of the parent class.
44
+ * @param {number[]} value - An array of numbers
45
+ * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
46
+ * `value` array joined together using the `_joint` property.
47
+ */
48
+ delete(value) {
49
+ return super.delete(value.join(this._joint));
50
+ }
51
+ }
52
+ exports.CoordinateSet = CoordinateSet;
@@ -0,0 +1,50 @@
1
+ import { HashFunction } from '../../types';
2
+ /**
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
8
+ */
9
+ export declare class HashMap<K, V> {
10
+ /**
11
+ * The constructor initializes the properties of a hash table, including the initial capacity, load factor, capacity
12
+ * multiplier, size, table array, and hash function.
13
+ * @param [initialCapacity=16] - The initial capacity is the initial size of the hash table. It determines the number of
14
+ * buckets or slots available for storing key-value pairs. The default value is 16.
15
+ * @param [loadFactor=0.75] - The load factor is a measure of how full the hash table can be before it is resized. It is
16
+ * a value between 0 and 1, where 1 means the hash table is completely full and 0 means it is completely empty. When the
17
+ * load factor is reached, the hash table will
18
+ * @param [hashFn] - The `hashFn` parameter is an optional parameter that represents the hash function used to calculate
19
+ * the index of a key in the hash table. If a custom hash function is not provided, a default hash function is used. The
20
+ * default hash function converts the key to a string, calculates the sum of the
21
+ */
22
+ constructor(initialCapacity?: number, loadFactor?: number, hashFn?: HashFunction<K>);
23
+ protected _initialCapacity: number;
24
+ get initialCapacity(): number;
25
+ protected _loadFactor: number;
26
+ get loadFactor(): number;
27
+ protected _capacityMultiplier: number;
28
+ get capacityMultiplier(): number;
29
+ protected _size: number;
30
+ get size(): number;
31
+ protected _table: Array<Array<[K, V]>>;
32
+ get table(): Array<Array<[K, V]>>;
33
+ protected _hashFn: HashFunction<K>;
34
+ get hashFn(): HashFunction<K>;
35
+ set(key: K, value: V): void;
36
+ get(key: K): V | undefined;
37
+ delete(key: K): void;
38
+ entries(): IterableIterator<[K, V]>;
39
+ [Symbol.iterator](): IterableIterator<[K, V]>;
40
+ clear(): void;
41
+ isEmpty(): boolean;
42
+ protected _hash(key: K): number;
43
+ /**
44
+ * The `resizeTable` function resizes the table used in a hash map by creating a new table with a specified capacity and
45
+ * rehashing the key-value pairs from the old table into the new table.
46
+ * @param {number} newCapacity - The newCapacity parameter is the desired capacity for the resized table. It represents
47
+ * the number of buckets that the new table should have.
48
+ */
49
+ protected resizeTable(newCapacity: number): void;
50
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HashMap = 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 HashMap {
12
+ /**
13
+ * The constructor initializes the properties of a hash table, including the initial capacity, load factor, capacity
14
+ * multiplier, size, table array, and hash function.
15
+ * @param [initialCapacity=16] - The initial capacity is the initial size of the hash table. It determines the number of
16
+ * buckets or slots available for storing key-value pairs. The default value is 16.
17
+ * @param [loadFactor=0.75] - The load factor is a measure of how full the hash table can be before it is resized. It is
18
+ * a value between 0 and 1, where 1 means the hash table is completely full and 0 means it is completely empty. When the
19
+ * load factor is reached, the hash table will
20
+ * @param [hashFn] - The `hashFn` parameter is an optional parameter that represents the hash function used to calculate
21
+ * the index of a key in the hash table. If a custom hash function is not provided, a default hash function is used. The
22
+ * default hash function converts the key to a string, calculates the sum of the
23
+ */
24
+ constructor(initialCapacity = 16, loadFactor = 0.75, hashFn) {
25
+ this._initialCapacity = initialCapacity;
26
+ this._loadFactor = loadFactor;
27
+ this._capacityMultiplier = 2;
28
+ this._size = 0;
29
+ this._table = new Array(initialCapacity);
30
+ this._hashFn =
31
+ hashFn ||
32
+ ((key) => {
33
+ const strKey = String(key);
34
+ let hash = 0;
35
+ for (let i = 0; i < strKey.length; i++) {
36
+ hash += strKey.charCodeAt(i);
37
+ }
38
+ return hash % this.table.length;
39
+ });
40
+ }
41
+ get initialCapacity() {
42
+ return this._initialCapacity;
43
+ }
44
+ get loadFactor() {
45
+ return this._loadFactor;
46
+ }
47
+ get capacityMultiplier() {
48
+ return this._capacityMultiplier;
49
+ }
50
+ get size() {
51
+ return this._size;
52
+ }
53
+ get table() {
54
+ return this._table;
55
+ }
56
+ get hashFn() {
57
+ return this._hashFn;
58
+ }
59
+ set(key, value) {
60
+ const loadFactor = this.size / this.table.length;
61
+ if (loadFactor >= this.loadFactor) {
62
+ this.resizeTable(this.table.length * this.capacityMultiplier);
63
+ }
64
+ const index = this._hash(key);
65
+ if (!this.table[index]) {
66
+ this.table[index] = [];
67
+ }
68
+ // Check if the key already exists in the bucket
69
+ for (let i = 0; i < this.table[index].length; i++) {
70
+ if (this.table[index][i][0] === key) {
71
+ this.table[index][i][1] = value;
72
+ return;
73
+ }
74
+ }
75
+ this.table[index].push([key, value]);
76
+ this._size++;
77
+ }
78
+ get(key) {
79
+ const index = this._hash(key);
80
+ if (!this.table[index]) {
81
+ return undefined;
82
+ }
83
+ for (const [k, v] of this.table[index]) {
84
+ if (k === key) {
85
+ return v;
86
+ }
87
+ }
88
+ return undefined;
89
+ }
90
+ delete(key) {
91
+ const index = this._hash(key);
92
+ if (!this.table[index]) {
93
+ return;
94
+ }
95
+ for (let i = 0; i < this.table[index].length; i++) {
96
+ if (this.table[index][i][0] === key) {
97
+ this.table[index].splice(i, 1);
98
+ this._size--;
99
+ // Check if the table needs to be resized down
100
+ const loadFactor = this.size / this.table.length;
101
+ if (loadFactor < this.loadFactor / this.capacityMultiplier) {
102
+ this.resizeTable(this.table.length / this.capacityMultiplier);
103
+ }
104
+ return;
105
+ }
106
+ }
107
+ }
108
+ *entries() {
109
+ for (const bucket of this.table) {
110
+ if (bucket) {
111
+ for (const [key, value] of bucket) {
112
+ yield [key, value];
113
+ }
114
+ }
115
+ }
116
+ }
117
+ [Symbol.iterator]() {
118
+ return this.entries();
119
+ }
120
+ clear() {
121
+ this._size = 0;
122
+ this._table = new Array(this.initialCapacity);
123
+ }
124
+ isEmpty() {
125
+ return this.size === 0;
126
+ }
127
+ _hash(key) {
128
+ return this._hashFn(key);
129
+ }
130
+ /**
131
+ * The `resizeTable` function resizes the table used in a hash map by creating a new table with a specified capacity and
132
+ * rehashing the key-value pairs from the old table into the new table.
133
+ * @param {number} newCapacity - The newCapacity parameter is the desired capacity for the resized table. It represents
134
+ * the number of buckets that the new table should have.
135
+ */
136
+ resizeTable(newCapacity) {
137
+ const newTable = new Array(newCapacity);
138
+ for (const bucket of this._table) {
139
+ // Note that this is this._table
140
+ if (bucket) {
141
+ for (const [key, value] of bucket) {
142
+ const newIndex = this._hash(key) % newCapacity;
143
+ if (!newTable[newIndex]) {
144
+ newTable[newIndex] = [];
145
+ }
146
+ newTable[newIndex].push([key, value]);
147
+ }
148
+ }
149
+ }
150
+ this._table = newTable; // Again, here is this._table
151
+ }
152
+ }
153
+ exports.HashMap = HashMap;
@@ -0,0 +1,103 @@
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 HashTableNode<K, V> {
9
+ key: K;
10
+ value: V;
11
+ next: HashTableNode<K, V> | null;
12
+ constructor(key: K, value: V);
13
+ }
14
+ import { HashFunction } from '../../types';
15
+ export declare class HashTable<K, V> {
16
+ protected static readonly DEFAULT_CAPACITY = 16;
17
+ protected static readonly LOAD_FACTOR = 0.75;
18
+ constructor(capacity?: number, hashFn?: HashFunction<K>);
19
+ protected _capacity: number;
20
+ get capacity(): number;
21
+ protected _size: number;
22
+ get size(): number;
23
+ protected _buckets: Array<HashTableNode<K, V> | null>;
24
+ get buckets(): Array<HashTableNode<K, V> | null>;
25
+ protected _hashFn: HashFunction<K>;
26
+ get hashFn(): HashFunction<K>;
27
+ /**
28
+ * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
29
+ * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
30
+ * table. It is of type K, which is a generic type representing the key's data type.
31
+ * @param {V} value - The parameter `value` represents the value that you want to associate with the given key in the hash
32
+ * table.
33
+ * @returns Nothing is being returned. The return type of the `put` method is `void`, which means it does not return any
34
+ * value.
35
+ */
36
+ set(key: K, value: V): void;
37
+ /**
38
+ * The `get` function retrieves the value associated with a given key from a hash table.
39
+ * @param {K} key - The `key` parameter represents the key of the element that we want to retrieve from the data
40
+ * structure.
41
+ * @returns The method is returning the value associated with the given key if it exists in the hash table. If the key is
42
+ * not found, it returns `undefined`.
43
+ */
44
+ get(key: K): V | undefined;
45
+ /**
46
+ * The delete function removes a key-value pair from a hash table.
47
+ * @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
48
+ * table.
49
+ * @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
50
+ * any value.
51
+ */
52
+ delete(key: K): void;
53
+ /**
54
+ * The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
55
+ * capacity of the data structure.
56
+ * @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
57
+ * code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
58
+ * function is used to
59
+ * @returns the hash value of the key modulo the capacity of the data structure.
60
+ */
61
+ protected _defaultHashFn(key: K): number;
62
+ /**
63
+ * The `_multiplicativeStringHashFn` function calculates a hash value for a given string key using the multiplicative
64
+ * string hash function.
65
+ * @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
66
+ * type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
67
+ * @returns a number, which is the result of the multiplicative string hash function applied to the input key.
68
+ */
69
+ protected _multiplicativeStringHashFn<K>(key: K): number;
70
+ /**
71
+ * The function `_murmurStringHashFn` calculates a hash value for a given string key using the MurmurHash algorithm.
72
+ * @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
73
+ * type, but it will be converted to a string using the `String()` function before calculating the hash.
74
+ * @returns a number, which is the hash value calculated for the given key.
75
+ */
76
+ protected _murmurStringHashFn<K>(key: K): number;
77
+ /**
78
+ * The _hash function takes a key and returns a number.
79
+ * @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
80
+ * @returns The hash function is returning a number.
81
+ */
82
+ protected _hash(key: K): number;
83
+ /**
84
+ * The function calculates a hash value for a given string using the djb2 algorithm.
85
+ * @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
86
+ * which we want to calculate the hash value.
87
+ * @returns a number, which is the hash value of the input string.
88
+ */
89
+ protected _stringHash(key: string): number;
90
+ /**
91
+ * The function `_objectHash` takes a key and returns a hash value, using a custom hash function for objects.
92
+ * @param {K} key - The parameter "key" is of type "K", which means it can be any type. It could be a string, number,
93
+ * boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for
94
+ * the key, which can be used for
95
+ * @returns a number, which is the hash value of the key.
96
+ */
97
+ protected _objectHash(key: K): number;
98
+ /**
99
+ * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
100
+ * capacity and rehashing all the existing key-value pairs into the new buckets.
101
+ */
102
+ protected _expand(): void;
103
+ }
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ /**
3
+ * data-structure-typed
4
+ *
5
+ * @author Tyler Zeng
6
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.HashTable = exports.HashTableNode = void 0;
11
+ class HashTableNode {
12
+ constructor(key, value) {
13
+ this.key = key;
14
+ this.value = value;
15
+ this.next = null;
16
+ }
17
+ }
18
+ exports.HashTableNode = HashTableNode;
19
+ class HashTable {
20
+ constructor(capacity = HashTable.DEFAULT_CAPACITY, hashFn) {
21
+ this._hashFn = hashFn || this._defaultHashFn;
22
+ this._capacity = Math.max(capacity, HashTable.DEFAULT_CAPACITY);
23
+ this._size = 0;
24
+ this._buckets = new Array(this._capacity).fill(null);
25
+ }
26
+ get capacity() {
27
+ return this._capacity;
28
+ }
29
+ get size() {
30
+ return this._size;
31
+ }
32
+ get buckets() {
33
+ return this._buckets;
34
+ }
35
+ get hashFn() {
36
+ return this._hashFn;
37
+ }
38
+ /**
39
+ * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
40
+ * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
41
+ * table. It is of type K, which is a generic type representing the key's data type.
42
+ * @param {V} value - The parameter `value` represents the value that you want to associate with the given key in the hash
43
+ * table.
44
+ * @returns Nothing is being returned. The return type of the `put` method is `void`, which means it does not return any
45
+ * value.
46
+ */
47
+ set(key, value) {
48
+ const index = this._hash(key);
49
+ const newNode = new HashTableNode(key, value);
50
+ if (!this._buckets[index]) {
51
+ this._buckets[index] = newNode;
52
+ }
53
+ else {
54
+ // Handle collisions, consider using open addressing, etc.
55
+ let currentNode = this._buckets[index];
56
+ while (currentNode) {
57
+ if (currentNode.key === key) {
58
+ // If the key already exists, update the value
59
+ currentNode.value = value;
60
+ return;
61
+ }
62
+ if (!currentNode.next) {
63
+ break;
64
+ }
65
+ currentNode = currentNode.next;
66
+ }
67
+ // Add to the end of the linked list
68
+ currentNode.next = newNode;
69
+ }
70
+ this._size++;
71
+ // If the load factor is too high, resize the hash table
72
+ if (this._size / this._capacity >= HashTable.LOAD_FACTOR) {
73
+ this._expand();
74
+ }
75
+ }
76
+ /**
77
+ * The `get` function retrieves the value associated with a given key from a hash table.
78
+ * @param {K} key - The `key` parameter represents the key of the element that we want to retrieve from the data
79
+ * structure.
80
+ * @returns The method is returning the value associated with the given key if it exists in the hash table. If the key is
81
+ * not found, it returns `undefined`.
82
+ */
83
+ get(key) {
84
+ const index = this._hash(key);
85
+ let currentNode = this._buckets[index];
86
+ while (currentNode) {
87
+ if (currentNode.key === key) {
88
+ return currentNode.value;
89
+ }
90
+ currentNode = currentNode.next;
91
+ }
92
+ return undefined; // Key not found
93
+ }
94
+ /**
95
+ * The delete function removes a key-value pair from a hash table.
96
+ * @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
97
+ * table.
98
+ * @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
99
+ * any value.
100
+ */
101
+ delete(key) {
102
+ const index = this._hash(key);
103
+ let currentNode = this._buckets[index];
104
+ let prevNode = null;
105
+ while (currentNode) {
106
+ if (currentNode.key === key) {
107
+ if (prevNode) {
108
+ prevNode.next = currentNode.next;
109
+ }
110
+ else {
111
+ this._buckets[index] = currentNode.next;
112
+ }
113
+ this._size--;
114
+ currentNode.next = null; // Release memory
115
+ return;
116
+ }
117
+ prevNode = currentNode;
118
+ currentNode = currentNode.next;
119
+ }
120
+ }
121
+ /**
122
+ * The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
123
+ * capacity of the data structure.
124
+ * @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
125
+ * code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
126
+ * function is used to
127
+ * @returns the hash value of the key modulo the capacity of the data structure.
128
+ */
129
+ _defaultHashFn(key) {
130
+ // Can be replaced with other hash functions as needed
131
+ const hashValue = typeof key === 'string' ? this._murmurStringHashFn(key) : this._objectHash(key);
132
+ return hashValue % this._capacity;
133
+ }
134
+ /**
135
+ * The `_multiplicativeStringHashFn` function calculates a hash value for a given string key using the multiplicative
136
+ * string hash function.
137
+ * @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
138
+ * type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
139
+ * @returns a number, which is the result of the multiplicative string hash function applied to the input key.
140
+ */
141
+ _multiplicativeStringHashFn(key) {
142
+ const keyString = String(key);
143
+ let hash = 0;
144
+ for (let i = 0; i < keyString.length; i++) {
145
+ const charCode = keyString.charCodeAt(i);
146
+ // Some constants for adjusting the hash function
147
+ const A = 0.618033988749895;
148
+ const M = 1 << 30; // 2^30
149
+ hash = (hash * A + charCode) % M;
150
+ }
151
+ return Math.abs(hash); // Take absolute value to ensure non-negative numbers
152
+ }
153
+ /**
154
+ * The function `_murmurStringHashFn` calculates a hash value for a given string key using the MurmurHash algorithm.
155
+ * @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
156
+ * type, but it will be converted to a string using the `String()` function before calculating the hash.
157
+ * @returns a number, which is the hash value calculated for the given key.
158
+ */
159
+ _murmurStringHashFn(key) {
160
+ const keyString = String(key);
161
+ const seed = 0;
162
+ let hash = seed;
163
+ for (let i = 0; i < keyString.length; i++) {
164
+ const char = keyString.charCodeAt(i);
165
+ hash = (hash ^ char) * 0x5bd1e995;
166
+ hash = (hash ^ (hash >>> 15)) * 0x27d4eb2d;
167
+ hash = hash ^ (hash >>> 15);
168
+ }
169
+ return Math.abs(hash);
170
+ }
171
+ /**
172
+ * The _hash function takes a key and returns a number.
173
+ * @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
174
+ * @returns The hash function is returning a number.
175
+ */
176
+ _hash(key) {
177
+ return this.hashFn(key);
178
+ }
179
+ /**
180
+ * The function calculates a hash value for a given string using the djb2 algorithm.
181
+ * @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
182
+ * which we want to calculate the hash value.
183
+ * @returns a number, which is the hash value of the input string.
184
+ */
185
+ _stringHash(key) {
186
+ let hash = 0;
187
+ for (let i = 0; i < key.length; i++) {
188
+ hash = (hash * 31 + key.charCodeAt(i)) & 0xffffffff;
189
+ }
190
+ return hash;
191
+ }
192
+ /**
193
+ * The function `_objectHash` takes a key and returns a hash value, using a custom hash function for objects.
194
+ * @param {K} key - The parameter "key" is of type "K", which means it can be any type. It could be a string, number,
195
+ * boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for
196
+ * the key, which can be used for
197
+ * @returns a number, which is the hash value of the key.
198
+ */
199
+ _objectHash(key) {
200
+ // If the key is an object, you can write a custom hash function
201
+ // For example, convert the object's properties to a string and use string hashing
202
+ // This is just an example; you should write a specific object hash function as needed
203
+ return this._stringHash(JSON.stringify(key));
204
+ }
205
+ /**
206
+ * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
207
+ * capacity and rehashing all the existing key-value pairs into the new buckets.
208
+ */
209
+ _expand() {
210
+ const newCapacity = this._capacity * 2;
211
+ const newBuckets = new Array(newCapacity).fill(null);
212
+ for (const bucket of this._buckets) {
213
+ let currentNode = bucket;
214
+ while (currentNode) {
215
+ const newIndex = this._hash(currentNode.key);
216
+ const newNode = new HashTableNode(currentNode.key, currentNode.value);
217
+ if (!newBuckets[newIndex]) {
218
+ newBuckets[newIndex] = newNode;
219
+ }
220
+ else {
221
+ let currentNewNode = newBuckets[newIndex];
222
+ while (currentNewNode.next) {
223
+ currentNewNode = currentNewNode.next;
224
+ }
225
+ currentNewNode.next = newNode;
226
+ }
227
+ currentNode = currentNode.next;
228
+ }
229
+ }
230
+ this._buckets = newBuckets;
231
+ this._capacity = newCapacity;
232
+ }
233
+ }
234
+ exports.HashTable = HashTable;
235
+ HashTable.DEFAULT_CAPACITY = 16;
236
+ HashTable.LOAD_FACTOR = 0.75;
@@ -0,0 +1,6 @@
1
+ export * from './hash-table';
2
+ export * from './coordinate-map';
3
+ export * from './coordinate-set';
4
+ export * from './tree-map';
5
+ export * from './tree-set';
6
+ export * from './hash-map';
@@ -0,0 +1,22 @@
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("./hash-table"), exports);
18
+ __exportStar(require("./coordinate-map"), exports);
19
+ __exportStar(require("./coordinate-set"), exports);
20
+ __exportStar(require("./tree-map"), exports);
21
+ __exportStar(require("./tree-set"), exports);
22
+ __exportStar(require("./hash-map"), exports);
@@ -0,0 +1,2 @@
1
+ export declare class TreeMap {
2
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreeMap = void 0;
4
+ class TreeMap {
5
+ }
6
+ exports.TreeMap = TreeMap;
@@ -0,0 +1,2 @@
1
+ export declare class TreeSet {
2
+ }