pub fn connected_components(data: &[&[usize]]) -> Vec<usize>
Expand description
Finds connected components using a Kruskal-like approach. Each input slice of usizes represents a set of nodes that form a complete subgraph (i.e., all of them are connected).
Returns a vector where each index corresponds to a graph node index and the value is the identifier of the connected component (the minimal node in that component).
use binius_utils::graph::connected_components;
assert_eq!(connected_components(&[]), vec![]);
assert_eq!(connected_components(&[&[0], &[1]]), vec![0, 1]);
assert_eq!(connected_components(&[&[0, 1], &[1, 2], &[2, 3], &[4]]), vec![0, 0, 0, 0, 4]);
assert_eq!(
connected_components(&[&[0, 1, 2], &[5, 6, 7, 8], &[9], &[2, 3, 9]]),
vec![0, 0, 0, 0, 4, 5, 5, 5, 5, 0]
);