ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::ListMFSet Class Reference

the union of disjoint sets on lists, each element with the head of its list More...

#include <ADS/mfset/ListMFSet.h>

Public member functions

 ListMFSet (int n)
 the \( n \) singletons \( \{ 0 \} , \ldots , \{ n - 1 \} \)
int n (void) const
 the number \( n \) of elements
int find (int x) const
 the head of the list of \( x \), in \( O( 1 ) \) time
bool merge (int x, int y)
 joins the lists of \( x \) and \( y \), the shorter after the longer, its elements relabeled; true if they were distinct
long relabels (void) const
 the elements relabeled so far
const std::vector< int > & members (int x) const
 the members of the set of \( x \)

Detailed description

the union of disjoint sets on lists, each element with the head of its list

Constructor and destructor documentation

◆ ListMFSet()

ADS::ListMFSet::ListMFSet ( int n)
explicit

the \( n \) singletons \( \{ 0 \} , \ldots , \{ n - 1 \} \)

Precondition
\( n \ge 0 \)

Member function documentation

◆ find()

int ADS::ListMFSet::find ( int x) const
nodiscard

the head of the list of \( x \), in \( O( 1 ) \) time

Precondition
\( x \in [ 0 , n ) \)

◆ members()

const std::vector< int > & ADS::ListMFSet::members ( int x) const
nodiscard

the members of the set of \( x \)

Precondition
\( x \in [ 0 , n ) \)

◆ merge()

bool ADS::ListMFSet::merge ( int x,
int y )

joins the lists of \( x \) and \( y \), the shorter after the longer, its elements relabeled; true if they were distinct

In pseudocode (section 10.2.1), \( \mathit{head}[ x ] \) the head of the list of \( x \) and \( L[ a ] \) the list of the head \( a \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{merge}( x , y ) \cr 2 & \quad a \gets \mathit{head}[ x ];\ b \gets \mathit{head}[ y ]; \ \textbf{if}\ a = b\ \textbf{then return false} \cr 3 & \quad \textbf{if}\ |L[ a ]| < |L[ b ]|\ \textbf{then}\ a \leftrightarrow b\quad \triangleright\ \text{the shorter list is } L[ b ] \cr 4 & \quad \textbf{foreach}\ z \in L[ b ]\ \textbf{do}\ \text{append } z \text{ to } L[ a ];\ \mathit{head}[ z ] \gets a \cr 5 & \quad \text{empty } L[ b ];\ \textbf{return true} \end{array}} \]

Precondition
\( x , y \in [ 0 , n ) \)
Postcondition
\( x \) and \( y \) have the same head

◆ n()

int ADS::ListMFSet::n ( void ) const
nodiscard

the number \( n \) of elements

◆ relabels()

long ADS::ListMFSet::relabels ( void ) const
nodiscard

the elements relabeled so far


The documentation for this class was generated from the following file: