Skip to content

API 面概览

冻结日期: 2026-07-03 | 版本: v0.1.3 原则: 所有 pub API 在 v1.x 中保持兼容,破坏性变更需 major 版本


类型定义说明
NodeIdpub(all) struct NodeId(Int)节点唯一标识符,Newtype 模式
Nodepub(all) struct Node { id, data }带数据的节点
Edgepub(all) struct Edge { from, to, data }带数据的边
GraphReadable (12 methods, 根 trait)
├── GraphWritable (5 methods, 动态存储)
├── GraphDirected (6 methods, 有向扩展)
│ └── GraphFull = GraphWritable + GraphDirected (组合别名)
└── GraphBatchReadable (2 methods, CSR/CSC 专属)

模式示例适用类型
自由函数 new_xxx()new_directed()AdjList, Matrix, EdgeList
关联函数 Type::new()CSRBuilder::new()CSR/CSC Builder
类型ReadableWritableDirectedFullBatchReadable
DirectedAdjList
UndirectedAdjList
DirectedMatrix
UndirectedMatrix
EdgeListGraph
UndirectedEdgeListGraph
CSRGraph
CSCGraph
方法适用类型
add_edge_unchecked(from, to, data)DirectedAdjList, UndirectedAdjList
add_edges_batch(edges)DirectedAdjList, UndirectedAdjList

约定示例说明
图参数名graph所有泛型算法统一
源/汇参数名source, sinkInt 类型(Flow 模块)
起点参数名startNodeId 类型(遍历/最短路径)
模块返回类型状态
traversalBfsResult, DfsResult
shortest_pathShortestPathResult, KShortestPathsResult, FloydWarshallResult
mstMstResult
connectivityConnectedComponentsResult, SCCResult, BCCResult
flowMaxFlowResult, MinCostMaxFlowResult, StoerWagnerResult
matchingMatchingResult, KMMatchingResult
communityCommunityResult
centralityCentralityResult
pagerankPageRankResult
coloringColoringResult, ChromaticNumberResult, EdgeColoringResult
cliqueCliqueResult, IndependentSetResult, VertexCoverResult
cutpointsCutPointResult, BridgeResult
eulerEulerPathResult, EulerCircuitResult
hamiltonianHamiltonianResult, TSPResult

函数签名说明
write_dot(G, String) -> StringDOT 序列化
parse_dot_into(String) -> Result[UndirectedAdjList, IOError]DOT 反序列化
graph_to_json(G, Bool) -> StringJSON 序列化
parse_json_into(String) -> Result[UndirectedAdjList, IOError]JSON 反序列化
basic_stats(G) -> GraphStats图统计
degree_distribution(G) -> DegreeDistribution度分布