Skip to main content

bfs_simple

Function bfs_simple 

Source
pub fn bfs_simple(
    graph: &Graph,
    root: VertexId,
    mode: BfsMode,
) -> IgraphResult<BfsSimple>
Expand description

Mode-aware BFS from a single root, returning visit order, layer boundaries, and BFS-tree parents.

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

For undirected graphs the mode parameter is ignored (edges are always treated as bidirectional). For directed graphs, BfsMode::Out follows outgoing edges, BfsMode::In follows incoming edges, and BfsMode::All ignores direction.

ยงExamples

use rust_igraph::{Graph, BfsMode, bfs_simple};

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

let r = bfs_simple(&g, 0, BfsMode::Out).unwrap();
assert_eq!(r.order, vec![0, 1, 2, 3]);
assert_eq!(r.layers, vec![0, 1, 3, 4]);
assert_eq!(r.parents[3], Some(1));