Skip to main content

bfs_tree

Function bfs_tree 

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

Multi-output BFS from root. Returns visit order, per-vertex distances, and per-vertex BFS-tree parent in a single pass.

Counterpart of igraph_bfs(_, root, _, _, &order, _, &father, &dist, _, _) — the common subset of the upstream callback-driven variant.

For directed graphs traversal follows out-edges (matching upstream’s IGRAPH_OUT mode default). Errors if root is out of range.

§Examples

use rust_igraph::{Graph, bfs_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 = bfs_tree(&g, 0).unwrap();
assert_eq!(r.order, vec![0, 1, 2, 3]);
assert_eq!(r.distances, vec![Some(0), Some(1), Some(1), Some(2)]);
assert_eq!(r.parents, vec![None, Some(0), Some(0), Some(1)]);