Graaf

Rust-powered directed graphs.
Table of Contents
Installation
Add this to your Cargo.toml:
[]
= "0.97.1"
Representations
Arc-Weighted Sparse Digraphs
AdjacencyListWeightedrepresents digraphs as a vector of maps.
Unweighted Dense Digraphs
AdjacencyMatrixrepresents digraphs as a matrix using a bit vector.
Unweighted Sparse Digraphs
AdjacencyListrepresents digraphs as a vector of sets.AdjacencyMaprepresents digraphs as a map of sets.EdgeListrepresents digraphs as a vector of tuples.
Generators
Bicliquegenerates a complete bipartite digraph.Circuitgenerates a circuit digraph.Completegenerates a complete digraph.Cyclegenerates a bidirectional circuit.Emptygenerates a digraph without arcs.ErdosRenyigenerates a random digraph.GrowingNetworkgenerates a growing network digraph.Pathgenerates a path digraph.RandomTournamentgenerates a random tournament.Stargenerates a star digraph.Wheelgenerates a wheel digraph.
Operations
AddArcWeightedadds an arc to an arc-weighted digraph.AddArcadds an arc to an unweighted digraph.ArcWeightreturns an arc's weight.ArcsWeightediterates over a digraph's weighted arcs.Arcsiterates over a digraph's arcs.Complementreturns a digraph's complement.Conversereturns a digraph's converse.DegreeSequenceiterates over a digraph's degrees.Degreereturns a vertex's degree.FilterVerticesfilters a digraph's vertices.HasArcchecks whether a digraph contains an arc.HasEdgechecks whether a digraph contains an edge.HasWalkchecks whether a digraph contains a walk.InNeighborsiterates over a vertex's in-neighbors.IndegreeSequenceiterates over a digraph's indegrees.Indegreereturns a vertex's indegree.IsBalancedchecks whether a digraph is balanced.IsCompletechecks whether a digraph is complete.IsIsolatedchecks whether a vertex is isolated.IsOrientedchecks whether a digraph is oriented.IsPendantchecks whether a vertex is a pendant.IsRegularchecks whether a digraph is regular.IsSemicompletechecks whether a digraph is semicomplete.IsSimplechecks whether a digraph is simple.IsSpanningSubdigraphchecks whether a digraph spans a superdigraph.IsSubdigraphchecks whether a digraph is a subdigraph.IsSuperdigraphchecks whether a digraph is a superdigraph.IsSymmetricchecks whether a digraph is symmetric.IsTournamentchecks whether a digraph is a tournament.Orderreturns the number of vertices in a digraph.OutNeighborsWeightediterates over a vertex's weighted out-neighbors.OutNeighborsiterates over a vertex's out-neighbors.OutdegreeSequenceiterates over a digraph's outdegrees.Outdegreereturns a vertex's outdegree.RemoveArcremoves an arc from a digraph.SemidegreeSequenceiterates over a digraph's semidegrees.Sinksiterates over a digraph's sinks.Sizereturns the number of arcs in a digraph.Sourcesiterates over a digraph's sources.Unionreturns the union of two digraphs.Verticesiterates over a digraph's vertices.
Algorithms
Bellman-Ford-Moore
The Bellman-Ford-Moore algorithm finds the shortest distances from a source vertex to all other vertices in an arc-weighted digraph with negative weights.
BellmanFordMoore::distancesfinds the shortest distances.
Breadth-First Search
A breadth-first search explores an unweighted digraph's vertices in order of their distance from a source.
Bfsiterates the vertices.BfsDistiterates the vertices and their distance from the source.BfsPrediterates the vertices and their predecessors.BfsDist::distancesfinds the shortest distances.BfsPred::cyclesreturns the cycles along the shortest path.BfsPred::predecessorsfinds the predecessors.BfsPred::shortest_pathfinds the shortest path.
Depth-First Search
A depth-first search explores an unweighted digraph's vertices in order of their depth from a source.
Dfsiterates the vertices.DfsDistiterates the vertices and their distance from the source.DfsPrediterates the vertices and their predecessors.DfsPred::predecessorsfinds the predecessors.
Dijkstra
Dijkstra's algorithm finds the shortest paths in an arc-weighted digraph.
Dijkstraiterates the vertices.DijkstraDistiterates the vertices.DijkstraPrediterates the vertices and their predecessors.DijkstraDist::distancesfinds the shortest distances.DijkstraPred::predecessorsfinds the predecessors.DijkstraPred::shortest_pathfinds the shortest path.
Distance Matrix
A DistanceMatrix contains the shortest distances between all vertex pairs in a digraph.
DistanceMatrix::centerfinds the digraph's center.DistanceMatrix::diameterfinds the digraph's diameter.DistanceMatrix::eccentricitiesreturns the vertices' eccentricities.DistanceMatrix::is_connectedchecks the digraph's connectedness.DistanceMatrix::peripheryfinds the digraph's periphery.
Floyd-Warshall
The Floyd-Warshall algorithm finds the distance between each vertex pair in an arc-weighted digraph.
FloydWarshall::distancesfinds the shortest distances.
Johnson's Circuit-Finding Algorithm
Johnson's circuit-finding algorithm finds all circuits in a digraph.
Johnson75::circuitsfinds all circuits.
Predecessor Tree
A PredecessorTree contains the vertex predecessors.
PredecessorTree::searchfinds a vertex by value.PredecessorTree::search_byfinds a vertex by predicate.
Tarjan
Tarjan's algorithm finds strongly connected components in a digraph.
Tarjan::componentsfinds strongly connected components.
Changelog
See CHANGELOG.md for a list of changes.
License
Licensed under Apache License, Version 2.0 or MIT license at your option.
Contact
Feel free to reach out with questions or suggestions.