@graphty/algorithms 1.2.0 → 1.4.2

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 (337) hide show
  1. package/README.md +375 -276
  2. package/dist/algorithms.d.ts +42 -2
  3. package/dist/algorithms.js +11402 -2
  4. package/dist/algorithms.js.map +1 -1
  5. package/dist/src/algorithms/centrality/betweenness.d.ts +14 -0
  6. package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
  7. package/dist/src/algorithms/centrality/betweenness.js +144 -169
  8. package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
  9. package/dist/src/algorithms/centrality/closeness.d.ts +35 -1
  10. package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
  11. package/dist/src/algorithms/centrality/closeness.js +70 -149
  12. package/dist/src/algorithms/centrality/closeness.js.map +1 -1
  13. package/dist/src/algorithms/centrality/degree.d.ts +7 -0
  14. package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
  15. package/dist/src/algorithms/centrality/degree.js +12 -9
  16. package/dist/src/algorithms/centrality/degree.js.map +1 -1
  17. package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts +57 -0
  18. package/dist/src/algorithms/centrality/delta-pagerank-simple.d.ts.map +1 -0
  19. package/dist/src/algorithms/centrality/delta-pagerank-simple.js +304 -0
  20. package/dist/src/algorithms/centrality/delta-pagerank-simple.js.map +1 -0
  21. package/dist/src/algorithms/centrality/delta-pagerank.d.ts +106 -0
  22. package/dist/src/algorithms/centrality/delta-pagerank.d.ts.map +1 -0
  23. package/dist/src/algorithms/centrality/delta-pagerank.js +320 -0
  24. package/dist/src/algorithms/centrality/delta-pagerank.js.map +1 -0
  25. package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -3
  26. package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
  27. package/dist/src/algorithms/centrality/eigenvector.js +11 -4
  28. package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
  29. package/dist/src/algorithms/centrality/hits.d.ts +10 -3
  30. package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
  31. package/dist/src/algorithms/centrality/hits.js +11 -4
  32. package/dist/src/algorithms/centrality/hits.js.map +1 -1
  33. package/dist/src/algorithms/centrality/index.d.ts +3 -1
  34. package/dist/src/algorithms/centrality/index.d.ts.map +1 -1
  35. package/dist/src/algorithms/centrality/index.js +2 -1
  36. package/dist/src/algorithms/centrality/index.js.map +1 -1
  37. package/dist/src/algorithms/centrality/katz.d.ts +10 -3
  38. package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
  39. package/dist/src/algorithms/centrality/katz.js +13 -8
  40. package/dist/src/algorithms/centrality/katz.js.map +1 -1
  41. package/dist/src/algorithms/centrality/pagerank.d.ts +31 -0
  42. package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
  43. package/dist/src/algorithms/centrality/pagerank.js +61 -1
  44. package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
  45. package/dist/src/algorithms/community/girvan-newman.d.ts +2 -3
  46. package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
  47. package/dist/src/algorithms/community/girvan-newman.js +67 -57
  48. package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
  49. package/dist/src/algorithms/community/index.d.ts +2 -0
  50. package/dist/src/algorithms/community/index.d.ts.map +1 -1
  51. package/dist/src/algorithms/community/index.js.map +1 -1
  52. package/dist/src/algorithms/community/label-propagation.d.ts +11 -4
  53. package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
  54. package/dist/src/algorithms/community/label-propagation.js +60 -38
  55. package/dist/src/algorithms/community/label-propagation.js.map +1 -1
  56. package/dist/src/algorithms/community/leiden.d.ts +3 -3
  57. package/dist/src/algorithms/community/leiden.d.ts.map +1 -1
  58. package/dist/src/algorithms/community/leiden.js +70 -44
  59. package/dist/src/algorithms/community/leiden.js.map +1 -1
  60. package/dist/src/algorithms/community/louvain-optimized.d.ts +149 -0
  61. package/dist/src/algorithms/community/louvain-optimized.d.ts.map +1 -0
  62. package/dist/src/algorithms/community/louvain-optimized.js +338 -0
  63. package/dist/src/algorithms/community/louvain-optimized.js.map +1 -0
  64. package/dist/src/algorithms/community/louvain.d.ts +2 -3
  65. package/dist/src/algorithms/community/louvain.d.ts.map +1 -1
  66. package/dist/src/algorithms/community/louvain.js +35 -81
  67. package/dist/src/algorithms/community/louvain.js.map +1 -1
  68. package/dist/src/algorithms/community/modularity-utils.d.ts +55 -0
  69. package/dist/src/algorithms/community/modularity-utils.d.ts.map +1 -0
  70. package/dist/src/algorithms/community/modularity-utils.js +108 -0
  71. package/dist/src/algorithms/community/modularity-utils.js.map +1 -0
  72. package/dist/src/algorithms/components/connected.d.ts +23 -0
  73. package/dist/src/algorithms/components/connected.d.ts.map +1 -1
  74. package/dist/src/algorithms/components/connected.js +29 -3
  75. package/dist/src/algorithms/components/connected.js.map +1 -1
  76. package/dist/src/algorithms/matching/bipartite.d.ts +10 -0
  77. package/dist/src/algorithms/matching/bipartite.d.ts.map +1 -1
  78. package/dist/src/algorithms/matching/bipartite.js +18 -40
  79. package/dist/src/algorithms/matching/bipartite.js.map +1 -1
  80. package/dist/src/algorithms/matching/index.d.ts.map +1 -1
  81. package/dist/src/algorithms/matching/index.js.map +1 -1
  82. package/dist/src/algorithms/matching/isomorphism.d.ts +8 -0
  83. package/dist/src/algorithms/matching/isomorphism.d.ts.map +1 -1
  84. package/dist/src/algorithms/matching/isomorphism.js +36 -2
  85. package/dist/src/algorithms/matching/isomorphism.js.map +1 -1
  86. package/dist/src/algorithms/mst/index.d.ts.map +1 -1
  87. package/dist/src/algorithms/mst/index.js.map +1 -1
  88. package/dist/src/algorithms/mst/kruskal.d.ts +14 -0
  89. package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
  90. package/dist/src/algorithms/mst/kruskal.js +17 -3
  91. package/dist/src/algorithms/mst/kruskal.js.map +1 -1
  92. package/dist/src/algorithms/mst/prim.d.ts +9 -0
  93. package/dist/src/algorithms/mst/prim.d.ts.map +1 -1
  94. package/dist/src/algorithms/mst/prim.js +9 -0
  95. package/dist/src/algorithms/mst/prim.js.map +1 -1
  96. package/dist/src/algorithms/shortest-path/bellman-ford.d.ts +10 -0
  97. package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
  98. package/dist/src/algorithms/shortest-path/bellman-ford.js +11 -12
  99. package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
  100. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts +44 -0
  101. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.d.ts.map +1 -0
  102. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js +195 -0
  103. package/dist/src/algorithms/shortest-path/bidirectional-dijkstra.js.map +1 -0
  104. package/dist/src/algorithms/shortest-path/dijkstra.d.ts +20 -2
  105. package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
  106. package/dist/src/algorithms/shortest-path/dijkstra.js +30 -14
  107. package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
  108. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +17 -0
  109. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
  110. package/dist/src/algorithms/shortest-path/floyd-warshall.js +17 -0
  111. package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
  112. package/dist/src/algorithms/shortest-path/index.d.ts.map +1 -1
  113. package/dist/src/algorithms/shortest-path/index.js.map +1 -1
  114. package/dist/src/algorithms/traversal/bfs-unified.d.ts +42 -0
  115. package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -0
  116. package/dist/src/algorithms/traversal/bfs-unified.js +370 -0
  117. package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -0
  118. package/dist/src/algorithms/traversal/bfs-variants.d.ts +77 -0
  119. package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -0
  120. package/dist/src/algorithms/traversal/bfs-variants.js +402 -0
  121. package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -0
  122. package/dist/src/algorithms/traversal/bfs.d.ts +4 -18
  123. package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
  124. package/dist/src/algorithms/traversal/bfs.js +5 -182
  125. package/dist/src/algorithms/traversal/bfs.js.map +1 -1
  126. package/dist/src/algorithms/traversal/dfs.d.ts +10 -0
  127. package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
  128. package/dist/src/algorithms/traversal/dfs.js +48 -0
  129. package/dist/src/algorithms/traversal/dfs.js.map +1 -1
  130. package/dist/src/algorithms/traversal/index.d.ts.map +1 -1
  131. package/dist/src/algorithms/traversal/index.js.map +1 -1
  132. package/dist/src/benchmark-all-algorithms.d.ts +25 -0
  133. package/dist/src/benchmark-all-algorithms.d.ts.map +1 -0
  134. package/dist/src/benchmark-all-algorithms.js +491 -0
  135. package/dist/src/benchmark-all-algorithms.js.map +1 -0
  136. package/dist/src/clustering/hierarchical.d.ts +23 -15
  137. package/dist/src/clustering/hierarchical.d.ts.map +1 -1
  138. package/dist/src/clustering/hierarchical.js +226 -224
  139. package/dist/src/clustering/hierarchical.js.map +1 -1
  140. package/dist/src/clustering/index.d.ts +4 -2
  141. package/dist/src/clustering/index.d.ts.map +1 -1
  142. package/dist/src/clustering/index.js +2 -2
  143. package/dist/src/clustering/index.js.map +1 -1
  144. package/dist/src/clustering/k-core.d.ts +17 -19
  145. package/dist/src/clustering/k-core.d.ts.map +1 -1
  146. package/dist/src/clustering/k-core.js +68 -30
  147. package/dist/src/clustering/k-core.js.map +1 -1
  148. package/dist/src/clustering/mcl.d.ts +6 -0
  149. package/dist/src/clustering/mcl.d.ts.map +1 -1
  150. package/dist/src/clustering/mcl.js +34 -3
  151. package/dist/src/clustering/mcl.js.map +1 -1
  152. package/dist/src/clustering/spectral.d.ts +11 -0
  153. package/dist/src/clustering/spectral.d.ts.map +1 -1
  154. package/dist/src/clustering/spectral.js +99 -47
  155. package/dist/src/clustering/spectral.js.map +1 -1
  156. package/dist/src/core/graph.d.ts +45 -0
  157. package/dist/src/core/graph.d.ts.map +1 -1
  158. package/dist/src/core/graph.js +49 -5
  159. package/dist/src/core/graph.js.map +1 -1
  160. package/dist/src/data-structures/index.d.ts.map +1 -1
  161. package/dist/src/data-structures/index.js.map +1 -1
  162. package/dist/src/data-structures/priority-queue.d.ts +18 -1
  163. package/dist/src/data-structures/priority-queue.d.ts.map +1 -1
  164. package/dist/src/data-structures/priority-queue.js +26 -5
  165. package/dist/src/data-structures/priority-queue.js.map +1 -1
  166. package/dist/src/data-structures/union-find.d.ts +21 -0
  167. package/dist/src/data-structures/union-find.d.ts.map +1 -1
  168. package/dist/src/data-structures/union-find.js +21 -0
  169. package/dist/src/data-structures/union-find.js.map +1 -1
  170. package/dist/src/flow/ford-fulkerson.d.ts +20 -12
  171. package/dist/src/flow/ford-fulkerson.d.ts.map +1 -1
  172. package/dist/src/flow/ford-fulkerson.js +170 -217
  173. package/dist/src/flow/ford-fulkerson.js.map +1 -1
  174. package/dist/src/flow/min-cut.d.ts +6 -8
  175. package/dist/src/flow/min-cut.d.ts.map +1 -1
  176. package/dist/src/flow/min-cut.js +34 -12
  177. package/dist/src/flow/min-cut.js.map +1 -1
  178. package/dist/src/index.d.ts +3 -1
  179. package/dist/src/index.d.ts.map +1 -1
  180. package/dist/src/index.js +6 -1
  181. package/dist/src/index.js.map +1 -1
  182. package/dist/src/link-prediction/adamic-adar.d.ts +26 -0
  183. package/dist/src/link-prediction/adamic-adar.d.ts.map +1 -1
  184. package/dist/src/link-prediction/adamic-adar.js +47 -30
  185. package/dist/src/link-prediction/adamic-adar.js.map +1 -1
  186. package/dist/src/link-prediction/common-neighbors.d.ts +21 -0
  187. package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
  188. package/dist/src/link-prediction/common-neighbors.js +31 -14
  189. package/dist/src/link-prediction/common-neighbors.js.map +1 -1
  190. package/dist/src/link-prediction/index.d.ts.map +1 -1
  191. package/dist/src/optimized/bit-packed.d.ts +193 -0
  192. package/dist/src/optimized/bit-packed.d.ts.map +1 -0
  193. package/dist/src/optimized/bit-packed.js +342 -0
  194. package/dist/src/optimized/bit-packed.js.map +1 -0
  195. package/dist/src/optimized/csr-graph.d.ts +149 -0
  196. package/dist/src/optimized/csr-graph.d.ts.map +1 -0
  197. package/dist/src/optimized/csr-graph.js +404 -0
  198. package/dist/src/optimized/csr-graph.js.map +1 -0
  199. package/dist/src/optimized/direction-optimized-bfs.d.ts +95 -0
  200. package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -0
  201. package/dist/src/optimized/direction-optimized-bfs.js +242 -0
  202. package/dist/src/optimized/direction-optimized-bfs.js.map +1 -0
  203. package/dist/src/optimized/graph-adapter.d.ts +111 -0
  204. package/dist/src/optimized/graph-adapter.d.ts.map +1 -0
  205. package/dist/src/optimized/graph-adapter.js +194 -0
  206. package/dist/src/optimized/graph-adapter.js.map +1 -0
  207. package/dist/src/optimized/index.d.ts +14 -0
  208. package/dist/src/optimized/index.d.ts.map +1 -0
  209. package/dist/src/optimized/index.js +30 -0
  210. package/dist/src/optimized/index.js.map +1 -0
  211. package/dist/src/pathfinding/astar.d.ts +25 -9
  212. package/dist/src/pathfinding/astar.d.ts.map +1 -1
  213. package/dist/src/pathfinding/astar.js +25 -10
  214. package/dist/src/pathfinding/astar.js.map +1 -1
  215. package/dist/src/pathfinding/utils.d.ts +15 -6
  216. package/dist/src/pathfinding/utils.d.ts.map +1 -1
  217. package/dist/src/pathfinding/utils.js +19 -7
  218. package/dist/src/pathfinding/utils.js.map +1 -1
  219. package/dist/src/research/grsbm.d.ts +0 -1
  220. package/dist/src/research/grsbm.d.ts.map +1 -1
  221. package/dist/src/research/grsbm.js +28 -23
  222. package/dist/src/research/grsbm.js.map +1 -1
  223. package/dist/src/research/index.d.ts.map +1 -1
  224. package/dist/src/research/index.js.map +1 -1
  225. package/dist/src/research/sync.d.ts +0 -1
  226. package/dist/src/research/sync.d.ts.map +1 -1
  227. package/dist/src/research/sync.js +31 -36
  228. package/dist/src/research/sync.js.map +1 -1
  229. package/dist/src/research/terahac.d.ts +2 -1
  230. package/dist/src/research/terahac.d.ts.map +1 -1
  231. package/dist/src/research/terahac.js +39 -7
  232. package/dist/src/research/terahac.js.map +1 -1
  233. package/dist/src/types/index.d.ts +8 -0
  234. package/dist/src/types/index.d.ts.map +1 -1
  235. package/dist/src/utils/algorithm-utilities.d.ts +2 -0
  236. package/dist/src/utils/algorithm-utilities.d.ts.map +1 -0
  237. package/dist/src/utils/algorithm-utilities.js +2 -0
  238. package/dist/src/utils/algorithm-utilities.js.map +1 -0
  239. package/dist/src/utils/graph-converters.d.ts +110 -0
  240. package/dist/src/utils/graph-converters.d.ts.map +1 -0
  241. package/dist/src/utils/graph-converters.js +227 -0
  242. package/dist/src/utils/graph-converters.js.map +1 -0
  243. package/dist/src/utils/graph-utilities.d.ts +62 -0
  244. package/dist/src/utils/graph-utilities.d.ts.map +1 -0
  245. package/dist/src/utils/graph-utilities.js +148 -0
  246. package/dist/src/utils/graph-utilities.js.map +1 -0
  247. package/dist/src/utils/index.d.ts +5 -0
  248. package/dist/src/utils/index.d.ts.map +1 -0
  249. package/dist/src/utils/index.js +5 -0
  250. package/dist/src/utils/index.js.map +1 -0
  251. package/dist/src/utils/math-utilities.d.ts +63 -0
  252. package/dist/src/utils/math-utilities.d.ts.map +1 -0
  253. package/dist/src/utils/math-utilities.js +132 -0
  254. package/dist/src/utils/math-utilities.js.map +1 -0
  255. package/dist/src/utils/matrix-utilities.d.ts +2 -0
  256. package/dist/src/utils/matrix-utilities.d.ts.map +1 -0
  257. package/dist/src/utils/matrix-utilities.js +2 -0
  258. package/dist/src/utils/matrix-utilities.js.map +1 -0
  259. package/dist/src/utils/optimization-helpers.d.ts +42 -0
  260. package/dist/src/utils/optimization-helpers.d.ts.map +1 -0
  261. package/dist/src/utils/optimization-helpers.js +59 -0
  262. package/dist/src/utils/optimization-helpers.js.map +1 -0
  263. package/dist/src/utils/priorityQueue.d.ts +24 -0
  264. package/dist/src/utils/priorityQueue.d.ts.map +1 -1
  265. package/dist/src/utils/priorityQueue.js +34 -4
  266. package/dist/src/utils/priorityQueue.js.map +1 -1
  267. package/package.json +58 -39
  268. package/src/algorithms/centrality/betweenness.ts +185 -200
  269. package/src/algorithms/centrality/closeness.ts +93 -194
  270. package/src/algorithms/centrality/degree.ts +18 -22
  271. package/src/algorithms/centrality/delta-pagerank-simple.ts +374 -0
  272. package/src/algorithms/centrality/delta-pagerank.ts +458 -0
  273. package/src/algorithms/centrality/eigenvector.ts +14 -15
  274. package/src/algorithms/centrality/hits.ts +17 -17
  275. package/src/algorithms/centrality/index.ts +20 -13
  276. package/src/algorithms/centrality/katz.ts +17 -25
  277. package/src/algorithms/centrality/pagerank.ts +91 -16
  278. package/src/algorithms/community/girvan-newman.ts +90 -86
  279. package/src/algorithms/community/index.ts +6 -5
  280. package/src/algorithms/community/label-propagation.ts +69 -48
  281. package/src/algorithms/community/leiden.ts +88 -65
  282. package/src/algorithms/community/louvain-optimized.ts +474 -0
  283. package/src/algorithms/community/louvain.ts +52 -122
  284. package/src/algorithms/community/modularity-utils.ts +134 -0
  285. package/src/algorithms/components/connected.ts +40 -17
  286. package/src/algorithms/matching/bipartite.ts +24 -53
  287. package/src/algorithms/matching/index.ts +4 -4
  288. package/src/algorithms/matching/isomorphism.ts +53 -23
  289. package/src/algorithms/mst/index.ts +3 -4
  290. package/src/algorithms/mst/kruskal.ts +21 -6
  291. package/src/algorithms/mst/prim.ts +13 -4
  292. package/src/algorithms/shortest-path/bellman-ford.ts +16 -28
  293. package/src/algorithms/shortest-path/bidirectional-dijkstra.ts +248 -0
  294. package/src/algorithms/shortest-path/dijkstra.ts +38 -30
  295. package/src/algorithms/shortest-path/floyd-warshall.ts +21 -4
  296. package/src/algorithms/shortest-path/index.ts +5 -5
  297. package/src/algorithms/traversal/bfs-unified.ts +437 -0
  298. package/src/algorithms/traversal/bfs-variants.ts +520 -0
  299. package/src/algorithms/traversal/bfs.ts +5 -229
  300. package/src/algorithms/traversal/dfs.ts +61 -42
  301. package/src/algorithms/traversal/index.ts +3 -3
  302. package/src/benchmark-all-algorithms.ts +580 -0
  303. package/src/clustering/hierarchical.ts +268 -272
  304. package/src/clustering/index.ts +8 -6
  305. package/src/clustering/k-core.ts +93 -61
  306. package/src/clustering/mcl.ts +53 -23
  307. package/src/clustering/spectral.ts +130 -72
  308. package/src/core/graph.ts +58 -18
  309. package/src/data-structures/index.ts +2 -2
  310. package/src/data-structures/priority-queue.ts +36 -11
  311. package/src/data-structures/union-find.ts +22 -1
  312. package/src/flow/ford-fulkerson.ts +221 -262
  313. package/src/flow/min-cut.ts +59 -51
  314. package/src/index.ts +9 -2
  315. package/src/link-prediction/adamic-adar.ts +75 -74
  316. package/src/link-prediction/common-neighbors.ts +49 -49
  317. package/src/link-prediction/index.ts +1 -1
  318. package/src/optimized/bit-packed.ts +390 -0
  319. package/src/optimized/csr-graph.ts +518 -0
  320. package/src/optimized/direction-optimized-bfs.ts +310 -0
  321. package/src/optimized/graph-adapter.ts +248 -0
  322. package/src/optimized/index.ts +34 -0
  323. package/src/pathfinding/astar.ts +40 -25
  324. package/src/pathfinding/utils.ts +20 -13
  325. package/src/research/grsbm.ts +36 -39
  326. package/src/research/index.ts +4 -4
  327. package/src/research/sync.ts +41 -54
  328. package/src/research/terahac.ts +63 -21
  329. package/src/types/index.ts +8 -0
  330. package/src/utils/algorithm-utilities.ts +2 -0
  331. package/src/utils/graph-converters.ts +269 -0
  332. package/src/utils/graph-utilities.ts +173 -0
  333. package/src/utils/index.ts +4 -0
  334. package/src/utils/math-utilities.ts +149 -0
  335. package/src/utils/matrix-utilities.ts +2 -0
  336. package/src/utils/optimization-helpers.ts +87 -0
  337. package/src/utils/priorityQueue.ts +40 -6
