Expand description
Brings the entire graph-rs public API into scope.
use graph::prelude::*;Modules§
- astar
- A* goal-directed shortest path with a caller-supplied heuristic.
- bellman_
ford - Bellman-Ford single-source shortest path; handles negative weights.
- bfs
- Breadth-first search with distances and BFS tree.
- bipartite
- Bipartite check and 2-colouring via BFS.
- bridges
- Bridge finding (cut edges) via Tarjan’s DFS disc/low-link algorithm.
- components
- Connected components via BFS seeding.
- condensation
- DAG condensation: contract each SCC into a single super-node.
- cycle
- Cycle detection for directed and undirected graphs.
- dfs
- Recursive and iterative depth-first search.
- dijkstra
- Dijkstra’s single-source shortest path for non-negative weights.
- edmonds_
karp - Edmonds-Karp maximum flow using BFS augmenting paths. Edmonds-Karp maximum flow via BFS augmenting paths.
- euler
- Euler path and circuit via Hierholzer’s algorithm.
- flow_
graph - Index-based flow graph (residual graph) used by all flow algorithms. Index-based residual graph for flow algorithms.
- floyd_
warshall - Floyd-Warshall all-pairs shortest path.
- ford_
fulkerson - Ford-Fulkerson maximum flow using DFS augmenting paths. Ford-Fulkerson maximum flow via DFS augmenting paths.
- hamiltonian
- Hamiltonian path via backtracking (exact, exponential).
- hopcroft_
karp - Hopcroft-Karp maximum bipartite matching. Hopcroft-Karp maximum bipartite matching.
- kosaraju_
scc - Kosaraju’s two-pass SCC algorithm.
- kruskal
- Kruskal’s minimum spanning tree: sort edges, union-find cycle check.
- min_cut
- Minimum s-t cut extracted from a completed max-flow computation. Minimum s-t cut from a completed max-flow computation.
- paths
- Path reconstruction from BFS/DFS parent maps.
- prim
- Prim’s minimum spanning tree: priority-queue edge relaxation.
- tarjan_
scc - Tarjan’s single-pass SCC algorithm using DFS low-link values.
- topo
- Topological sort: DFS finish-order and Kahn’s algorithm.
- tsp
- Travelling Salesman Problem via Held-Karp bitmask DP.
Structs§
- Adjacency
List - A sparse graph representation backed by an adjacency list.
- Adjacency
Matrix - A dense graph representation backed by a 2-D adjacency matrix.
- Bellman
Ford Result - Result of a Bellman-Ford shortest-path search.
- Condensed
Graph - The result of condensing a directed graph into its SCC DAG.
- Deque
- A double-ended queue (deque) backed by
VecDeque. - Dijkstra
Result - Result of a Dijkstra shortest-path search from one source node.
- Disjoint
Set - Union-Find (disjoint set union) with union-by-rank.
- Edge
- A directed edge from
sourcetotargetcarrying a weight of typeW. - EdgeId
- A type-safe edge identifier.
- Flow
Graph - An index-based directed flow network supporting residual graph operations.
- Graph
Builder - A fluent builder for constructing graphs from either representation.
- MinCut
- The result of a minimum s-t cut computation.
- MinHeap
- A binary min-heap backed by a
Vec. - NodeId
- A type-safe node identifier.
- Priority
Queue - A keyed priority queue that pops by lowest priority first.
- Queue
- A FIFO queue backed by
VecDeque. - Spanning
Tree - The result of a minimum spanning tree computation.
- Stack
- A LIFO stack backed by a
Vec.
Enums§
- Euler
Error - Errors returned by Euler path/circuit algorithms.
- Graph
Error - Errors that can arise from graph operations.
Traits§
- Graph
- The central graph abstraction that every algorithm in graph-rs operates on.
Functions§
- articulation_
points - Finds all articulation points (cut vertices) in an undirected graph.
- astar
- Finds the shortest path from
starttogoalusing the A* search algorithm with a caller-supplied heuristic function. - bellman_
ford - Runs the Bellman-Ford algorithm from
source. - bfs
- Runs a breadth-first search from
startand returns a map ofNodeId → shortest hop distancefromstart. - bfs_
tree - Runs BFS from
startand returns aBfsTreewith distances and parents. - bridges
- Finds all bridges in an undirected graph using Tarjan’s algorithm.
- condensation
- Condenses a directed graph into its SCC DAG.
- connected_
components - Returns all connected components of the graph as a
Vec<Vec<NodeId>>. - dfs_
iterative - Runs an iterative depth-first search from
startusing an explicitStack, callingvisitorthe first time each node is discovered. - dfs_
recursive - Runs a recursive depth-first search from
start, callingvisitorthe first time each node is discovered. - dijkstra
- Runs Dijkstra’s algorithm from
sourceand returns shortest distances and the parent map. - edmonds_
karp - Computes the maximum flow from
sourcetosinkusing the Edmonds-Karp algorithm (Ford-Fulkerson with BFS augmenting paths). - euler_
circuit - Finds an Euler circuit in an undirected graph using Hierholzer’s algorithm.
- euler_
path - Finds an Euler path in an undirected graph using Hierholzer’s algorithm.
- floyd_
warshall - Runs the Floyd-Warshall all-pairs shortest-path algorithm.
- ford_
fulkerson - Computes the maximum flow from
sourcetosinkusing the Ford-Fulkerson algorithm with DFS augmenting paths. - hamiltonian_
path - Finds a Hamiltonian path starting from
startusing backtracking. - has_
cycle_ directed - Returns
trueif the directed graph contains at least one cycle. - has_
cycle_ undirected - Returns
trueif the undirected graph contains at least one cycle. - hopcroft_
karp - Computes the maximum bipartite matching using the Hopcroft-Karp algorithm.
- is_
bipartite - Checks whether the graph is bipartite and returns its 2-colouring.
- kosaraju_
scc - Finds all Strongly Connected Components (SCCs) using Kosaraju’s algorithm.
- kruskal
- Computes a Minimum Spanning Tree using Kruskal’s algorithm.
- min_cut
- Computes the minimum s-t cut from a
FlowGraphon which a max-flow algorithm has already been run. - prim
- Computes a Minimum Spanning Tree using Prim’s algorithm.
- reconstruct_
path - Reconstructs the path from
starttoendusing a parent map produced by BFS or DFS. - tarjan_
scc - Finds all Strongly Connected Components (SCCs) using Tarjan’s algorithm.
- topological_
sort_ dfs - Returns a topological ordering of the nodes using DFS finish order.
- topological_
sort_ kahn - Returns a topological ordering using Kahn’s algorithm (in-degree BFS).
- tsp_
held_ karp - Solves the Travelling Salesman Problem exactly using the Held-Karp bitmask dynamic programming algorithm.
Type Aliases§
- Unweighted
Edge - An unweighted directed edge (weight type
()). - Weighted
Edge - A weighted directed edge with
f64weights.