Skip to main content

connected_components

Function connected_components 

Source
pub fn connected_components(graph: &CsrGraph) -> usize
Expand description

Count the number of weakly connected components in the graph

Treats the graph as undirected for connectivity purposes. Two nodes are in the same component if there’s a path between them (ignoring edge direction).

§Arguments

  • graph - The CSR graph to analyze

§Returns

The number of weakly connected components

§Example

use trueno_graph::{CsrGraph, NodeId, connected_components};

// Two disconnected edges: 0 → 1, 2 → 3
let edges = vec![
    (NodeId(0), NodeId(1), 1.0),
    (NodeId(2), NodeId(3), 1.0),
];
let graph = CsrGraph::from_edge_list(&edges).unwrap();

assert_eq!(connected_components(&graph), 2);