Functions and types for working with graphs
Graaf is Dutch for
- graph
- count
- dig
This crate is in alpha, and the API will change. See the changelog for a provisional roadmap.
Installation
Add the following to your Cargo.toml:
[]
= "0.23.0"
Usage
use ;
let mut graph = ;
// ╭───╮ ╭───╮
// │ 0 │ → │ 1 │
// ╰───╯ ╰───╯
// ↑ ↓
// ╭───╮ ╭───╮
// │ 3 │ │ 2 │
// ╰───╯ ╰───╯
graph.add_edge;
graph.add_edge;
graph.add_edge;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let path = single_pair_shortest_path;
assert_eq!;
Overview
Algorithms
Common graph algorithms:
bfs: breadth-first searchdijkstra: Dijkstra's algorithmpredecessor: predecessor search
Operations
Graph operation traits and implementations:
AddEdgeadds an unweighted edge.AddWeightedEdgeadds a weighted edge.CountAllEdgescounts all edges.CountAllVerticescounts all vertices.EdgeWeightgets the weight of an edge.Indegreereturns the indegree of a vertex.IsEdgereturns whether an edge exists.IsSimplereturns whether a graph is simple.IterAllEdgesiterates over all unweighted edges.IterAllWeightedEdgesiterates over all weighted edges.IterEdgesiterates over all unweighted edges of a source vertex.IterVerticesiterates over all vertices.IterWeightedEdgesiterates over all weighted edges of a source vertex.Outdegreereturns the outdegree of a vertex.RemoveEdgeremoves an edge.
Features
adjacency_matrix: a representation for dense graphs, enabled by default.nightly: required foradjacency_matrix.
To disable these features, add the following to your Cargo.toml:
[]
= { = "0.23.0", = false }