[][src]Function pathfinding::undirected::connected_components::separate_components

pub fn separate_components<N>(
    groups: &[Vec<N>]
) -> (HashMap<N, usize>, Vec<usize>) where
    N: Clone + Hash + Eq

Separate components of an undirected graph into disjoint sets.

  • groups is a set of group of vertices connected together. It is acceptable for a group to contain only one node. Empty groups receive special treatment (see below).

This function returns a pair containing:

  • A mapping from every vertex to its set identifier. The set identifiers are opaque and will not necessarily be compact. However, it is guaranteed that they will not be greater than the number of groups.
  • A mapping from every group to its set identifier, with the identifiers being the same ones as the ones in the previous mapping. Each group corresponds to the identifier at the same index, except for empty group whose identifier is set to std::usize::MAX.

Note that if you have a raw undirected graph, you can build such a structure by creating a group for every vertex containing the vertex itself and its immediate neighbours.