Function rs_graph::algorithms::components
[−]
[src]
pub fn components<'g, G>(g: &'g G) -> (usize, IndexNodeVec<'g, G, usize>) where
G: IndexGraph<'g>,
Determines all components of a graph.
The function numbers all components and assigns each node the number its containing component. The number of components is returned.
The empty graph has 0 components.
Example
use rs_graph::{LinkedListGraph, Graph, Builder, classes, algorithms}; let mut g: LinkedListGraph = classes::cycle(5); { let (ncomps, comps) = algorithms::components(&g); assert_eq!(ncomps, 1); for u in g.nodes() { assert_eq!(comps[u], 0); } } let v = g.add_node(); { let (ncomps, comps) = algorithms::components(&g); assert_eq!(ncomps, 2); for u in g.nodes() { assert_eq!(comps[u], if u == v { 1 } else { 0 }); } }