pub fn unfold_tree(
graph: &Graph,
roots: &[VertexId],
mode: DegreeMode,
) -> IgraphResult<UnfoldTreeResult>Expand description
Unfold a graph into a tree by BFS, replicating multiply-visited vertices.
Starting from each root, BFS explores the graph. The first time a vertex is reached, it keeps its original ID. Subsequent visits via different edges create replica vertices with new IDs. The result is always a tree (or forest if multiple roots cover disjoint components).
For directed graphs, mode controls traversal: Out follows
outgoing edges, In follows incoming edges, All ignores
direction.
§Errors
Returns an error if any root is out of range.
§Examples
use rust_igraph::{Graph, unfold_tree, DegreeMode};
// Triangle: unfolding from vertex 0 creates a tree with 4 vertices.
let mut g = Graph::with_vertices(3);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
let result = unfold_tree(&g, &[0], DegreeMode::All).unwrap();
// BFS from 0: sees 1,2 directly. Edge 1-2 creates a replica.
assert_eq!(result.tree.vcount(), 4);
assert_eq!(result.tree.ecount(), 3);