@graphty/algorithms 2.1.2 → 2.2.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 (355) hide show
  1. package/README.md +139 -50
  2. package/dist/algorithms.js +15260 -10390
  3. package/dist/algorithms.js.map +1 -1
  4. package/dist/algorithms.standalone.js +26675 -21542
  5. package/dist/algorithms.standalone.js.map +1 -1
  6. package/dist/src/algorithms/centrality/betweenness.d.ts +18 -0
  7. package/dist/src/algorithms/centrality/betweenness.d.ts.map +1 -1
  8. package/dist/src/algorithms/centrality/betweenness.js +40 -1
  9. package/dist/src/algorithms/centrality/betweenness.js.map +1 -1
  10. package/dist/src/algorithms/centrality/closeness.d.ts +20 -0
  11. package/dist/src/algorithms/centrality/closeness.d.ts.map +1 -1
  12. package/dist/src/algorithms/centrality/closeness.js +93 -8
  13. package/dist/src/algorithms/centrality/closeness.js.map +1 -1
  14. package/dist/src/algorithms/centrality/degree.d.ts +9 -0
  15. package/dist/src/algorithms/centrality/degree.d.ts.map +1 -1
  16. package/dist/src/algorithms/centrality/degree.js +18 -0
  17. package/dist/src/algorithms/centrality/degree.js.map +1 -1
  18. package/dist/src/algorithms/centrality/eigenvector.d.ts +10 -0
  19. package/dist/src/algorithms/centrality/eigenvector.d.ts.map +1 -1
  20. package/dist/src/algorithms/centrality/eigenvector.js +29 -0
  21. package/dist/src/algorithms/centrality/eigenvector.js.map +1 -1
  22. package/dist/src/algorithms/centrality/hits.d.ts +9 -0
  23. package/dist/src/algorithms/centrality/hits.d.ts.map +1 -1
  24. package/dist/src/algorithms/centrality/hits.js +23 -0
  25. package/dist/src/algorithms/centrality/hits.js.map +1 -1
  26. package/dist/src/algorithms/centrality/katz.d.ts +9 -0
  27. package/dist/src/algorithms/centrality/katz.d.ts.map +1 -1
  28. package/dist/src/algorithms/centrality/katz.js +31 -0
  29. package/dist/src/algorithms/centrality/katz.js.map +1 -1
  30. package/dist/src/algorithms/centrality/pagerank.d.ts +13 -13
  31. package/dist/src/algorithms/centrality/pagerank.d.ts.map +1 -1
  32. package/dist/src/algorithms/centrality/pagerank.js +47 -10
  33. package/dist/src/algorithms/centrality/pagerank.js.map +1 -1
  34. package/dist/src/algorithms/community/girvan-newman-legacy.d.ts +27 -0
  35. package/dist/src/algorithms/community/girvan-newman-legacy.d.ts.map +1 -0
  36. package/dist/src/algorithms/community/girvan-newman-legacy.js +335 -0
  37. package/dist/src/algorithms/community/girvan-newman-legacy.js.map +1 -0
  38. package/dist/src/algorithms/community/girvan-newman.d.ts +5 -3
  39. package/dist/src/algorithms/community/girvan-newman.d.ts.map +1 -1
  40. package/dist/src/algorithms/community/girvan-newman.js +34 -308
  41. package/dist/src/algorithms/community/girvan-newman.js.map +1 -1
  42. package/dist/src/algorithms/community/label-propagation.d.ts +9 -6
  43. package/dist/src/algorithms/community/label-propagation.d.ts.map +1 -1
  44. package/dist/src/algorithms/community/label-propagation.js +24 -110
  45. package/dist/src/algorithms/community/label-propagation.js.map +1 -1
  46. package/dist/src/algorithms/components/connected.d.ts.map +1 -1
  47. package/dist/src/algorithms/components/connected.js +28 -77
  48. package/dist/src/algorithms/components/connected.js.map +1 -1
  49. package/dist/src/algorithms/mst/kruskal.d.ts.map +1 -1
  50. package/dist/src/algorithms/mst/kruskal.js +59 -3
  51. package/dist/src/algorithms/mst/kruskal.js.map +1 -1
  52. package/dist/src/algorithms/shortest-path/bellman-ford.d.ts.map +1 -1
  53. package/dist/src/algorithms/shortest-path/bellman-ford.js +46 -0
  54. package/dist/src/algorithms/shortest-path/bellman-ford.js.map +1 -1
  55. package/dist/src/algorithms/shortest-path/dijkstra.d.ts.map +1 -1
  56. package/dist/src/algorithms/shortest-path/dijkstra.js +27 -0
  57. package/dist/src/algorithms/shortest-path/dijkstra.js.map +1 -1
  58. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts +15 -5
  59. package/dist/src/algorithms/shortest-path/floyd-warshall.d.ts.map +1 -1
  60. package/dist/src/algorithms/shortest-path/floyd-warshall.js +97 -107
  61. package/dist/src/algorithms/shortest-path/floyd-warshall.js.map +1 -1
  62. package/dist/src/algorithms/traversal/bfs-unified.d.ts +2 -12
  63. package/dist/src/algorithms/traversal/bfs-unified.d.ts.map +1 -1
  64. package/dist/src/algorithms/traversal/bfs-unified.js +47 -308
  65. package/dist/src/algorithms/traversal/bfs-unified.js.map +1 -1
  66. package/dist/src/algorithms/traversal/bfs-variants.d.ts.map +1 -1
  67. package/dist/src/algorithms/traversal/bfs-variants.js +5 -25
  68. package/dist/src/algorithms/traversal/bfs-variants.js.map +1 -1
  69. package/dist/src/algorithms/traversal/bfs.d.ts +0 -3
  70. package/dist/src/algorithms/traversal/bfs.d.ts.map +1 -1
  71. package/dist/src/algorithms/traversal/bfs.js +0 -4
  72. package/dist/src/algorithms/traversal/bfs.js.map +1 -1
  73. package/dist/src/algorithms/traversal/dfs.d.ts.map +1 -1
  74. package/dist/src/algorithms/traversal/dfs.js +33 -154
  75. package/dist/src/algorithms/traversal/dfs.js.map +1 -1
  76. package/dist/src/clustering/hierarchical-legacy.d.ts +56 -0
  77. package/dist/src/clustering/hierarchical-legacy.d.ts.map +1 -0
  78. package/dist/src/clustering/hierarchical-legacy.js +441 -0
  79. package/dist/src/clustering/hierarchical-legacy.js.map +1 -0
  80. package/dist/src/clustering/hierarchical.d.ts +7 -39
  81. package/dist/src/clustering/hierarchical.d.ts.map +1 -1
  82. package/dist/src/clustering/hierarchical.js +56 -417
  83. package/dist/src/clustering/hierarchical.js.map +1 -1
  84. package/dist/src/clustering/k-core-legacy.d.ts +30 -0
  85. package/dist/src/clustering/k-core-legacy.d.ts.map +1 -0
  86. package/dist/src/clustering/k-core-legacy.js +191 -0
  87. package/dist/src/clustering/k-core-legacy.js.map +1 -0
  88. package/dist/src/clustering/k-core.d.ts +8 -7
  89. package/dist/src/clustering/k-core.d.ts.map +1 -1
  90. package/dist/src/clustering/k-core.js +33 -174
  91. package/dist/src/clustering/k-core.js.map +1 -1
  92. package/dist/src/clustering/mcl-legacy.d.ts +42 -0
  93. package/dist/src/clustering/mcl-legacy.d.ts.map +1 -0
  94. package/dist/src/clustering/mcl-legacy.js +386 -0
  95. package/dist/src/clustering/mcl-legacy.js.map +1 -0
  96. package/dist/src/clustering/mcl.d.ts +9 -32
  97. package/dist/src/clustering/mcl.d.ts.map +1 -1
  98. package/dist/src/clustering/mcl.js +48 -374
  99. package/dist/src/clustering/mcl.js.map +1 -1
  100. package/dist/src/index.d.ts +29 -3
  101. package/dist/src/index.d.ts.map +1 -1
  102. package/dist/src/index.js +2 -1
  103. package/dist/src/index.js.map +1 -1
  104. package/dist/src/indexed/accelerator.d.ts +141 -11
  105. package/dist/src/indexed/accelerator.d.ts.map +1 -1
  106. package/dist/src/indexed/accelerator.js +319 -5
  107. package/dist/src/indexed/accelerator.js.map +1 -1
  108. package/dist/src/indexed/all-pairs.d.ts +59 -0
  109. package/dist/src/indexed/all-pairs.d.ts.map +1 -0
  110. package/dist/src/indexed/all-pairs.js +274 -0
  111. package/dist/src/indexed/all-pairs.js.map +1 -0
  112. package/dist/src/indexed/bellman-ford.d.ts +25 -0
  113. package/dist/src/indexed/bellman-ford.d.ts.map +1 -0
  114. package/dist/src/indexed/bellman-ford.js +59 -0
  115. package/dist/src/indexed/bellman-ford.js.map +1 -0
  116. package/dist/src/indexed/betweenness.d.ts +85 -0
  117. package/dist/src/indexed/betweenness.d.ts.map +1 -0
  118. package/dist/src/indexed/betweenness.js +188 -0
  119. package/dist/src/indexed/betweenness.js.map +1 -0
  120. package/dist/src/indexed/bfs.d.ts +69 -2
  121. package/dist/src/indexed/bfs.d.ts.map +1 -1
  122. package/dist/src/indexed/bfs.js +148 -1
  123. package/dist/src/indexed/bfs.js.map +1 -1
  124. package/dist/src/indexed/bipartite.d.ts +37 -0
  125. package/dist/src/indexed/bipartite.d.ts.map +1 -0
  126. package/dist/src/indexed/bipartite.js +54 -0
  127. package/dist/src/indexed/bipartite.js.map +1 -0
  128. package/dist/src/indexed/closeness.d.ts +49 -0
  129. package/dist/src/indexed/closeness.d.ts.map +1 -0
  130. package/dist/src/indexed/closeness.js +127 -0
  131. package/dist/src/indexed/closeness.js.map +1 -0
  132. package/dist/src/indexed/common-neighbors.d.ts +14 -1
  133. package/dist/src/indexed/common-neighbors.d.ts.map +1 -1
  134. package/dist/src/indexed/common-neighbors.js +24 -14
  135. package/dist/src/indexed/common-neighbors.js.map +1 -1
  136. package/dist/src/indexed/degree.d.ts +19 -0
  137. package/dist/src/indexed/degree.d.ts.map +1 -0
  138. package/dist/src/indexed/degree.js +45 -0
  139. package/dist/src/indexed/degree.js.map +1 -0
  140. package/dist/src/indexed/delta-pagerank.d.ts +145 -0
  141. package/dist/src/indexed/delta-pagerank.d.ts.map +1 -0
  142. package/dist/src/indexed/delta-pagerank.js +428 -0
  143. package/dist/src/indexed/delta-pagerank.js.map +1 -0
  144. package/dist/src/indexed/dfs.d.ts +55 -0
  145. package/dist/src/indexed/dfs.d.ts.map +1 -0
  146. package/dist/src/indexed/dfs.js +146 -0
  147. package/dist/src/indexed/dfs.js.map +1 -0
  148. package/dist/src/indexed/eigenvector.d.ts +48 -0
  149. package/dist/src/indexed/eigenvector.d.ts.map +1 -0
  150. package/dist/src/indexed/eigenvector.js +162 -0
  151. package/dist/src/indexed/eigenvector.js.map +1 -0
  152. package/dist/src/indexed/facade.d.ts +109 -0
  153. package/dist/src/indexed/facade.d.ts.map +1 -0
  154. package/dist/src/indexed/facade.js +204 -0
  155. package/dist/src/indexed/facade.js.map +1 -0
  156. package/dist/src/indexed/flow.d.ts +120 -0
  157. package/dist/src/indexed/flow.d.ts.map +1 -0
  158. package/dist/src/indexed/flow.js +377 -0
  159. package/dist/src/indexed/flow.js.map +1 -0
  160. package/dist/src/indexed/girvan-newman.d.ts +42 -0
  161. package/dist/src/indexed/girvan-newman.d.ts.map +1 -0
  162. package/dist/src/indexed/girvan-newman.js +90 -0
  163. package/dist/src/indexed/girvan-newman.js.map +1 -0
  164. package/dist/src/indexed/grsbm.d.ts +85 -0
  165. package/dist/src/indexed/grsbm.d.ts.map +1 -0
  166. package/dist/src/indexed/grsbm.js +287 -0
  167. package/dist/src/indexed/grsbm.js.map +1 -0
  168. package/dist/src/indexed/hierarchical.d.ts +69 -0
  169. package/dist/src/indexed/hierarchical.d.ts.map +1 -0
  170. package/dist/src/indexed/hierarchical.js +245 -0
  171. package/dist/src/indexed/hierarchical.js.map +1 -0
  172. package/dist/src/indexed/index.d.ts +29 -3
  173. package/dist/src/indexed/index.d.ts.map +1 -1
  174. package/dist/src/indexed/index.js +29 -3
  175. package/dist/src/indexed/index.js.map +1 -1
  176. package/dist/src/indexed/isomorphism.d.ts +42 -0
  177. package/dist/src/indexed/isomorphism.d.ts.map +1 -0
  178. package/dist/src/indexed/isomorphism.js +269 -0
  179. package/dist/src/indexed/isomorphism.js.map +1 -0
  180. package/dist/src/indexed/label-propagation.d.ts +134 -0
  181. package/dist/src/indexed/label-propagation.d.ts.map +1 -0
  182. package/dist/src/indexed/label-propagation.js +486 -0
  183. package/dist/src/indexed/label-propagation.js.map +1 -0
  184. package/dist/src/indexed/leiden.d.ts +52 -0
  185. package/dist/src/indexed/leiden.d.ts.map +1 -0
  186. package/dist/src/indexed/leiden.js +384 -0
  187. package/dist/src/indexed/leiden.js.map +1 -0
  188. package/dist/src/indexed/link-prediction.d.ts +147 -0
  189. package/dist/src/indexed/link-prediction.d.ts.map +1 -0
  190. package/dist/src/indexed/link-prediction.js +317 -0
  191. package/dist/src/indexed/link-prediction.js.map +1 -0
  192. package/dist/src/indexed/markov.d.ts +54 -0
  193. package/dist/src/indexed/markov.d.ts.map +1 -0
  194. package/dist/src/indexed/markov.js +284 -0
  195. package/dist/src/indexed/markov.js.map +1 -0
  196. package/dist/src/indexed/matching.d.ts +53 -0
  197. package/dist/src/indexed/matching.d.ts.map +1 -0
  198. package/dist/src/indexed/matching.js +139 -0
  199. package/dist/src/indexed/matching.js.map +1 -0
  200. package/dist/src/indexed/min-cut.d.ts +48 -0
  201. package/dist/src/indexed/min-cut.d.ts.map +1 -0
  202. package/dist/src/indexed/min-cut.js +175 -0
  203. package/dist/src/indexed/min-cut.js.map +1 -0
  204. package/dist/src/indexed/modularity.d.ts +34 -0
  205. package/dist/src/indexed/modularity.d.ts.map +1 -0
  206. package/dist/src/indexed/modularity.js +74 -0
  207. package/dist/src/indexed/modularity.js.map +1 -0
  208. package/dist/src/indexed/mst.d.ts +29 -1
  209. package/dist/src/indexed/mst.d.ts.map +1 -1
  210. package/dist/src/indexed/mst.js +62 -0
  211. package/dist/src/indexed/mst.js.map +1 -1
  212. package/dist/src/indexed/pagerank.d.ts +29 -6
  213. package/dist/src/indexed/pagerank.d.ts.map +1 -1
  214. package/dist/src/indexed/pagerank.js +107 -11
  215. package/dist/src/indexed/pagerank.js.map +1 -1
  216. package/dist/src/indexed/point-to-point.d.ts +53 -0
  217. package/dist/src/indexed/point-to-point.d.ts.map +1 -0
  218. package/dist/src/indexed/point-to-point.js +173 -0
  219. package/dist/src/indexed/point-to-point.js.map +1 -0
  220. package/dist/src/indexed/scc.d.ts +53 -0
  221. package/dist/src/indexed/scc.d.ts.map +1 -0
  222. package/dist/src/indexed/scc.js +110 -0
  223. package/dist/src/indexed/scc.js.map +1 -0
  224. package/dist/src/indexed/spectral.d.ts +61 -0
  225. package/dist/src/indexed/spectral.d.ts.map +1 -0
  226. package/dist/src/indexed/spectral.js +476 -0
  227. package/dist/src/indexed/spectral.js.map +1 -0
  228. package/dist/src/indexed/structures/bit-set.d.ts +45 -0
  229. package/dist/src/indexed/structures/bit-set.d.ts.map +1 -0
  230. package/dist/src/indexed/structures/bit-set.js +57 -0
  231. package/dist/src/indexed/structures/bit-set.js.map +1 -0
  232. package/dist/src/indexed/structures/max-heap.d.ts +52 -0
  233. package/dist/src/indexed/structures/max-heap.d.ts.map +1 -0
  234. package/dist/src/indexed/structures/max-heap.js +66 -0
  235. package/dist/src/indexed/structures/max-heap.js.map +1 -0
  236. package/dist/src/indexed/structures/min-heap.d.ts +30 -1
  237. package/dist/src/indexed/structures/min-heap.d.ts.map +1 -1
  238. package/dist/src/indexed/structures/min-heap.js +46 -6
  239. package/dist/src/indexed/structures/min-heap.js.map +1 -1
  240. package/dist/src/indexed/structures/ring-queue.d.ts +41 -0
  241. package/dist/src/indexed/structures/ring-queue.d.ts.map +1 -0
  242. package/dist/src/indexed/structures/ring-queue.js +64 -0
  243. package/dist/src/indexed/structures/ring-queue.js.map +1 -0
  244. package/dist/src/indexed/sync.d.ts +50 -0
  245. package/dist/src/indexed/sync.d.ts.map +1 -0
  246. package/dist/src/indexed/sync.js +175 -0
  247. package/dist/src/indexed/sync.js.map +1 -0
  248. package/dist/src/indexed/terahac.d.ts +58 -0
  249. package/dist/src/indexed/terahac.d.ts.map +1 -0
  250. package/dist/src/indexed/terahac.js +244 -0
  251. package/dist/src/indexed/terahac.js.map +1 -0
  252. package/dist/src/indexed/to-snapshot.d.ts +45 -2
  253. package/dist/src/indexed/to-snapshot.d.ts.map +1 -1
  254. package/dist/src/indexed/to-snapshot.js +140 -6
  255. package/dist/src/indexed/to-snapshot.js.map +1 -1
  256. package/dist/src/link-prediction/common-neighbors-legacy.d.ts +71 -0
  257. package/dist/src/link-prediction/common-neighbors-legacy.d.ts.map +1 -0
  258. package/dist/src/link-prediction/common-neighbors-legacy.js +172 -0
  259. package/dist/src/link-prediction/common-neighbors-legacy.js.map +1 -0
  260. package/dist/src/link-prediction/common-neighbors.d.ts +11 -19
  261. package/dist/src/link-prediction/common-neighbors.d.ts.map +1 -1
  262. package/dist/src/link-prediction/common-neighbors.js +56 -123
  263. package/dist/src/link-prediction/common-neighbors.js.map +1 -1
  264. package/dist/src/optimized/direction-optimized-bfs.d.ts +6 -0
  265. package/dist/src/optimized/direction-optimized-bfs.d.ts.map +1 -1
  266. package/dist/src/optimized/direction-optimized-bfs.js +6 -0
  267. package/dist/src/optimized/direction-optimized-bfs.js.map +1 -1
  268. package/dist/src/research/grsbm-legacy.d.ts +82 -0
  269. package/dist/src/research/grsbm-legacy.d.ts.map +1 -0
  270. package/dist/src/research/grsbm-legacy.js +416 -0
  271. package/dist/src/research/grsbm-legacy.js.map +1 -0
  272. package/dist/src/research/grsbm.d.ts +9 -66
  273. package/dist/src/research/grsbm.d.ts.map +1 -1
  274. package/dist/src/research/grsbm.js +67 -391
  275. package/dist/src/research/grsbm.js.map +1 -1
  276. package/dist/src/research/sync-legacy.d.ts +48 -0
  277. package/dist/src/research/sync-legacy.d.ts.map +1 -0
  278. package/dist/src/research/sync-legacy.js +337 -0
  279. package/dist/src/research/sync-legacy.js.map +1 -0
  280. package/dist/src/research/sync.d.ts +10 -32
  281. package/dist/src/research/sync.d.ts.map +1 -1
  282. package/dist/src/research/sync.js +28 -316
  283. package/dist/src/research/sync.js.map +1 -1
  284. package/package.json +4 -3
  285. package/src/algorithms/centrality/betweenness.ts +51 -1
  286. package/src/algorithms/centrality/closeness.ts +112 -12
  287. package/src/algorithms/centrality/degree.ts +19 -0
  288. package/src/algorithms/centrality/eigenvector.ts +34 -0
  289. package/src/algorithms/centrality/hits.ts +24 -0
  290. package/src/algorithms/centrality/katz.ts +32 -0
  291. package/src/algorithms/centrality/pagerank.ts +53 -13
  292. package/src/algorithms/community/girvan-newman-legacy.ts +414 -0
  293. package/src/algorithms/community/girvan-newman.ts +36 -386
  294. package/src/algorithms/community/label-propagation.ts +24 -133
  295. package/src/algorithms/components/connected.ts +28 -95
  296. package/src/algorithms/mst/kruskal.ts +65 -4
  297. package/src/algorithms/shortest-path/bellman-ford.ts +49 -0
  298. package/src/algorithms/shortest-path/dijkstra.ts +29 -0
  299. package/src/algorithms/shortest-path/floyd-warshall.ts +106 -136
  300. package/src/algorithms/traversal/bfs-unified.ts +52 -366
  301. package/src/algorithms/traversal/bfs-variants.ts +5 -28
  302. package/src/algorithms/traversal/bfs.ts +0 -4
  303. package/src/algorithms/traversal/dfs.ts +39 -182
  304. package/src/clustering/hierarchical-legacy.ts +551 -0
  305. package/src/clustering/hierarchical.ts +64 -520
  306. package/src/clustering/k-core-legacy.ts +229 -0
  307. package/src/clustering/k-core.ts +38 -209
  308. package/src/clustering/mcl-legacy.ts +498 -0
  309. package/src/clustering/mcl.ts +46 -479
  310. package/src/index.ts +90 -3
  311. package/src/indexed/accelerator.ts +502 -16
  312. package/src/indexed/all-pairs.ts +342 -0
  313. package/src/indexed/bellman-ford.ts +72 -0
  314. package/src/indexed/betweenness.ts +258 -0
  315. package/src/indexed/bfs.ts +189 -3
  316. package/src/indexed/bipartite.ts +77 -0
  317. package/src/indexed/closeness.ts +160 -0
  318. package/src/indexed/common-neighbors.ts +31 -14
  319. package/src/indexed/degree.ts +55 -0
  320. package/src/indexed/delta-pagerank.ts +513 -0
  321. package/src/indexed/dfs.ts +189 -0
  322. package/src/indexed/eigenvector.ts +202 -0
  323. package/src/indexed/facade.ts +229 -0
  324. package/src/indexed/flow.ts +500 -0
  325. package/src/indexed/girvan-newman.ts +120 -0
  326. package/src/indexed/grsbm.ts +390 -0
  327. package/src/indexed/hierarchical.ts +295 -0
  328. package/src/indexed/index.ts +94 -3
  329. package/src/indexed/isomorphism.ts +305 -0
  330. package/src/indexed/label-propagation.ts +582 -0
  331. package/src/indexed/leiden.ts +436 -0
  332. package/src/indexed/link-prediction.ts +399 -0
  333. package/src/indexed/markov.ts +324 -0
  334. package/src/indexed/matching.ts +192 -0
  335. package/src/indexed/min-cut.ts +201 -0
  336. package/src/indexed/modularity.ts +81 -0
  337. package/src/indexed/mst.ts +79 -1
  338. package/src/indexed/pagerank.ts +128 -15
  339. package/src/indexed/point-to-point.ts +220 -0
  340. package/src/indexed/scc.ts +132 -0
  341. package/src/indexed/spectral.ts +550 -0
  342. package/src/indexed/structures/bit-set.ts +65 -0
  343. package/src/indexed/structures/max-heap.ts +74 -0
  344. package/src/indexed/structures/min-heap.ts +51 -6
  345. package/src/indexed/structures/ring-queue.ts +70 -0
  346. package/src/indexed/sync.ts +229 -0
  347. package/src/indexed/terahac.ts +290 -0
  348. package/src/indexed/to-snapshot.ts +156 -6
  349. package/src/link-prediction/common-neighbors-legacy.ts +252 -0
  350. package/src/link-prediction/common-neighbors.ts +65 -168
  351. package/src/optimized/direction-optimized-bfs.ts +6 -1
  352. package/src/research/grsbm-legacy.ts +586 -0
  353. package/src/research/grsbm.ts +76 -555
  354. package/src/research/sync-legacy.ts +456 -0
  355. package/src/research/sync.ts +30 -431
