connected_components

Function connected_components 

Source
pub fn connected_components<G>(graph: &G) -> Vec<Vec<NodeId>>
where G: Graph,
Expand description

Returns all connected components of the graph as a Vec<Vec<NodeId>>.

Each inner Vec is one component — the set of nodes reachable from each other. For directed graphs, this treats edges as undirected (weak connectivity). Components are returned in the order their seed node was encountered during iteration.

§Examples

use graph_core::{AdjacencyList, Graph};
use graph_traversal::connected_components;

let mut g: AdjacencyList<()> = AdjacencyList::undirected();
let a = g.add_node(());
let b = g.add_node(());
let c = g.add_node(()); // isolated
g.add_edge(a, b, 1.0).unwrap();

let comps = connected_components(&g);
assert_eq!(comps.len(), 2);