Graaf

Rust-powered directed graphs.
Table of Contents
Installation
Add the following to your Cargo.toml:
[]
= "0.88.7"
Representations
AdjacencyListrepresents unweighted sparse digraphs.AdjacencyMatrixrepresents unweighted dense digraphs.AdjacencyListWeightedrepresents arc-weighted sparse digraphs.EdgeListrepresents unweighted sparse digraphs.
Generators
Bicliquegenerates a complete bipartite digraph.Circuitgenerates a circuit digraph.Completegenerates a complete digraph.Cyclegenerates a bidirectional circuit.Emptygenerates a digraph with no arcs.ErdosRenyigenerates a random 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 a digraph's weighted arcs.Arcsiterates a digraph's arcs.Complementreturns a digraph's complement.Conversereturns a digraph's converse.DegreeSequenceiterates a digraph's degrees.Degreereturns a vertex's degree.HasArcchecks whether a digraph contains an arc.HasEdgechecks whether a digraph contains an edge.HasWalkchecks whether a digraph contains a walk.InNeighborsiterates a vertex's in-neighbors.IndegreeSequenceiterates 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 a vertex's weighted out-neighbors.OutNeighborsiterates a vertex's out-neighbors.OutdegreeSequenceiterates a digraph's outdegrees.Outdegreereturns a vertex's outdegree.RemoveArcremoves an arc from a digraph.SemidegreeSequenceiterates a digraph's semidegrees.Sinksiterates a digraph's sinks.Sizereturns the number of arcs in a digraph.Sourcesiterates a digraph's sources.Unionreturns the union of two digraphs.Verticesiterates 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.
bellman_ford_moore::single_source_distancesfinds the shortest distances.
Breadth-First Search
A breadth-first search explores the vertices of an unweighted digraph 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 the vertices of an unweighted digraph 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 pairs of vertices in a digraph.
DistanceMatrix::centerfinds the center of the digraph.DistanceMatrix::diameterfinds the diameter of the digraph.DistanceMatrix::eccentricitiesreturns the eccentricities of the vertices.DistanceMatrix::is_connectedchecks if the digraph is connected.DistanceMatrix::peripheryfinds the periphery of the digraph.
Floyd-Warshall
The Floyd-Warshall algorithm finds the distance between each pair of vertices in an arc-weighted digraph.
floyd_warshall::distancesfinds the shortest distances.
Predecessor Tree
A PredecessorTree is the result of a search and contains the predecessors of the vertices.
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::strongly_connected_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.