@@ -5,7 +5,25 @@
5
5
  * `../core/graph.js`.
6
6
  * @module
7
7
  */
8
- import { GraphBuilder } from "@graphty/graph-format";
8
+ import { GraphBuilder, GraphFormatError } from "@graphty/graph-format";
9
+ /**
10
+ * Whether every edge still carries the weight it was frozen with. `mutationCount` counts topology
11
+ * changes only, and `graph.getEdge(u, v)` hands out the live edge, so a weight can change in place
12
+ * without moving the counter.
13
+ * @param graph - The legacy graph
14
+ * @param weights - The weights recorded at freeze
15
+ * @returns True when no weight changed
16
+ */
17
+ function sameWeights(graph, weights) {
18
+ let i = 0;
19
+ for (const edge of graph.edges()) {
20
+ // Object.is, so a NaN weight (kept in the topology cache) matches itself.
21
+ if (!Object.is(edge.weight, weights[i++])) {
22
+ return false;
23
+ }
24
+ }
25
+ return i === weights.length;
26
+ }
9
27
  /**
10
28
  * One entry per graph, REPLACED rather than appended to on a mutation. The entry holds the
11
29
  * mutationCount it was built at, which is what makes a stale hit impossible -- the bug the old
@@ -13,7 +31,8 @@ import { GraphBuilder } from "@graphty/graph-format";
13
31
  */
