largest_component

Function largest_component 

Source
pub fn largest_component<T, S>(
    graph: &S,
    directed: bool,
    connection: &str,
) -> SparseResult<(usize, Vec<usize>)>
where T: Float + Debug + Copy + 'static, S: SparseArray<T>,
Expand description

Find the largest connected component

§Arguments

  • graph - The graph as a sparse matrix
  • directed - Whether the graph is directed
  • connection - 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();