Skip to main content

dfs_tree

Function dfs_tree 

Source
pub fn dfs_tree(graph: &Graph, root: VertexId) -> IgraphResult<DfsTree>
Expand description

Multi-output DFS from root. Returns visit order (pre and post), per-vertex parents, and DFS-tree depth in a single pass.

Counterpart of igraph_dfs(_, root, _, _, &order, &order_out, &father, &dist, _, _).

For directed graphs, traversal follows out-edges. Errors if root is out of range.

ยงExamples

use rust_igraph::{Graph, dfs_tree};

// Tree:
//     0
//    / \
//   1   2
//   |
//   3
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 3).unwrap();

let r = dfs_tree(&g, 0).unwrap();
assert_eq!(r.order[0], 0);
assert_eq!(r.parents[0], None); // root
assert_eq!(r.parents[1], Some(0));
assert_eq!(r.parents[3], Some(1));
assert_eq!(r.dist[3], Some(2));
assert_eq!(r.order_out.last(), Some(&0)); // root finishes last