14
32
  const SNAPSHOT_CACHE = new WeakMap();
15
33
  /**
16
- * Freeze a legacy `Graph` into a `GraphSnapshot`, memoised on the graph's `mutationCount`.
34
+ * Freeze a legacy `Graph` into a `GraphSnapshot`, memoised on the graph's `mutationCount` and its
35
+ * edge weights (a weight set in place does not move the counter, so a hit re-reads the weights).
17
36
  *
18
37
  * The builder is created with `weightDtype: "f64"` so a legacy graph's double weights survive
19
38
  * exactly: at freeze, graph-format keeps the original values in an f64 edge column with role
@@ -32,11 +51,25 @@ const SNAPSHOT_CACHE = new WeakMap();
32
51
  */
33
52
  export function toSnapshot(graph, options = {}) {
34
53
  const checksum = options.checksum === true;
35
- const cached = SNAPSHOT_CACHE.get(graph);
54
+ return cachedFreeze(SNAPSHOT_CACHE, graph, checksum, true);
55
+ }
56
+ /**
57
+ * Freeze `graph` through `cache`, reusing the entry while the graph is unchanged.
58
+ * @param cache - The cache to read and replace the entry in
59
+ * @param graph - The legacy graph
60
+ * @param checksum - Whether to record checksums
61
+ * @param weighted - Whether to keep the edge weights
62
+ * @returns The snapshot
63
+ */
64
+ function cachedFreeze(cache, graph, checksum, weighted) {
65
+ const cached = cache.get(graph);
36
66
  // A checksummed snapshot answers a plain request; a plain one cannot answer a checksummed
37
67
  // request -- validate({ checksum: true }) throws E_INVALID_SNAPSHOT ("no-checksum") when none
38
68
  // were recorded (graph-format/src/types/snapshot.ts:401-405).
39
- if (cached !== undefined && cached.mutationCount === graph.mutationCount && (cached.checksum || !checksum)) {
69
+ if (cached !== undefined &&
70
+ cached.mutationCount === graph.mutationCount &&
71
+ (cached.checksum || !checksum) &&
72
+ sameWeights(graph, cached.weights)) {
40
73
  return cached.snapshot;
41
74
  }
42
75
  const builder = new GraphBuilder({
@@ -48,11 +81,112 @@ export function toSnapshot(graph, options = {}) {
48
81
  for (const node of graph.nodes()) {
49
82
  builder.addNode(node.id);
50
83
  }
84
+ const weights = [];
51
85
  for (const edge of graph.edges()) {
52
- builder.addEdge(edge.source, edge.target, edge.weight);
86
+ builder.addEdge(edge.source, edge.target, weighted ? edge.weight : undefined);
87
+ weights.push(edge.weight);
53
88
  }
54
89
  const snapshot = builder.freeze({ label: "algorithms.toSnapshot", checksum });
55
- SNAPSHOT_CACHE.set(graph, { mutationCount: graph.mutationCount, checksum, snapshot });
90
+ cache.set(graph, { mutationCount: graph.mutationCount, checksum, snapshot, weights });
56
91
  return snapshot;
57
92
  }
93
+ /** Snapshots frozen without weights, for graphs holding a NaN weight; see {@link toTopologySnapshot}. */
94
+ const TOPOLOGY_CACHE = new WeakMap();
95
+ /**
96
+ * {@link toSnapshot}, or null when an edge weight is NaN: a legacy `Graph` accepts one, a snapshot
97
+ * does not. A facade whose legacy answer depends on how NaN compares keeps its legacy code for such
98
+ * a graph.
99
+ * @param graph - The legacy graph
100
+ * @param options - Conversion options
101
+ * @returns The snapshot, or null
102
+ */
103
+ export function toSnapshotOrNull(graph, options = {}) {
104
+ try {
105
+ return toSnapshot(graph, options);
106
+ }
107
+ catch (error) {
108
+ if (error instanceof GraphFormatError && error.code === "E_INVALID_WEIGHT") {
109
+ return null;
110
+ }
111
+ throw error;
112
+ }
113
+ }
114
+ /**
115
+ * A snapshot for a port that reads no weights (a traversal, the components, a clustering or link
116
+ * prediction that counts neighbours): {@link toSnapshot}, or,
117
+ * when a NaN weight stops that, the same nodes and edges frozen without weights, so a graph with a
118
+ * NaN weight traverses as it always did.
119
+ * @param graph - The legacy graph
120
+ * @returns The snapshot; its weights are not to be read
121
+ */
122
+ export function toTopologySnapshot(graph) {
123
+ return toSnapshotOrNull(graph) ?? cachedFreeze(TOPOLOGY_CACHE, graph, false, false);
124
+ }
125
+ /**
126
+ * The order a legacy `Graph` hands out each node's neighbours in, as the `arcOrder` option of the
127
+ * order-sensitive traversals (`depthFirstSearch`, `topologicalSort`, `stronglyConnectedComponents`,
128
+ * `condensation`, `breadthFirstSearch`). A snapshot row is sorted by neighbour index, while the
129
+ * legacy adjacency Map is in insertion order, so a traversal that must visit nodes in the legacy
130
+ * order -- a facade keeping its published result -- passes this.
131
+ * @param graph - The legacy graph
132
+ * @param s - A snapshot with the graph's nodes in the same order and its neighbour pairs, such as
133
+ * `toSnapshot(graph)`; parallel arcs of one pair are kept together in row order
134
+ * @returns For every row, its arcs in legacy neighbour order
135
+ */
136
+ export function legacyArcOrder(graph, s) {
137
+ const order = new Uint32Array(s.arcCount);
138
+ let next = 0;
139
+ for (const node of graph.nodes()) {
140
+ const u = s.ids.requireIndex(node.id);
141
+ if (next !== s.rowPtr[u]) {
142
+ throw new Error("legacyArcOrder: the snapshot does not hold this graph's nodes and neighbours");
143
+ }
144
+ for (const neighbor of graph.neighbors(node.id)) {
145
+ // Every arc to this neighbour, in row order: the legacy graph holds one edge per pair,
146
+ // but a multigraph snapshot of it may hold several.
147
+ const [lo, hi] = s.arcsBetween(u, s.ids.requireIndex(neighbor));
148
+ for (let a = lo; a < hi; a++) {
149
+ order[next++] = a;
150
+ }
151
+ }
152
+ if (next !== s.rowPtr[u + 1]) {
153
+ throw new Error("legacyArcOrder: the snapshot does not hold this graph's nodes and neighbours");
154
+ }
155
+ }
156
+ return order;
157
+ }
158
+ const LEGACY_ONLY_CACHE = new WeakMap();
159
+ /**
160
+ * Whether a facade must run its legacy code on this graph because a snapshot cannot stand in for it:
161
+ * - an edge weight is NaN, which the graph-format builder rejects, so `toSnapshot` would throw where
162
+ * the legacy code returns a result (the unweighted functions never even read the weight);
163
+ * - two node ids share a spelling (the number 1 and the string "1"), so a result keyed by
164
+ * `String(id)` holds one entry for both, and which value it holds depends on how the legacy code
165
+ * wrote it (betweenness adds the two, others keep the last).
166
+ * Memoised on the graph's `mutationCount`, like {@link toSnapshot}.
167
+ * @param graph - The legacy graph
168
+ * @returns True when the facade must call its legacy implementation
169
+ */
170
+ export function needsLegacyCode(graph) {
171
+ const cached = LEGACY_ONLY_CACHE.get(graph);
172
+ if (cached?.mutationCount === graph.mutationCount) {
173
+ return cached.value;
174
+ }
175
+ let value = false;
176
+ for (const edge of graph.edges()) {
177
+ if (Number.isNaN(edge.weight)) {
178
+ value = true;
179
+ break;
180
+ }
181
+ }
182
+ if (!value) {
183
+ const spellings = new Set();
184
+ for (const node of graph.nodes()) {
185
+ spellings.add(String(node.id));
186
+ }
187
+ value = spellings.size !== graph.nodeCount;
188
+ }
189
+ LEGACY_ONLY_CACHE.set(graph, { mutationCount: graph.mutationCount, value });
190
+ return value;
191
+ }
58
192
  //# sourceMappingURL=to-snapshot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"to-snapshot.js","sourceRoot":"","sources":["../../../src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CAAC;QACD,KAAK,GAAG,SAAS,CAAC,IAAI,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/C,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import type { Graph } from "../core/graph.js";
2
+ import type { NodeId } from "../types/index.js";
3
+ /**
4
+ * Common Neighbors link prediction implementation
5
+ *
6
+ * Predicts the likelihood of a link between two nodes based on the number
7
+ * of common neighbors they share. The intuition is that nodes with many
8
+ * common neighbors are more likely to be connected.
9
+ *
10
+ * Time complexity: O(k²) where k is the average degree
11
+ * Space complexity: O(k)
12
+ */
13
+ export interface LinkPredictionScore {
14
+ source: NodeId;
15
+ target: NodeId;
16
+ score: number;
17
+ }
18
+ export interface LinkPredictionOptions {
19
+ directed?: boolean;
20
+ includeExisting?: boolean;
21
+ topK?: number;
22
+ }
23
+ /**
24
+ * Calculate common neighbors score for a pair of nodes
25
+ * @param graph - The input graph
26
+ * @param source - The source node ID
27
+ * @param target - The target node ID
28
+ * @param options - Link prediction options
29
+ * @returns The number of common neighbors
30
+ */
31
+ export declare function commonNeighborsScore(graph: Graph, source: NodeId, target: NodeId, options?: LinkPredictionOptions): number;
32
+ /**
33
+ * Calculate common neighbors scores for all possible node pairs
34
+ * @param graph - The input graph
35
+ * @param options - Link prediction options
36
+ * @returns Array of link prediction scores sorted by score descending
37
+ */
38
+ export declare function commonNeighborsPrediction(graph: Graph, options?: LinkPredictionOptions): LinkPredictionScore[];
39
+ /**
40
+ * Calculate common neighbors scores for specific node pairs
41
+ * @param graph - The input graph
42
+ * @param pairs - Array of node ID pairs to calculate scores for
43
+ * @param options - Link prediction options
44
+ * @returns Array of link prediction scores for the specified pairs
45
+ */
46
+ export declare function commonNeighborsForPairs(graph: Graph, pairs: [NodeId, NodeId][], options?: LinkPredictionOptions): LinkPredictionScore[];
47
+ /**
48
+ * Get top candidates for link prediction for a specific node
49
+ * @param graph - The input graph
50
+ * @param node - The node ID to get candidates for
51
+ * @param options - Link prediction options with optional candidate list
52
+ * @returns Array of top link prediction candidates sorted by score descending
53
+ */
54
+ export declare function getTopCandidatesForNode(graph: Graph, node: NodeId, options?: LinkPredictionOptions & {
55
+ candidates?: NodeId[];
56
+ }): LinkPredictionScore[];
57
+ /**
58
+ * Calculate precision and recall for link prediction evaluation
59
+ * @param trainingGraph - The training graph without test edges
60
+ * @param testEdges - Array of node pairs that are actual edges
61
+ * @param nonEdges - Array of node pairs that are not edges
62
+ * @param options - Link prediction options
63
+ * @returns Evaluation metrics including precision, recall, F1 score, and AUC
64
+ */
65
+ export declare function evaluateCommonNeighbors(trainingGraph: Graph, testEdges: [NodeId, NodeId][], nonEdges: [NodeId, NodeId][], options?: LinkPredictionOptions): {
66
+ precision: number;
67
+ recall: number;
68
+ f1Score: number;
69
+ auc: number;
70
+ };
71
+ //# sourceMappingURL=common-neighbors-legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-neighbors-legacy.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors-legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;GASG;AAEH,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GACpC,MAAM,CAcR;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,qBAA0B,GAAG,mBAAmB,EAAE,CA0ClH;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACzB,OAAO,GAAE,qBAA0B,GACpC,mBAAmB,EAAE,CAMvB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAAqB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAChE,mBAAmB,EAAE,CA+BvB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACnC,aAAa,EAAE,KAAK,EACpB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC7B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC5B,OAAO,GAAE,qBAA0B,GACpC;IACC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACf,CAgEA"}
@@ -0,0 +1,172 @@
1
+ import { getCommonNeighbors, getIntermediateNodes } from "../utils/graph-utilities.js";
2
+ /**
3
+ * Calculate common neighbors score for a pair of nodes
4
+ * @param graph - The input graph
5
+ * @param source - The source node ID
6
+ * @param target - The target node ID
7
+ * @param options - Link prediction options
8
+ * @returns The number of common neighbors
9
+ */
10
+ export function commonNeighborsScore(graph, source, target, options = {}) {
11
+ if (!graph.hasNode(source) || !graph.hasNode(target)) {
12
+ return 0;
13
+ }
14
+ const { directed = false } = options;
15
+ // Use utility function to get common neighbors
16
+ // For directed graphs, we want intermediate nodes that form paths source->X->target
17
+ const commonNeighborsSet = directed
18
+ ? getIntermediateNodes(graph, source, target)
19
+ : getCommonNeighbors(graph, source, target, false);
20
+ return commonNeighborsSet.size;
21
+ }
22
+ /**
23
+ * Calculate common neighbors scores for all possible node pairs
24
+ * @param graph - The input graph
25
+ * @param options - Link prediction options
26
+ * @returns Array of link prediction scores sorted by score descending
27
+ */
28
+ export function commonNeighborsPrediction(graph, options = {}) {
29
+ const { directed = false, includeExisting = false, topK } = options;
30
+ const scores = [];
31
+ const nodes = Array.from(graph.nodes()).map((n) => n.id);
32
+ for (let i = 0; i < nodes.length; i++) {
33
+ for (let j = i + 1; j < nodes.length; j++) {
34
+ const source = nodes[i];
35
+ const target = nodes[j];
36
+ if (source === undefined || target === undefined) {
37
+ continue;
38
+ }
39
+ // Skip existing edges unless requested
40
+ if (!includeExisting && graph.hasEdge(source, target)) {
41
+ continue;
42
+ }
43
+ const score = commonNeighborsScore(graph, source, target, { directed });
44
+ if (score > 0) {
45
+ scores.push({ source, target, score });
46
+ // For undirected graphs, also add the reverse pair
47
+ if (!directed && source !== target) {
48
+ scores.push({ source: target, target: source, score });
49
+ }
50
+ }
51
+ }
52
+ }
53
+ // Sort by score in descending order
54
+ scores.sort((a, b) => b.score - a.score);
55
+ // Return top K if specified
56
+ if (topK && topK > 0) {
57
+ return scores.slice(0, topK);
58
+ }
59
+ return scores;
60
+ }
61
+ /**
62
+ * Calculate common neighbors scores for specific node pairs
63
+ * @param graph - The input graph
64
+ * @param pairs - Array of node ID pairs to calculate scores for
65
+ * @param options - Link prediction options
66
+ * @returns Array of link prediction scores for the specified pairs
67
+ */
68
+ export function commonNeighborsForPairs(graph, pairs, options = {}) {
69
+ return pairs.map(([source, target]) => ({
70
+ source,
71
+ target,
72
+ score: commonNeighborsScore(graph, source, target, options),
73
+ }));
74
+ }
75
+ /**
76
+ * Get top candidates for link prediction for a specific node
77
+ * @param graph - The input graph
78
+ * @param node - The node ID to get candidates for
79
+ * @param options - Link prediction options with optional candidate list
80
+ * @returns Array of top link prediction candidates sorted by score descending
81
+ */
82
+ export function getTopCandidatesForNode(graph, node, options = {}) {
83
+ if (!graph.hasNode(node)) {
84
+ return [];
85
+ }
86
+ const { directed = false, includeExisting = false, topK = 10, candidates } = options;
87
+ const scores = [];
88
+ const targetNodes = candidates ?? Array.from(graph.nodes()).map((n) => n.id);
89
+ for (const target of targetNodes) {
90
+ if (target === node) {
91
+ continue;
92
+ }
93
+ // Skip existing edges unless requested
94
+ if (!includeExisting && graph.hasEdge(node, target)) {
95
+ continue;
96
+ }
97
+ const score = commonNeighborsScore(graph, node, target, { directed });
98
+ if (score > 0) {
99
+ scores.push({ source: node, target, score });
100
+ }
101
+ }
102
+ // Sort by score in descending order
103
+ scores.sort((a, b) => b.score - a.score);
104
+ return scores.slice(0, topK);
105
+ }
106
+ /**
107
+ * Calculate precision and recall for link prediction evaluation
108
+ * @param trainingGraph - The training graph without test edges
109
+ * @param testEdges - Array of node pairs that are actual edges
110
+ * @param nonEdges - Array of node pairs that are not edges
111
+ * @param options - Link prediction options
112
+ * @returns Evaluation metrics including precision, recall, F1 score, and AUC
113
+ */
114
+ export function evaluateCommonNeighbors(trainingGraph, testEdges, nonEdges, options = {}) {
115
+ // Get scores for test edges and non-edges
116
+ const testScores = commonNeighborsForPairs(trainingGraph, testEdges, options);
117
+ const nonEdgeScores = commonNeighborsForPairs(trainingGraph, nonEdges, options);
118
+ // Combine and sort all scores
119
+ const allScores = [
120
+ ...testScores.map((s) => ({ ...s, isActualEdge: true })),
121
+ ...nonEdgeScores.map((s) => ({ ...s, isActualEdge: false })),
122
+ ].sort((a, b) => b.score - a.score);
123
+ // Calculate precision and recall at different thresholds
124
+ let truePositives = 0;
125
+ let falsePositives = 0;
126
+ let bestF1 = 0;
127
+ let bestPrecision = 0;
128
+ let bestRecall = 0;
129
+ const totalPositives = testEdges.length;
130
+ for (const scoreItem of allScores) {
131
+ if (scoreItem.isActualEdge) {
132
+ truePositives++;
133
+ }
134
+ else {
135
+ falsePositives++;
136
+ }
137
+ const precision = truePositives / (truePositives + falsePositives);
138
+ const recall = truePositives / totalPositives;
139
+ const f1 = precision + recall > 0 ? (2 * (precision * recall)) / (precision + recall) : 0;
140
+ if (f1 > bestF1) {
141
+ bestF1 = f1;
142
+ bestPrecision = precision;
143
+ bestRecall = recall;
144
+ }
145
+ }
146
+ // Calculate AUC (Area Under Curve)
147
+ let auc = 0;
148
+ let tpCount = 0;
149
+ let fpCount = 0;
150
+ for (const item of allScores) {
151
+ if (item.isActualEdge) {
152
+ tpCount++;
153
+ }
154
+ else {
155
+ auc += tpCount;
156
+ fpCount++;
157
+ }
158
+ }
159
+ if (tpCount > 0 && fpCount > 0) {
160
+ auc = auc / (tpCount * fpCount);
161
+ }
162
+ else {
163
+ auc = 0.5; // Random performance
164
+ }
165
+ return {
166
+ precision: bestPrecision,
167
+ recall: bestRecall,
168
+ f1Score: bestF1,
169
+ auc,
170
+ };
171
+ }
172
+ //# sourceMappingURL=common-neighbors-legacy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-neighbors-legacy.js","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors-legacy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAyBvF;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAChC,KAAY,EACZ,MAAc,EACd,MAAc,EACd,UAAiC,EAAE;IAEnC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,OAAO,CAAC,CAAC;IACb,CAAC;IAED,MAAM,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAErC,+CAA+C;IAC/C,oFAAoF;IACpF,MAAM,kBAAkB,GAAG,QAAQ;QAC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AAE,GAAG,MAAM,EAAE,CAAC;YACd,MAAM,GAAG,EAAE,CAAC;YACZ,aAAa,GAAG,SAAS,CAAC;YAC1B,UAAU,GAAG,MAAM,CAAC;QACxB,CAAC;IACL,CAAC;IAED,mCAAmC;IACnC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC;QACd,CAAC;aAAM,CAAC;YACJ,GAAG,IAAI,OAAO,CAAC;YACf,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;IAED,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAC7B,GAAG,GAAG,GAAG,GAAG,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACJ,GAAG,GAAG,GAAG,CAAC,CAAC,qBAAqB;IACpC,CAAC;IAED,OAAO;QACH,SAAS,EAAE,aAAa;QACxB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,MAAM;QACf,GAAG;KACN,CAAC;AACN,CAAC"}
@@ -1,25 +1,17 @@
1
- import type { Graph } from "../core/graph.js";
2
- import type { NodeId } from "../types/index.js";
3
1
  /**
4
- * Common Neighbors link prediction implementation
5
- *
6
- * Predicts the likelihood of a link between two nodes based on the number
7
- * of common neighbors they share. The intuition is that nodes with many
8
- * common neighbors are more likely to be connected.
2
+ * Common-neighbour link prediction over a legacy `Graph`. Every function here delegates to its
3
+ * `indexed.*` port over an unweighted snapshot of the graph (the scores never read a weight) and
4
+ * keeps its signature and result shape; the results equal the pre-migration implementation in
5
+ * `common-neighbors-legacy.ts` exactly.
9
6
  *
10
- * Time complexity: O(k²) where k is the average degree
11
- * Space complexity: O(k)
7
+ * A node argument is looked up by the id itself, never by its spelling, as `graph.hasNode` does: a
8
+ * node that is not in the graph scores 0 and has no candidates.
9
+ * @module
12
10
  */
13
- export interface LinkPredictionScore {
14
- source: NodeId;
15
- target: NodeId;
16
- score: number;
17
- }
18
- export interface LinkPredictionOptions {
19
- directed?: boolean;
20
- includeExisting?: boolean;
21
- topK?: number;
22
- }
11
+ import type { Graph } from "../core/graph.js";
12
+ import type { NodeId } from "../types/index.js";
13
+ import type { LinkPredictionOptions, LinkPredictionScore } from "./common-neighbors-legacy.js";
14
+ export type { LinkPredictionOptions, LinkPredictionScore } from "./common-neighbors-legacy.js";
23
15
  /**
24
16
  * Calculate common neighbors score for a pair of nodes
25
17
  * @param graph - The input graph
@@ -1 +1 @@
1
- {"version":3,"file":"common-neighbors.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;;;;;;;;GASG;AAEH,MAAM,WAAW,mBAAmB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GACpC,MAAM,CAcR;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,qBAA0B,GAAG,mBAAmB,EAAE,CA0ClH;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACzB,OAAO,GAAE,qBAA0B,GACpC,mBAAmB,EAAE,CAMvB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,qBAAqB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAChE,mBAAmB,EAAE,CA+BvB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACnC,aAAa,EAAE,KAAK,EACpB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC7B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAC5B,OAAO,GAAE,qBAA0B,GACpC;IACC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACf,CAgEA"}
1
+ {"version":3,"file":"common-neighbors.d.ts","sourceRoot":"","sources":["../../../src/link-prediction/common-neighbors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAW9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAE/F,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AA6B/F;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GACpC,MAAM,CAQR;AAED;;;;;GAKG;AACH,wBAAgB,yBAA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