|
ADS
Algorithms and Data Structures
|
The MFSET of section 10.2, the union of disjoint sets: MFSet( n ) makes the \( n \) components \( \{ 0 \} , \ldots , \{ n - 1 \} \), find( x ) gives the representative of the component of \( x \), and merge( x , y ) joins the components of \( x \) and \( y \), if they are distinct. More...
#include "ADS/Contract.h"#include "ADS/graph/Graph.h"#include <stdexcept>#include <utility>#include <vector>#include "ADS/mfset/impl/MFSet.tpp"Go to the source code of this file.
Classes | |
| class | ADS::MFSet |
| the union of disjoint sets on a forest More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| template<Graph G> | |
| MFSet | ADS::components (const G &g) |
| the MFSET of the connected components of an unoriented graph, built by merging the ends of each edge (the cc() of section 10.2.5); its elements are the names \( [ 0 , \mathrm{bound}() ) \) of \( g \), so that a name that is not a node of \( g \), a deleted one, is a component of its own, counted by count() | |
The MFSET of section 10.2, the union of disjoint sets: MFSet( n ) makes the \( n \) components \( \{ 0 \} , \ldots , \{ n - 1 \} \), find( x ) gives the representative of the component of \( x \), and merge( x , y ) joins the components of \( x \) and \( y \), if they are distinct.
MFSet keeps the components as a forest, a vector of parents \( p \), the roots with \( p[ x ] = x \) being the representatives (section 10.2.2): find() goes up to the root, merge() makes a root a child of the other. Two heuristics may be switched off, to study them:
find() is the iterative version in two passes, the root first and then the compression, with no stack (exercise 10.8). ListMFSet.h has the realization on lists of section 10.2.1. components() gives the MFSET of the connected components of an unoriented graph, which can then follow new edges (section 10.2.5).
The contracts [see Contract.h]: the elements are in \( [ 0 , n ) \), find() gives a root and after merge() \( x \) and \( y \) have the same root; the invariant is that the parents form a forest of count() trees, the rank growing toward the roots with the union by rank, and \( \mathit{size}[ r ] \) the number of nodes of the tree of each root \( r \) with the union by size. merge() of two elements already in the same component returns false and changes nothing, a relaxation of the precondition that they are in distinct components which some specifications state. The operations are defined in MFSet.tpp.