Struct petgraph::visit::Dfs [] [src]

pub struct Dfs<N, VM> {
    pub stack: Vec<N>,
    pub discovered: VM,
}

A depth first search (DFS) of a graph.

Using a Dfs you can run a traversal over a graph while still retaining mutable access to it, if you use it like the following example:

use petgraph::{Graph, Dfs};

let mut graph = Graph::<_,()>::new();
let a = graph.add_node(0);

let mut dfs = Dfs::new(&graph, a);
while let Some(nx) = dfs.next(&graph) {
    // we can access `graph` mutably here still
    graph[nx] += 1;
}

assert_eq!(graph[a], 1);Run

Note: The algorithm may not behave correctly if nodes are removed during iteration. It may not necessarily visit added nodes or edges.

Fields

The stack of nodes to visit

The map of discovered nodes

Methods

impl<N, VM> Dfs<N, VM> where N: Copy, VM: VisitMap<N>
[src]

Create a new Dfs, using the graph's visitor map, and put start in the stack of nodes to visit.

Create a new Dfs using the graph's visitor map, and no stack.

Keep the discovered map, but clear the visit stack and restart the dfs from a particular node.

Return the next node in the dfs, or None if the traversal is done.

Trait Implementations

impl<N: Clone, VM: Clone> Clone for Dfs<N, VM>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<N: Debug, VM: Debug> Debug for Dfs<N, VM>
[src]

Formats the value using the given formatter.