Skip to main content

biconnected_components

Function biconnected_components 

Source
pub fn biconnected_components(
    graph: &Graph,
) -> IgraphResult<BiconnectedComponents>
Expand description

Compute the biconnected components of graph.

Counterpart of igraph_biconnected_components(). The graph is treated as undirected. Isolated vertices are not part of any component. See BiconnectedComponents for the output shape.

ยงExamples

use rust_igraph::{Graph, biconnected_components};

// Cycle 0-1-2-0 plus pendant 2-3-4: components are {0,1,2}, {2,3}, {3,4}.
let mut g = Graph::with_vertices(5);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 0).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(3, 4).unwrap();
let bc = biconnected_components(&g).unwrap();
assert_eq!(bc.count, 3);
let mut aps = bc.articulation_points.clone();
aps.sort_unstable();
assert_eq!(aps, vec![2, 3]);
// component_edges partitions every edge across all components.
let total: usize = bc.component_edges.iter().map(Vec::len).sum();
assert_eq!(total, g.ecount());