Function rs_graph::dfs::undirected [] [src]

pub fn undirected<'g, G>(
    g: &'g G,
    u: G::Node
) -> NodeVec<'g, G, Option<G::Edge>> where
    G: IndexGraph<'g>, 

Do a depth-first-search on an undirected graph starting in u.

The function returns the incoming edge of each node.

Example

use rs_graph::{LinkedListGraph, Graph, IndexGraph, classes, dfs};

let g: LinkedListGraph = classes::peterson();
let u = g.id2node(0);
let tree = dfs::undirected(&g, u);

let dist = |mut v| {
    let mut d = 0;
    while let Some(e) = tree[v] {
        let (x,y) = g.enodes(e);
        d += 1;
        v = if x == v { y } else { x };
    }
    d
};
let dists: Vec<_> = g.nodes().map(|v| dist(v)).collect();
assert!(tree[u].is_none());
for n in 0..10 {
    assert_eq!(dists.iter().filter(|&&d| d == n).count(), 1);
}