min-heap-typed 1.37.9 → 1.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (334) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +100 -0
  2. package/dist/data-structures/binary-tree/avl-tree.js +341 -0
  3. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +144 -0
  4. package/dist/data-structures/binary-tree/binary-indexed-tree.js +261 -0
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +409 -0
  6. package/dist/data-structures/binary-tree/binary-tree.js +1065 -0
  7. package/dist/data-structures/binary-tree/bst.d.ts +167 -0
  8. package/dist/data-structures/binary-tree/bst.js +512 -0
  9. package/dist/data-structures/binary-tree/index.d.ts +7 -0
  10. package/dist/data-structures/binary-tree/index.js +23 -0
  11. package/dist/data-structures/binary-tree/rb-tree.d.ts +13 -0
  12. package/dist/data-structures/binary-tree/rb-tree.js +27 -0
  13. package/dist/data-structures/binary-tree/segment-tree.d.ts +83 -0
  14. package/dist/data-structures/binary-tree/segment-tree.js +228 -0
  15. package/dist/data-structures/binary-tree/tree-multiset.d.ts +122 -0
  16. package/dist/data-structures/binary-tree/tree-multiset.js +351 -0
  17. package/dist/data-structures/graph/abstract-graph.d.ts +332 -0
  18. package/dist/data-structures/graph/abstract-graph.js +923 -0
  19. package/dist/data-structures/graph/directed-graph.d.ts +200 -0
  20. package/dist/data-structures/graph/directed-graph.js +422 -0
  21. package/dist/data-structures/graph/index.d.ts +4 -0
  22. package/dist/data-structures/graph/index.js +20 -0
  23. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  24. package/dist/data-structures/graph/map-graph.js +111 -0
  25. package/dist/data-structures/graph/undirected-graph.d.ts +127 -0
  26. package/dist/data-structures/graph/undirected-graph.js +252 -0
  27. package/dist/data-structures/hash/coordinate-map.d.ts +45 -0
  28. package/dist/data-structures/hash/coordinate-map.js +65 -0
  29. package/dist/data-structures/hash/coordinate-set.d.ts +37 -0
  30. package/dist/data-structures/hash/coordinate-set.js +55 -0
  31. package/dist/data-structures/hash/hash-map.d.ts +56 -0
  32. package/dist/data-structures/hash/hash-map.js +171 -0
  33. package/dist/data-structures/hash/hash-table.d.ts +106 -0
  34. package/dist/data-structures/hash/hash-table.js +245 -0
  35. package/dist/data-structures/hash/index.d.ts +6 -0
  36. package/dist/data-structures/hash/index.js +22 -0
  37. package/dist/data-structures/hash/tree-map.d.ts +2 -0
  38. package/dist/data-structures/hash/tree-map.js +6 -0
  39. package/dist/data-structures/hash/tree-set.d.ts +2 -0
  40. package/dist/data-structures/hash/tree-set.js +6 -0
  41. package/dist/data-structures/heap/heap.d.ts +224 -0
  42. package/dist/data-structures/heap/heap.js +497 -0
  43. package/dist/data-structures/heap/index.d.ts +3 -0
  44. package/dist/data-structures/heap/index.js +19 -0
  45. package/dist/data-structures/heap/max-heap.d.ts +12 -0
  46. package/dist/data-structures/heap/max-heap.js +24 -0
  47. package/dist/data-structures/heap/min-heap.d.ts +12 -0
  48. package/dist/data-structures/heap/min-heap.js +24 -0
  49. package/dist/data-structures/index.d.ts +11 -0
  50. package/dist/data-structures/index.js +27 -0
  51. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +234 -0
  52. package/dist/data-structures/linked-list/doubly-linked-list.js +583 -0
  53. package/dist/data-structures/linked-list/index.d.ts +3 -0
  54. package/dist/data-structures/linked-list/index.js +19 -0
  55. package/dist/data-structures/linked-list/singly-linked-list.d.ts +157 -0
  56. package/dist/data-structures/linked-list/singly-linked-list.js +448 -0
  57. package/dist/data-structures/linked-list/skip-linked-list.d.ts +61 -0
  58. package/dist/data-structures/linked-list/skip-linked-list.js +142 -0
  59. package/dist/data-structures/matrix/index.d.ts +4 -0
  60. package/dist/data-structures/matrix/index.js +20 -0
  61. package/dist/data-structures/matrix/matrix.d.ts +21 -0
  62. package/dist/data-structures/matrix/matrix.js +28 -0
  63. package/dist/data-structures/matrix/matrix2d.d.ts +108 -0
  64. package/dist/data-structures/matrix/matrix2d.js +203 -0
  65. package/dist/data-structures/matrix/navigator.d.ts +52 -0
  66. package/dist/data-structures/matrix/navigator.js +106 -0
  67. package/dist/data-structures/matrix/vector2d.d.ts +201 -0
  68. package/dist/data-structures/matrix/vector2d.js +291 -0
  69. package/dist/data-structures/priority-queue/index.d.ts +3 -0
  70. package/dist/data-structures/priority-queue/index.js +19 -0
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -0
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +24 -0
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -0
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +24 -0
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +12 -0
  76. package/dist/data-structures/priority-queue/priority-queue.js +17 -0
  77. package/dist/data-structures/queue/deque.d.ts +165 -0
  78. package/dist/data-structures/queue/deque.js +276 -0
  79. package/dist/data-structures/queue/index.d.ts +2 -0
  80. package/dist/data-structures/queue/index.js +18 -0
  81. package/dist/data-structures/queue/queue.d.ts +107 -0
  82. package/dist/data-structures/queue/queue.js +170 -0
  83. package/dist/data-structures/stack/index.d.ts +1 -0
  84. package/dist/data-structures/stack/index.js +17 -0
  85. package/dist/data-structures/stack/stack.d.ts +63 -0
  86. package/dist/data-structures/stack/stack.js +91 -0
  87. package/dist/data-structures/tree/index.d.ts +1 -0
  88. package/dist/data-structures/tree/index.js +17 -0
  89. package/dist/data-structures/tree/tree.d.ts +14 -0
  90. package/dist/data-structures/tree/tree.js +58 -0
  91. package/dist/data-structures/trie/index.d.ts +1 -0
  92. package/dist/data-structures/trie/index.js +17 -0
  93. package/dist/data-structures/trie/trie.d.ts +84 -0
  94. package/dist/data-structures/trie/trie.js +268 -0
  95. package/dist/index.d.ts +3 -3
  96. package/dist/index.js +3 -3
  97. package/dist/interfaces/binary-tree.d.ts +7 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/doubly-linked-list.d.ts +1 -0
  100. package/dist/interfaces/doubly-linked-list.js +2 -0
  101. package/dist/interfaces/graph.d.ts +5 -0
  102. package/dist/interfaces/graph.js +2 -0
  103. package/dist/interfaces/heap.d.ts +1 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +8 -0
  106. package/dist/interfaces/index.js +24 -0
  107. package/dist/interfaces/navigator.d.ts +1 -0
  108. package/dist/interfaces/navigator.js +2 -0
  109. package/dist/interfaces/priority-queue.d.ts +1 -0
  110. package/dist/interfaces/priority-queue.js +2 -0
  111. package/dist/interfaces/segment-tree.d.ts +1 -0
  112. package/dist/interfaces/segment-tree.js +2 -0
  113. package/dist/interfaces/singly-linked-list.d.ts +1 -0
  114. package/dist/interfaces/singly-linked-list.js +2 -0
  115. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +4 -0
  116. package/dist/types/data-structures/binary-tree/avl-tree.js +2 -0
  117. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  118. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +2 -0
  119. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +31 -0
  120. package/dist/types/data-structures/binary-tree/binary-tree.js +24 -0
  121. package/dist/types/data-structures/binary-tree/bst.d.ts +7 -0
  122. package/dist/types/data-structures/binary-tree/bst.js +2 -0
  123. package/dist/types/data-structures/binary-tree/index.d.ts +6 -0
  124. package/dist/types/data-structures/binary-tree/index.js +22 -0
  125. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +8 -0
  126. package/dist/types/data-structures/binary-tree/rb-tree.js +8 -0
  127. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  128. package/dist/types/data-structures/binary-tree/segment-tree.js +2 -0
  129. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +4 -0
  130. package/dist/types/data-structures/binary-tree/tree-multiset.js +2 -0
  131. package/dist/types/data-structures/graph/abstract-graph.d.ts +10 -0
  132. package/dist/types/data-structures/graph/abstract-graph.js +2 -0
  133. package/dist/types/data-structures/graph/directed-graph.d.ts +6 -0
  134. package/dist/types/data-structures/graph/directed-graph.js +9 -0
  135. package/dist/types/data-structures/graph/index.d.ts +3 -0
  136. package/dist/types/data-structures/graph/index.js +19 -0
  137. package/dist/types/data-structures/graph/map-graph.d.ts +1 -0
  138. package/dist/types/data-structures/graph/map-graph.js +2 -0
  139. package/dist/types/data-structures/graph/undirected-graph.d.ts +1 -0
  140. package/dist/types/data-structures/graph/undirected-graph.js +2 -0
  141. package/dist/types/data-structures/hash/coordinate-map.d.ts +1 -0
  142. package/dist/types/data-structures/hash/coordinate-map.js +2 -0
  143. package/dist/types/data-structures/hash/coordinate-set.d.ts +1 -0
  144. package/dist/types/data-structures/hash/coordinate-set.js +2 -0
  145. package/dist/types/data-structures/hash/hash-map.d.ts +1 -0
  146. package/dist/types/data-structures/hash/hash-map.js +2 -0
  147. package/dist/types/data-structures/hash/hash-table.d.ts +1 -0
  148. package/dist/types/data-structures/hash/hash-table.js +2 -0
  149. package/dist/types/data-structures/hash/index.d.ts +1 -0
  150. package/dist/types/data-structures/hash/index.js +2 -0
  151. package/dist/types/data-structures/hash/tree-map.d.ts +1 -0
  152. package/dist/types/data-structures/hash/tree-map.js +2 -0
  153. package/dist/types/data-structures/hash/tree-set.d.ts +1 -0
  154. package/dist/types/data-structures/hash/tree-set.js +2 -0
  155. package/dist/types/data-structures/heap/heap.d.ts +1 -0
  156. package/dist/types/data-structures/heap/heap.js +2 -0
  157. package/dist/types/data-structures/heap/index.d.ts +1 -0
  158. package/dist/types/data-structures/heap/index.js +17 -0
  159. package/dist/types/data-structures/heap/max-heap.d.ts +1 -0
  160. package/dist/types/data-structures/heap/max-heap.js +2 -0
  161. package/dist/types/data-structures/heap/min-heap.d.ts +1 -0
  162. package/dist/types/data-structures/heap/min-heap.js +2 -0
  163. package/dist/types/data-structures/index.d.ts +11 -0
  164. package/dist/types/data-structures/index.js +27 -0
  165. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -0
  166. package/dist/types/data-structures/linked-list/doubly-linked-list.js +2 -0
  167. package/dist/types/data-structures/linked-list/index.d.ts +2 -0
  168. package/dist/types/data-structures/linked-list/index.js +18 -0
  169. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +1 -0
  170. package/dist/types/data-structures/linked-list/singly-linked-list.js +2 -0
  171. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +1 -0
  172. package/dist/types/data-structures/linked-list/skip-linked-list.js +2 -0
  173. package/dist/types/data-structures/matrix/index.d.ts +1 -0
  174. package/dist/types/data-structures/matrix/index.js +17 -0
  175. package/dist/types/data-structures/matrix/matrix.d.ts +1 -0
  176. package/dist/types/data-structures/matrix/matrix.js +2 -0
  177. package/dist/types/data-structures/matrix/matrix2d.d.ts +1 -0
  178. package/dist/types/data-structures/matrix/matrix2d.js +2 -0
  179. package/dist/types/data-structures/matrix/navigator.d.ts +14 -0
  180. package/dist/types/data-structures/matrix/navigator.js +2 -0
  181. package/dist/types/data-structures/matrix/vector2d.d.ts +1 -0
  182. package/dist/types/data-structures/matrix/vector2d.js +2 -0
  183. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  184. package/dist/types/data-structures/priority-queue/index.js +19 -0
  185. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  186. package/dist/types/data-structures/priority-queue/max-priority-queue.js +2 -0
  187. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  188. package/dist/types/data-structures/priority-queue/min-priority-queue.js +2 -0
  189. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  190. package/dist/types/data-structures/priority-queue/priority-queue.js +2 -0
  191. package/dist/types/data-structures/queue/deque.d.ts +1 -0
  192. package/dist/types/data-structures/queue/deque.js +2 -0
  193. package/dist/types/data-structures/queue/index.d.ts +2 -0
  194. package/dist/types/data-structures/queue/index.js +18 -0
  195. package/dist/types/data-structures/queue/queue.d.ts +1 -0
  196. package/dist/types/data-structures/queue/queue.js +2 -0
  197. package/dist/types/data-structures/stack/index.d.ts +1 -0
  198. package/dist/types/data-structures/stack/index.js +17 -0
  199. package/dist/types/data-structures/stack/stack.d.ts +1 -0
  200. package/dist/types/data-structures/stack/stack.js +2 -0
  201. package/dist/types/data-structures/tree/index.d.ts +1 -0
  202. package/dist/types/data-structures/tree/index.js +17 -0
  203. package/dist/types/data-structures/tree/tree.d.ts +1 -0
  204. package/dist/types/data-structures/tree/tree.js +2 -0
  205. package/dist/types/data-structures/trie/index.d.ts +1 -0
  206. package/dist/types/data-structures/trie/index.js +17 -0
  207. package/dist/types/data-structures/trie/trie.d.ts +1 -0
  208. package/dist/types/data-structures/trie/trie.js +2 -0
  209. package/dist/types/helpers.d.ts +9 -0
  210. package/dist/types/helpers.js +9 -0
  211. package/dist/types/index.d.ts +3 -0
  212. package/dist/types/index.js +19 -0
  213. package/dist/types/utils/index.d.ts +2 -0
  214. package/dist/types/utils/index.js +18 -0
  215. package/dist/types/utils/utils.d.ts +7 -0
  216. package/dist/types/utils/utils.js +2 -0
  217. package/dist/types/utils/validate-type.d.ts +19 -0
  218. package/dist/types/utils/validate-type.js +2 -0
  219. package/dist/utils/index.d.ts +1 -0
  220. package/dist/utils/index.js +17 -0
  221. package/dist/utils/utils.d.ts +20 -0
  222. package/dist/utils/utils.js +73 -0
  223. package/package.json +1 -4
  224. package/src/data-structures/binary-tree/avl-tree.ts +342 -0
  225. package/src/data-structures/binary-tree/binary-indexed-tree.ts +298 -0
  226. package/src/data-structures/binary-tree/binary-tree.ts +1141 -0
  227. package/src/data-structures/binary-tree/bst.ts +529 -0
  228. package/src/data-structures/binary-tree/index.ts +7 -0
  229. package/src/data-structures/binary-tree/rb-tree.ts +366 -0
  230. package/src/data-structures/binary-tree/segment-tree.ts +257 -0
  231. package/src/data-structures/binary-tree/tree-multiset.ts +375 -0
  232. package/src/data-structures/graph/abstract-graph.ts +1044 -0
  233. package/src/data-structures/graph/directed-graph.ts +470 -0
  234. package/src/data-structures/graph/index.ts +4 -0
  235. package/src/data-structures/graph/map-graph.ts +134 -0
  236. package/src/data-structures/graph/undirected-graph.ts +274 -0
  237. package/src/data-structures/hash/coordinate-map.ts +67 -0
  238. package/src/data-structures/hash/coordinate-set.ts +56 -0
  239. package/src/data-structures/hash/hash-map.ts +209 -0
  240. package/src/data-structures/hash/hash-table.ts +280 -0
  241. package/src/data-structures/hash/index.ts +6 -0
  242. package/src/data-structures/hash/tree-map.ts +1 -0
  243. package/src/data-structures/hash/tree-set.ts +1 -0
  244. package/src/data-structures/heap/heap.ts +561 -0
  245. package/src/data-structures/heap/index.ts +3 -0
  246. package/src/data-structures/heap/max-heap.ts +24 -0
  247. package/src/data-structures/heap/min-heap.ts +24 -0
  248. package/src/data-structures/index.ts +11 -0
  249. package/src/data-structures/linked-list/doubly-linked-list.ts +636 -0
  250. package/src/data-structures/linked-list/index.ts +3 -0
  251. package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
  252. package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
  253. package/src/data-structures/matrix/index.ts +4 -0
  254. package/src/data-structures/matrix/matrix.ts +27 -0
  255. package/src/data-structures/matrix/matrix2d.ts +213 -0
  256. package/src/data-structures/matrix/navigator.ts +121 -0
  257. package/src/data-structures/matrix/vector2d.ts +316 -0
  258. package/src/data-structures/priority-queue/index.ts +3 -0
  259. package/src/data-structures/priority-queue/max-priority-queue.ts +23 -0
  260. package/src/data-structures/priority-queue/min-priority-queue.ts +23 -0
  261. package/src/data-structures/priority-queue/priority-queue.ts +16 -0
  262. package/src/data-structures/queue/deque.ts +297 -0
  263. package/src/data-structures/queue/index.ts +2 -0
  264. package/src/data-structures/queue/queue.ts +191 -0
  265. package/src/data-structures/stack/index.ts +1 -0
  266. package/src/data-structures/stack/stack.ts +98 -0
  267. package/src/data-structures/tree/index.ts +1 -0
  268. package/src/data-structures/tree/tree.ts +67 -0
  269. package/src/data-structures/trie/index.ts +1 -0
  270. package/src/data-structures/trie/trie.ts +286 -0
  271. package/src/index.ts +3 -3
  272. package/src/interfaces/binary-tree.ts +10 -0
  273. package/src/interfaces/doubly-linked-list.ts +1 -0
  274. package/src/interfaces/graph.ts +7 -0
  275. package/src/interfaces/heap.ts +1 -0
  276. package/src/interfaces/index.ts +8 -0
  277. package/src/interfaces/navigator.ts +1 -0
  278. package/src/interfaces/priority-queue.ts +1 -0
  279. package/src/interfaces/segment-tree.ts +1 -0
  280. package/src/interfaces/singly-linked-list.ts +1 -0
  281. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -0
  282. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  283. package/src/types/data-structures/binary-tree/binary-tree.ts +35 -0
  284. package/src/types/data-structures/binary-tree/bst.ts +11 -0
  285. package/src/types/data-structures/binary-tree/index.ts +6 -0
  286. package/src/types/data-structures/binary-tree/rb-tree.ts +8 -0
  287. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  288. package/src/types/data-structures/binary-tree/tree-multiset.ts +6 -0
  289. package/src/types/data-structures/graph/abstract-graph.ts +11 -0
  290. package/src/types/data-structures/graph/directed-graph.ts +8 -0
  291. package/src/types/data-structures/graph/index.ts +3 -0
  292. package/src/types/data-structures/graph/map-graph.ts +1 -0
  293. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  294. package/src/types/data-structures/hash/coordinate-map.ts +1 -0
  295. package/src/types/data-structures/hash/coordinate-set.ts +1 -0
  296. package/src/types/data-structures/hash/hash-map.ts +1 -0
  297. package/src/types/data-structures/hash/hash-table.ts +1 -0
  298. package/src/types/data-structures/hash/index.ts +1 -0
  299. package/src/types/data-structures/hash/tree-map.ts +1 -0
  300. package/src/types/data-structures/hash/tree-set.ts +1 -0
  301. package/src/types/data-structures/heap/heap.ts +1 -0
  302. package/src/types/data-structures/heap/index.ts +1 -0
  303. package/src/types/data-structures/heap/max-heap.ts +1 -0
  304. package/src/types/data-structures/heap/min-heap.ts +1 -0
  305. package/src/types/data-structures/index.ts +11 -0
  306. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -0
  307. package/src/types/data-structures/linked-list/index.ts +2 -0
  308. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -0
  309. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  310. package/src/types/data-structures/matrix/index.ts +1 -0
  311. package/src/types/data-structures/matrix/matrix.ts +1 -0
  312. package/src/types/data-structures/matrix/matrix2d.ts +1 -0
  313. package/src/types/data-structures/matrix/navigator.ts +14 -0
  314. package/src/types/data-structures/matrix/vector2d.ts +1 -0
  315. package/src/types/data-structures/priority-queue/index.ts +3 -0
  316. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  317. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  318. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  319. package/src/types/data-structures/queue/deque.ts +1 -0
  320. package/src/types/data-structures/queue/index.ts +2 -0
  321. package/src/types/data-structures/queue/queue.ts +1 -0
  322. package/src/types/data-structures/stack/index.ts +1 -0
  323. package/src/types/data-structures/stack/stack.ts +1 -0
  324. package/src/types/data-structures/tree/index.ts +1 -0
  325. package/src/types/data-structures/tree/tree.ts +1 -0
  326. package/src/types/data-structures/trie/index.ts +1 -0
  327. package/src/types/data-structures/trie/trie.ts +1 -0
  328. package/src/types/helpers.ts +13 -0
  329. package/src/types/index.ts +3 -0
  330. package/src/types/utils/index.ts +2 -0
  331. package/src/types/utils/utils.ts +6 -0
  332. package/src/types/utils/validate-type.ts +35 -0
  333. package/src/utils/index.ts +1 -0
  334. package/src/utils/utils.ts +86 -0
