Graaf

Rust-powered directed graphs.
Table of Contents
Installation
Add the following to your Cargo.toml:
[]
= "0.87.3"
Representations
adjacency_listrepresents unweighted sparse digraphs.adjacency_matrixrepresents unweighted dense digraphs.adjacency_list_weightedrepresents arc-weighted sparse digraphs.edge_listrepresents 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.
Operations
AddArcWeightedadds an arc to an arc-weighted digraph.AddArcadds an arc to an unweighted digraph.ArcWeightreturns an arc's weight.ArcsWeightedreturns a digraph's weighted arcs.Arcsreturns a digraph's arcs.Complementreturns a digraph's complement.Conversereturns a digraph's converse.DegreeSequencereturns a digraph's degree sequence.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.InNeighborsreturns a vertex's in-neighbors.IndegreeSequencereturns a digraph's indegree sequence.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.OutNeighborsWeightedreturns a vertex's weighted out-neighbors.OutNeighborsreturns a vertex's out-neighbors.OutdegreeSequencereturns a digraph's outdegree sequence.Outdegreereturns a vertex's outdegree.RemoveArcremoves an arc from a digraph.SemidegreeSequencereturns a digraph's semidegree sequence.Sinksreturns a digraph's sinks.Sizereturns the number of arcs in a digraph.Sourcesreturns a digraph's sources.Verticesreturns a digraph's vertices.
Algorithms
Bellman-Ford-Moore
The Bellman-Ford-Moore algorithm finds the shortest paths in an arc-weighted digraph with negative weights.
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 over the vertices.BfsDistiterates over the vertices and their distance from the source.BfsPrediterates over the vertices and their predecessors.BfsDist::distancesfinds the shortest distances.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 over the vertices.DfsDistiterates over the vertices and their distance from the source.DfsPrediterates over the vertices and their predecessors.DfsPred::predecessorsfinds the predecessors.
Dijkstra
Dijkstra's algorithm finds the shortest paths in an arc-weighted digraph.
Dijkstraiterates over the vertices.DijkstraDistiterates over the vertices.DijkstraPrediterates over 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.
centerfinds the center of the digraph.diameterfinds the diameter of the digraph.eccentricitiesreturns the eccentricities of the vertices.is_connectedchecks if the digraph is connected.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.
distancesfinds the shortest distances.
Predecessor Tree
A PredecessorTree is the result of a search and contains the predecessors of the vertices.
These functions produce a PredecessorTree:
Tarjan
Tarjan's algorithm finds strongly connected components in a digraph.
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.