data-structure-typed 1.21.4 → 1.32.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 (660) hide show
  1. package/.auto-changelog +9 -0
  2. package/.auto-changelog-template.hbs +36 -0
  3. package/.eslintrc.js +61 -0
  4. package/.gitattributes +112 -0
  5. package/.github/workflows/ci.yml +30 -0
  6. package/.prettierignore +6 -0
  7. package/.prettierrc.js +16 -0
  8. package/CHANGELOG.md +17 -0
  9. package/CODE-OF-CONDUCT.md +80 -0
  10. package/COMMANDS.md +28 -0
  11. package/README.md +147 -95
  12. package/SECURITY.md +15 -0
  13. package/coverage/clover.xml +3393 -0
  14. package/coverage/coverage-final.json +67 -0
  15. package/coverage/lcov-report/base.css +224 -0
  16. package/coverage/lcov-report/block-navigation.js +87 -0
  17. package/coverage/lcov-report/favicon.png +0 -0
  18. package/coverage/lcov-report/index.html +386 -0
  19. package/coverage/lcov-report/prettify.css +1 -0
  20. package/coverage/lcov-report/prettify.js +2 -0
  21. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  22. package/coverage/lcov-report/sorter.js +196 -0
  23. package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +88 -0
  24. package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +4966 -0
  25. package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +1015 -0
  26. package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +88 -0
  27. package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +313 -0
  28. package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +226 -0
  29. package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +1714 -0
  30. package/coverage/lcov-report/src/data-structures/binary-tree/index.html +296 -0
  31. package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +121 -0
  32. package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +388 -0
  33. package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +811 -0
  34. package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +88 -0
  35. package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +2185 -0
  36. package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +88 -0
  37. package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +3205 -0
  38. package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +1495 -0
  39. package/coverage/lcov-report/src/data-structures/graph/index.html +176 -0
  40. package/coverage/lcov-report/src/data-structures/graph/index.ts.html +97 -0
  41. package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +472 -0
  42. package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +907 -0
  43. package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +286 -0
  44. package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +253 -0
  45. package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +88 -0
  46. package/coverage/lcov-report/src/data-structures/hash/index.html +206 -0
  47. package/coverage/lcov-report/src/data-structures/hash/index.ts.html +103 -0
  48. package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +88 -0
  49. package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +88 -0
  50. package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +88 -0
  51. package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +721 -0
  52. package/coverage/lcov-report/src/data-structures/heap/index.html +161 -0
  53. package/coverage/lcov-report/src/data-structures/heap/index.ts.html +94 -0
  54. package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +178 -0
  55. package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +181 -0
  56. package/coverage/lcov-report/src/data-structures/index.html +116 -0
  57. package/coverage/lcov-report/src/data-structures/index.ts.html +118 -0
  58. package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +1804 -0
  59. package/coverage/lcov-report/src/data-structures/linked-list/index.html +161 -0
  60. package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +94 -0
  61. package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +1588 -0
  62. package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +88 -0
  63. package/coverage/lcov-report/src/data-structures/matrix/index.html +176 -0
  64. package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +97 -0
  65. package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +166 -0
  66. package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +721 -0
  67. package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +448 -0
  68. package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +1033 -0
  69. package/coverage/lcov-report/src/data-structures/priority-queue/index.html +161 -0
  70. package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +94 -0
  71. package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +253 -0
  72. package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +256 -0
  73. package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +1162 -0
  74. package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +976 -0
  75. package/coverage/lcov-report/src/data-structures/queue/index.html +146 -0
  76. package/coverage/lcov-report/src/data-structures/queue/index.ts.html +91 -0
  77. package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +658 -0
  78. package/coverage/lcov-report/src/data-structures/stack/index.html +131 -0
  79. package/coverage/lcov-report/src/data-structures/stack/index.ts.html +88 -0
  80. package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +379 -0
  81. package/coverage/lcov-report/src/data-structures/tree/index.html +131 -0
  82. package/coverage/lcov-report/src/data-structures/tree/index.ts.html +88 -0
  83. package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +292 -0
  84. package/coverage/lcov-report/src/data-structures/trie/index.html +131 -0
  85. package/coverage/lcov-report/src/data-structures/trie/index.ts.html +88 -0
  86. package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +760 -0
  87. package/coverage/lcov-report/src/index.html +116 -0
  88. package/coverage/lcov-report/src/index.ts.html +97 -0
  89. package/coverage/lcov-report/src/interfaces/index.html +116 -0
  90. package/coverage/lcov-report/src/interfaces/index.ts.html +130 -0
  91. package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +235 -0
  92. package/coverage/lcov-report/src/types/data-structures/bst.ts.html +124 -0
  93. package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +109 -0
  94. package/coverage/lcov-report/src/types/data-structures/index.html +176 -0
  95. package/coverage/lcov-report/src/types/data-structures/index.ts.html +130 -0
  96. package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +106 -0
  97. package/coverage/lcov-report/src/types/index.html +116 -0
  98. package/coverage/lcov-report/src/types/index.ts.html +94 -0
  99. package/coverage/lcov-report/src/types/utils/index.html +116 -0
  100. package/coverage/lcov-report/src/types/utils/index.ts.html +91 -0
  101. package/coverage/lcov-report/src/utils/index.html +131 -0
  102. package/coverage/lcov-report/src/utils/index.ts.html +88 -0
  103. package/coverage/lcov-report/src/utils/utils.ts.html +322 -0
  104. package/coverage/lcov-report/test/utils/index.html +146 -0
  105. package/coverage/lcov-report/test/utils/index.ts.html +91 -0
  106. package/coverage/lcov-report/test/utils/magnitude.ts.html +148 -0
  107. package/coverage/lcov-report/test/utils/number.ts.html +94 -0
  108. package/coverage/lcov.info +6676 -0
  109. package/dist/data-structures/binary-tree/aa-tree.js +6 -2
  110. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
  111. package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
  112. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
  113. package/dist/data-structures/binary-tree/avl-tree.js +122 -151
  114. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
  115. package/dist/data-structures/binary-tree/b-tree.js +6 -2
  116. package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
  117. package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
  118. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  119. package/dist/data-structures/binary-tree/binary-tree.js +31 -32
  120. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
  121. package/dist/data-structures/binary-tree/bst.js +266 -208
  122. package/dist/data-structures/binary-tree/bst.js.map +1 -0
  123. package/dist/data-structures/binary-tree/index.js +1 -0
  124. package/dist/data-structures/binary-tree/index.js.map +1 -0
  125. package/dist/data-structures/binary-tree/rb-tree.js +46 -37
  126. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
  127. package/dist/data-structures/binary-tree/segment-tree.js +124 -127
  128. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
  129. package/dist/data-structures/binary-tree/splay-tree.js +6 -2
  130. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
  131. package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
  132. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
  133. package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
  134. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
  135. package/dist/data-structures/graph/abstract-graph.js +582 -609
  136. package/dist/data-structures/graph/abstract-graph.js.map +1 -0
  137. package/dist/data-structures/graph/directed-graph.js +276 -312
  138. package/dist/data-structures/graph/directed-graph.js.map +1 -0
  139. package/dist/data-structures/graph/index.js +1 -0
  140. package/dist/data-structures/graph/index.js.map +1 -0
  141. package/dist/data-structures/graph/map-graph.js +88 -100
  142. package/dist/data-structures/graph/map-graph.js.map +1 -0
  143. package/dist/data-structures/graph/undirected-graph.js +180 -195
  144. package/dist/data-structures/graph/undirected-graph.js.map +1 -0
  145. package/dist/data-structures/hash/coordinate-map.js +46 -58
  146. package/dist/data-structures/hash/coordinate-map.js.map +1 -0
  147. package/dist/data-structures/hash/coordinate-set.js +43 -48
  148. package/dist/data-structures/hash/coordinate-set.js.map +1 -0
  149. package/dist/data-structures/hash/hash-table.js +6 -2
  150. package/dist/data-structures/hash/hash-table.js.map +1 -0
  151. package/dist/data-structures/hash/index.js +1 -0
  152. package/dist/data-structures/hash/index.js.map +1 -0
  153. package/dist/data-structures/hash/pair.js +6 -2
  154. package/dist/data-structures/hash/pair.js.map +1 -0
  155. package/dist/data-structures/hash/tree-map.js +6 -2
  156. package/dist/data-structures/hash/tree-map.js.map +1 -0
  157. package/dist/data-structures/hash/tree-set.js +6 -2
  158. package/dist/data-structures/hash/tree-set.js.map +1 -0
  159. package/dist/data-structures/heap/heap.js +83 -120
  160. package/dist/data-structures/heap/heap.js.map +1 -0
  161. package/dist/data-structures/heap/index.js +1 -0
  162. package/dist/data-structures/heap/index.js.map +1 -0
  163. package/dist/data-structures/heap/max-heap.js +27 -24
  164. package/dist/data-structures/heap/max-heap.js.map +1 -0
  165. package/dist/data-structures/heap/min-heap.js +27 -25
  166. package/dist/data-structures/heap/min-heap.js.map +1 -0
  167. package/dist/data-structures/index.js +1 -0
  168. package/dist/data-structures/index.js.map +1 -0
  169. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
  170. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  171. package/dist/data-structures/linked-list/index.js +1 -0
  172. package/dist/data-structures/linked-list/index.js.map +1 -0
  173. package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
  174. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
  175. package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
  176. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
  177. package/dist/data-structures/matrix/index.js +1 -0
  178. package/dist/data-structures/matrix/index.js.map +1 -0
  179. package/dist/data-structures/matrix/matrix.js +9 -22
  180. package/dist/data-structures/matrix/matrix.js.map +1 -0
  181. package/dist/data-structures/matrix/matrix2d.js +75 -149
  182. package/dist/data-structures/matrix/matrix2d.js.map +1 -0
  183. package/dist/data-structures/matrix/navigator.js +38 -46
  184. package/dist/data-structures/matrix/navigator.js.map +1 -0
  185. package/dist/data-structures/matrix/vector2d.js +90 -254
  186. package/dist/data-structures/matrix/vector2d.js.map +1 -0
  187. package/dist/data-structures/priority-queue/index.js +1 -0
  188. package/dist/data-structures/priority-queue/index.js.map +1 -0
  189. package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
  190. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  191. package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
  192. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  193. package/dist/data-structures/priority-queue/priority-queue.js +150 -241
  194. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
  195. package/dist/data-structures/queue/deque.js +130 -162
  196. package/dist/data-structures/queue/deque.js.map +1 -0
  197. package/dist/data-structures/queue/index.js +1 -0
  198. package/dist/data-structures/queue/index.js.map +1 -0
  199. package/dist/data-structures/queue/queue.js +181 -100
  200. package/dist/data-structures/queue/queue.js.map +1 -0
  201. package/dist/data-structures/stack/index.js +1 -0
  202. package/dist/data-structures/stack/index.js.map +1 -0
  203. package/dist/data-structures/stack/stack.js +23 -71
  204. package/dist/data-structures/stack/stack.js.map +1 -0
  205. package/dist/data-structures/tree/index.js +1 -0
  206. package/dist/data-structures/tree/index.js.map +1 -0
  207. package/dist/data-structures/tree/tree.js +46 -33
  208. package/dist/data-structures/tree/tree.js.map +1 -0
  209. package/dist/data-structures/trie/index.js +1 -0
  210. package/dist/data-structures/trie/index.js.map +1 -0
  211. package/dist/data-structures/trie/trie.js +201 -129
  212. package/dist/data-structures/trie/trie.js.map +1 -0
  213. package/dist/index.js +1 -0
  214. package/dist/index.js.map +1 -0
  215. package/dist/interfaces/abstract-binary-tree.js +1 -0
  216. package/dist/interfaces/abstract-binary-tree.js.map +1 -0
  217. package/dist/interfaces/abstract-graph.js +1 -0
  218. package/dist/interfaces/abstract-graph.js.map +1 -0
  219. package/dist/interfaces/avl-tree.js +1 -0
  220. package/dist/interfaces/avl-tree.js.map +1 -0
  221. package/dist/interfaces/binary-tree.js +1 -0
  222. package/dist/interfaces/binary-tree.js.map +1 -0
  223. package/dist/interfaces/bst.js +1 -0
  224. package/dist/interfaces/bst.js.map +1 -0
  225. package/dist/interfaces/directed-graph.js +1 -0
  226. package/dist/interfaces/directed-graph.js.map +1 -0
  227. package/dist/interfaces/doubly-linked-list.js +1 -0
  228. package/dist/interfaces/doubly-linked-list.js.map +1 -0
  229. package/dist/interfaces/heap.js +1 -0
  230. package/dist/interfaces/heap.js.map +1 -0
  231. package/dist/interfaces/index.js +1 -0
  232. package/dist/interfaces/index.js.map +1 -0
  233. package/dist/interfaces/navigator.js +1 -0
  234. package/dist/interfaces/navigator.js.map +1 -0
  235. package/dist/interfaces/priority-queue.js +1 -0
  236. package/dist/interfaces/priority-queue.js.map +1 -0
  237. package/dist/interfaces/rb-tree.js +1 -0
  238. package/dist/interfaces/rb-tree.js.map +1 -0
  239. package/dist/interfaces/segment-tree.js +1 -0
  240. package/dist/interfaces/segment-tree.js.map +1 -0
  241. package/dist/interfaces/singly-linked-list.js +1 -0
  242. package/dist/interfaces/singly-linked-list.js.map +1 -0
  243. package/dist/interfaces/tree-multiset.js +1 -0
  244. package/dist/interfaces/tree-multiset.js.map +1 -0
  245. package/dist/interfaces/undirected-graph.js +1 -0
  246. package/dist/interfaces/undirected-graph.js.map +1 -0
  247. package/dist/types/data-structures/abstract-binary-tree.js +1 -7
  248. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
  249. package/dist/types/data-structures/abstract-graph.js +1 -0
  250. package/dist/types/data-structures/abstract-graph.js.map +1 -0
  251. package/dist/types/data-structures/avl-tree.js +1 -0
  252. package/dist/types/data-structures/avl-tree.js.map +1 -0
  253. package/dist/types/data-structures/binary-tree.js +1 -0
  254. package/dist/types/data-structures/binary-tree.js.map +1 -0
  255. package/dist/types/data-structures/bst.js +1 -0
  256. package/dist/types/data-structures/bst.js.map +1 -0
  257. package/dist/types/data-structures/directed-graph.js +1 -0
  258. package/dist/types/data-structures/directed-graph.js.map +1 -0
  259. package/dist/types/data-structures/doubly-linked-list.js +1 -0
  260. package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
  261. package/dist/types/data-structures/heap.js +1 -0
  262. package/dist/types/data-structures/heap.js.map +1 -0
  263. package/dist/types/data-structures/index.js +1 -0
  264. package/dist/types/data-structures/index.js.map +1 -0
  265. package/dist/types/data-structures/map-graph.js +1 -0
  266. package/dist/types/data-structures/map-graph.js.map +1 -0
  267. package/dist/types/data-structures/navigator.js +1 -0
  268. package/dist/types/data-structures/navigator.js.map +1 -0
  269. package/dist/types/data-structures/priority-queue.js +1 -0
  270. package/dist/types/data-structures/priority-queue.js.map +1 -0
  271. package/dist/types/data-structures/rb-tree.js +1 -0
  272. package/dist/types/data-structures/rb-tree.js.map +1 -0
  273. package/dist/types/data-structures/segment-tree.js +1 -0
  274. package/dist/types/data-structures/segment-tree.js.map +1 -0
  275. package/dist/types/data-structures/singly-linked-list.js +1 -0
  276. package/dist/types/data-structures/singly-linked-list.js.map +1 -0
  277. package/dist/types/data-structures/tree-multiset.js +1 -0
  278. package/dist/types/data-structures/tree-multiset.js.map +1 -0
  279. package/dist/types/helpers.js +1 -0
  280. package/dist/types/helpers.js.map +1 -0
  281. package/dist/types/index.js +1 -0
  282. package/dist/types/index.js.map +1 -0
  283. package/dist/types/utils/index.js +1 -0
  284. package/dist/types/utils/index.js.map +1 -0
  285. package/dist/types/utils/utils.js +1 -0
  286. package/dist/types/utils/utils.js.map +1 -0
  287. package/dist/types/utils/validate-type.js +1 -0
  288. package/dist/types/utils/validate-type.js.map +1 -0
  289. package/dist/utils/index.js +1 -0
  290. package/dist/utils/index.js.map +1 -0
  291. package/dist/utils/utils.js +108 -22
  292. package/dist/utils/utils.js.map +1 -0
  293. package/docs/.nojekyll +1 -0
  294. package/docs/assets/highlight.css +127 -0
  295. package/docs/assets/main.js +58 -0
  296. package/docs/assets/search.js +1 -0
  297. package/docs/assets/style.css +1367 -0
  298. package/docs/classes/AVLTree.html +2182 -0
  299. package/docs/classes/AVLTreeNode.html +399 -0
  300. package/docs/classes/AaTree.html +202 -0
  301. package/docs/classes/AbstractBinaryTree.html +1836 -0
  302. package/docs/classes/AbstractBinaryTreeNode.html +441 -0
  303. package/docs/classes/AbstractEdge.html +345 -0
  304. package/docs/classes/AbstractGraph.html +1105 -0
  305. package/docs/classes/AbstractVertex.html +299 -0
  306. package/docs/classes/ArrayDeque.html +469 -0
  307. package/docs/classes/BST.html +2026 -0
  308. package/docs/classes/BSTNode.html +400 -0
  309. package/docs/classes/BTree.html +202 -0
  310. package/docs/classes/BinaryIndexedTree.html +371 -0
  311. package/docs/classes/BinaryTree.html +1867 -0
  312. package/docs/classes/BinaryTreeNode.html +399 -0
  313. package/docs/classes/Character.html +250 -0
  314. package/docs/classes/CoordinateMap.html +513 -0
  315. package/docs/classes/CoordinateSet.html +474 -0
  316. package/docs/classes/Deque.html +1005 -0
  317. package/docs/classes/DirectedEdge.html +404 -0
  318. package/docs/classes/DirectedGraph.html +1530 -0
  319. package/docs/classes/DirectedVertex.html +286 -0
  320. package/docs/classes/DoublyLinkedList.html +998 -0
  321. package/docs/classes/DoublyLinkedListNode.html +327 -0
  322. package/docs/classes/HashTable.html +202 -0
  323. package/docs/classes/Heap.html +647 -0
  324. package/docs/classes/HeapItem.html +296 -0
  325. package/docs/classes/LinkedListQueue.html +884 -0
  326. package/docs/classes/MapEdge.html +391 -0
  327. package/docs/classes/MapGraph.html +1583 -0
  328. package/docs/classes/MapVertex.html +356 -0
  329. package/docs/classes/Matrix2D.html +532 -0
  330. package/docs/classes/MatrixNTI2D.html +270 -0
  331. package/docs/classes/MaxHeap.html +671 -0
  332. package/docs/classes/MaxPriorityQueue.html +866 -0
  333. package/docs/classes/MinHeap.html +672 -0
  334. package/docs/classes/MinPriorityQueue.html +868 -0
  335. package/docs/classes/Navigator.html +343 -0
  336. package/docs/classes/ObjectDeque.html +527 -0
  337. package/docs/classes/Pair.html +202 -0
  338. package/docs/classes/PriorityQueue.html +790 -0
  339. package/docs/classes/Queue.html +521 -0
  340. package/docs/classes/RBTree.html +2024 -0
  341. package/docs/classes/RBTreeNode.html +431 -0
  342. package/docs/classes/SegmentTree.html +464 -0
  343. package/docs/classes/SegmentTreeNode.html +387 -0
  344. package/docs/classes/SinglyLinkedList.html +830 -0
  345. package/docs/classes/SinglyLinkedListNode.html +300 -0
  346. package/docs/classes/SkipLinkedList.html +202 -0
  347. package/docs/classes/SplayTree.html +202 -0
  348. package/docs/classes/Stack.html +398 -0
  349. package/docs/classes/TreeMap.html +202 -0
  350. package/docs/classes/TreeMultiset.html +2510 -0
  351. package/docs/classes/TreeMultisetNode.html +447 -0
  352. package/docs/classes/TreeNode.html +344 -0
  353. package/docs/classes/TreeSet.html +202 -0
  354. package/docs/classes/Trie.html +402 -0
  355. package/docs/classes/TrieNode.html +310 -0
  356. package/docs/classes/TwoThreeTree.html +202 -0
  357. package/docs/classes/UndirectedEdge.html +374 -0
  358. package/docs/classes/UndirectedGraph.html +1285 -0
  359. package/docs/classes/UndirectedVertex.html +284 -0
  360. package/docs/classes/Vector2D.html +835 -0
  361. package/docs/enums/CP.html +211 -0
  362. package/docs/enums/FamilyPosition.html +239 -0
  363. package/docs/enums/LoopType.html +212 -0
  364. package/docs/enums/RBColor.html +204 -0
  365. package/docs/enums/TopologicalProperty.html +211 -0
  366. package/docs/functions/arrayRemove.html +208 -0
  367. package/docs/functions/isThunk.html +186 -0
  368. package/docs/functions/toThunk.html +186 -0
  369. package/docs/functions/trampoline.html +186 -0
  370. package/docs/functions/trampolineAsync.html +186 -0
  371. package/docs/functions/uuidV4.html +181 -0
  372. package/docs/index.html +693 -0
  373. package/docs/interfaces/IAVLTree.html +1245 -0
  374. package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
  375. package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
  376. package/docs/interfaces/IAbstractGraph.html +433 -0
  377. package/docs/interfaces/IBST.html +1245 -0
  378. package/docs/interfaces/IDirectedGraph.html +570 -0
  379. package/docs/interfaces/IRBTree.html +1247 -0
  380. package/docs/interfaces/IUNDirectedGraph.html +463 -0
  381. package/docs/modules.html +328 -0
  382. package/docs/types/AVLTreeNodeNested.html +182 -0
  383. package/docs/types/AVLTreeOptions.html +180 -0
  384. package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
  385. package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
  386. package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
  387. package/docs/types/AbstractBinaryTreeOptions.html +182 -0
  388. package/docs/types/BSTComparator.html +192 -0
  389. package/docs/types/BSTNodeNested.html +182 -0
  390. package/docs/types/BSTOptions.html +182 -0
  391. package/docs/types/BinaryTreeDeletedResult.html +189 -0
  392. package/docs/types/BinaryTreeNodeId.html +177 -0
  393. package/docs/types/BinaryTreeNodeNested.html +182 -0
  394. package/docs/types/BinaryTreeNodePropertyName.html +177 -0
  395. package/docs/types/BinaryTreeOptions.html +180 -0
  396. package/docs/types/DFSOrderPattern.html +177 -0
  397. package/docs/types/DijkstraResult.html +199 -0
  398. package/docs/types/Direction.html +177 -0
  399. package/docs/types/DummyAny.html +190 -0
  400. package/docs/types/EdgeId.html +177 -0
  401. package/docs/types/HeapOptions.html +198 -0
  402. package/docs/types/IAVLTreeNode.html +184 -0
  403. package/docs/types/IBSTNode.html +184 -0
  404. package/docs/types/IBinaryTree.html +182 -0
  405. package/docs/types/IBinaryTreeNode.html +184 -0
  406. package/docs/types/IRBTreeNode.html +184 -0
  407. package/docs/types/ITreeMultiset.html +182 -0
  408. package/docs/types/ITreeMultisetNode.html +184 -0
  409. package/docs/types/KeyValueObject.html +182 -0
  410. package/docs/types/KeyValueObjectWithId.html +184 -0
  411. package/docs/types/MapGraphCoordinate.html +177 -0
  412. package/docs/types/NavigatorParams.html +211 -0
  413. package/docs/types/NodeOrPropertyName.html +177 -0
  414. package/docs/types/NonNumberNonObjectButDefined.html +177 -0
  415. package/docs/types/ObjectWithNonNumberId.html +184 -0
  416. package/docs/types/ObjectWithNumberId.html +184 -0
  417. package/docs/types/ObjectWithoutId.html +177 -0
  418. package/docs/types/PriorityQueueComparator.html +197 -0
  419. package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
  420. package/docs/types/PriorityQueueOptions.html +191 -0
  421. package/docs/types/RBTreeNodeNested.html +182 -0
  422. package/docs/types/RBTreeOptions.html +180 -0
  423. package/docs/types/RestrictValById.html +177 -0
  424. package/docs/types/SegmentTreeNodeVal.html +177 -0
  425. package/docs/types/SpecifyOptional.html +184 -0
  426. package/docs/types/Thunk.html +185 -0
  427. package/docs/types/ToThunkFn.html +185 -0
  428. package/docs/types/TopologicalStatus.html +177 -0
  429. package/docs/types/TreeMultisetNodeNested.html +182 -0
  430. package/docs/types/TreeMultisetOptions.html +180 -0
  431. package/docs/types/TrlAsyncFn.html +190 -0
  432. package/docs/types/TrlFn.html +190 -0
  433. package/docs/types/Turning.html +177 -0
  434. package/docs/types/VertexId.html +177 -0
  435. package/docs/variables/THUNK_SYMBOL.html +177 -0
  436. package/jest.config.js +7 -0
  437. package/lib/data-structures/binary-tree/aa-tree.js +2 -0
  438. package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +194 -22
  439. package/lib/data-structures/binary-tree/abstract-binary-tree.js +1291 -0
  440. package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
  441. package/lib/data-structures/binary-tree/avl-tree.js +311 -0
  442. package/lib/data-structures/binary-tree/b-tree.js +2 -0
  443. package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
  444. package/lib/data-structures/binary-tree/binary-tree.js +35 -0
  445. package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
  446. package/lib/data-structures/binary-tree/bst.js +551 -0
  447. package/lib/data-structures/binary-tree/index.js +12 -0
  448. package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
  449. package/lib/data-structures/binary-tree/rb-tree.js +22 -0
  450. package/lib/data-structures/binary-tree/segment-tree.js +210 -0
  451. package/lib/data-structures/binary-tree/splay-tree.js +2 -0
  452. package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
  453. package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
  454. package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
  455. package/lib/data-structures/graph/abstract-graph.js +918 -0
  456. package/lib/data-structures/graph/directed-graph.js +416 -0
  457. package/lib/data-structures/graph/index.js +4 -0
  458. package/lib/data-structures/graph/map-graph.js +105 -0
  459. package/lib/data-structures/graph/undirected-graph.js +246 -0
  460. package/lib/data-structures/hash/coordinate-map.js +61 -0
  461. package/lib/data-structures/hash/coordinate-set.js +51 -0
  462. package/lib/data-structures/hash/hash-table.js +2 -0
  463. package/lib/data-structures/hash/index.js +6 -0
  464. package/lib/data-structures/hash/pair.js +2 -0
  465. package/lib/data-structures/hash/tree-map.js +2 -0
  466. package/lib/data-structures/hash/tree-set.js +2 -0
  467. package/lib/data-structures/heap/heap.js +152 -0
  468. package/lib/data-structures/heap/index.js +3 -0
  469. package/lib/data-structures/heap/max-heap.js +26 -0
  470. package/lib/data-structures/heap/min-heap.js +27 -0
  471. package/lib/data-structures/index.js +11 -0
  472. package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
  473. package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
  474. package/lib/data-structures/linked-list/index.js +3 -0
  475. package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
  476. package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
  477. package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
  478. package/lib/data-structures/matrix/index.js +4 -0
  479. package/lib/data-structures/matrix/matrix.js +24 -0
  480. package/lib/data-structures/matrix/matrix2d.js +195 -0
  481. package/lib/data-structures/matrix/navigator.js +101 -0
  482. package/lib/data-structures/matrix/vector2d.js +287 -0
  483. package/lib/data-structures/priority-queue/index.js +3 -0
  484. package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
  485. package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
  486. package/lib/data-structures/priority-queue/priority-queue.js +317 -0
  487. package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
  488. package/lib/data-structures/queue/deque.js +270 -0
  489. package/lib/data-structures/queue/index.js +2 -0
  490. package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
  491. package/lib/data-structures/queue/queue.js +165 -0
  492. package/lib/data-structures/stack/index.js +1 -0
  493. package/lib/data-structures/stack/stack.js +87 -0
  494. package/lib/data-structures/tree/index.js +1 -0
  495. package/lib/data-structures/tree/tree.js +56 -0
  496. package/lib/data-structures/trie/index.js +1 -0
  497. package/lib/data-structures/trie/trie.js +205 -0
  498. package/lib/index.js +4 -0
  499. package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
  500. package/lib/interfaces/binary-tree.d.ts +4 -0
  501. package/{dist → lib}/interfaces/bst.d.ts +1 -2
  502. package/lib/interfaces/heap.js +1 -0
  503. package/lib/interfaces/index.js +15 -0
  504. package/lib/interfaces/navigator.d.ts +1 -0
  505. package/lib/interfaces/navigator.js +1 -0
  506. package/lib/interfaces/priority-queue.d.ts +1 -0
  507. package/lib/interfaces/priority-queue.js +1 -0
  508. package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
  509. package/lib/interfaces/rb-tree.js +1 -0
  510. package/lib/interfaces/segment-tree.d.ts +1 -0
  511. package/lib/interfaces/segment-tree.js +1 -0
  512. package/lib/interfaces/singly-linked-list.d.ts +1 -0
  513. package/lib/interfaces/singly-linked-list.js +1 -0
  514. package/lib/interfaces/tree-multiset.d.ts +5 -0
  515. package/lib/interfaces/tree-multiset.js +1 -0
  516. package/lib/interfaces/undirected-graph.js +1 -0
  517. package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
  518. package/lib/types/data-structures/abstract-binary-tree.js +22 -0
  519. package/lib/types/data-structures/abstract-graph.js +1 -0
  520. package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
  521. package/lib/types/data-structures/avl-tree.js +1 -0
  522. package/lib/types/data-structures/binary-tree.js +1 -0
  523. package/lib/types/data-structures/bst.js +6 -0
  524. package/lib/types/data-structures/directed-graph.js +6 -0
  525. package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
  526. package/lib/types/data-structures/doubly-linked-list.js +1 -0
  527. package/lib/types/data-structures/heap.js +1 -0
  528. package/lib/types/data-structures/index.js +15 -0
  529. package/lib/types/data-structures/map-graph.js +1 -0
  530. package/lib/types/data-structures/navigator.js +1 -0
  531. package/lib/types/data-structures/priority-queue.js +1 -0
  532. package/lib/types/data-structures/rb-tree.js +5 -0
  533. package/lib/types/data-structures/segment-tree.js +1 -0
  534. package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
  535. package/lib/types/data-structures/singly-linked-list.js +1 -0
  536. package/lib/types/data-structures/tree-multiset.js +1 -0
  537. package/lib/types/helpers.d.ts +1 -0
  538. package/lib/types/helpers.js +1 -0
  539. package/lib/types/index.js +3 -0
  540. package/lib/types/utils/index.js +2 -0
  541. package/{dist → lib}/types/utils/utils.d.ts +1 -1
  542. package/lib/types/utils/utils.js +1 -0
  543. package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
  544. package/lib/types/utils/validate-type.js +1 -0
  545. package/lib/utils/index.js +1 -0
  546. package/lib/utils/utils.js +57 -0
  547. package/package.json +150 -56
  548. package/rename_clear_files.sh +29 -0
  549. package/test/integration/avl-tree.test.ts +111 -0
  550. package/test/integration/bst.test.ts +371 -0
  551. package/test/integration/heap.test.js +19 -0
  552. package/test/integration/index.html +44 -0
  553. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
  554. package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
  555. package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
  556. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
  557. package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
  558. package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
  559. package/test/unit/data-structures/graph/index.ts +2 -0
  560. package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
  561. package/test/unit/data-structures/graph/overall.test.ts +50 -0
  562. package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
  563. package/test/unit/data-structures/heap/heap.test.ts +56 -0
  564. package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
  565. package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
  566. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
  567. package/test/unit/data-structures/linked-list/index.ts +4 -0
  568. package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
  569. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
  570. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
  571. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +108 -0
  572. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
  573. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
  574. package/test/unit/data-structures/queue/queue.test.ts +36 -0
  575. package/test/utils/index.ts +2 -0
  576. package/test/utils/magnitude.ts +21 -0
  577. package/test/utils/number.ts +3 -0
  578. package/tsconfig.build.json +33 -0
  579. package/tsconfig.json +38 -0
  580. package/umd/bundle.min.js +3 -0
  581. package/umd/bundle.min.js.map +1 -0
  582. package/webpack.config.js +28 -0
  583. package/dist/bundle.js +0 -2
  584. package/dist/interfaces/binary-tree.d.ts +0 -6
  585. package/dist/interfaces/tree-multiset.d.ts +0 -7
  586. /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
  587. /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
  588. /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  589. /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
  590. /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
  591. /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  592. /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
  593. /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
  594. /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
  595. /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
  596. /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
  597. /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
  598. /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
  599. /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
  600. /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
  601. /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
  602. /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
  603. /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
  604. /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
  605. /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
  606. /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
  607. /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
  608. /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
  609. /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
  610. /package/{dist → lib}/data-structures/index.d.ts +0 -0
  611. /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
  612. /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  613. /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
  614. /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
  615. /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
  616. /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
  617. /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
  618. /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
  619. /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  620. /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  621. /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
  622. /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
  623. /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
  624. /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
  625. /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
  626. /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
  627. /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
  628. /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
  629. /package/{dist → lib}/index.d.ts +0 -0
  630. /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
  631. /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
  632. /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
  633. /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
  634. /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
  635. /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
  636. /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
  637. /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
  638. /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
  639. /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
  640. /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
  641. /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
  642. /package/{dist → lib}/interfaces/index.d.ts +0 -0
  643. /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
  644. /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
  645. /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
  646. /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
  647. /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
  648. /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
  649. /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
  650. /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
  651. /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
  652. /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
  653. /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
  654. /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
  655. /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
  656. /package/{dist → lib}/types/index.d.ts +0 -0
  657. /package/{dist → lib}/types/utils/index.d.ts +0 -0
  658. /package/{dist → lib}/utils/index.d.ts +0 -0
  659. /package/{dist → lib}/utils/utils.d.ts +0 -0
  660. /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
