graaf/
lib.rs

1//! # Graaf
2//!
3//! Rust-powered directed graphs.
4//!
5//! # Table of Contents
6//!
7//! - [Representations](#representations)
8//! - [Generators](#generators)
9//! - [Operations](#operations)
10//! - [Algorithms](#algorithms)
11//!    - [Bellman-Ford-Moore](#bellman-ford-moore)
12//!    - [Breadth-First Search](#breadth-first-search)
13//!    - [Depth-First Search](#depth-first-search)
14//!    - [Dijkstra](#dijkstra)
15//!    - [Distance Matrix](#distance-matrix)
16//!    - [Floyd-Warshall](#floyd-warshall)
17//!    - [Johnson's Circuit-Finding
18//!      Algorithm](#johnsons-circuit-finding-algorithm)
19//!    - [Predecessor Tree](#predecessor-tree)
20//!    - [Tarjan](#tarjan)
21//!
22//! # Representations
23//!
24//! ## Arc-Weighted Sparse Digraphs
25//!
26//! - [`AdjacencyListWeighted`] represents a digraph as a vector of maps.
27//!
28//! ## Unweighted Dense Digraphs
29//!
30//! - [`AdjacencyMatrix`] represents a digraph as a matrix using a bit vector.
31//!
32//! ## Unweighted Sparse Digraphs
33//!
34//! - [`AdjacencyList`] represents a digraph as a vector of sets.
35//! - [`AdjacencyMap`] represents a digraph as a map of sets.
36//! - [`EdgeList`] represents a digraph as a vector of tuples.
37//!
38//! # Generators
39//!
40//! - [`Biclique`] generates a complete bipartite digraph.
41//! - [`Circuit`] generates a circuit digraph.
42//! - [`Complete`] generates a complete digraph.
43//! - [`Cycle`] generates a bidirectional circuit.
44//! - [`Empty`] generates a digraph without arcs.
45//! - [`ErdosRenyi`] generates a random digraph.
46//! - [`RandomRecursiveTree`] generates a random recursive tree.
47//! - [`Path`] generates a path digraph.
48//! - [`RandomTournament`] generates a random tournament.
49//! - [`Star`] generates a star digraph.
50//! - [`Wheel`] generates a wheel digraph.
51//!
52//! # Operations
53//!
54//! - [`AddArcWeighted`] adds an arc to an arc-weighted digraph.
55//! - [`AddArc`] adds an arc to an unweighted digraph.
56//! - [`ArcWeight`] returns an arc's weight.
57//! - [`ArcsWeighted`] iterates a digraph's weighted arcs.
58//! - [`Arcs`] iterates a digraph's arcs.
59//! - [`Complement`] returns a digraph's complement.
60//! - [`ContiguousOrder`] returns a contiguous digraph's order.
61//! - [`Converse`] returns a digraph's converse.
62//! - [`DegreeSequence`] iterates a digraph's degrees.
63//! - [`Degree`] returns a vertex's degree.
64//! - [`FilterVertices`] filters a digraph's vertices.
65//! - [`HasArc`] checks whether a digraph contains an arc.
66//! - [`HasEdge`] checks whether a digraph contains an edge.
67//! - [`HasWalk`] checks whether a digraph contains a walk.
68//! - [`InNeighbors`] iterates a vertex's in-neighbors.
69//! - [`IndegreeSequence`] iterates a digraph's indegrees.
70//! - [`Indegree`] returns a vertex's indegree.
71//! - [`IsBalanced`] checks whether a digraph is balanced.
72//! - [`IsComplete`] checks whether a digraph is complete.
73//! - [`IsIsolated`] checks whether a vertex is isolated.
74//! - [`IsOriented`] checks whether a digraph is oriented.
75//! - [`IsPendant`] checks whether a vertex is a pendant.
76//! - [`IsRegular`] checks whether a digraph is regular.
77//! - [`IsSemicomplete`] checks whether a digraph is semicomplete.
78//! - [`IsSimple`] checks whether a digraph is simple.
79//! - [`IsSpanningSubdigraph`] checks whether a digraph spans a superdigraph.
80//! - [`IsSubdigraph`] checks whether a digraph is a subdigraph.
81//! - [`IsSuperdigraph`] checks whether a digraph is a superdigraph.
82//! - [`IsSymmetric`] checks whether a digraph is symmetric.
83//! - [`IsTournament`] checks whether a digraph is a tournament.
84//! - [`Order`] counts the vertices in a digraph.
85//! - [`OutNeighborsWeighted`] iterates a vertex's weighted out-neighbors.
86//! - [`OutNeighbors`] iterates a vertex's out-neighbors.
87//! - [`OutdegreeSequence`] iterates a digraph's outdegrees.
88//! - [`Outdegree`] returns a vertex's outdegree.
89//! - [`RemoveArc`] removes an arc from a digraph.
90//! - [`SemidegreeSequence`] iterates a digraph's semidegrees.
91//! - [`Sinks`] iterates a digraph's sinks.
92//! - [`Size`] counts the arcs in a digraph.
93//! - [`Sources`] iterates a digraph's sources.
94//! - [`Union`] returns the union of two digraphs.
95//! - [`Vertices`] iterates a digraph's vertices.
96//!
97//! # Algorithms
98//!
99//! ## Bellman-Ford-Moore
100//!
101//! - [`BellmanFordMoore::distances`] finds the shortest distances from a
102//!   source vertex to all other vertices in an arc-weighted digraph with
103//!   negative weights.
104//!
105//! ## Breadth-First Search
106//!
107//! A breadth-first search explores an unweighted digraph's vertices in order
108//! of their distance from a source.
109//!
110//! - [`Bfs`] iterates the vertices.
111//! - [`BfsDist`] iterates the vertices and their distance from the source.
112//! - [`BfsPred`] iterates the vertices and their predecessors.
113//! - [`BfsDist::distances`](BfsDist::distances) finds the shortest distances.
114//! - [`BfsPred::cycles`](BfsPred::cycles) returns the cycles along the
115//!   shortest path.
116//! - [`BfsPred::predecessors`](BfsPred::predecessors) finds the predecessors.
117//! - [`BfsPred::shortest_path`](BfsPred::shortest_path) finds the shortest
118//!   path.
119//!
120//! ## Depth-First Search
121//!
122//! A depth-first search explores an unweighted digraph's vertices in order of
123//! their distance from a source.
124//!
125//! - [`Dfs`] iterates the vertices.
126//! - [`DfsDist`] iterates the vertices and their distance from the source.
127//! - [`DfsPred`] iterates the vertices and their predecessors.
128//! - [`DfsPred::predecessors`](DfsPred::predecessors) finds the predecessors.
129//!
130//! ## Dijkstra
131//!
132//! Dijkstra's algorithm finds the shortest paths from one or more source
133//! vertices in an arc-weighted digraph.
134//!
135//! - [`Dijkstra`] iterates the vertices.
136//! - [`DijkstraDist`] iterates the vertices and their distance from the
137//!   source.
138//! - [`DijkstraPred`] iterates the vertices and their predecessors.
139//! - [`DijkstraDist::distances`](DijkstraDist::distances) finds the shortest
140//!   distances.
141//! - [`DijkstraPred::predecessors`](DijkstraPred::predecessors) finds the
142//!   predecessors.
143//! - [`DijkstraPred::shortest_path`](DijkstraPred::shortest_path) finds the
144//!   shortest path.
145//!
146//! ## Distance Matrix
147//!
148//! A [`DistanceMatrix`] contains the shortest distances between all vertex
149//! pairs in a digraph.
150//!
151//! - [`DistanceMatrix::center`](DistanceMatrix::center) finds the digraph's
152//!   center.
153//! - [`DistanceMatrix::diameter`](DistanceMatrix::diameter) finds the
154//!   digraph's diameter.
155//! - [`DistanceMatrix::eccentricities`](DistanceMatrix::eccentricities) finds
156//!   the vertices' eccentricities.
157//! - [`DistanceMatrix::is_connected`](DistanceMatrix::is_connected) checks the
158//!   digraph's connectedness.
159//! - [`DistanceMatrix::periphery`](DistanceMatrix::periphery) finds the
160//!   digraph's periphery.
161//!
162//! ## Floyd-Warshall
163//!
164//! - [`FloydWarshall::distances`] finds the distance between each vertex pair
165//!   in an arc-weighted digraph.
166//!
167//! ## Johnson's Circuit-Finding Algorithm
168//!
169//! - [`Johnson75::circuits`] finds a digraph's circuits.
170//!
171//! ## Predecessor Tree
172//!
173//! A [`PredecessorTree`] is the result of a search and contains the vertices'
174//! predecessors.
175//!
176//! - [`PredecessorTree::search`] finds a vertex by value.
177//! - [`PredecessorTree::search_by`] finds a vertex by predicate.
178//!
179//! ## Tarjan
180//!
181//! - [`Tarjan::components`] finds strongly connected components in a digraph.
182
183pub mod algo;
184pub mod r#gen;
185pub mod op;
186#[cfg(test)]
187pub mod proptest_strategy;
188pub mod repr;
189
190pub use repr::{
191    AdjacencyList,
192    AdjacencyListWeighted,
193    AdjacencyMap,
194    AdjacencyMatrix,
195    EdgeList,
196};
197
198pub use op::{
199    AddArc,
200    AddArcWeighted,
201    ArcWeight,
202    Arcs,
203    ArcsWeighted,
204    Complement,
205    ContiguousOrder,
206    Converse,
207    Degree,
208    DegreeSequence,
209    FilterVertices,
210    HasArc,
211    HasEdge,
212    HasWalk,
213    InNeighbors,
214    Indegree,
215    IndegreeSequence,
216    IsBalanced,
217    IsComplete,
218    IsIsolated,
219    IsOriented,
220    IsPendant,
221    IsRegular,
222    IsSemicomplete,
223    IsSimple,
224    IsSpanningSubdigraph,
225    IsSubdigraph,
226    IsSuperdigraph,
227    IsSymmetric,
228    IsTournament,
229    Order,
230    OutNeighbors,
231    OutNeighborsWeighted,
232    Outdegree,
233    OutdegreeSequence,
234    RemoveArc,
235    SemidegreeSequence,
236    Sinks,
237    Size,
238    Sources,
239    Union,
240    Vertices,
241};
242
243pub use r#gen::{
244    Biclique,
245    Circuit,
246    Complete,
247    Cycle,
248    Empty,
249    ErdosRenyi,
250    Path,
251    RandomRecursiveTree,
252    RandomTournament,
253    Star,
254    Wheel,
255};
256
257pub use algo::{
258    bellman_ford_moore::BellmanFordMoore,
259    bfs::Bfs,
260    bfs_dist::BfsDist,
261    bfs_pred::BfsPred,
262    dfs::Dfs,
263    dfs_dist::DfsDist,
264    dfs_pred::DfsPred,
265    dijkstra::Dijkstra,
266    dijkstra_dist::DijkstraDist,
267    dijkstra_pred::DijkstraPred,
268    distance_matrix::DistanceMatrix,
269    floyd_warshall::FloydWarshall,
270    johnson_75::Johnson75,
271    predecessor_tree::PredecessorTree,
272    tarjan::Tarjan,
273};