[][src]Function rs_graph::search::dfs::start_with_data

Important traits for DFS<'a, A, S, St>
pub fn start_with_data<'a, A, S, St>(
    adj: A,
    src: A::Node,
    data: (S, St)
) -> DFS<'a, A, S, St> where
    A: Adjacencies<'a>,
    S: ItemMap<A::Node, A::Edge>,
    St: ItemStack<A::Incidence>, 

Start and return a DFS iterator with user defined data structures.

The returned iterator traverses the edges in depth-first order. The iterator returns the next node and its incoming edge.

Note that the start node is not returned by the iterator.

The algorithm requires a pair (M, S) with M implementing ItemMap<Node, Edge>, and S implementing ItemStack<_> as internal data structures. The map is used to store the last edge of the path from the source to each reachable node. The stack is used to handle the nodes in depth-first order. The data structures can be reused for multiple searches.

Parameter

  • adj: adjacency information for the graph
  • src: the source node at which the search should start.
  • data: the data structures used in the algorithm

Example

use rs_graph::LinkedListGraph;
use rs_graph::traits::*;
use rs_graph::classes;
use rs_graph::search::dfs;
use std::collections::HashMap;

let g: LinkedListGraph = classes::peterson();
let mut cnt = 0;
for (u, e) in dfs::start_with_data(g.neighbors(), g.id2node(0),
                                   (HashMap::new(), Vec::new()))
{
    assert_ne!(g.node_id(u), 0);
    cnt += 1;
}
assert_eq!(cnt, g.num_nodes() - 1);