@@ -1,157 +1,164 @@
1
1
  "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = 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
- const utils_1 = require("../../utils");
12
- const priority_queue_1 = require("../priority-queue");
13
- class AbstractVertex {
14
- /**
15
- * The function is a protected constructor that takes an id and an optional value as parameters.
16
- * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
17
- * used to uniquely identify the vertex object.
18
- * @param {T} [val] - The parameter "val" is an optional parameter of type T. It is used to assign a value to the
19
- * vertex. If no value is provided, it will be set to undefined.
20
- */
21
- constructor(id, val) {
40
+ var utils_1 = require("../../utils");
41
+ var priority_queue_1 = require("../priority-queue");
42
+ var AbstractVertex = (function () {
43
+ function AbstractVertex(id, val) {
22
44
  this._id = id;
23
45
  this._val = val;
24
46
  }
25
- get id() {
26
- return this._id;
27
- }
28
- set id(v) {
29
- this._id = v;
30
- }
31
- get val() {
32
- return this._val;
33
- }
34
- set val(value) {
35
- this._val = value;
36
- }
37
- }
47
+ Object.defineProperty(AbstractVertex.prototype, "id", {
48
+ get: function () {
49
+ return this._id;
50
+ },
51
+ set: function (v) {
52
+ this._id = v;
53
+ },
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+ Object.defineProperty(AbstractVertex.prototype, "val", {
58
+ get: function () {
59
+ return this._val;
60
+ },
61
+ set: function (value) {
62
+ this._val = value;
63
+ },
64
+ enumerable: false,
65
+ configurable: true
66
+ });
67
+ return AbstractVertex;
68
+ }());
38
69
  exports.AbstractVertex = AbstractVertex;
39
- class AbstractEdge {
40
- /**
41
- * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
42
- * object.
43
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
44
- * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
45
- * will be assigned.
46
- * @param {T} [val] - The `val` parameter is of type `T`, which means it can be any type. It is an optional parameter,
47
- * meaning it can be omitted when creating an instance of the class.
48
- */
49
- constructor(weight, val) {
70
+ var AbstractEdge = (function () {
71
+ function AbstractEdge(weight, val) {
50
72
  this._weight = weight !== undefined ? weight : 1;
51
73
  this._val = val;
52
74
  this._hashCode = (0, utils_1.uuidV4)();
53
75
  }
54
- get val() {
55
- return this._val;
56
- }
57
- set val(value) {
58
- this._val = value;
59
- }
60
- get weight() {
61
- return this._weight;
62
- }
63
- set weight(v) {
64
- this._weight = v;
65
- }
66
- get hashCode() {
67
- return this._hashCode;
68
- }
69
- /**
70
- * 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.
71
- * 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.
72
- */
73
- /**
74
- * The function sets the value of the _hashCode property to the provided string.
75
- * @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
76
- * "_hashCode" property.
77
- */
78
- _setHashCode(v) {
76
+ Object.defineProperty(AbstractEdge.prototype, "val", {
77
+ get: function () {
78
+ return this._val;
79
+ },
80
+ set: function (value) {
81
+ this._val = value;
82
+ },
83
+ enumerable: false,
84
+ configurable: true
85
+ });
86
+ Object.defineProperty(AbstractEdge.prototype, "weight", {
87
+ get: function () {
88
+ return this._weight;
89
+ },
90
+ set: function (v) {
91
+ this._weight = v;
92
+ },
93
+ enumerable: false,
94
+ configurable: true
95
+ });
96
+ Object.defineProperty(AbstractEdge.prototype, "hashCode", {
97
+ get: function () {
98
+ return this._hashCode;
99
+ },
100
+ enumerable: false,
101
+ configurable: true
102
+ });
103
+ AbstractEdge.prototype._setHashCode = function (v) {
79
104
  this._hashCode = v;
80
- }
81
- }
105
+ };
106
+ return AbstractEdge;
107
+ }());
82
108
  exports.AbstractEdge = AbstractEdge;
83
- class AbstractGraph {
84
- constructor() {
109
+ var AbstractGraph = (function () {
110
+ function AbstractGraph() {
85
111
  this._vertices = new Map();
86
112
  }
87
- get vertices() {
88
- return this._vertices;
89
- }
90
- /**
91
- * The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
92
- * @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
93
- * the `_vertices` map.
94
- * @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
95
- * map. If the vertex does not exist, it returns `null`.
96
- */
97
- getVertex(vertexId) {
113
+ Object.defineProperty(AbstractGraph.prototype, "vertices", {
114
+ get: function () {
115
+ return this._vertices;
116
+ },
117
+ enumerable: false,
118
+ configurable: true
119
+ });
120
+ AbstractGraph.prototype.getVertex = function (vertexId) {
98
121
  return this._vertices.get(vertexId) || null;
99
- }
100
- /**
101
- * The function checks if a vertex exists in a graph.
102
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
103
- * (`VertexId`).
104
- * @returns a boolean value.
105
- */
106
- hasVertex(vertexOrId) {
122
+ };
123
+ AbstractGraph.prototype.hasVertex = function (vertexOrId) {
107
124
  return this._vertices.has(this._getVertexId(vertexOrId));
108
- }
109
- addVertex(idOrVertex, val) {
125
+ };
126
+ AbstractGraph.prototype.addVertex = function (idOrVertex, val) {
110
127
  if (idOrVertex instanceof AbstractVertex) {
111
128
  return this._addVertexOnly(idOrVertex);
112
129
  }
113
130
  else {
114
- const newVertex = this.createVertex(idOrVertex, val);
131
+ var newVertex = this.createVertex(idOrVertex, val);
115
132
  return this._addVertexOnly(newVertex);
116
133
  }
117
- }
118
- /**
119
- * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
120
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
121
- * (`VertexId`).
122
- * @returns The method is returning a boolean value.
123
- */
124
- removeVertex(vertexOrId) {
125
- const vertexId = this._getVertexId(vertexOrId);
134
+ };
135
+ AbstractGraph.prototype.removeVertex = function (vertexOrId) {
136
+ var vertexId = this._getVertexId(vertexOrId);
126
137
  return this._vertices.delete(vertexId);
127
- }
128
- /**
129
- * The function removes all vertices from a graph and returns a boolean indicating if any vertices were removed.
130
- * @param {V[] | VertexId[]} vertices - The `vertices` parameter can be either an array of vertices (`V[]`) or an array
131
- * of vertex IDs (`VertexId[]`).
132
- * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
133
- * were removed.
134
- */
135
- removeAllVertices(vertices) {
136
- const removed = [];
137
- for (const v of vertices) {
138
- removed.push(this.removeVertex(v));
138
+ };
139
+ AbstractGraph.prototype.removeAllVertices = function (vertices) {
140
+ var e_1, _a;
141
+ var removed = [];
142
+ try {
143
+ for (var vertices_1 = __values(vertices), vertices_1_1 = vertices_1.next(); !vertices_1_1.done; vertices_1_1 = vertices_1.next()) {
144
+ var v = vertices_1_1.value;
145
+ removed.push(this.removeVertex(v));
146
+ }
147
+ }
148
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
149
+ finally {
150
+ try {
151
+ if (vertices_1_1 && !vertices_1_1.done && (_a = vertices_1.return)) _a.call(vertices_1);
152
+ }
153
+ finally { if (e_1) throw e_1.error; }
139
154
  }
140
155
  return removed.length > 0;
141
- }
142
- /**
143
- * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
144
- * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
145
- * identifier of a vertex in a graph, while V represents the type of the vertex object itself.
146
- * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
147
- * `VertexId` or a `V` type, which represents the type of the vertex.
148
- * @returns A boolean value is being returned.
149
- */
150
- hasEdge(v1, v2) {
151
- const edge = this.getEdge(v1, v2);
156
+ };
157
+ AbstractGraph.prototype.hasEdge = function (v1, v2) {
158
+ var edge = this.getEdge(v1, v2);
152
159
  return !!edge;
153
- }
154
- addEdge(srcOrEdge, dest, weight, val) {
160
+ };
161
+ AbstractGraph.prototype.addEdge = function (srcOrEdge, dest, weight, val) {
155
162
  if (srcOrEdge instanceof AbstractEdge) {
156
163
  return this._addEdgeOnly(srcOrEdge);
157
164
  }
@@ -163,27 +170,16 @@ class AbstractGraph {
163
170
  srcOrEdge = srcOrEdge.id;
164
171
  if (dest instanceof AbstractVertex)
165
172
  dest = dest.id;
166
- const newEdge = this.createEdge(srcOrEdge, dest, weight, val);
173
+ var newEdge = this.createEdge(srcOrEdge, dest, weight, val);
167
174
  return this._addEdgeOnly(newEdge);
168
175
  }
169
176
  else {
170
177
  throw new Error('dest must be a Vertex or vertex id while srcOrEdge is an Edge');
171
178
  }
172
179
  }
173
- }
174
- /**
175
- * The function sets the weight of an edge between two vertices in a graph.
176
- * @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
177
- * the source vertex of the edge.
178
- * @param {VertexId | V} destOrId - The `destOrId` parameter represents the destination vertex of the edge. It can be
179
- * either a `VertexId` or a vertex object `V`.
180
- * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrId)
181
- * and the destination vertex (destOrId).
182
- * @returns a boolean value. If the edge exists between the source and destination vertices, the function will update
183
- * the weight of the edge and return true. If the edge does not exist, the function will return false.
184
- */
185
- setEdgeWeight(srcOrId, destOrId, weight) {
186
- const edge = this.getEdge(srcOrId, destOrId);
180
+ };
181
+ AbstractGraph.prototype.setEdgeWeight = function (srcOrId, destOrId, weight) {
182
+ var edge = this.getEdge(srcOrId, destOrId);
187
183
  if (edge) {
188
184
  edge.weight = weight;
189
185
  return true;
@@ -191,102 +187,110 @@ class AbstractGraph {
191
187
  else {
192
188
  return false;
193
189
  }
194
- }
195
- /**
196
- * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
197
- * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
198
- * It is the starting vertex for finding paths.
199
- * @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
200
- * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
201
- */
202
- getAllPathsBetween(v1, v2) {
203
- const paths = [];
204
- const vertex1 = this._getVertex(v1);
205
- const vertex2 = this._getVertex(v2);
190
+ };
191
+ AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
192
+ var _this = this;
193
+ var paths = [];
194
+ var vertex1 = this._getVertex(v1);
195
+ var vertex2 = this._getVertex(v2);
206
196
  if (!(vertex1 && vertex2)) {
207
197
  return [];
208
198
  }
209
- const dfs = (cur, dest, visiting, path) => {
199
+ var dfs = function (cur, dest, visiting, path) {
200
+ var e_2, _a;
210
201
  visiting.set(cur, true);
211
202
  if (cur === dest) {
212
- paths.push([vertex1, ...path]);
203
+ paths.push(__spreadArray([vertex1], __read(path), false));
213
204
  }
214
- const neighbors = this.getNeighbors(cur);
215
- for (const neighbor of neighbors) {
205
+ var neighbors = _this.getNeighbors(cur);
206
+ var _loop_1 = function (neighbor) {
216
207
  if (!visiting.get(neighbor)) {
217
208
  path.push(neighbor);
218
209
  dfs(neighbor, dest, visiting, path);
219
- (0, utils_1.arrayRemove)(path, (vertex) => vertex === neighbor);
210
+ (0, utils_1.arrayRemove)(path, function (vertex) { return vertex === neighbor; });
220
211
  }
212
+ };
213
+ try {
214
+ for (var neighbors_1 = __values(neighbors), neighbors_1_1 = neighbors_1.next(); !neighbors_1_1.done; neighbors_1_1 = neighbors_1.next()) {
215
+ var neighbor = neighbors_1_1.value;
216
+ _loop_1(neighbor);
217
+ }
218
+ }
219
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
220
+ finally {
221
+ try {
222
+ if (neighbors_1_1 && !neighbors_1_1.done && (_a = neighbors_1.return)) _a.call(neighbors_1);
223
+ }
224
+ finally { if (e_2) throw e_2.error; }
221
225
  }
222
226
  visiting.set(cur, false);
223
227
  };
224
228
  dfs(vertex1, vertex2, new Map(), []);
225
229
  return paths;
226
- }
227
- /**
228
- * The function calculates the sum of weights along a given path.
229
- * @param {V[]} path - An array of vertices (V) representing a path in a graph.
230
- * @returns The function `getPathSumWeight` returns the sum of the weights of the edges in the given path.
231
- */
232
- getPathSumWeight(path) {
230
+ };
231
+ AbstractGraph.prototype.getPathSumWeight = function (path) {
233
232
  var _a;
234
- let sum = 0;
235
- for (let i = 0; i < path.length; i++) {
233
+ var sum = 0;
234
+ for (var i = 0; i < path.length; i++) {
236
235
  sum += ((_a = this.getEdge(path[i], path[i + 1])) === null || _a === void 0 ? void 0 : _a.weight) || 0;
237
236
  }
238
237
  return sum;
239
- }
240
- /**
241
- * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
242
- * weights or using a breadth-first search algorithm.
243
- * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
244
- * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
245
- * you want to find the minimum cost or weight from the source vertex `v1`.
246
- * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
247
- * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
248
- * the edges. If isWeight is set to false or not provided, the function will calculate the
249
- * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
250
- * and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
251
- * vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
252
- * minimum number of
253
- */
254
- getMinCostBetween(v1, v2, isWeight) {
238
+ };
239
+ AbstractGraph.prototype.getMinCostBetween = function (v1, v2, isWeight) {
240
+ var e_3, _a, e_4, _b;
255
241
  if (isWeight === undefined)
256
242
  isWeight = false;
257
243
  if (isWeight) {
258
- const allPaths = this.getAllPathsBetween(v1, v2);
259
- let min = Infinity;
260
- for (const path of allPaths) {
261
- min = Math.min(this.getPathSumWeight(path), min);
244
+ var allPaths = this.getAllPathsBetween(v1, v2);
245
+ var min = Infinity;
246
+ try {
247
+ for (var allPaths_1 = __values(allPaths), allPaths_1_1 = allPaths_1.next(); !allPaths_1_1.done; allPaths_1_1 = allPaths_1.next()) {
248
+ var path = allPaths_1_1.value;
249
+ min = Math.min(this.getPathSumWeight(path), min);
250
+ }
251
+ }
252
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
253
+ finally {
254
+ try {
255
+ if (allPaths_1_1 && !allPaths_1_1.done && (_a = allPaths_1.return)) _a.call(allPaths_1);
256
+ }
257
+ finally { if (e_3) throw e_3.error; }
262
258
  }
263
259
  return min;
264
260
  }
265
261
  else {
266
- // BFS
267
- const vertex2 = this._getVertex(v2);
268
- const vertex1 = this._getVertex(v1);
262
+ var vertex2 = this._getVertex(v2);
263
+ var vertex1 = this._getVertex(v1);
269
264
  if (!(vertex1 && vertex2)) {
270
265
  return null;
271
266
  }
272
- const visited = new Map();
273
- const queue = [vertex1];
267
+ var visited = new Map();
268
+ var queue = [vertex1];
274
269
  visited.set(vertex1, true);
275
- let cost = 0;
270
+ var cost = 0;
276
271
  while (queue.length > 0) {
277
- for (let i = 0; i < queue.length; i++) {
278
- const cur = queue.shift();
272
+ for (var i = 0; i < queue.length; i++) {
273
+ var cur = queue.shift();
279
274
  if (cur === vertex2) {
280
275
  return cost;
281
276
  }
282
- // TODO consider optimizing to AbstractGraph
283
277
  if (cur !== undefined) {
284
- const neighbors = this.getNeighbors(cur);
285
- for (const neighbor of neighbors) {
286
- if (!visited.has(neighbor)) {
287
- visited.set(neighbor, true);
288
- queue.push(neighbor);
278
+ var neighbors = this.getNeighbors(cur);
279
+ try {
280
+ for (var neighbors_2 = (e_4 = void 0, __values(neighbors)), neighbors_2_1 = neighbors_2.next(); !neighbors_2_1.done; neighbors_2_1 = neighbors_2.next()) {
281
+ var neighbor = neighbors_2_1.value;
282
+ if (!visited.has(neighbor)) {
283
+ visited.set(neighbor, true);
284
+ queue.push(neighbor);
285
+ }
286
+ }
287
+ }
288
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
289
+ finally {
290
+ try {
291
+ if (neighbors_2_1 && !neighbors_2_1.done && (_b = neighbors_2.return)) _b.call(neighbors_2);
289
292
  }
293
+ finally { if (e_4) throw e_4.error; }
290
294
  }
291
295
  }
292
296
  }
@@ -294,146 +298,170 @@ class AbstractGraph {
294
298
  }
295
299
  return null;
296
300
  }
297
- }
298
- /**
299
- * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
300
- * using a breadth-first search algorithm.
301
- * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
302
- * object (`V`) or a vertex ID (`VertexId`).
303
- * @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
304
- * path.
305
- * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
306
- * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
307
- * to false, the function will use breadth-first search (BFS) to find the minimum path.
308
- * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
309
- * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
310
- */
311
- getMinPathBetween(v1, v2, isWeight) {
301
+ };
302
+ AbstractGraph.prototype.getMinPathBetween = function (v1, v2, isWeight) {
303
+ var e_5, _a;
304
+ var _this = this;
312
305
  if (isWeight === undefined)
313
306
  isWeight = false;
314
307
  if (isWeight) {
315
- const allPaths = this.getAllPathsBetween(v1, v2);
316
- let min = Infinity;
317
- let minIndex = -1;
318
- let index = 0;
319
- for (const path of allPaths) {
320
- const pathSumWeight = this.getPathSumWeight(path);
321
- if (pathSumWeight < min) {
322
- min = pathSumWeight;
323
- minIndex = index;
324
- }
325
- index++;
308
+ var allPaths = this.getAllPathsBetween(v1, v2);
309
+ var min = Infinity;
310
+ var minIndex = -1;
311
+ var index = 0;
312
+ try {
313
+ for (var allPaths_2 = __values(allPaths), allPaths_2_1 = allPaths_2.next(); !allPaths_2_1.done; allPaths_2_1 = allPaths_2.next()) {
314
+ var path = allPaths_2_1.value;
315
+ var pathSumWeight = this.getPathSumWeight(path);
316
+ if (pathSumWeight < min) {
317
+ min = pathSumWeight;
318
+ minIndex = index;
319
+ }
320
+ index++;
321
+ }
322
+ }
323
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
324
+ finally {
325
+ try {
326
+ if (allPaths_2_1 && !allPaths_2_1.done && (_a = allPaths_2.return)) _a.call(allPaths_2);
327
+ }
328
+ finally { if (e_5) throw e_5.error; }
326
329
  }
327
330
  return allPaths[minIndex] || null;
328
331
  }
329
332
  else {
330
- // BFS
331
- let minPath = [];
332
- const vertex1 = this._getVertex(v1);
333
- const vertex2 = this._getVertex(v2);
334
- if (!(vertex1 && vertex2)) {
333
+ var minPath_1 = [];
334
+ var vertex1_1 = this._getVertex(v1);
335
+ var vertex2 = this._getVertex(v2);
336
+ if (!(vertex1_1 && vertex2)) {
335
337
  return [];
336
338
  }
337
- const dfs = (cur, dest, visiting, path) => {
339
+ var dfs_1 = function (cur, dest, visiting, path) {
340
+ var e_6, _a;
338
341
  visiting.set(cur, true);
339
342
  if (cur === dest) {
340
- minPath = [vertex1, ...path];
343
+ minPath_1 = __spreadArray([vertex1_1], __read(path), false);
341
344
  return;
342
345
  }
343
- const neighbors = this.getNeighbors(cur);
344
- for (const neighbor of neighbors) {
346
+ var neighbors = _this.getNeighbors(cur);
347
+ var _loop_2 = function (neighbor) {
345
348
  if (!visiting.get(neighbor)) {
346
349
  path.push(neighbor);
347
- dfs(neighbor, dest, visiting, path);
348
- (0, utils_1.arrayRemove)(path, (vertex) => vertex === neighbor);
350
+ dfs_1(neighbor, dest, visiting, path);
351
+ (0, utils_1.arrayRemove)(path, function (vertex) { return vertex === neighbor; });
352
+ }
353
+ };
354
+ try {
355
+ for (var neighbors_3 = __values(neighbors), neighbors_3_1 = neighbors_3.next(); !neighbors_3_1.done; neighbors_3_1 = neighbors_3.next()) {
356
+ var neighbor = neighbors_3_1.value;
357
+ _loop_2(neighbor);
358
+ }
359
+ }
360
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
361
+ finally {
362
+ try {
363
+ if (neighbors_3_1 && !neighbors_3_1.done && (_a = neighbors_3.return)) _a.call(neighbors_3);
349
364
  }
365
+ finally { if (e_6) throw e_6.error; }
350
366
  }
351
367
  visiting.set(cur, false);
352
368
  };
353
- dfs(vertex1, vertex2, new Map(), []);
354
- return minPath;
369
+ dfs_1(vertex1_1, vertex2, new Map(), []);
370
+ return minPath_1;
355
371
  }
356
- }
357
- /**
358
- * Dijkstra algorithm time: O(VE) space: O(V + E)
359
- * /
360
-
361
- /**
362
- * Dijkstra algorithm time: O(VE) space: O(V + E)
363
- * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
364
- * a graph without using a heap data structure.
365
- * @param {V | VertexId} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
366
- * vertex object or a vertex ID.
367
- * @param {V | VertexId | null} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
368
- * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
369
- * identifier. If no destination is provided, the value is set to `null`.
370
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
371
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
372
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
373
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
374
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
375
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
376
- * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
377
- */
378
- dijkstraWithoutHeap(src, dest, getMinDist, genPaths) {
372
+ };
373
+ AbstractGraph.prototype.dijkstraWithoutHeap = function (src, dest, getMinDist, genPaths) {
374
+ var e_7, _a, e_8, _b;
379
375
  if (getMinDist === undefined)
380
376
  getMinDist = false;
381
377
  if (genPaths === undefined)
382
378
  genPaths = false;
383
379
  if (dest === undefined)
384
380
  dest = null;
385
- let minDist = Infinity;
386
- let minDest = null;
387
- let minPath = [];
388
- const paths = [];
389
- const vertices = this._vertices;
390
- const distMap = new Map();
391
- const seen = new Set();
392
- const preMap = new Map(); // predecessor
393
- const srcVertex = this._getVertex(src);
394
- const destVertex = dest ? this._getVertex(dest) : null;
381
+ var minDist = Infinity;
382
+ var minDest = null;
383
+ var minPath = [];
384
+ var paths = [];
385
+ var vertices = this._vertices;
386
+ var distMap = new Map();
387
+ var seen = new Set();
388
+ var preMap = new Map();
389
+ var srcVertex = this._getVertex(src);
390
+ var destVertex = dest ? this._getVertex(dest) : null;
395
391
  if (!srcVertex) {
396
392
  return null;
397
393
  }
398
- for (const vertex of vertices) {
399
- const vertexOrId = vertex[1];
400
- if (vertexOrId instanceof AbstractVertex)
401
- distMap.set(vertexOrId, Infinity);
394
+ try {
395
+ for (var vertices_2 = __values(vertices), vertices_2_1 = vertices_2.next(); !vertices_2_1.done; vertices_2_1 = vertices_2.next()) {
396
+ var vertex = vertices_2_1.value;
397
+ var vertexOrId = vertex[1];
398
+ if (vertexOrId instanceof AbstractVertex)
399
+ distMap.set(vertexOrId, Infinity);
400
+ }
401
+ }
402
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
403
+ finally {
404
+ try {
405
+ if (vertices_2_1 && !vertices_2_1.done && (_a = vertices_2.return)) _a.call(vertices_2);
406
+ }
407
+ finally { if (e_7) throw e_7.error; }
402
408
  }
403
409
  distMap.set(srcVertex, 0);
404
410
  preMap.set(srcVertex, null);
405
- const getMinOfNoSeen = () => {
406
- let min = Infinity;
407
- let minV = null;
408
- for (const [key, val] of distMap) {
409
- if (!seen.has(key)) {
410
- if (val < min) {
411
- min = val;
412
- minV = key;
411
+ var getMinOfNoSeen = function () {
412
+ var e_9, _a;
413
+ var min = Infinity;
414
+ var minV = null;
415
+ try {
416
+ for (var distMap_1 = __values(distMap), distMap_1_1 = distMap_1.next(); !distMap_1_1.done; distMap_1_1 = distMap_1.next()) {
417
+ var _b = __read(distMap_1_1.value, 2), key = _b[0], val = _b[1];
418
+ if (!seen.has(key)) {
419
+ if (val < min) {
420
+ min = val;
421
+ minV = key;
422
+ }
413
423
  }
414
424
  }
415
425
  }
426
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
427
+ finally {
428
+ try {
429
+ if (distMap_1_1 && !distMap_1_1.done && (_a = distMap_1.return)) _a.call(distMap_1);
430
+ }
431
+ finally { if (e_9) throw e_9.error; }
432
+ }
416
433
  return minV;
417
434
  };
418
- const getPaths = (minV) => {
419
- for (const vertex of vertices) {
420
- const vertexOrId = vertex[1];
421
- if (vertexOrId instanceof AbstractVertex) {
422
- const path = [vertexOrId];
423
- let parent = preMap.get(vertexOrId);
424
- while (parent) {
425
- path.push(parent);
426
- parent = preMap.get(parent);
435
+ var getPaths = function (minV) {
436
+ var e_10, _a;
437
+ try {
438
+ for (var vertices_3 = __values(vertices), vertices_3_1 = vertices_3.next(); !vertices_3_1.done; vertices_3_1 = vertices_3.next()) {
439
+ var vertex = vertices_3_1.value;
440
+ var vertexOrId = vertex[1];
441
+ if (vertexOrId instanceof AbstractVertex) {
442
+ var path = [vertexOrId];
443
+ var parent_1 = preMap.get(vertexOrId);
444
+ while (parent_1) {
445
+ path.push(parent_1);
446
+ parent_1 = preMap.get(parent_1);
447
+ }
448
+ var reversed = path.reverse();
449
+ if (vertex[1] === minV)
450
+ minPath = reversed;
451
+ paths.push(reversed);
427
452
  }
428
- const reversed = path.reverse();
429
- if (vertex[1] === minV)
430
- minPath = reversed;
431
- paths.push(reversed);
432
453
  }
433
454
  }
455
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
456
+ finally {
457
+ try {
458
+ if (vertices_3_1 && !vertices_3_1.done && (_a = vertices_3.return)) _a.call(vertices_3);
459
+ }
460
+ finally { if (e_10) throw e_10.error; }
461
+ }
434
462
  };
435
- for (let i = 1; i < vertices.size; i++) {
436
- const cur = getMinOfNoSeen();
463
+ for (var i = 1; i < vertices.size; i++) {
464
+ var cur = getMinOfNoSeen();
437
465
  if (cur) {
438
466
  seen.add(cur);
439
467
  if (destVertex && destVertex === cur) {
@@ -443,120 +471,123 @@ class AbstractGraph {
443
471
  if (genPaths) {
444
472
  getPaths(destVertex);
445
473
  }
446
- return { distMap, preMap, seen, paths, minDist, minPath };
447
- }
448
- const neighbors = this.getNeighbors(cur);
449
- for (const neighbor of neighbors) {
450
- if (!seen.has(neighbor)) {
451
- const edge = this.getEdge(cur, neighbor);
452
- if (edge) {
453
- const curFromMap = distMap.get(cur);
454
- const neighborFromMap = distMap.get(neighbor);
455
- // TODO after no-non-null-assertion not ensure the logic
456
- if (curFromMap !== undefined && neighborFromMap !== undefined) {
457
- if (edge.weight + curFromMap < neighborFromMap) {
458
- distMap.set(neighbor, edge.weight + curFromMap);
459
- preMap.set(neighbor, cur);
474
+ return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
475
+ }
476
+ var neighbors = this.getNeighbors(cur);
477
+ try {
478
+ for (var neighbors_4 = (e_8 = void 0, __values(neighbors)), neighbors_4_1 = neighbors_4.next(); !neighbors_4_1.done; neighbors_4_1 = neighbors_4.next()) {
479
+ var neighbor = neighbors_4_1.value;
480
+ if (!seen.has(neighbor)) {
481
+ var edge = this.getEdge(cur, neighbor);
482
+ if (edge) {
483
+ var curFromMap = distMap.get(cur);
484
+ var neighborFromMap = distMap.get(neighbor);
485
+ if (curFromMap !== undefined && neighborFromMap !== undefined) {
486
+ if (edge.weight + curFromMap < neighborFromMap) {
487
+ distMap.set(neighbor, edge.weight + curFromMap);
488
+ preMap.set(neighbor, cur);
489
+ }
460
490
  }
461
491
  }
462
492
  }
463
493
  }
464
494
  }
495
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
496
+ finally {
497
+ try {
498
+ if (neighbors_4_1 && !neighbors_4_1.done && (_b = neighbors_4.return)) _b.call(neighbors_4);
499
+ }
500
+ finally { if (e_8) throw e_8.error; }
501
+ }
465
502
  }
466
503
  }
467
- getMinDist && distMap.forEach((d, v) => {
468
- if (v !== srcVertex) {
469
- if (d < minDist) {
470
- minDist = d;
471
- if (genPaths)
472
- minDest = v;
504
+ getMinDist &&
505
+ distMap.forEach(function (d, v) {
506
+ if (v !== srcVertex) {
507
+ if (d < minDist) {
508
+ minDist = d;
509
+ if (genPaths)
510
+ minDest = v;
511
+ }
473
512
  }
474
- }
475
- });
513
+ });
476
514
  genPaths && getPaths(minDest);
477
- return { distMap, preMap, seen, paths, minDist, minPath };
478
- }
479
- /**
480
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
481
- *
482
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
483
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
484
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
485
- *
486
- * /
487
-
488
- /**
489
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
490
- * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
491
- * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
492
- * @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
493
- * start. It can be either a vertex object or a vertex ID.
494
- * @param {V | VertexId | null} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
495
- * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
496
- * will calculate the shortest paths to all other vertices from the source vertex.
497
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
498
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
499
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
500
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
501
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
502
- * shortest paths from the source vertex to all other vertices in the graph. If `genPaths
503
- * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
504
- */
505
- dijkstra(src, dest, getMinDist, genPaths) {
506
- var _a;
515
+ return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
516
+ };
517
+ AbstractGraph.prototype.dijkstra = function (src, dest, getMinDist, genPaths) {
518
+ var e_11, _a, e_12, _b;
519
+ var _c;
507
520
  if (getMinDist === undefined)
508
521
  getMinDist = false;
509
522
  if (genPaths === undefined)
510
523
  genPaths = false;
511
524
  if (dest === undefined)
512
525
  dest = null;
513
- let minDist = Infinity;
514
- let minDest = null;
515
- let minPath = [];
516
- const paths = [];
517
- const vertices = this._vertices;
518
- const distMap = new Map();
519
- const seen = new Set();
520
- const preMap = new Map(); // predecessor
521
- const srcVertex = this._getVertex(src);
522
- const destVertex = dest ? this._getVertex(dest) : null;
526
+ var minDist = Infinity;
527
+ var minDest = null;
528
+ var minPath = [];
529
+ var paths = [];
530
+ var vertices = this._vertices;
531
+ var distMap = new Map();
532
+ var seen = new Set();
533
+ var preMap = new Map();
534
+ var srcVertex = this._getVertex(src);
535
+ var destVertex = dest ? this._getVertex(dest) : null;
523
536
  if (!srcVertex)
524
537
  return null;
525
- for (const vertex of vertices) {
526
- const vertexOrId = vertex[1];
527
- if (vertexOrId instanceof AbstractVertex)
528
- distMap.set(vertexOrId, Infinity);
538
+ try {
539
+ for (var vertices_4 = __values(vertices), vertices_4_1 = vertices_4.next(); !vertices_4_1.done; vertices_4_1 = vertices_4.next()) {
540
+ var vertex = vertices_4_1.value;
541
+ var vertexOrId = vertex[1];
542
+ if (vertexOrId instanceof AbstractVertex)
543
+ distMap.set(vertexOrId, Infinity);
544
+ }
545
+ }
546
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
547
+ finally {
548
+ try {
549
+ if (vertices_4_1 && !vertices_4_1.done && (_a = vertices_4.return)) _a.call(vertices_4);
550
+ }
551
+ finally { if (e_11) throw e_11.error; }
529
552
  }
530
- const heap = new priority_queue_1.PriorityQueue({ comparator: (a, b) => a.id - b.id });
553
+ var heap = new priority_queue_1.PriorityQueue({
554
+ comparator: function (a, b) { return a.id - b.id; }
555
+ });
531
556
  heap.add({ id: 0, val: srcVertex });
532
557
  distMap.set(srcVertex, 0);
533
558
  preMap.set(srcVertex, null);
534
- /**
535
- * The function `getPaths` retrieves all paths from vertices to a specified minimum vertex.
536
- * @param {V | null} minV - The parameter `minV` is of type `V | null`. It represents the minimum vertex value or
537
- * null.
538
- */
539
- const getPaths = (minV) => {
540
- for (const vertex of vertices) {
541
- const vertexOrId = vertex[1];
542
- if (vertexOrId instanceof AbstractVertex) {
543
- const path = [vertexOrId];
544
- let parent = preMap.get(vertexOrId);
545
- while (parent) {
546
- path.push(parent);
547
- parent = preMap.get(parent);
559
+ var getPaths = function (minV) {
560
+ var e_13, _a;
561
+ try {
562
+ for (var vertices_5 = __values(vertices), vertices_5_1 = vertices_5.next(); !vertices_5_1.done; vertices_5_1 = vertices_5.next()) {
563
+ var vertex = vertices_5_1.value;
564
+ var vertexOrId = vertex[1];
565
+ if (vertexOrId instanceof AbstractVertex) {
566
+ var path = [vertexOrId];
567
+ var parent_2 = preMap.get(vertexOrId);
568
+ while (parent_2) {
569
+ path.push(parent_2);
570
+ parent_2 = preMap.get(parent_2);
571
+ }
572
+ var reversed = path.reverse();
573
+ if (vertex[1] === minV)
574
+ minPath = reversed;
575
+ paths.push(reversed);
548
576
  }
549
- const reversed = path.reverse();
550
- if (vertex[1] === minV)
551
- minPath = reversed;
552
- paths.push(reversed);
553
577
  }
554
578
  }
579
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
580
+ finally {
581
+ try {
582
+ if (vertices_5_1 && !vertices_5_1.done && (_a = vertices_5.return)) _a.call(vertices_5);
583
+ }
584
+ finally { if (e_13) throw e_13.error; }
585
+ }
555
586
  };
556
587
  while (heap.size > 0) {
557
- const curHeapNode = heap.poll();
558
- const dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.id;
559
- const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.val;
588
+ var curHeapNode = heap.poll();
589
+ var dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.id;
590
+ var cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.val;
560
591
  if (dist !== undefined) {
561
592
  if (cur) {
562
593
  seen.add(cur);
@@ -567,29 +598,39 @@ class AbstractGraph {
567
598
  if (genPaths) {
568
599
  getPaths(destVertex);
569
600
  }
570
- return { distMap, preMap, seen, paths, minDist, minPath };
601
+ return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
571
602
  }
572
- const neighbors = this.getNeighbors(cur);
573
- for (const neighbor of neighbors) {
574
- if (!seen.has(neighbor)) {
575
- const weight = (_a = this.getEdge(cur, neighbor)) === null || _a === void 0 ? void 0 : _a.weight;
576
- if (typeof weight === 'number') {
577
- const distSrcToNeighbor = distMap.get(neighbor);
578
- if (distSrcToNeighbor) {
579
- if (dist + weight < distSrcToNeighbor) {
580
- heap.add({ id: dist + weight, val: neighbor });
581
- preMap.set(neighbor, cur);
582
- distMap.set(neighbor, dist + weight);
603
+ var neighbors = this.getNeighbors(cur);
604
+ try {
605
+ for (var neighbors_5 = (e_12 = void 0, __values(neighbors)), neighbors_5_1 = neighbors_5.next(); !neighbors_5_1.done; neighbors_5_1 = neighbors_5.next()) {
606
+ var neighbor = neighbors_5_1.value;
607
+ if (!seen.has(neighbor)) {
608
+ var weight = (_c = this.getEdge(cur, neighbor)) === null || _c === void 0 ? void 0 : _c.weight;
609
+ if (typeof weight === 'number') {
610
+ var distSrcToNeighbor = distMap.get(neighbor);
611
+ if (distSrcToNeighbor) {
612
+ if (dist + weight < distSrcToNeighbor) {
613
+ heap.add({ id: dist + weight, val: neighbor });
614
+ preMap.set(neighbor, cur);
615
+ distMap.set(neighbor, dist + weight);
616
+ }
583
617
  }
584
618
  }
585
619
  }
586
620
  }
587
621
  }
622
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
623
+ finally {
624
+ try {
625
+ if (neighbors_5_1 && !neighbors_5_1.done && (_b = neighbors_5.return)) _b.call(neighbors_5);
626
+ }
627
+ finally { if (e_12) throw e_12.error; }
628
+ }
588
629
  }
589
630
  }
590
631
  }
591
632
  if (getMinDist) {
592
- distMap.forEach((d, v) => {
633
+ distMap.forEach(function (d, v) {
593
634
  if (v !== srcVertex) {
594
635
  if (d < minDist) {
595
636
  minDist = d;
@@ -602,62 +643,41 @@ class AbstractGraph {
602
643
  if (genPaths) {
603
644
  getPaths(minDest);
604
645
  }
605
- return { distMap, preMap, seen, paths, minDist, minPath };
606
- }
607
- /**
608
- * BellmanFord time:O(VE) space:O(V)
609
- * one to rest pairs
610
- * /
611
-
612
- /**
613
- * BellmanFord time:O(VE) space:O(V)
614
- * one to rest pairs
615
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
616
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
617
- * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
618
- * @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
619
- * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
620
- * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
621
- * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
622
- * calculate the minimum distance from the source vertex to all other vertices in the graph. If `getMin` is set to
623
- * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
624
- * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertices from the source
625
- * vertex.
626
- * @returns The function `bellmanFord` returns an object with the following properties:
627
- */
628
- bellmanFord(src, scanNegativeCycle, getMin, genPath) {
646
+ return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
647
+ };
648
+ AbstractGraph.prototype.bellmanFord = function (src, scanNegativeCycle, getMin, genPath) {
649
+ var e_14, _a;
629
650
  if (getMin === undefined)
630
651
  getMin = false;
631
652
  if (genPath === undefined)
632
653
  genPath = false;
633
- const srcVertex = this._getVertex(src);
634
- const paths = [];
635
- const distMap = new Map();
636
- const preMap = new Map(); // predecessor
637
- let min = Infinity;
638
- let minPath = [];
639
- // TODO
640
- let hasNegativeCycle;
654
+ var srcVertex = this._getVertex(src);
655
+ var paths = [];
656
+ var distMap = new Map();
657
+ var preMap = new Map();
658
+ var min = Infinity;
659
+ var minPath = [];
660
+ var hasNegativeCycle;
641
661
  if (scanNegativeCycle)
642
662
  hasNegativeCycle = false;
643
663
  if (!srcVertex)
644
- return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
645
- const vertices = this._vertices;
646
- const numOfVertices = vertices.size;
647
- const edges = this.edgeSet();
648
- const numOfEdges = edges.length;
649
- this._vertices.forEach(vertex => {
664
+ return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
665
+ var vertices = this._vertices;
666
+ var numOfVertices = vertices.size;
667
+ var edges = this.edgeSet();
668
+ var numOfEdges = edges.length;
669
+ this._vertices.forEach(function (vertex) {
650
670
  distMap.set(vertex, Infinity);
651
671
  });
652
672
  distMap.set(srcVertex, 0);
653
- for (let i = 1; i < numOfVertices; ++i) {
654
- for (let j = 0; j < numOfEdges; ++j) {
655
- const ends = this.getEndsOfEdge(edges[j]);
673
+ for (var i = 1; i < numOfVertices; ++i) {
674
+ for (var j = 0; j < numOfEdges; ++j) {
675
+ var ends = this.getEndsOfEdge(edges[j]);
656
676
  if (ends) {
657
- const [s, d] = ends;
658
- const weight = edges[j].weight;
659
- const sWeight = distMap.get(s);
660
- const dWeight = distMap.get(d);
677
+ var _b = __read(ends, 2), s = _b[0], d = _b[1];
678
+ var weight = edges[j].weight;
679
+ var sWeight = distMap.get(s);
680
+ var dWeight = distMap.get(d);
661
681
  if (sWeight !== undefined && dWeight !== undefined) {
662
682
  if (distMap.get(s) !== Infinity && sWeight + weight < dWeight) {
663
683
  distMap.set(d, sWeight + weight);
@@ -667,9 +687,9 @@ class AbstractGraph {
667
687
  }
668
688
  }
669
689
  }
670
- let minDest = null;
690
+ var minDest = null;
671
691
  if (getMin) {
672
- distMap.forEach((d, v) => {
692
+ distMap.forEach(function (d, v) {
673
693
  if (v !== srcVertex) {
674
694
  if (d < min) {
675
695
  min = d;
@@ -680,93 +700,67 @@ class AbstractGraph {
680
700
  });
681
701
  }
682
702
  if (genPath) {
683
- for (const vertex of vertices) {
684
- const vertexOrId = vertex[1];
685
- if (vertexOrId instanceof AbstractVertex) {
686
- const path = [vertexOrId];
687
- let parent = preMap.get(vertexOrId);
688
- while (parent !== undefined) {
689
- path.push(parent);
690
- parent = preMap.get(parent);
703
+ try {
704
+ for (var vertices_6 = __values(vertices), vertices_6_1 = vertices_6.next(); !vertices_6_1.done; vertices_6_1 = vertices_6.next()) {
705
+ var vertex = vertices_6_1.value;
706
+ var vertexOrId = vertex[1];
707
+ if (vertexOrId instanceof AbstractVertex) {
708
+ var path = [vertexOrId];
709
+ var parent_3 = preMap.get(vertexOrId);
710
+ while (parent_3 !== undefined) {
711
+ path.push(parent_3);
712
+ parent_3 = preMap.get(parent_3);
713
+ }
714
+ var reversed = path.reverse();
715
+ if (vertex[1] === minDest)
716
+ minPath = reversed;
717
+ paths.push(reversed);
691
718
  }
692
- const reversed = path.reverse();
693
- if (vertex[1] === minDest)
694
- minPath = reversed;
695
- paths.push(reversed);
696
719
  }
697
720
  }
721
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
722
+ finally {
723
+ try {
724
+ if (vertices_6_1 && !vertices_6_1.done && (_a = vertices_6.return)) _a.call(vertices_6);
725
+ }
726
+ finally { if (e_14) throw e_14.error; }
727
+ }
698
728
  }
699
- for (let j = 0; j < numOfEdges; ++j) {
700
- const ends = this.getEndsOfEdge(edges[j]);
729
+ for (var j = 0; j < numOfEdges; ++j) {
730
+ var ends = this.getEndsOfEdge(edges[j]);
701
731
  if (ends) {
702
- const [s] = ends;
703
- const weight = edges[j].weight;
704
- const sWeight = distMap.get(s);
732
+ var _c = __read(ends, 1), s = _c[0];
733
+ var weight = edges[j].weight;
734
+ var sWeight = distMap.get(s);
705
735
  if (sWeight) {
706
736
  if (sWeight !== Infinity && sWeight + weight < sWeight)
707
737
  hasNegativeCycle = true;
708
738
  }
709
739
  }
710
740
  }
711
- return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
712
- }
713
- /**
714
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
715
- * /
716
-
717
- /**
718
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
719
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
720
- */
721
- /**
722
- * BellmanFord time:O(VE) space:O(V)
723
- * one to rest pairs
724
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
725
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
726
- */
727
- /**
728
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
729
- * all pairs
730
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
731
- */
732
- /**
733
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
734
- * all pairs
735
- * /
736
-
737
- /**
738
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
739
- * all pairs
740
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
741
- * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
742
- * graph.
743
- * @returns The function `floyd()` returns an object with two properties: `costs` and `predecessor`. The `costs`
744
- * property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
745
- * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest
746
- * path between vertices in the
747
- */
748
- floyd() {
741
+ return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
742
+ };
743
+ AbstractGraph.prototype.floyd = function () {
749
744
  var _a;
750
- const idAndVertices = [...this._vertices];
751
- const n = idAndVertices.length;
752
- const costs = [];
753
- const predecessor = [];
754
- // successors
755
- for (let i = 0; i < n; i++) {
745
+ var idAndVertices = __spreadArray([], __read(this._vertices), false);
746
+ var n = idAndVertices.length;
747
+ var costs = [];
748
+ var predecessor = [];
749
+ for (var i = 0; i < n; i++) {
756
750
  costs[i] = [];
757
751
  predecessor[i] = [];
758
- for (let j = 0; j < n; j++) {
752
+ for (var j = 0; j < n; j++) {
759
753
  predecessor[i][j] = null;
760
754
  }
761
755
  }
762
- for (let i = 0; i < n; i++) {
763
- for (let j = 0; j < n; j++) {
756
+ for (var i = 0; i < n; i++) {
757
+ for (var j = 0; j < n; j++) {
764
758
  costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) === null || _a === void 0 ? void 0 : _a.weight) || Infinity;
765
759
  }
766
760
  }
767
- for (let k = 0; k < n; k++) {
768
- for (let i = 0; i < n; i++) {
769
- for (let j = 0; j < n; j++) {
761
+ for (var k = 0; k < n; k++) {
762
+ for (var i = 0; i < n; i++) {
763
+ for (var j = 0; j < n; j++) {
770
764
  if (costs[i][j] > costs[i][k] + costs[k][j]) {
771
765
  costs[i][j] = costs[i][k] + costs[k][j];
772
766
  predecessor[i][j] = idAndVertices[k][1];
@@ -774,42 +768,11 @@ class AbstractGraph {
774
768
  }
775
769
  }
776
770
  }
777
- return { costs, predecessor };
778
- }
779
- /**
780
- * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
781
- * Tarjan can find cycles in directed or undirected graph
782
- * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
783
- * Tarjan solve the bi-connected components of undirected graphs;
784
- * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
785
- * /
786
-
787
- /**
788
- * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
789
- * Tarjan can find cycles in directed or undirected graph
790
- * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
791
- * Tarjan solve the bi-connected components of undirected graphs;
792
- * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
793
- * The `tarjan` function is used to perform various graph analysis tasks such as finding articulation points, bridges,
794
- * strongly connected components (SCCs), and cycles in a graph.
795
- * @param {boolean} [needArticulationPoints] - A boolean value indicating whether or not to calculate and return the
796
- * articulation points in the graph. Articulation points are the vertices in a graph whose removal would increase the
797
- * number of connected components in the graph.
798
- * @param {boolean} [needBridges] - A boolean flag indicating whether the algorithm should find and return the bridges
799
- * (edges whose removal would increase the number of connected components in the graph).
800
- * @param {boolean} [needSCCs] - A boolean value indicating whether the Strongly Connected Components (SCCs) of the
801
- * graph are needed. If set to true, the function will calculate and return the SCCs of the graph. If set to false, the
802
- * SCCs will not be calculated or returned.
803
- * @param {boolean} [needCycles] - A boolean flag indicating whether the algorithm should find cycles in the graph. If
804
- * set to true, the algorithm will return a map of cycles, where the keys are the low values of the SCCs and the values
805
- * are arrays of vertices that form cycles within the SCCs.
806
- * @returns The function `tarjan` returns an object with the following properties:
807
- */
808
- tarjan(needArticulationPoints, needBridges, needSCCs, needCycles) {
809
- // !! in undirected graph we will not let child visit parent when DFS
810
- // !! articulation point(in DFS search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2)
811
- // !! bridge: low(child) > dfn(cur)
812
- const defaultConfig = false;
771
+ return { costs: costs, predecessor: predecessor };
772
+ };
773
+ AbstractGraph.prototype.tarjan = function (needArticulationPoints, needBridges, needSCCs, needCycles) {
774
+ var _this = this;
775
+ var defaultConfig = false;
813
776
  if (needArticulationPoints === undefined)
814
777
  needArticulationPoints = defaultConfig;
815
778
  if (needBridges === undefined)
@@ -818,60 +781,69 @@ class AbstractGraph {
818
781
  needSCCs = defaultConfig;
819
782
  if (needCycles === undefined)
820
783
  needCycles = defaultConfig;
821
- const dfnMap = new Map();
822
- const lowMap = new Map();
823
- const vertices = this._vertices;
824
- vertices.forEach(v => {
784
+ var dfnMap = new Map();
785
+ var lowMap = new Map();
786
+ var vertices = this._vertices;
787
+ vertices.forEach(function (v) {
825
788
  dfnMap.set(v, -1);
826
789
  lowMap.set(v, Infinity);
827
790
  });
828
- const [root] = vertices.values();
829
- const articulationPoints = [];
830
- const bridges = [];
831
- let dfn = 0;
832
- const dfs = (cur, parent) => {
791
+ var _a = __read(vertices.values(), 1), root = _a[0];
792
+ var articulationPoints = [];
793
+ var bridges = [];
794
+ var dfn = 0;
795
+ var dfs = function (cur, parent) {
796
+ var e_15, _a;
833
797
  dfn++;
834
798
  dfnMap.set(cur, dfn);
835
799
  lowMap.set(cur, dfn);
836
- const neighbors = this.getNeighbors(cur);
837
- let childCount = 0; // child in DFS tree not child in graph
838
- for (const neighbor of neighbors) {
839
- if (neighbor !== parent) {
840
- if (dfnMap.get(neighbor) === -1) {
841
- childCount++;
842
- dfs(neighbor, cur);
843
- }
844
- const childLow = lowMap.get(neighbor);
845
- const curLow = lowMap.get(cur);
846
- // TODO after no-non-null-assertion not ensure the logic
847
- if (curLow !== undefined && childLow !== undefined) {
848
- lowMap.set(cur, Math.min(curLow, childLow));
849
- }
850
- const curFromMap = dfnMap.get(cur);
851
- if (childLow !== undefined && curFromMap !== undefined) {
852
- if (needArticulationPoints) {
853
- if ((cur === root && childCount >= 2) || ((cur !== root) && (childLow >= curFromMap))) {
854
- // todo not ensure the logic if (cur === root && childCount >= 2 || ((cur !== root) && (childLow >= curFromMap))) {
855
- articulationPoints.push(cur);
856
- }
800
+ var neighbors = _this.getNeighbors(cur);
801
+ var childCount = 0;
802
+ try {
803
+ for (var neighbors_6 = __values(neighbors), neighbors_6_1 = neighbors_6.next(); !neighbors_6_1.done; neighbors_6_1 = neighbors_6.next()) {
804
+ var neighbor = neighbors_6_1.value;
805
+ if (neighbor !== parent) {
806
+ if (dfnMap.get(neighbor) === -1) {
807
+ childCount++;
808
+ dfs(neighbor, cur);
857
809
  }
858
- if (needBridges) {
859
- if (childLow > curFromMap) {
860
- const edgeCurToNeighbor = this.getEdge(cur, neighbor);
861
- if (edgeCurToNeighbor) {
862
- bridges.push(edgeCurToNeighbor);
810
+ var childLow = lowMap.get(neighbor);
811
+ var curLow = lowMap.get(cur);
812
+ if (curLow !== undefined && childLow !== undefined) {
813
+ lowMap.set(cur, Math.min(curLow, childLow));
814
+ }
815
+ var curFromMap = dfnMap.get(cur);
816
+ if (childLow !== undefined && curFromMap !== undefined) {
817
+ if (needArticulationPoints) {
818
+ if ((cur === root && childCount >= 2) || (cur !== root && childLow >= curFromMap)) {
819
+ articulationPoints.push(cur);
820
+ }
821
+ }
822
+ if (needBridges) {
823
+ if (childLow > curFromMap) {
824
+ var edgeCurToNeighbor = _this.getEdge(cur, neighbor);
825
+ if (edgeCurToNeighbor) {
826
+ bridges.push(edgeCurToNeighbor);
827
+ }
863
828
  }
864
829
  }
865
830
  }
866
831
  }
867
832
  }
868
833
  }
834
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
835
+ finally {
836
+ try {
837
+ if (neighbors_6_1 && !neighbors_6_1.done && (_a = neighbors_6.return)) _a.call(neighbors_6);
838
+ }
839
+ finally { if (e_15) throw e_15.error; }
840
+ }
869
841
  };
870
842
  dfs(root, null);
871
- let SCCs = new Map();
872
- const getSCCs = () => {
873
- const SCCs = new Map();
874
- lowMap.forEach((low, vertex) => {
843
+ var SCCs = new Map();
844
+ var getSCCs = function () {
845
+ var SCCs = new Map();
846
+ lowMap.forEach(function (low, vertex) {
875
847
  var _a;
876
848
  if (!SCCs.has(low)) {
877
849
  SCCs.set(low, [vertex]);
@@ -885,37 +857,38 @@ class AbstractGraph {
885
857
  if (needSCCs) {
886
858
  SCCs = getSCCs();
887
859
  }
888
- const cycles = new Map();
860
+ var cycles = new Map();
889
861
  if (needCycles) {
890
- let SCCs = new Map();
891
- if (SCCs.size < 1) {
892
- SCCs = getSCCs();
862
+ var SCCs_1 = new Map();
863
+ if (SCCs_1.size < 1) {
864
+ SCCs_1 = getSCCs();
893
865
  }
894
- SCCs.forEach((SCC, low) => {
866
+ SCCs_1.forEach(function (SCC, low) {
895
867
  if (SCC.length > 1) {
896
868
  cycles.set(low, SCC);
897
869
  }
898
870
  });
899
871
  }
900
- return { dfnMap, lowMap, bridges, articulationPoints, SCCs, cycles };
901
- }
902
- _addVertexOnly(newVertex) {
872
+ return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
873
+ };
874
+ AbstractGraph.prototype._addVertexOnly = function (newVertex) {
903
875
  if (this.hasVertex(newVertex)) {
904
876
  return false;
905
- // throw (new Error('Duplicated vertex id is not allowed'));
906
877
  }
907
878
  this._vertices.set(newVertex.id, newVertex);
908
879
  return true;
909
- }
910
- _getVertex(vertexOrId) {
911
- const vertexId = this._getVertexId(vertexOrId);
880
+ };
881
+ AbstractGraph.prototype._getVertex = function (vertexOrId) {
882
+ var vertexId = this._getVertexId(vertexOrId);
912
883
  return this._vertices.get(vertexId) || null;
913
- }
914
- _getVertexId(vertexOrId) {
884
+ };
885
+ AbstractGraph.prototype._getVertexId = function (vertexOrId) {
915
886
  return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
916
- }
917
- _setVertices(value) {
887
+ };
888
+ AbstractGraph.prototype._setVertices = function (value) {
918
889
  this._vertices = value;
919
- }
920
- }
890
+ };
891
+ return AbstractGraph;
892
+ }());
921
893
  exports.AbstractGraph = AbstractGraph;
894
+ //# sourceMappingURL=abstract-graph.js.map