pub fn largest_component<T, S>(
graph: &S,
directed: bool,
connection: &str,
) -> SparseResult<(usize, Vec<usize>)>
Expand description
Find the largest connected component
§Arguments
graph
- The graph as a sparse matrixdirected
- Whether the graph is directedconnection
- Type of connectivity for directed graphs
§Returns
A tuple containing:
- Size of the largest component
- Optional indices of vertices in the largest component
§Examples
use scirs2_sparse::csgraph::largest_component;
use scirs2_sparse::csr_array::CsrArray;
// Create a symmetric graph with components of different sizes
let rows = vec![0, 1, 1, 2, 2, 3, 3, 4];
let cols = vec![1, 0, 2, 1, 3, 2, 4, 3];
let data = vec![1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0];
let graph = CsrArray::from_triplets(&rows, &cols, &data, (5, 5), false).unwrap();
let (size, indices) = largest_component(&graph, false, "weak").unwrap();