Skip to main content

dfs_simple

Function dfs_simple 

Source
pub fn dfs_simple(
    graph: &Graph,
    root: VertexId,
    mode: DfsMode,
) -> IgraphResult<DfsSimple>
Expand description

Mode-aware DFS from a single root, returning pre/post-order, parents, and DFS-tree depth.

Counterpart of igraph_dfs from references/igraph/src/graph/visitors.c.

For undirected graphs the mode parameter is ignored. For directed graphs, DfsMode::Out follows outgoing edges, DfsMode::In follows incoming edges, and DfsMode::All ignores direction.

ยงExamples

use rust_igraph::{Graph, DfsMode, dfs_simple};

let mut g = Graph::new(4, true).unwrap();
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(0, 3).unwrap();

let r = dfs_simple(&g, 0, DfsMode::Out).unwrap();
assert_eq!(r.order[0], 0);
assert_eq!(r.parents[1], Some(0));
assert_eq!(r.dist[2], Some(2));