pub fn connected_components(graph: &Graph) -> IgraphResult<ConnectedComponents>Expand description
Compute the weak connected components of graph.
Counterpart of igraph_connected_components(_, _, _, _, IGRAPH_WEAK).
On undirected graphs this is just “the connected components”; on
directed graphs it ignores edge direction (each edge counts as both
ways).
§Examples
use rust_igraph::{Graph, connected_components};
// Two components: {0, 1, 2} and {3, 4}.
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(3, 4).unwrap();
let cc = connected_components(&g).unwrap();
assert_eq!(cc.count, 2);
assert_eq!(cc.membership[0], cc.membership[1]);
assert_eq!(cc.membership[1], cc.membership[2]);
assert_eq!(cc.membership[3], cc.membership[4]);
assert_ne!(cc.membership[0], cc.membership[3]);