@@ -0,0 +1,242 @@
1
+ import { CompactDistanceArray, GraphBitSet } from "./bit-packed.js";
2
+ /**
3
+ * Direction-Optimized Breadth-First Search
4
+ *
5
+ * Dynamically switches between top-down and bottom-up search strategies
6
+ * based on the size of the frontier. Particularly effective for low-diameter
7
+ * graphs like social networks.
8
+ *
9
+ * Based on: Beamer, S., Asanović, K., & Patterson, D. (2012).
10
+ * "Direction-optimizing breadth-first search." SC'12.
11
+ */
12
+ export class DirectionOptimizedBFS {
13
+ /**
14
+ * Creates a new DirectionOptimizedBFS instance.
15
+ * @param graph - The CSR graph to perform BFS on
16
+ * @param options - Optional configuration for switching thresholds
17
+ */
18
+ constructor(graph, options) {
19
+ this.graph = graph;
20
+ this.alpha = options?.alpha ?? 15;
21
+ this.beta = options?.beta ?? 18;
22
+ const nodeCount = graph.nodeCount();
23
+ this.parent = new Int32Array(nodeCount).fill(-1);
24
+ this.frontier = new GraphBitSet(nodeCount);
25
+ this.nextFrontier = new GraphBitSet(nodeCount);
26
+ this.distances = new CompactDistanceArray(nodeCount);
27
+ }
28
+ /**
29
+ * Perform BFS from a single source node.
30
+ * @param source - The source node ID to start the BFS from
31
+ * @returns The BFS result containing distances and parent pointers
32
+ */
33
+ search(source) {
34
+ const sourceIndex = this.graph.nodeToIndex(source);
35
+ this.parent[sourceIndex] = -2; // Mark as source
36
+ this.frontier.add(sourceIndex);
37
+ this.distances.set(sourceIndex, 0);
38
+ // let currentDistance = 0; // Variable not used
39
+ // Initialize edgesToCheck to total edges to prevent immediate switch to bottom-up
40
+ let edgesToCheck = this.graph.edgeCount();
41
+ let scoutCount = 0; // Will be set after first top-down step
42
+ let awakeCount = 1; // Number of nodes in current frontier
43
+ let oldAwakeCount = 0;
44
+ // Direction tracking
45
+ let useBottomUp = false;
46
+ while (!this.frontier.isEmpty()) {
47
+ oldAwakeCount = awakeCount;
48
+ if (useBottomUp) {
49
+ // Check if we should switch back to top-down
50
+ if (awakeCount >= oldAwakeCount || awakeCount > this.graph.nodeCount() / this.beta) {
51
+ useBottomUp = false;
52
+ }
53
+ }
54
+ else {
55
+ // Check if we should switch to bottom-up
56
+ if (scoutCount > edgesToCheck / this.alpha) {
57
+ useBottomUp = true;
58
+ }
59
+ }
60
+ if (useBottomUp) {
61
+ awakeCount = this.bottomUpStep();
62
+ }
63
+ else {
64
+ scoutCount = this.topDownStep();
65
+ awakeCount = this.nextFrontier.size();
66
+ }
67
+ // Swap frontiers
68
+ this.frontier.swap(this.nextFrontier);
69
+ this.nextFrontier.clear();
70
+ // currentDistance++; // Variable not used
71
+ edgesToCheck = this.calculateEdgesToCheck();
72
+ }
73
+ return this.buildResult();
74
+ }
75
+ /**
76
+ * Top-down BFS step - explore from frontier.
77
+ * @returns The scout count (total degree of newly discovered nodes)
78
+ */
79
+ topDownStep() {
80
+ let scoutCount = 0;
81
+ // Iterate through frontier nodes
82
+ for (const node of this.frontier) {
83
+ const currentDistance = this.distances.get(node);
84
+ for (const neighbor of this.graph.iterateNeighborIndices(node)) {
85
+ if (this.parent[neighbor] === -1) {
86
+ this.parent[neighbor] = node;
87
+ this.distances.set(neighbor, currentDistance + 1);
88
+ this.nextFrontier.add(neighbor);
89
+ scoutCount += this.graph.outDegreeByIndex(neighbor);
90
+ }
91
+ }
92
+ }
93
+ return scoutCount;
94
+ }
95
+ /**
96
+ * Bottom-up BFS step - check unvisited nodes for frontier neighbors.
97
+ * @returns The number of newly discovered nodes
98
+ */
99
+ bottomUpStep() {
100
+ const nodeCount = this.graph.nodeCount();
101
+ let awakeCount = 0;
102
+ // Check all unvisited nodes
103
+ for (let node = 0; node < nodeCount; node++) {
104
+ if (this.parent[node] === -1) {
105
+ // Use incoming edges for bottom-up traversal
106
+ for (const neighbor of this.graph.iterateIncomingNeighborIndices(node)) {
107
+ if (this.frontier.has(neighbor)) {
108
+ this.parent[node] = neighbor;
109
+ const neighborDist = this.distances.get(neighbor);
110
+ this.distances.set(node, neighborDist + 1);
111
+ this.nextFrontier.add(node);
112
+ awakeCount++;
113
+ break; // Found a parent, no need to check more
114
+ }
115
+ }
116
+ }
117
+ }
118
+ return awakeCount;
119
+ }
120
+ /**
121
+ * Calculate edges to check for switching heuristic.
122
+ * @returns The total number of outgoing edges from frontier nodes
123
+ */
124
+ calculateEdgesToCheck() {
125
+ let count = 0;
126
+ for (const node of this.frontier) {
127
+ count += this.graph.outDegreeByIndex(node);
128
+ }
129
+ return count;
130
+ }
131
+ /**
132
+ * Build result map from internal data structures.
133
+ * @returns The BFS result containing distances and parent pointers
134
+ */
135
+ buildResult() {
136
+ const distances = new Map();
137
+ const parents = new Map();
138
+ let visitedCount = 0;
139
+ for (let i = 0; i < this.graph.nodeCount(); i++) {
140
+ if (this.parent[i] !== -1) {
141
+ const nodeId = this.graph.indexToNodeId(i);
142
+ distances.set(nodeId, this.distances.get(i));
143
+ if (this.parent[i] === -2) {
144
+ // Source node
145
+ parents.set(nodeId, null);
146
+ }
147
+ else {
148
+ // Regular node with parent
149
+ const parentIndex = this.parent[i];
150
+ if (parentIndex !== undefined && parentIndex >= 0) {
151
+ parents.set(nodeId, this.graph.indexToNodeId(parentIndex));
152
+ }
153
+ }
154
+ visitedCount++;
155
+ }
156
+ }
157
+ return { distances, parents, visitedCount };
158
+ }
159
+ /**
160
+ * Perform multi-source BFS from multiple source nodes.
161
+ * @param sources - Array of source node IDs to start the BFS from
162
+ * @returns The BFS result containing distances and parent pointers
163
+ */
164
+ searchMultiple(sources) {
165
+ // Initialize multiple sources
166
+ for (const source of sources) {
167
+ const sourceIndex = this.graph.nodeToIndex(source);
168
+ this.parent[sourceIndex] = -2; // Mark as source
169
+ this.frontier.add(sourceIndex);
170
+ this.distances.set(sourceIndex, 0);
171
+ }
172
+ // let currentDistance = 0; // Variable not used
173
+ let edgesToCheck = 0;
174
+ let scoutCount = 0;
175
+ // Calculate initial edges to check
176
+ for (const node of this.frontier) {
177
+ const degree = this.graph.outDegreeByIndex(node);
178
+ edgesToCheck += degree;
179
+ scoutCount += degree;
180
+ }
181
+ let awakeCount = sources.length;
182
+ let oldAwakeCount = 0;
183
+ let useBottomUp = false;
184
+ while (!this.frontier.isEmpty()) {
185
+ oldAwakeCount = awakeCount;
186
+ if (useBottomUp) {
187
+ if (awakeCount >= oldAwakeCount || awakeCount > this.graph.nodeCount() / this.beta) {
188
+ useBottomUp = false;
189
+ }
190
+ }
191
+ else {
192
+ if (scoutCount > edgesToCheck / this.alpha) {
193
+ useBottomUp = true;
194
+ }
195
+ }
196
+ if (useBottomUp) {
197
+ awakeCount = this.bottomUpStep();
198
+ }
199
+ else {
200
+ scoutCount = this.topDownStep();
201
+ awakeCount = this.nextFrontier.size();
202
+ }
203
+ this.frontier.swap(this.nextFrontier);
204
+ this.nextFrontier.clear();
205
+ // currentDistance++; // Variable not used
206
+ edgesToCheck = this.calculateEdgesToCheck();
207
+ }
208
+ return this.buildResult();
209
+ }
210
+ /**
211
+ * Reset internal state for reuse
212
+ */
213
+ reset() {
214
+ this.parent.fill(-1);
215
+ this.frontier.clear();
216
+ this.nextFrontier.clear();
217
+ this.distances.clear();
218
+ }
219
+ }
220
+ /**
221
+ * Convenience function for single-source BFS.
222
+ * @param graph - The CSR graph to perform BFS on
223
+ * @param source - The source node ID to start the BFS from
224
+ * @param options - Optional configuration for switching thresholds
225
+ * @returns The BFS result containing distances and parent pointers
226
+ */
227
+ export function directionOptimizedBFS(graph, source, options) {
228
+ const bfs = new DirectionOptimizedBFS(graph, options);
229
+ return bfs.search(source);
230
+ }
231
+ /**
232
+ * Convenience function for multi-source BFS.
233
+ * @param graph - The CSR graph to perform BFS on
234
+ * @param sources - Array of source node IDs to start the BFS from
235
+ * @param options - Optional configuration for switching thresholds
236
+ * @returns The BFS result containing distances and parent pointers
237
+ */
238
+ export function directionOptimizedBFSMultiple(graph, sources, options) {
239
+ const bfs = new DirectionOptimizedBFS(graph, options);
240
+ return bfs.searchMultiple(sources);
241
+ }
242
+ //# sourceMappingURL=direction-optimized-bfs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direction-optimized-bfs.js","sourceRoot":"","sources":["../../../src/optimized/direction-optimized-bfs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;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C,MAAM,GAAG,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CACzC,KAAwB,EACxB,OAAkB,EAClB,OAAsC;IAEtC,MAAM,GAAG,GAAG,IAAI,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,111 @@
1
+ import type { Graph } from "../core/graph.js";
2
+ import type { NodeId } from "../types/index.js";
3
+ import { CSRGraph, type ReadonlyGraph } from "./csr-graph.js";
4
+ /**
5
+ * Adapter to convert standard Graph to CSR format
6
+ *
7
+ * Provides transparent conversion while maintaining API compatibility
8
+ */
9
+ export declare class GraphAdapter<TNodeId = NodeId> implements ReadonlyGraph<TNodeId> {
10
+ private csrGraph;
11
+ /**
12
+ * Creates a new GraphAdapter that wraps or converts a graph to CSR format.
13
+ * @param graph - The graph to adapt (either standard Graph or ReadonlyGraph)
14
+ */
15
+ constructor(graph: Graph | ReadonlyGraph<TNodeId>);
16
+ /**
17
+ * Convert standard graph to CSR format.
18
+ * @param graph - The graph to convert
19
+ * @returns A new CSRGraph instance
20
+ */
21
+ private convertToCSR;
22
+ /**
23
+ * Get the total number of nodes in the graph.
24
+ * @returns The number of nodes
25
+ */
26
+ nodeCount(): number;
27
+ /**
28
+ * Get the total number of edges in the graph.
29
+ * @returns The number of edges
30
+ */
31
+ edgeCount(): number;
32
+ /**
33
+ * Check if a node exists in the graph.
34
+ * @param nodeId - The node ID to check
35
+ * @returns True if the node exists, false otherwise
36
+ */
37
+ hasNode(nodeId: TNodeId): boolean;
38
+ /**
39
+ * Check if an edge exists between two nodes.
40
+ * @param source - The source node ID
41
+ * @param target - The target node ID
42
+ * @returns True if the edge exists, false otherwise
43
+ */
44
+ hasEdge(source: TNodeId, target: TNodeId): boolean;
45
+ /**
46
+ * Get neighbors of a node as node IDs.
47
+ * @param nodeId - The node ID to get neighbors for
48
+ * @returns An iterator over neighbor node IDs
49
+ */
50
+ neighbors(nodeId: TNodeId): IterableIterator<TNodeId>;
51
+ /**
52
+ * Get the out-degree (number of outgoing edges) of a node.
53
+ * @param nodeId - The node ID to get the out-degree for
54
+ * @returns The number of outgoing edges from the node
55
+ */
56
+ outDegree(nodeId: TNodeId): number;
57
+ /**
58
+ * Get all nodes in the graph.
59
+ * @returns An iterator over all node IDs
60
+ */
61
+ nodes(): IterableIterator<TNodeId>;
62
+ /**
63
+ * Get the underlying CSR graph.
64
+ * @returns The CSRGraph instance used internally
65
+ */
66
+ getCSRGraph(): CSRGraph<TNodeId>;
67
+ }
68
+ /**
69
+ * Configuration for graph algorithm optimizations
70
+ */
71
+ export interface GraphAlgorithmConfig {
72
+ useDirectionOptimizedBFS?: boolean;
73
+ useCSRFormat?: boolean;
74
+ useBitPackedStructures?: boolean;
75
+ bfsAlpha?: number;
76
+ bfsBeta?: number;
77
+ preallocateSize?: number;
78
+ enableCaching?: boolean;
79
+ }
80
+ /**
81
+ * Configure optimizations globally.
82
+ * @deprecated This function is a no-op and will be removed in a future version
83
+ * @param _config - The configuration object (ignored)
84
+ */
85
+ export declare function configureOptimizations(_config: GraphAlgorithmConfig): void;
86
+ /**
87
+ * Get current configuration.
88
+ * @deprecated This function returns empty config and will be removed in a future version
89
+ * @returns An empty configuration object
90
+ */
91
+ export declare function getOptimizationConfig(): GraphAlgorithmConfig;
92
+ /**
93
+ * Check if a graph is already in CSR format.
94
+ * @param graph - The graph to check
95
+ * @returns True if the graph is a CSRGraph instance
96
+ */
97
+ export declare function isCSRGraph<TNodeId = NodeId>(graph: unknown): graph is CSRGraph<TNodeId>;
98
+ /**
99
+ * Convert any graph to CSR format.
100
+ * @param graph - The graph to convert
101
+ * @returns A CSRGraph instance (either the original if already CSR, or a new converted one)
102
+ */
103
+ export declare function toCSRGraph<TNodeId = NodeId>(graph: Graph | ReadonlyGraph<TNodeId> | CSRGraph<TNodeId>): CSRGraph<TNodeId>;
104
+ /**
105
+ * Create an optimized graph from nodes and edges.
106
+ * @param nodes - Array of node IDs
107
+ * @param edges - Array of edge tuples [source, target, weight?]
108
+ * @returns A new CSRGraph instance
109
+ */
110
+ export declare function createOptimizedGraph<TNodeId = NodeId>(nodes: TNodeId[], edges: [TNodeId, TNodeId, number?][]): CSRGraph<TNodeId>;
111
+ //# sourceMappingURL=graph-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-adapter.d.ts","sourceRoot":"","sources":["../../../src/optimized/graph-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE9D;;;;GAIG;AACH,qBAAa,YAAY,CAAC,OAAO,GAAG,MAAM,CAAE,YAAW,aAAa,CAAC,OAAO,CAAC;IACzE,OAAO,CAAC,QAAQ,CAAoB;IAEpC;;;OAGG;gBACS,KAAK,EAAE,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC;IAUjD;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAuDpB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAIjC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO;IAIlD;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAIrD;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM;IAIlC;;;OAGG;IACH,KAAK,IAAI,gBAAgB,CAAC,OAAO,CAAC;IAIlC;;;OAGG;IACH,WAAW,IAAI,QAAQ,CAAC,OAAO,CAAC;CAGnC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IAEjC,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAGjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC,OAAO,CAAC,CAEvF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAG,MAAM,EACvC,KAAK,EAAE,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,GAC1D,QAAQ,CAAC,OAAO,CAAC,CAOnB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAG,MAAM,EACjD,KAAK,EAAE,OAAO,EAAE,EAChB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,GACrC,QAAQ,CAAC,OAAO,CAAC,CAqBnB"}
@@ -0,0 +1,194 @@
1
+ import { CSRGraph } from "./csr-graph.js";
2
+ /**
3
+ * Adapter to convert standard Graph to CSR format
4
+ *
5
+ * Provides transparent conversion while maintaining API compatibility
6
+ */
7
+ export class GraphAdapter {
8
+ /**
9
+ * Creates a new GraphAdapter that wraps or converts a graph to CSR format.
10
+ * @param graph - The graph to adapt (either standard Graph or ReadonlyGraph)
11
+ */
12
+ constructor(graph) {
13
+ // Check if already a CSRGraph
14
+ if (graph instanceof CSRGraph) {
15
+ this.csrGraph = graph;
16
+ }
17
+ else {
18
+ // Convert to CSR format
19
+ this.csrGraph = this.convertToCSR(graph);
20
+ }
21
+ }
22
+ /**
23
+ * Convert standard graph to CSR format.
24
+ * @param graph - The graph to convert
25
+ * @returns A new CSRGraph instance
26
+ */
27
+ convertToCSR(graph) {
28
+ const adjacencyList = new Map();
29
+ const weights = new Map();
30
+ // Handle both Graph and ReadonlyGraph interfaces
31
+ if ("nodes" in graph && typeof graph.nodes === "function") {
32
+ // Build adjacency list from Graph
33
+ for (const node of graph.nodes()) {
34
+ const nodeId = node.id;
35
+ const neighbors = [];
36
+ const graphTyped = graph;
37
+ for (const neighborId of graphTyped.neighbors(nodeId)) {
38
+ neighbors.push(neighborId);
39
+ // Get edge weight if available
40
+ if ("getEdge" in graph && typeof graph.getEdge === "function") {
41
+ const edge = graphTyped.getEdge(nodeId, neighborId);
42
+ if (edge?.weight !== undefined) {
43
+ weights.set(`${String(nodeId)}-${String(neighborId)}`, edge.weight);
44
+ }
45
+ }
46
+ }
47
+ adjacencyList.set(nodeId, neighbors);
48
+ }
49
+ }
50
+ else if ("nodeIds" in graph && typeof graph.nodeIds === "function") {
51
+ const readonlyGraph = graph;
52
+ for (const nodeId of readonlyGraph.nodeIds()) {
53
+ adjacencyList.set(nodeId, []);
54
+ }
55
+ // Build adjacency from edges
56
+ if ("edges" in readonlyGraph && typeof readonlyGraph.edges === "function") {
57
+ for (const edge of readonlyGraph.edges()) {
58
+ const neighbors = adjacencyList.get(edge.source);
59
+ if (neighbors) {
60
+ neighbors.push(edge.target);
61
+ if (edge.weight !== undefined) {
62
+ weights.set(`${String(edge.source)}-${String(edge.target)}`, edge.weight);
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ return new CSRGraph(adjacencyList, weights.size > 0 ? weights : undefined);
69
+ }
70
+ // Delegate all methods to CSR implementation
71
+ /**
72
+ * Get the total number of nodes in the graph.
73
+ * @returns The number of nodes
74
+ */
75
+ nodeCount() {
76
+ return this.csrGraph.nodeCount();
77
+ }
78
+ /**
79
+ * Get the total number of edges in the graph.
80
+ * @returns The number of edges
81
+ */
82
+ edgeCount() {
83
+ return this.csrGraph.edgeCount();
84
+ }
85
+ /**
86
+ * Check if a node exists in the graph.
87
+ * @param nodeId - The node ID to check
88
+ * @returns True if the node exists, false otherwise
89
+ */
90
+ hasNode(nodeId) {
91
+ return this.csrGraph.hasNode(nodeId);
92
+ }
93
+ /**
94
+ * Check if an edge exists between two nodes.
95
+ * @param source - The source node ID
96
+ * @param target - The target node ID
97
+ * @returns True if the edge exists, false otherwise
98
+ */
99
+ hasEdge(source, target) {
100
+ return this.csrGraph.hasEdge(source, target);
101
+ }
102
+ /**
103
+ * Get neighbors of a node as node IDs.
104
+ * @param nodeId - The node ID to get neighbors for
105
+ * @returns An iterator over neighbor node IDs
106
+ */
107
+ neighbors(nodeId) {
108
+ return this.csrGraph.neighbors(nodeId);
109
+ }
110
+ /**
111
+ * Get the out-degree (number of outgoing edges) of a node.
112
+ * @param nodeId - The node ID to get the out-degree for
113
+ * @returns The number of outgoing edges from the node
114
+ */
115
+ outDegree(nodeId) {
116
+ return this.csrGraph.outDegree(nodeId);
117
+ }
118
+ /**
119
+ * Get all nodes in the graph.
120
+ * @returns An iterator over all node IDs
121
+ */
122
+ nodes() {
123
+ return this.csrGraph.nodes();
124
+ }
125
+ /**
126
+ * Get the underlying CSR graph.
127
+ * @returns The CSRGraph instance used internally
128
+ */
129
+ getCSRGraph() {
130
+ return this.csrGraph;
131
+ }
132
+ }
133
+ /**
134
+ * Configure optimizations globally.
135
+ * @deprecated This function is a no-op and will be removed in a future version
136
+ * @param _config - The configuration object (ignored)
137
+ */
138
+ export function configureOptimizations(_config) {
139
+ // No-op for backward compatibility
140
+ }
141
+ /**
142
+ * Get current configuration.
143
+ * @deprecated This function returns empty config and will be removed in a future version
144
+ * @returns An empty configuration object
145
+ */
146
+ export function getOptimizationConfig() {
147
+ return {};
148
+ }
149
+ /**
150
+ * Check if a graph is already in CSR format.
151
+ * @param graph - The graph to check
152
+ * @returns True if the graph is a CSRGraph instance
153
+ */
154
+ export function isCSRGraph(graph) {
155
+ return graph instanceof CSRGraph;
156
+ }
157
+ /**
158
+ * Convert any graph to CSR format.
159
+ * @param graph - The graph to convert
160
+ * @returns A CSRGraph instance (either the original if already CSR, or a new converted one)
161
+ */
162
+ export function toCSRGraph(graph) {
163
+ if (isCSRGraph(graph)) {
164
+ return graph;
165
+ }
166
+ const adapter = new GraphAdapter(graph);
167
+ return adapter.getCSRGraph();
168
+ }
169
+ /**
170
+ * Create an optimized graph from nodes and edges.
171
+ * @param nodes - Array of node IDs
172
+ * @param edges - Array of edge tuples [source, target, weight?]
173
+ * @returns A new CSRGraph instance
174
+ */
175
+ export function createOptimizedGraph(nodes, edges) {
176
+ const adjacencyList = new Map();
177
+ const weights = new Map();
178
+ // Initialize nodes
179
+ for (const node of nodes) {
180
+ adjacencyList.set(node, []);
181
+ }
182
+ // Add edges
183
+ for (const [source, target, weight] of edges) {
184
+ const neighbors = adjacencyList.get(source);
185
+ if (neighbors) {
186
+ neighbors.push(target);
187
+ if (weight !== undefined) {
188
+ weights.set(`${String(source)}-${String(target)}`, weight);
189
+ }
190
+ }
191
+ }
192
+ return new CSRGraph(adjacencyList, weights.size > 0 ? weights : undefined);
193
+ }
194
+ //# sourceMappingURL=graph-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-adapter.js","sourceRoot":"","sources":["../../../src/optimized/graph-adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAsB,MAAM,gBAAgB,CAAC;AAE9D;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAGrB;;;OAGG;IACH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,EAAE,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAChC,KAAgB,EAChB,KAAoC;IAEpC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAsB,CAAC;IACpD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE1C,mBAAmB;IACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,YAAY;IACZ,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,SAAS,EAAE,CAAC;YACZ,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YAC/D,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,IAAI,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Optimized graph algorithm implementations
3
+ *
4
+ * High-performance implementations using:
5
+ * - Direction-Optimized BFS
6
+ * - Compressed Sparse Row (CSR) format
7
+ * - Bit-packed data structures
8
+ */
9
+ export { configureOptimizations, getOptimizationConfig, type GraphAlgorithmConfig } from "./graph-adapter.js";
10
+ export { CompactDistanceArray, GraphBitSet, VisitedBitArray } from "./bit-packed.js";
11
+ export { CSRGraph } from "./csr-graph.js";
12
+ export { DirectionOptimizedBFS } from "./direction-optimized-bfs.js";
13
+ export { createOptimizedGraph, isCSRGraph, toCSRGraph } from "./graph-adapter.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/optimized/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAgB9G,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAGrE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Optimized graph algorithm implementations
3
+ *
4
+ * High-performance implementations using:
5
+ * - Direction-Optimized BFS
6
+ * - Compressed Sparse Row (CSR) format
7
+ * - Bit-packed data structures
8
+ */
9
+ // Configuration and optimization control
10
+ // These deprecated functions are intentionally re-exported for backward compatibility
11
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
12
+ export { configureOptimizations, getOptimizationConfig } from "./graph-adapter.js";
13
+ // Note: The main BFS functions in algorithms/traversal/bfs.ts automatically
14
+ // use these optimizations for large graphs (>10k nodes) when optimizations are enabled.
15
+ // No manual configuration needed - just use breadthFirstSearch, shortestPathBFS, etc.
16
+ //
17
+ // The previously exported bfsOptimized, shortestPathBFSOptimized, and
18
+ // singleSourceShortestPathBFSOptimized functions have been removed since they
19
+ // are no longer needed. All optimization happens automatically.
20
+ // BFS optimization functions have been removed. The main BFS functions
21
+ // (breadthFirstSearch, shortestPathBFS, singleSourceShortestPathBFS)
22
+ // in algorithms/traversal/bfs.ts now automatically use optimizations
23
+ // for large graphs without requiring manual configuration.
24
+ // Export data structures for advanced users
25
+ export { CompactDistanceArray, GraphBitSet, VisitedBitArray } from "./bit-packed.js";
26
+ export { CSRGraph } from "./csr-graph.js";
27
+ export { DirectionOptimizedBFS } from "./direction-optimized-bfs.js";
28
+ // Export utilities
29
+ export { createOptimizedGraph, isCSRGraph, toCSRGraph } from "./graph-adapter.js";
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/optimized/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,yCAAyC;AACzC,sFAAsF;AACtF,4DAA4D;AAC5D,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAA6B,MAAM,oBAAoB,CAAC;AAE9G,4EAA4E;AAC5E,wFAAwF;AACxF,sFAAsF;AACtF,EAAE;AACF,sEAAsE;AACtE,8EAA8E;AAC9E,gEAAgE;AAEhE,uEAAuE;AACvE,qEAAqE;AACrE,qEAAqE;AACrE,2DAA2D;AAE3D,4CAA4C;AAC5C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,mBAAmB;AACnB,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}