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

the structure with buckets of exercise 19.17: for \( k = 0 , 1 \) the nodes by the number \( h \) of their edges to \( V_k \), bucket( k , h ), its size dim( k , h ), and the least and largest bucket not empty; a node leaves a bucket in \( O( 1 ) \) by its place in it More...

#include <ADS/intractable/Heuristics.h>

Public member functions

 Buckets (int n)
 the empty structure for the nodes \( [ 0 , n ) \)
void insert (int u)
 \( u \) with no edges to either side, in the buckets 0
void remove (int u)
 takes \( u \) out of its two buckets, moving the least and the largest bucket not empty if they empty
void inc (int k, int u)
 \( u \) has one more edge to \( V_k \), and moves to the next bucket
bool contains (int u) const
 whether \( u \) is in the structure
int count (int k, int u) const
 the edges of \( u \) to \( V_k \)
const Nodes & bucket (int k, int h) const
 the nodes with \( h \) edges to \( V_k \)
int dim (int k, int h) const
 the number of the nodes with \( h \) edges to \( V_k \)
int min (int k) const
 the least \( h \) with bucket( k , h ) not empty, \( n + 1 \) if none
int max (int k) const
 the largest \( h \) with bucket( k , h ) not empty, \( -1 \) if none
int choose (int k) const
 the node to add to \( V_k \): in the least bucket of \( V_{1-k} \), the one with most edges to \( V_k \), the first of the bucket on ties

Detailed description

the structure with buckets of exercise 19.17: for \( k = 0 , 1 \) the nodes by the number \( h \) of their edges to \( V_k \), bucket( k , h ), its size dim( k , h ), and the least and largest bucket not empty; a node leaves a bucket in \( O( 1 ) \) by its place in it

Constructor and destructor documentation

◆ Buckets()

ADS::Buckets::Buckets ( int n)
explicit

the empty structure for the nodes \( [ 0 , n ) \)

Precondition
\( n \ge 0 \)

Member function documentation

◆ bucket()

const Nodes & ADS::Buckets::bucket ( int k,
int h ) const
nodiscard

the nodes with \( h \) edges to \( V_k \)

Precondition
\( k \) is 0 or 1 and \( 0 \le h \le n \)

◆ choose()

int ADS::Buckets::choose ( int k) const
nodiscard

the node to add to \( V_k \): in the least bucket of \( V_{1-k} \), the one with most edges to \( V_k \), the first of the bucket on ties

Precondition
\( k \) is 0 or 1 and the structure is not empty
Postcondition
the result is in the structure

◆ contains()

bool ADS::Buckets::contains ( int u) const
nodiscard

whether \( u \) is in the structure

Precondition
\( u \) is a node

◆ count()

int ADS::Buckets::count ( int k,
int u ) const
nodiscard

the edges of \( u \) to \( V_k \)

Precondition
\( k \) is 0 or 1 and \( u \) is a node

◆ dim()

int ADS::Buckets::dim ( int k,
int h ) const
nodiscard

the number of the nodes with \( h \) edges to \( V_k \)

Precondition
\( k \) is 0 or 1 and \( 0 \le h \le n \)

◆ inc()

void ADS::Buckets::inc ( int k,
int u )

\( u \) has one more edge to \( V_k \), and moves to the next bucket

Precondition
\( u \) is in the structure, \( k \) is 0 or 1, and \( u \) has fewer than \( n \) edges to \( V_k \)

◆ insert()

void ADS::Buckets::insert ( int u)

\( u \) with no edges to either side, in the buckets 0

Precondition
\( u \) is a node out of the structure

◆ max()

int ADS::Buckets::max ( int k) const
nodiscard

the largest \( h \) with bucket( k , h ) not empty, \( -1 \) if none

Precondition
\( k \) is 0 or 1

◆ min()

int ADS::Buckets::min ( int k) const
nodiscard

the least \( h \) with bucket( k , h ) not empty, \( n + 1 \) if none

Precondition
\( k \) is 0 or 1

◆ remove()

void ADS::Buckets::remove ( int u)

takes \( u \) out of its two buckets, moving the least and the largest bucket not empty if they empty

In pseudocode (exercise 19.17), with \( h_k[ u ] \) the edges of \( u \) to \( V_k \) and \( p_k[ u ] \) its place in its bucket; inc() is \( \mathrm{take}( k , u ) \), \( h_k[ u ] \gets h_k[ u ] + 1 \) and the append of \( u \) to the bucket of \( h_k[ u ] \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{remove}( u )\quad \triangleright\ u \text{ leaves both families of buckets} \cr 2 & \quad \mathrm{take}( 0 , u );\ \mathrm{take}( 1 , u ) \cr 3 & \textbf{procedure}\ \mathrm{take}( k , u )\quad \triangleright\ h_k[ u ] \text{ its bucket, } p_k[ u ] \text{ its place there} \cr 4 & \quad B \gets \mathrm{bucket}( k , h_k[ u ] );\ p \gets p_k[ u ] \cr 5 & \quad \text{move the last node } x \text{ of } B \text{ to } B[ p ] \text{, set } p_k[ x ] \gets p \text{, and shorten } B \text{ by one}\quad \triangleright\ O( 1 ) \cr 6 & \quad \textbf{if}\ B = \emptyset\ \textbf{then}\ \text{move } \mathit{min}( k ) \text{ up and } \mathit{max}( k ) \text{ down past the empty buckets,} \cr & \qquad \text{if they were at } h_k[ u ] \text{, within } [ 0 , n ] \end{array}} \]

Precondition
\( u \) is in the structure

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