⚡
比纯 JS 快 10–500 倍
Rust/WASM 内核在 10k 节点上运行 PageRank 仅需 ~100ms。介数中心性在秒级而非分钟级完成。同样的算法,原生速度。
npm install @graphrs/core @graphrs/community @graphrs/centralityimport { Graph } from '@graphrs/core';
import { louvain } from '@graphrs/community';
import { pagerank } from '@graphrs/centrality';
const graph = Graph.fromEdges([
[0, 1], [1, 2], [2, 0], // 社区 A
[3, 4], [4, 5], [5, 3], // 社区 B
[2, 3], // 桥边
]);
const communities = await louvain(graph);
// → { membership: [0,0,0,1,1,1], modularity: 0.357 }
const pr = await pagerank(graph);
// → { scores: [0.12, 0.15, 0.23, 0.18, 0.16, 0.16] }Python 有 igraph(C 内核,快)和 networkx(纯 Python,慢)。 JavaScript 在快速图计算领域一直是空白 — 直到现在。
| graphology | cytoscape.js | @graphrs | |
|---|---|---|---|
| 社区检测 | 2 种算法 | 0 | 10+ |
| 中心性度量 | 7 | 2 | 15+ |
| 布局算法 | 3 | 扩展 | 16 |
| 网络流 | 0 | 0 | 完整 |
| 同构 | 0 | 0 | VF2 |
| 10k 节点 PageRank | ~5–10 秒 | N/A | ~100 毫秒 |
# AntV G6 — 布局 + 社区检测 + 中心性
npm install @graphrs/g6
# React Flow — 自动布局 Hook(React Flow 没有内置布局功能)
npm install @graphrs/react-flow// G6: 即插即用布局
import { createGraphrsLayout } from '@graphrs/g6';
new G6Graph({ layout: createGraphrsLayout({ algorithm: 'fruchterman-reingold' }) });
// React Flow: 一行代码自动布局
import { useGraphrsLayout } from '@graphrs/react-flow';
const { nodes, edges } = useGraphrsLayout(initialNodes, initialEdges);