|
1 |
| -//! A graph module for use in dataflow, region resolution, and elsewhere. |
| 1 | +//! See [`LinkedGraph`]. |
2 | 2 | //!
|
3 | 3 | //! # Interface details
|
4 | 4 | //!
|
@@ -28,7 +28,23 @@ use tracing::debug;
|
28 | 28 | #[cfg(test)]
|
29 | 29 | mod tests;
|
30 | 30 |
|
31 |
| -pub struct Graph<N, E> { |
| 31 | +/// A concrete graph implementation that supports: |
| 32 | +/// - Nodes and/or edges labelled with custom data types (`N` and `E` respectively). |
| 33 | +/// - Incremental addition of new nodes/edges (but not removal). |
| 34 | +/// - Flat storage of node/edge data in a pair of vectors. |
| 35 | +/// - Iteration over any node's out-edges or in-edges, via linked lists |
| 36 | +/// threaded through the node/edge data. |
| 37 | +/// |
| 38 | +/// # Caution |
| 39 | +/// This is an older graph implementation that is still used by some pieces |
| 40 | +/// of diagnostic/debugging code. New code that needs a graph data structure |
| 41 | +/// should consider using `VecGraph` instead, or implementing its own |
| 42 | +/// special-purpose graph with the specific features needed. |
| 43 | +/// |
| 44 | +/// This graph implementation predates the later [graph traits](crate::graph), |
| 45 | +/// and does not implement those traits, so it has its own implementations of a |
| 46 | +/// few basic graph algorithms. |
| 47 | +pub struct LinkedGraph<N, E> { |
32 | 48 | nodes: Vec<Node<N>>,
|
33 | 49 | edges: Vec<Edge<E>>,
|
34 | 50 | }
|
@@ -71,13 +87,13 @@ impl NodeIndex {
|
71 | 87 | }
|
72 | 88 | }
|
73 | 89 |
|
74 |
| -impl<N: Debug, E: Debug> Graph<N, E> { |
75 |
| - pub fn new() -> Graph<N, E> { |
76 |
| - Graph { nodes: Vec::new(), edges: Vec::new() } |
| 90 | +impl<N: Debug, E: Debug> LinkedGraph<N, E> { |
| 91 | + pub fn new() -> Self { |
| 92 | + Self { nodes: Vec::new(), edges: Vec::new() } |
77 | 93 | }
|
78 | 94 |
|
79 |
| - pub fn with_capacity(nodes: usize, edges: usize) -> Graph<N, E> { |
80 |
| - Graph { nodes: Vec::with_capacity(nodes), edges: Vec::with_capacity(edges) } |
| 95 | + pub fn with_capacity(nodes: usize, edges: usize) -> Self { |
| 96 | + Self { nodes: Vec::with_capacity(nodes), edges: Vec::with_capacity(edges) } |
81 | 97 | }
|
82 | 98 |
|
83 | 99 | // # Simple accessors
|
@@ -249,7 +265,7 @@ impl<N: Debug, E: Debug> Graph<N, E> {
|
249 | 265 | // # Iterators
|
250 | 266 |
|
251 | 267 | pub struct AdjacentEdges<'g, N, E> {
|
252 |
| - graph: &'g Graph<N, E>, |
| 268 | + graph: &'g LinkedGraph<N, E>, |
253 | 269 | direction: Direction,
|
254 | 270 | next: EdgeIndex,
|
255 | 271 | }
|
@@ -285,15 +301,15 @@ impl<'g, N: Debug, E: Debug> Iterator for AdjacentEdges<'g, N, E> {
|
285 | 301 | }
|
286 | 302 |
|
287 | 303 | pub struct DepthFirstTraversal<'g, N, E> {
|
288 |
| - graph: &'g Graph<N, E>, |
| 304 | + graph: &'g LinkedGraph<N, E>, |
289 | 305 | stack: Vec<NodeIndex>,
|
290 | 306 | visited: DenseBitSet<usize>,
|
291 | 307 | direction: Direction,
|
292 | 308 | }
|
293 | 309 |
|
294 | 310 | impl<'g, N: Debug, E: Debug> DepthFirstTraversal<'g, N, E> {
|
295 | 311 | pub fn with_start_node(
|
296 |
| - graph: &'g Graph<N, E>, |
| 312 | + graph: &'g LinkedGraph<N, E>, |
297 | 313 | start_node: NodeIndex,
|
298 | 314 | direction: Direction,
|
299 | 315 | ) -> Self {
|
|
0 commit comments