ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::IndexedHeapPair< K, Bd, D > Class Template Reference

the ids \( [ 0 , n ) \) by a key, the least on top, with the least of their bounds More...

#include <ADS/priority/IndexedHeapPair.h>

Public types

using Key = K
 the type of the keys of selection
using Bound = Bd
 the type of the bounds

Public member functions

 IndexedHeapPair (int n=0)
 the empty queue of the ids \( [ 0 , n ) \)
void reset (int n)
 the empty queue of the ids \( [ 0 , n ) \), the room kept
int ids (void) const
 the number of ids, \( n \)
bool empty (void) const
 whether the queue has no id
std::size_t size (void) const
 the number of ids in the queue, \( s \)
bool contains (int id) const
 whether the id is in the queue
const K & key (int id) const
 the key of an id in the queue
const Bd & bound (int id) const
 the bound of an id in the queue
void push (int id, const K &k, const Bd &b)
 inserts the id with the key \( k \) and the bound \( b \), in \( O( \log_D s ) \) time
void update (int id, const K &k, const Bd &b)
 sets the key of the id to \( k \) and its bound to \( b \), each heap moving the id up or down, in \( O( D \log_D s ) \) time
void erase (int id)
 removes the id from the queue, in \( O( D \log_D s ) \) time
int top (void) const
 the id of least key
const K & topKey (void) const
 the least key, that of top()
const Bd & minBound (void) const
 the least bound of the ids in the queue
int minBoundId (void) const
 an id of least bound
int pop (void)
 removes the id of least key and returns it, in \( O( D \log_D s ) \) time
int popMinBound (void)
 removes the id of least bound and returns it, as pop() by the other heap
void clear (void)
 removes all the ids, in \( O( s ) \) time

Detailed description

template<class K, class Bd = K, unsigned D = 4>
class ADS::IndexedHeapPair< K, Bd, D >

the ids \( [ 0 , n ) \) by a key, the least on top, with the least of their bounds

Member typedef documentation

◆ Bound

template<class K, class Bd = K, unsigned D = 4>
using ADS::IndexedHeapPair< K, Bd, D >::Bound = Bd

the type of the bounds

◆ Key

template<class K, class Bd = K, unsigned D = 4>
using ADS::IndexedHeapPair< K, Bd, D >::Key = K

the type of the keys of selection

Constructor and destructor documentation

◆ IndexedHeapPair()

template<class K, class Bd = K, unsigned D = 4>
ADS::IndexedHeapPair< K, Bd, D >::IndexedHeapPair ( int n = 0)
inlineexplicit

the empty queue of the ids \( [ 0 , n ) \)

Precondition
\( n \ge 0 \)

Member function documentation

◆ bound()

template<class K, class Bd = K, unsigned D = 4>
const Bd & ADS::IndexedHeapPair< K, Bd, D >::bound ( int id) const
inlinenodiscard

the bound of an id in the queue

Precondition
the id is in the queue

◆ clear()

template<class K, class Bd = K, unsigned D = 4>
void ADS::IndexedHeapPair< K, Bd, D >::clear ( void )
inline

removes all the ids, in \( O( s ) \) time

◆ contains()

template<class K, class Bd = K, unsigned D = 4>
bool ADS::IndexedHeapPair< K, Bd, D >::contains ( int id) const
inlinenodiscard

whether the id is in the queue

Precondition
\( \mathit{id} \in [ 0 , n ) \)

◆ empty()

template<class K, class Bd = K, unsigned D = 4>
bool ADS::IndexedHeapPair< K, Bd, D >::empty ( void ) const
inlinenodiscard

whether the queue has no id

◆ erase()

template<class K, class Bd = K, unsigned D = 4>
void ADS::IndexedHeapPair< K, Bd, D >::erase ( int id)

removes the id from the queue, in \( O( D \log_D s ) \) time

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{erase}( \mathit{id} ) \cr 2 & \quad H_K.\mathrm{erase}( \mathit{id} ); \ H_B.\mathrm{erase}( \mathit{id} ) \end{array}} \]

Precondition
the id is in the queue

◆ ids()