@@ -0,0 +1,245 @@
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, val) {
13
+ this.key = key;
14
+ this.val = val;
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
+ set capacity(value) {
30
+ this._capacity = value;
31
+ }
32
+ get size() {
33
+ return this._size;
34
+ }
35
+ get buckets() {
36
+ return this._buckets;
37
+ }
38
+ set buckets(value) {
39
+ this._buckets = value;
40
+ }
41
+ get hashFn() {
42
+ return this._hashFn;
43
+ }
44
+ set hashFn(value) {
45
+ this._hashFn = value;
46
+ }
47
+ /**
48
+ * The set function adds a key-value pair to the hash table, handling collisions and resizing if necessary.
49
+ * @param {K} key - The key parameter represents the key of the key-value pair that you want to insert into the hash
50
+ * table. It is of type K, which is a generic type representing the key's data type.
51
+ * @param {V} val - The parameter `val` represents the value that you want to associate with the given key in the hash
52
+ * table.
53
+ * @returns Nothing is being returned. The return type of the `put` method is `void`, which means it does not return any
54
+ * value.
55
+ */
56
+ set(key, val) {
57
+ const index = this._hash(key);
58
+ const newNode = new HashTableNode(key, val);
59
+ if (!this._buckets[index]) {
60
+ this._buckets[index] = newNode;
61
+ }
62
+ else {
63
+ // Handle collisions, consider using open addressing, etc.
64
+ let currentNode = this._buckets[index];
65
+ while (currentNode) {
66
+ if (currentNode.key === key) {
67
+ // If the key already exists, update the value
68
+ currentNode.val = val;
69
+ return;
70
+ }
71
+ if (!currentNode.next) {
72
+ break;
73
+ }
74
+ currentNode = currentNode.next;
75
+ }
76
+ // Add to the end of the linked list
77
+ currentNode.next = newNode;
78
+ }
79
+ this._size++;
80
+ // If the load factor is too high, resize the hash table
81
+ if (this._size / this._capacity >= HashTable.LOAD_FACTOR) {
82
+ this._expand();
83
+ }
84
+ }
85
+ /**
86
+ * The `get` function retrieves the value associated with a given key from a hash table.
87
+ * @param {K} key - The `key` parameter represents the key of the element that we want to retrieve from the data
88
+ * structure.
89
+ * @returns The method is returning the value associated with the given key if it exists in the hash table. If the key is
90
+ * not found, it returns `undefined`.
91
+ */
92
+ get(key) {
93
+ const index = this._hash(key);
94
+ let currentNode = this._buckets[index];
95
+ while (currentNode) {
96
+ if (currentNode.key === key) {
97
+ return currentNode.val;
98
+ }
99
+ currentNode = currentNode.next;
100
+ }
101
+ return undefined; // Key not found
102
+ }
103
+ /**
104
+ * The delete function removes a key-value pair from a hash table.
105
+ * @param {K} key - The `key` parameter represents the key of the key-value pair that needs to be removed from the hash
106
+ * table.
107
+ * @returns Nothing is being returned. The `delete` method has a return type of `void`, which means it does not return
108
+ * any value.
109
+ */
110
+ delete(key) {
111
+ const index = this._hash(key);
112
+ let currentNode = this._buckets[index];
113
+ let prevNode = null;
114
+ while (currentNode) {
115
+ if (currentNode.key === key) {
116
+ if (prevNode) {
117
+ prevNode.next = currentNode.next;
118
+ }
119
+ else {
120
+ this._buckets[index] = currentNode.next;
121
+ }
122
+ this._size--;
123
+ currentNode.next = null; // Release memory
124
+ return;
125
+ }
126
+ prevNode = currentNode;
127
+ currentNode = currentNode.next;
128
+ }
129
+ }
130
+ /**
131
+ * The function `_defaultHashFn` calculates the hash value of a given key and returns the remainder when divided by the
132
+ * capacity of the data structure.
133
+ * @param {K} key - The `key` parameter is the input value that needs to be hashed. It can be of any type, but in this
134
+ * code snippet, it is checked whether the key is a string or an object. If it is a string, the `_murmurStringHashFn`
135
+ * function is used to
136
+ * @returns the hash value of the key modulo the capacity of the data structure.
137
+ */
138
+ _defaultHashFn(key) {
139
+ // Can be replaced with other hash functions as needed
140
+ const hashValue = typeof key === 'string' ? this._murmurStringHashFn(key) : this._objectHash(key);
141
+ return hashValue % this._capacity;
142
+ }
143
+ /**
144
+ * The `_multiplicativeStringHashFn` function calculates a hash value for a given string key using the multiplicative
145
+ * string hash function.
146
+ * @param {K} key - The `key` parameter is the input value for which we want to calculate the hash. It can be of any
147
+ * type, as it is generic (`K`). The function converts the `key` to a string using the `String()` function.
148
+ * @returns a number, which is the result of the multiplicative string hash function applied to the input key.
149
+ */
150
+ _multiplicativeStringHashFn(key) {
151
+ const keyString = String(key);
152
+ let hash = 0;
153
+ for (let i = 0; i < keyString.length; i++) {
154
+ const charCode = keyString.charCodeAt(i);
155
+ // Some constants for adjusting the hash function
156
+ const A = 0.618033988749895;
157
+ const M = 1 << 30; // 2^30
158
+ hash = (hash * A + charCode) % M;
159
+ }
160
+ return Math.abs(hash); // Take absolute value to ensure non-negative numbers
161
+ }
162
+ /**
163
+ * The function `_murmurStringHashFn` calculates a hash value for a given string key using the MurmurHash algorithm.
164
+ * @param {K} key - The `key` parameter is the input value for which you want to calculate the hash. It can be of any
165
+ * type, but it will be converted to a string using the `String()` function before calculating the hash.
166
+ * @returns a number, which is the hash value calculated for the given key.
167
+ */
168
+ _murmurStringHashFn(key) {
169
+ const keyString = String(key);
170
+ const seed = 0;
171
+ let hash = seed;
172
+ for (let i = 0; i < keyString.length; i++) {
173
+ const char = keyString.charCodeAt(i);
174
+ hash = (hash ^ char) * 0x5bd1e995;
175
+ hash = (hash ^ (hash >>> 15)) * 0x27d4eb2d;
176
+ hash = hash ^ (hash >>> 15);
177
+ }
178
+ return Math.abs(hash);
179
+ }
180
+ /**
181
+ * The _hash function takes a key and returns a number.
182
+ * @param {K} key - The parameter "key" is of type K, which represents the type of the key that will be hashed.
183
+ * @returns The hash function is returning a number.
184
+ */
185
+ _hash(key) {
186
+ return this.hashFn(key);
187
+ }
188
+ /**
189
+ * The function calculates a hash value for a given string using the djb2 algorithm.
190
+ * @param {string} key - The `key` parameter in the `stringHash` function is a string value that represents the input for
191
+ * which we want to calculate the hash value.
192
+ * @returns a number, which is the hash value of the input string.
193
+ */
194
+ _stringHash(key) {
195
+ let hash = 0;
196
+ for (let i = 0; i < key.length; i++) {
197
+ hash = (hash * 31 + key.charCodeAt(i)) & 0xffffffff;
198
+ }
199
+ return hash;
200
+ }
201
+ /**
202
+ * The function `_objectHash` takes a key and returns a hash value, using a custom hash function for objects.
203
+ * @param {K} key - The parameter "key" is of type "K", which means it can be any type. It could be a string, number,
204
+ * boolean, object, or any other type of value. The purpose of the objectHash function is to generate a hash value for
205
+ * the key, which can be used for
206
+ * @returns a number, which is the hash value of the key.
207
+ */
208
+ _objectHash(key) {
209
+ // If the key is an object, you can write a custom hash function
210
+ // For example, convert the object's properties to a string and use string hashing
211
+ // This is just an example; you should write a specific object hash function as needed
212
+ return this._stringHash(JSON.stringify(key));
213
+ }
214
+ /**
215
+ * The `expand` function increases the capacity of a hash table by creating a new array of buckets with double the
216
+ * capacity and rehashing all the existing key-value pairs into the new buckets.
217
+ */
218
+ _expand() {
219
+ const newCapacity = this._capacity * 2;
220
+ const newBuckets = new Array(newCapacity).fill(null);
221
+ for (const bucket of this._buckets) {
222
+ let currentNode = bucket;
223
+ while (currentNode) {
224
+ const newIndex = this._hash(currentNode.key);
225
+ const newNode = new HashTableNode(currentNode.key, currentNode.val);
226
+ if (!newBuckets[newIndex]) {
227
+ newBuckets[newIndex] = newNode;
228
+ }
229
+ else {
230
+ let currentNewNode = newBuckets[newIndex];
231
+ while (currentNewNode.next) {
232
+ currentNewNode = currentNewNode.next;
233
+ }
234
+ currentNewNode.next = newNode;
235
+ }
236
+ currentNode = currentNode.next;
237
+ }
238
+ }
239
+ this._buckets = newBuckets;
240
+ this._capacity = newCapacity;
241
+ }
242
+ }
243
+ exports.HashTable = HashTable;
244
+ HashTable.DEFAULT_CAPACITY = 16;
245
+ 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
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreeSet = void 0;
4
+ class TreeSet {
5
+ }
6
+ exports.TreeSet = TreeSet;
@@ -0,0 +1,224 @@
1
+ /**
2
+ * data-structure-typed
3
+ * @author Kirk Qi
4
+ * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
5
+ * @license MIT License
6
+ */
7
+ import type { Comparator, DFSOrderPattern } from '../../types';
8
+ export declare class Heap<E> {
9
+ protected nodes: E[];
10
+ protected readonly comparator: Comparator<E>;
11
+ constructor(comparator: Comparator<E>);
12
+ /**
13
+ * Get the size (number of elements) of the heap.
14
+ */
15
+ get size(): number;
16
+ /**
17
+ * Get the last element in the heap, which is not necessarily a leaf node.
18
+ * @returns The last element or undefined if the heap is empty.
19
+ */
20
+ get leaf(): E | undefined;
21
+ /**
22
+ * Static method that creates a binary heap from an array of nodes and a comparison function.
23
+ * @param nodes
24
+ * @param comparator - Comparison function.
25
+ * @returns A new Heap instance.
26
+ */
27
+ static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E>;
28
+ /**
29
+ * Insert an element into the heap and maintain the heap properties.
30
+ * @param element - The element to be inserted.
31
+ */
32
+ add(element: E): Heap<E>;
33
+ /**
34
+ * Insert an element into the heap and maintain the heap properties.
35
+ * @param element - The element to be inserted.
36
+ */
37
+ push(element: E): Heap<E>;
38
+ /**
39
+ * Remove and return the top element (smallest or largest element) from the heap.
40
+ * @returns The top element or undefined if the heap is empty.
41
+ */
42
+ poll(): E | undefined;
43
+ /**
44
+ * Remove and return the top element (smallest or largest element) from the heap.
45
+ * @returns The top element or undefined if the heap is empty.
46
+ */
47
+ pop(): E | undefined;
48
+ /**
49
+ * Peek at the top element of the heap without removing it.
50
+ * @returns The top element or undefined if the heap is empty.
51
+ */
52
+ peek(): E | undefined;
53
+ /**
54
+ * Check if the heap is empty.
55
+ * @returns True if the heap is empty, otherwise false.
56
+ */
57
+ isEmpty(): boolean;
58
+ /**
59
+ * Reset the nodes of the heap. Make the nodes empty.
60
+ */
61
+ clear(): void;
62
+ /**
63
+ * Clear and add nodes of the heap
64
+ * @param nodes
65
+ */
66
+ refill(nodes: E[]): void;
67
+ /**
68
+ * Use a comparison function to check whether a binary heap contains a specific element.
69
+ * @param element - the element to check.
70
+ * @returns Returns true if the specified element is contained; otherwise, returns false.
71
+ */
72
+ has(element: E): boolean;
73
+ /**
74
+ * Depth-first search (DFS) method, different traversal orders can be selected。
75
+ * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
76
+ * @returns An array containing elements traversed in the specified order.
77
+ */
78
+ dfs(order: DFSOrderPattern): E[];
79
+ /**
80
+ * Convert the heap to an array.
81
+ * @returns An array containing the elements of the heap.
82
+ */
83
+ toArray(): E[];
84
+ getNodes(): E[];
85
+ /**
86
+ * Clone the heap, creating a new heap with the same elements.
87
+ * @returns A new Heap instance containing the same elements.
88
+ */
89
+ clone(): Heap<E>;
90
+ /**
91
+ * Sort the elements in the heap and return them as an array.
92
+ * @returns An array containing the elements sorted in ascending order.
93
+ */
94
+ sort(): E[];
95
+ /**
96
+ * Float operation to maintain heap properties after adding an element.
97
+ * @param index - The index of the newly added element.
98
+ */
99
+ protected bubbleUp(index: number): void;
100
+ /**
101
+ * Sinking operation to maintain heap properties after removing the top element.
102
+ * @param index - The index from which to start sinking.
103
+ */
104
+ protected sinkDown(index: number): void;
105
+ /**
106
+ * Fix the entire heap to maintain heap properties.
107
+ */
108
+ protected fix(): void;
109
+ }
110
+ export declare class FibonacciHeapNode<E> {
111
+ element: E;
112
+ degree: number;
113
+ left?: FibonacciHeapNode<E>;
114
+ right?: FibonacciHeapNode<E>;
115
+ child?: FibonacciHeapNode<E>;
116
+ parent?: FibonacciHeapNode<E>;
117
+ marked: boolean;
118
+ constructor(element: E, degree?: number);
119
+ }
120
+ export declare class FibonacciHeap<E> {
121
+ root?: FibonacciHeapNode<E>;
122
+ size: number;
123
+ protected min?: FibonacciHeapNode<E>;
124
+ protected readonly comparator: Comparator<E>;
125
+ constructor(comparator?: Comparator<E>);
126
+ /**
127
+ * Get the size (number of elements) of the heap.
128
+ * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
129
+ */
130
+ clear(): void;
131
+ /**
132
+ * O(1) time operation.
133
+ * Insert an element into the heap and maintain the heap properties.
134
+ * @param element
135
+ * @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
136
+ */
137
+ add(element: E): FibonacciHeap<E>;
138
+ /**
139
+ * O(1) time operation.
140
+ * Insert an element into the heap and maintain the heap properties.
141
+ * @param element
142
+ * @returns {FibonacciHeap<E>} FibonacciHeap<E> - The heap itself.
143
+ */
144
+ push(element: E): FibonacciHeap<E>;
145
+ /**
146
+ * O(1) time operation.
147
+ * Peek at the top element of the heap without removing it.
148
+ * @returns The top element or undefined if the heap is empty.
149
+ * @protected
150
+ */
151
+ peek(): E | undefined;
152
+ /**
153
+ * O(1) time operation.
154
+ * Get the size (number of elements) of the heap.
155
+ * @param {FibonacciHeapNode<E>} head - The head of the linked list.
156
+ * @protected
157
+ * @returns FibonacciHeapNode<E>[] - An array containing the nodes of the linked list.
158
+ */
159
+ consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[];
160
+ /**
161
+ * O(log n) time operation.
162
+ * Remove and return the top element (smallest or largest element) from the heap.
163
+ * @param parent
164
+ * @param node
165
+ */
166
+ mergeWithChild(parent: FibonacciHeapNode<E>, node: FibonacciHeapNode<E>): void;
167
+ /**
168
+ * O(log n) time operation.
169
+ * Remove and return the top element (smallest or largest element) from the heap.
170
+ * @returns The top element or undefined if the heap is empty.
171
+ */
172
+ poll(): E | undefined;
173
+ /**
174
+ * O(log n) time operation.
175
+ * Remove and return the top element (smallest or largest element) from the heap.
176
+ * @returns The top element or undefined if the heap is empty.
177
+ */
178
+ pop(): E | undefined;
179
+ /**
180
+ * O(log n) time operation.
181
+ * merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
182
+ * @param heapToMerge
183
+ */
184
+ merge(heapToMerge: FibonacciHeap<E>): void;
185
+ /**
186
+ * Default comparator function used by the heap.
187
+ * @param {E} a
188
+ * @param {E} b
189
+ * @protected
190
+ */
191
+ protected defaultComparator(a: E, b: E): number;
192
+ /**
193
+ * Create a new node.
194
+ * @param element
195
+ * @protected
196
+ */
197
+ protected createNode(element: E): FibonacciHeapNode<E>;
198
+ /**
199
+ * Merge the given node with the root list.
200
+ * @param node - The node to be merged.
201
+ */
202
+ protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
203
+ /**
204
+ * O(log n) time operation.
205
+ * Remove and return the top element (smallest or largest element) from the heap.
206
+ * @param node - The node to be removed.
207
+ * @protected
208
+ */
209
+ protected removeFromRoot(node: FibonacciHeapNode<E>): void;
210
+ /**
211
+ * O(log n) time operation.
212
+ * Remove and return the top element (smallest or largest element) from the heap.
213
+ * @param y
214
+ * @param x
215
+ * @protected
216
+ */
217
+ protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
218
+ /**
219
+ * O(log n) time operation.
220
+ * Remove and return the top element (smallest or largest element) from the heap.
221
+ * @protected
222
+ */
223
+ protected consolidate(): void;
224
+ }