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,449 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import {arrayRemove} from '../../utils';
9
+ import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
10
+ import type {TopologicalStatus, VertexKey} from '../../types';
11
+ import {IGraph} from '../../interfaces';
12
+
13
+ export class DirectedVertex<V = any> extends AbstractVertex<V> {
14
+ /**
15
+ * The constructor function initializes a vertex with an optional value.
16
+ * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
17
+ * used to uniquely identify the vertex within a graph or data structure.
18
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It is used to initialize the value of the
19
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
20
+ */
21
+ constructor(key: VertexKey, value?: V) {
22
+ super(key, value);
23
+ }
24
+ }
25
+
26
+ export class DirectedEdge<E = any> extends AbstractEdge<E> {
27
+ src: VertexKey;
28
+ dest: VertexKey;
29
+
30
+ /**
31
+ * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
32
+ * and value.
33
+ * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
34
+ * a graph.
35
+ * @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
36
+ * `VertexKey`, which is likely a unique identifier for a vertex in a graph.
37
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
38
+ * @param {E} [value] - The `value` parameter is an optional parameter of type `E`. It represents the value associated with
39
+ * the edge.
40
+ */
41
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E) {
42
+ super(weight, value);
43
+ this.src = src;
44
+ this.dest = dest;
45
+ }
46
+ }
47
+
48
+ export class DirectedGraph<
49
+ V = any,
50
+ E = any,
51
+ VO extends DirectedVertex<V> = DirectedVertex<V>,
52
+ EO extends DirectedEdge<E> = DirectedEdge<E>
53
+ >
54
+ extends AbstractGraph<V, E, VO, EO>
55
+ implements IGraph<V, E, VO, EO> {
56
+ /**
57
+ * The constructor function initializes an instance of a class.
58
+ */
59
+ constructor() {
60
+ super();
61
+ }
62
+
63
+ protected _outEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();
64
+
65
+ get outEdgeMap(): Map<VO, EO[]> {
66
+ return this._outEdgeMap;
67
+ }
68
+
69
+ protected _inEdgeMap: Map<VO, EO[]> = new Map<VO, EO[]>();
70
+
71
+ get inEdgeMap(): Map<VO, EO[]> {
72
+ return this._inEdgeMap;
73
+ }
74
+
75
+ /**
76
+ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
77
+ * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
78
+ */
79
+
80
+ /**
81
+ * The function creates a new vertex with an optional value and returns it.
82
+ * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
83
+ * could be a number or a string depending on how you want to identify your vertices.
84
+ * @param [value] - The 'value' parameter is an optional value that can be assigned to the vertex. If a value is provided,
85
+ * it will be assigned to the 'value' property of the vertex. If no value is provided, the 'value' property will be
86
+ * assigned the same value as the 'key' parameter
87
+ * @returns a new instance of a DirectedVertex object, casted as type VO.
88
+ */
89
+ createVertex(key: VertexKey, value?: V): VO {
90
+ return new DirectedVertex(key, value ?? key) as VO;
91
+ }
92
+
93
+ /**
94
+ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
95
+ * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
96
+ */
97
+
98
+ /**
99
+ * The function creates a directed edge between two vertices with an optional weight and value.
100
+ * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
101
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
102
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
103
+ * weight is provided, it defaults to 1.
104
+ * @param [value] - The 'value' parameter is an optional value that can be assigned to the edge. It can be of any type and
105
+ * is used to store additional information or data associated with the edge.
106
+ * @returns a new instance of a DirectedEdge object, casted as type EO.
107
+ */
108
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO {
109
+ return new DirectedEdge(src, dest, weight ?? 1, value) as EO;
110
+ }
111
+
112
+ /**
113
+ * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
114
+ * @param {VO | VertexKey | null} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
115
+ * @param {VO | VertexKey | null} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
116
+ * destination vertex of the edge. It can be either a vertex object (`VO`), a vertex ID (`VertexKey`), or `null` if the
117
+ * destination is not specified.
118
+ * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
119
+ */
120
+ getEdge(srcOrKey: VO | VertexKey | null, destOrKey: VO | VertexKey | null): EO | null {
121
+ let edges: EO[] = [];
122
+
123
+ if (srcOrKey !== null && destOrKey !== null) {
124
+ const src: VO | null = this._getVertex(srcOrKey);
125
+ const dest: VO | null = this._getVertex(destOrKey);
126
+
127
+ if (src && dest) {
128
+ const srcOutEdges = this._outEdgeMap.get(src);
129
+ if (srcOutEdges) {
130
+ edges = srcOutEdges.filter(edge => edge.dest === dest.key);
131
+ }
132
+ }
133
+ }
134
+
135
+ return edges[0] || null;
136
+ }
137
+
138
+ /**
139
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
140
+ * @param {VO | VertexKey} srcOrKey - The source vertex or its ID.
141
+ * @param {VO | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
142
+ * @returns the removed edge (EO) if it exists, or null if either the source or destination vertex does not exist.
143
+ */
144
+ deleteEdgeSrcToDest(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | null {
145
+ const src: VO | null = this._getVertex(srcOrKey);
146
+ const dest: VO | null = this._getVertex(destOrKey);
147
+ let removed: EO | null = null;
148
+ if (!src || !dest) {
149
+ return null;
150
+ }
151
+
152
+ const srcOutEdges = this._outEdgeMap.get(src);
153
+ if (srcOutEdges) {
154
+ arrayRemove<EO>(srcOutEdges, (edge: EO) => edge.dest === dest.key);
155
+ }
156
+
157
+ const destInEdges = this._inEdgeMap.get(dest);
158
+ if (destInEdges) {
159
+ removed = arrayRemove<EO>(destInEdges, (edge: EO) => edge.src === src.key)[0] || null;
160
+ }
161
+ return removed;
162
+ }
163
+
164
+ /**
165
+ * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
166
+ * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
167
+ * and `dest`, which represent the source and destination vertices of the edge, respectively.
168
+ * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `null` if the edge does not exist.
169
+ */
170
+ deleteEdge(edge: EO): EO | null {
171
+ let removed: EO | null = null;
172
+ const src = this._getVertex(edge.src);
173
+ const dest = this._getVertex(edge.dest);
174
+ if (src && dest) {
175
+ const srcOutEdges = this._outEdgeMap.get(src);
176
+ if (srcOutEdges && srcOutEdges.length > 0) {
177
+ arrayRemove(srcOutEdges, (edge: EO) => edge.src === src.key);
178
+ }
179
+
180
+ const destInEdges = this._inEdgeMap.get(dest);
181
+ if (destInEdges && destInEdges.length > 0) {
182
+ removed = arrayRemove(destInEdges, (edge: EO) => edge.dest === dest.key)[0];
183
+ }
184
+ }
185
+
186
+ return removed;
187
+ }
188
+
189
+ /**
190
+ * The function removes edges between two vertices and returns the removed edges.
191
+ * @param {VertexKey | VO} v1 - The parameter `v1` can be either a `VertexKey` or a `VO`. A `VertexKey` represents the
192
+ * unique identifier of a vertex in a graph, while `VO` represents the actual vertex object.
193
+ * @param {VertexKey | VO} v2 - The parameter `v2` represents either a `VertexKey` or a `VO` object. It is used to specify
194
+ * the second vertex in the edge that needs to be removed.
195
+ * @returns an array of removed edges (EO[]).
196
+ */
197
+ deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[] {
198
+ const removed: EO[] = [];
199
+
200
+ if (v1 && v2) {
201
+ const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2);
202
+ const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1);
203
+
204
+ v1ToV2 && removed.push(v1ToV2);
205
+ v2ToV1 && removed.push(v2ToV1);
206
+ }
207
+
208
+ return removed;
209
+ }
210
+
211
+ /**
212
+ * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
213
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
214
+ * (`VertexKey`).
215
+ * @returns The method `incomingEdgesOf` returns an array of edges (`EO[]`).
216
+ */
217
+ incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[] {
218
+ const target = this._getVertex(vertexOrKey);
219
+ if (target) {
220
+ return this.inEdgeMap.get(target) || [];
221
+ }
222
+ return [];
223
+ }
224
+
225
+ /**
226
+ * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
227
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`VO`) or a vertex ID
228
+ * (`VertexKey`).
229
+ * @returns The method `outgoingEdgesOf` returns an array of edges (`EO[]`).
230
+ */
231
+ outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[] {
232
+ const target = this._getVertex(vertexOrKey);
233
+ if (target) {
234
+ return this._outEdgeMap.get(target) || [];
235
+ }
236
+ return [];
237
+ }
238
+
239
+ /**
240
+ * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
241
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
242
+ * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
243
+ */
244
+ degreeOf(vertexOrKey: VertexKey | VO): number {
245
+ return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
246
+ }
247
+
248
+ /**
249
+ * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
250
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
251
+ * @returns The number of incoming edges of the specified vertex or vertex ID.
252
+ */
253
+ inDegreeOf(vertexOrKey: VertexKey | VO): number {
254
+ return this.incomingEdgesOf(vertexOrKey).length;
255
+ }
256
+
257
+ /**
258
+ * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
259
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
260
+ * @returns The number of outgoing edges from the specified vertex or vertex ID.
261
+ */
262
+ outDegreeOf(vertexOrKey: VertexKey | VO): number {
263
+ return this.outgoingEdgesOf(vertexOrKey).length;
264
+ }
265
+
266
+ /**
267
+ * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
268
+ * @param {VertexKey | VO} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `VO`.
269
+ * @returns The function `edgesOf` returns an array of edges.
270
+ */
271
+ edgesOf(vertexOrKey: VertexKey | VO): EO[] {
272
+ return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
273
+ }
274
+
275
+ /**
276
+ * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
277
+ * @param {EO} e - The parameter "e" is of type EO, which represents an edge in a graph.
278
+ * @returns either a vertex object (VO) or null.
279
+ */
280
+ getEdgeSrc(e: EO): VO | null {
281
+ return this._getVertex(e.src);
282
+ }
283
+
284
+ /**
285
+ * The function "getEdgeDest" returns the destination vertex of an edge.
286
+ * @param {EO} e - The parameter "e" is of type "EO", which represents an edge in a graph.
287
+ * @returns either a vertex object of type VO or null.
288
+ */
289
+ getEdgeDest(e: EO): VO | null {
290
+ return this._getVertex(e.dest);
291
+ }
292
+
293
+ /**
294
+ * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
295
+ * @param {VO | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
296
+ * find the destinations. It can be either a `VO` object, a `VertexKey` value, or `null`.
297
+ * @returns an array of vertices (VO[]).
298
+ */
299
+ getDestinations(vertex: VO | VertexKey | null): VO[] {
300
+ if (vertex === null) {
301
+ return [];
302
+ }
303
+ const destinations: VO[] = [];
304
+ const outgoingEdges = this.outgoingEdgesOf(vertex);
305
+ for (const outEdge of outgoingEdges) {
306
+ const child = this.getEdgeDest(outEdge);
307
+ if (child) {
308
+ destinations.push(child);
309
+ }
310
+ }
311
+ return destinations;
312
+ }
313
+
314
+ /**
315
+ * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
316
+ * in the sorted order, or null if the graph contains a cycle.
317
+ * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
318
+ * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
319
+ * specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
320
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
321
+ */
322
+ topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | null {
323
+ propertyName = propertyName ?? 'key';
324
+ // When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
325
+ // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
326
+ const statusMap: Map<VO | VertexKey, TopologicalStatus> = new Map<VO | VertexKey, TopologicalStatus>();
327
+ for (const entry of this.vertices) {
328
+ statusMap.set(entry[1], 0);
329
+ }
330
+
331
+ let sorted: (VO | VertexKey)[] = [];
332
+ let hasCycle = false;
333
+ const dfs = (cur: VO | VertexKey) => {
334
+ statusMap.set(cur, 1);
335
+ const children = this.getDestinations(cur);
336
+ for (const child of children) {
337
+ const childStatus = statusMap.get(child);
338
+ if (childStatus === 0) {
339
+ dfs(child);
340
+ } else if (childStatus === 1) {
341
+ hasCycle = true;
342
+ }
343
+ }
344
+ statusMap.set(cur, 2);
345
+ sorted.push(cur);
346
+ };
347
+
348
+ for (const entry of this.vertices) {
349
+ if (statusMap.get(entry[1]) === 0) {
350
+ dfs(entry[1]);
351
+ }
352
+ }
353
+
354
+ if (hasCycle) return null;
355
+
356
+ if (propertyName === 'key') sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
357
+ return sorted.reverse();
358
+ }
359
+
360
+ /**
361
+ * The `edgeSet` function returns an array of all the edges in the graph.
362
+ * @returns The `edgeSet()` method returns an array of edges (`EO[]`).
363
+ */
364
+ edgeSet(): EO[] {
365
+ let edges: EO[] = [];
366
+ this._outEdgeMap.forEach(outEdges => {
367
+ edges = [...edges, ...outEdges];
368
+ });
369
+ return edges;
370
+ }
371
+
372
+ /**
373
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
374
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
375
+ * (`VertexKey`).
376
+ * @returns an array of vertices (VO[]).
377
+ */
378
+ getNeighbors(vertexOrKey: VO | VertexKey): VO[] {
379
+ const neighbors: VO[] = [];
380
+ const vertex = this._getVertex(vertexOrKey);
381
+ if (vertex) {
382
+ const outEdges = this.outgoingEdgesOf(vertex);
383
+ for (const outEdge of outEdges) {
384
+ const neighbor = this._getVertex(outEdge.dest);
385
+ // TODO after no-non-null-assertion not ensure the logic
386
+ if (neighbor) {
387
+ neighbors.push(neighbor);
388
+ }
389
+ }
390
+ }
391
+ return neighbors;
392
+ }
393
+
394
+ /**
395
+ * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
396
+ * otherwise it returns null.
397
+ * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph.
398
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[VO, VO]` if the edge exists in the
399
+ * graph. If the edge does not exist, it returns `null`.
400
+ */
401
+ getEndsOfEdge(edge: EO): [VO, VO] | null {
402
+ if (!this.hasEdge(edge.src, edge.dest)) {
403
+ return null;
404
+ }
405
+ const v1 = this._getVertex(edge.src);
406
+ const v2 = this._getVertex(edge.dest);
407
+ if (v1 && v2) {
408
+ return [v1, v2];
409
+ } else {
410
+ return null;
411
+ }
412
+ }
413
+
414
+ /**
415
+ * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
416
+ * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
417
+ * needs to be added to the graph.
418
+ * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
419
+ * source or destination vertex does not exist in the graph.
420
+ */
421
+ protected _addEdgeOnly(edge: EO): boolean {
422
+ if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
423
+ return false;
424
+ }
425
+
426
+ const srcVertex = this._getVertex(edge.src);
427
+ const destVertex = this._getVertex(edge.dest);
428
+
429
+ // TODO after no-non-null-assertion not ensure the logic
430
+ if (srcVertex && destVertex) {
431
+ const srcOutEdges = this._outEdgeMap.get(srcVertex);
432
+ if (srcOutEdges) {
433
+ srcOutEdges.push(edge);
434
+ } else {
435
+ this._outEdgeMap.set(srcVertex, [edge]);
436
+ }
437
+
438
+ const destInEdges = this._inEdgeMap.get(destVertex);
439
+ if (destInEdges) {
440
+ destInEdges.push(edge);
441
+ } else {
442
+ this._inEdgeMap.set(destVertex, [edge]);
443
+ }
444
+ return true;
445
+ } else {
446
+ return false;
447
+ }
448
+ }
449
+ }
@@ -0,0 +1,4 @@
1
+ export * from './abstract-graph';
2
+ export * from './directed-graph';
3
+ export * from './undirected-graph';
4
+ export * from './map-graph';
@@ -0,0 +1,106 @@
1
+ import {MapGraphCoordinate, VertexKey} from '../../types';
2
+ import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph';
3
+
4
+ export class MapVertex<V = any> extends DirectedVertex<V> {
5
+ lat: number;
6
+ long: number;
7
+
8
+ /**
9
+ * The constructor function initializes an object with an key, latitude, longitude, and an optional value.
10
+ * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
11
+ * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
12
+ * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
13
+ * values representing points north of the equator and negative values representing points south of the equator.
14
+ * @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
15
+ * coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
16
+ * values ranging from -180 to 180.
17
+ * @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
18
+ * creating an instance of the class.
19
+ */
20
+ constructor(key: VertexKey, value: V, lat: number, long: number) {
21
+ super(key, value);
22
+ this.lat = lat;
23
+ this.long = long;
24
+ }
25
+ }
26
+
27
+ export class MapEdge<E = any> extends DirectedEdge<E> {
28
+ /**
29
+ * The constructor function initializes a new instance of a class with the given source, destination, weight, and
30
+ * value.
31
+ * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
32
+ * a graph.
33
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
34
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
35
+ * @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
36
+ * information or data associated with the edge.
37
+ */
38
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E) {
39
+ super(src, dest, weight, value);
40
+ }
41
+ }
42
+
43
+ export class MapGraph<
44
+ V = any,
45
+ E = any,
46
+ VO extends MapVertex<V> = MapVertex<V>,
47
+ EO extends MapEdge<E> = MapEdge<E>
48
+ > extends DirectedGraph<V, E, VO, EO> {
49
+ /**
50
+ * The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
51
+ * @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
52
+ * starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
53
+ * graph.
54
+ * @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
55
+ * `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
56
+ * it will default to `undefined`.
57
+ */
58
+ constructor(origin: MapGraphCoordinate, bottomRight?: MapGraphCoordinate) {
59
+ super();
60
+ this._origin = origin;
61
+ this._bottomRight = bottomRight;
62
+ }
63
+
64
+ protected _origin: MapGraphCoordinate = [0, 0];
65
+
66
+ get origin(): MapGraphCoordinate {
67
+ return this._origin;
68
+ }
69
+
70
+ protected _bottomRight: MapGraphCoordinate | undefined;
71
+
72
+ get bottomRight(): MapGraphCoordinate | undefined {
73
+ return this._bottomRight;
74
+ }
75
+
76
+ /**
77
+ * The function creates a new vertex with the given key, value, latitude, and longitude.
78
+ * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
79
+ * be a string or a number depending on how you define it in your code.
80
+ * @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
81
+ * is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
82
+ * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
83
+ * position of the vertex on the Earth's surface in the north-south direction.
84
+ * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
85
+ * @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
86
+ */
87
+ override createVertex(key: VertexKey, value?: V, lat: number = this.origin[0], long: number = this.origin[1]): VO {
88
+ return new MapVertex(key, value, lat, long) as VO;
89
+ }
90
+
91
+ /**
92
+ * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
93
+ * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
94
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
95
+ * created.
96
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
97
+ * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
98
+ * If the weight is not provided, it can be set to a default value or left undefined.
99
+ * @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
100
+ * depending on the specific implementation of the `MapEdge` class.
101
+ * @returns a new instance of the `MapEdge` class, cast as type `EO`.
102
+ */
103
+ override createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO {
104
+ return new MapEdge(src, dest, weight, value) as EO;
105
+ }
106
+ }