template<class K, class Bd = K, unsigned D = 4>
int ADS::IndexedHeapPair< K, Bd, D >::ids ( void ) const
inlinenodiscard

the number of ids, \( n \)

◆ key()

template<class K, class Bd = K, unsigned D = 4>
const K & ADS::IndexedHeapPair< K, Bd, D >::key ( int id) const
inlinenodiscard

the key of an id in the queue

Precondition
the id is in the queue

◆ minBound()

template<class K, class Bd = K, unsigned D = 4>
const Bd & ADS::IndexedHeapPair< K, Bd, D >::minBound ( void ) const
inlinenodiscard

the least bound of the ids in the queue

Precondition
the queue is not empty

◆ minBoundId()

template<class K, class Bd = K, unsigned D = 4>
int ADS::IndexedHeapPair< K, Bd, D >::minBoundId ( void ) const
inlinenodiscard

an id of least bound

Precondition
the queue is not empty

◆ pop()

template<class K, class Bd = K, unsigned D = 4>
int ADS::IndexedHeapPair< K, Bd, D >::pop ( void )

removes the id of least key and returns it, in \( O( D \log_D s ) \) time

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{pop}() \cr 2 & \quad \mathit{id} \gets H_K.\mathrm{pop}().\mathit{id}; \ H_B.\mathrm{erase}( \mathit{id} ) \cr 3 & \quad \textbf{return}\ \mathit{id} \end{array}} \]

Precondition
the queue is not empty

◆ popMinBound()

template<class K, class Bd = K, unsigned D = 4>
int ADS::IndexedHeapPair< K, Bd, D >::popMinBound ( void )

removes the id of least bound and returns it, as pop() by the other heap

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{popMinBound}() \cr 2 & \quad \mathit{id} \gets H_B.\mathrm{pop}().\mathit{id}; \ H_K.\mathrm{erase}( \mathit{id} );\ \textbf{return} \ \mathit{id} \end{array}} \]

Precondition
the queue is not empty

◆ push()

template<class K, class Bd = K, unsigned D = 4>
void ADS::IndexedHeapPair< K, Bd, D >::push ( int id,
const K & k,
const Bd & b )

inserts the id with the key \( k \) and the bound \( b \), in \( O( \log_D s ) \) time

In pseudocode (beyond the book), \( H_K \) and \( H_B \) the heaps by the keys and by the bounds:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{push}( \mathit{id} , k , b ) \cr 2 & \quad H_K.\mathrm{push}( \mathit{id} , k ); \ H_B.\mathrm{push}( \mathit{id} , b ) \end{array}} \]

Precondition
\( \mathit{id} \in [ 0 , n ) \), not in the queue

◆ reset()

template<class K, class Bd = K, unsigned D = 4>
void ADS::IndexedHeapPair< K, Bd, D >::reset ( int n)
inline

the empty queue of the ids \( [ 0 , n ) \), the room kept

Precondition
\( n \ge 0 \)

◆ size()

template<class K, class Bd = K, unsigned D = 4>
std::size_t ADS::IndexedHeapPair< K, Bd, D >::size ( void ) const
inlinenodiscard

the number of ids in the queue, \( s \)

◆ top()

template<class K, class Bd = K, unsigned D = 4>
int ADS::IndexedHeapPair< K, Bd, D >::top ( void ) const
inlinenodiscard

the id of least key

Precondition
the queue is not empty

◆ topKey()

template<class K, class Bd = K, unsigned D = 4>
const K & ADS::IndexedHeapPair< K, Bd, D >::topKey ( void ) const
inlinenodiscard

the least key, that of top()

Precondition
the queue is not empty

◆ update()

template<class K, class Bd = K, unsigned D = 4>
void ADS::IndexedHeapPair< K, Bd, D >::update ( int id,
const K & k,
const Bd & b )

sets the key of the id to \( k \) and its bound to \( b \), each heap moving the id up or down, in \( O( D \log_D s ) \) time

In pseudocode (beyond the book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{update}( \mathit{id} , k , b ) \cr 2 & \quad H_K.\mathrm{update}( \mathit{id} , k ); \ H_B.\mathrm{update}( \mathit{id} , b ) \end{array}} \]

Precondition
the id is in the queue

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