Skip to main content

Module components

Module components 

Source
Expand description

The algorithms for the components of a graph, and for the edges and nodes whose removal splits them - Java’s class Components.

sccs_of returns the SCCs (strongly connected components), and wccs_of the weakly connected components. ccs_of returns the weakly connected components under another name: the connected components of the graph read as undirected. biconnectivity_of returns the bridges, articulation points and biconnected components. Bridges and articulation points are the edges and nodes whose removal splits a connected component. strong_connectivity_of returns the strong bridges and strong articulation points, which split an SCC.

use graphity_core::{components, BiAdjacentGraph, GraphBuilder};

let mut b = GraphBuilder::new();
b.add_nodes(4);
b.add_edge_pairs(&[0, 1, 1, 0, 1, 2, 2, 3]);
let graph = b.build();

let sccs = components::sccs_of(&graph);
assert_eq!(sccs.scc_count(), 3);
assert_eq!(components::wccs_of(&graph).group_count(), 1);
let biconnectivity = components::biconnectivity_of(&BiAdjacentGraph::of(&graph));
assert_eq!(biconnectivity.articulation_points(), [1, 2]);

A graph is always directed, and each function says how it reads the edges. sccs_of and strong_connectivity_of follow them in their direction. wccs_of, ccs_of and biconnectivity_of read the graph as undirected: an edge connects its source and target whether or not the reverse edge exists, and the edges a -> b and b -> a count as one undirected edge, not two. An undirected graph can therefore be stored with one edge per pair of neighbors or with both directions, and these functions read it the same way. For the bridges this matters: read as two edges, the two directions would form a cycle, and no edge stored in both directions could be a bridge.

Functions§

biconnectivity_of
Returns the bridges, articulation points and biconnected components of graph, read as undirected.
ccs_of
Returns the connected components of graph read as undirected. Equivalent to wccs_of(graph).
sccs_of
Returns the SCCs of graph. Uses Tarjan’s algorithm, without recursion.
strong_connectivity_of
Returns the strong bridges and strong articulation points of graph. These are the edges and nodes whose removal splits an SCC.
wccs_of
Returns the weakly connected components of graph. These are the components of the graph read as undirected.