2个稳定版本
1.0.1 | 2024年1月26日 |
---|---|
1.0.0 | 2023年10月25日 |
#789 在 数据结构 中
每月 27 次下载
用于 2 crates
11KB
198 行
terrain-graph
基于邻接表的Rust简单图库。
这是fastlem的一个子项目。
此库包含以下结构
DirectedGraph
UndirectedGraph
EdgeAttributedDirectedGraph
EdgeAttributedUndirectedGraph
使用方法
[dependencies]
terrain-graph = "1.0.1"
以下是如何使用 UndirectedGraph
和 DirectedGraph
的基本示例
use terrain_graph::*;
// Create an undirected graph
let mut undirected_graph = UndirectedGraph::new(5);
undirected_graph.add_edge(0, 1);
undirected_graph.add_edge(0, 2);
println!("{}", undirected_graph.has_edge(1, 0)); // Outputs: true
println!("{}", undirected_graph.degree(0)); // Outputs: 2
// Create a directed graph
let mut directed_graph = DirectedGraph::new(5);
directed_graph.add_edge(0, 1);
directed_graph.add_edge(0, 2);
println!("{}", directed_graph.has_edge(1, 0)); // Outputs: false
println!("{}", directed_graph.outdegree(0)); // Outputs: 2
println!("{}", directed_graph.indegree(1)); // Outputs: 1