ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::DialQueue< T, K, Policy > Class Template Reference

a monotone queue of items with integer keys of the type K on a circular window of buckets, the keys beyond it in a radix heap More...

#include <ADS/priority/DialQueue.h>

Public types

using Item = T
 the type of the items
using Key = K
 the type of the keys
using modifications
 the events: an item inserted or erased with its key, the queue emptied or rebuilt
using Subject = typename Policy::template bind< modifications , DialQueue >
 the subject

Public member functions

 DialQueue (std::size_t c=1023)
 an empty queue whose window has room for the keys up to \( c \) above the last one extracted: \( W \) buckets, the least power of 2 above \( c \), and 64 at least
template<class... O>
requires ( sizeof...( O ) > 0 )
 DialQueue (std::size_t c, O &... o)
 an empty queue as DialQueue( c ), the static observers o...
void push (const T &x, K k)
 pushes \( x \) with the key \( k \), in \( O( 1 ) \) time if \( k < \ell + W \)
const T & top (void)
 an item of least key, the last pushed among those of its bucket that did not come through the overflow (equal keys in no given order)
K topKey (void)
 the least key
K peekKey (void) const
 the least key, which does not move \( \ell \): the keys pushed next need only be not smaller than the last one extracted, as if peekKey() were not called
T pop (void)
 removes top() and returns it, in \( O( 1 + W / 64 ) \) time if the overflow is not used
bool empty (void) const
 whether the queue has no item
std::size_t size (void) const
 the number of items, \( n \)
void clear (void)
 removes the items, the buckets keeping their memory; any key may be pushed next
std::size_t window (void) const
 the number of buckets of the window, \( W \)
void rebase (K k)
 the keys pushed next may start from \( k \), the items placed again for \( \ell = k \), in \( O( n + W ) \) time
void extract (K theta, std::vector< T > &out)
 every item of key at most \( \theta \) appended to out, by increasing keys, each extracted as by pop()
Subject & subject (void)
 the subject, for ADS::batch() and ADS::quiet()
const Subject & subject (void) const
 the subject
template<class O>
requires ( Subject::dynamic )
int attach (O &o)
 attaches the observer \( o \) and gives its number
void detach (int id)
 detaches the observer number \( \mathit{id} \)

Detailed description

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
class ADS::DialQueue< T, K, Policy >

a monotone queue of items with integer keys of the type K on a circular window of buckets, the keys beyond it in a radix heap

Member typedef documentation

◆ Item

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
using ADS::DialQueue< T, K, Policy >::Item = T

the type of the items

◆ Key

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
using ADS::DialQueue< T, K, Policy >::Key = K

the type of the keys

◆ modifications

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
using ADS::DialQueue< T, K, Policy >::modifications
Initial value:
the structure emptied
Definition Modification.h:699
the item of handle , key and value erased, told before the removal outside a batch
Definition Modification.h:568
anything may have changed: forget and recompute
Definition Modification.h:708
a list of types, the events of a structure [see Modification.h]
Definition Modification.h:482

the events: an item inserted or erased with its key, the queue emptied or rebuilt

◆ Subject

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
using ADS::DialQueue< T, K, Policy >::Subject = typename Policy::template bind< modifications , DialQueue >

the subject

Constructor and destructor documentation

◆ DialQueue() [1/2]

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
ADS::DialQueue< T, K, Policy >::DialQueue ( std::size_t c = 1023)
explicit

an empty queue whose window has room for the keys up to \( c \) above the last one extracted: \( W \) buckets, the least power of 2 above \( c \), and 64 at least

Precondition
\( c \ge 0 \)

◆ DialQueue() [2/2]

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
template<class... O>
requires ( sizeof...( O ) > 0 )
ADS::DialQueue< T, K, Policy >::DialQueue ( std::size_t c,
O &... o )

an empty queue as DialQueue( c ), the static observers o...

Precondition
\( c \ge 0 \)

Member function documentation

◆ attach()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
template<class O>
requires ( Subject::dynamic )
int ADS::DialQueue< T, K, Policy >::attach ( O & o)
inline

attaches the observer \( o \) and gives its number

Precondition
no batch is open

◆ clear()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
void ADS::DialQueue< T, K, Policy >::clear ( void )

removes the items, the buckets keeping their memory; any key may be pushed next

◆ detach()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
void ADS::DialQueue< T, K, Policy >::detach ( int id)
inline

detaches the observer number \( \mathit{id} \)

Precondition
it is attached, no batch is open

◆ empty()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
bool ADS::DialQueue< T, K, Policy >::empty ( void ) const
inlinenodiscard

whether the queue has no item

◆ extract()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
void ADS::DialQueue< T, K, Policy >::extract ( K theta,
std::vector< T > & out )

every item of key at most \( \theta \) appended to out, by increasing keys, each extracted as by pop()

◆ peekKey()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
K ADS::DialQueue< T, K, Policy >::peekKey ( void ) const
nodiscard

the least key, which does not move \( \ell \): the keys pushed next need only be not smaller than the last one extracted, as if peekKey() were not called

Precondition
the queue is not empty

◆ pop()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
T ADS::DialQueue< T, K, Policy >::pop ( void )

removes top() and returns it, in \( O( 1 + W / 64 ) \) time if the overflow is not used

In pseudocode (the queue of Dial, beyond the book), the window moved to the least key first:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{pop}() \cr 2 & \quad \textbf{if}\ B[ \ell \bmod W ] = \emptyset\ \textbf{then} \cr 3 & \qquad d \gets \text{the distance from } \ell \bmod W \text{ of} \text{ the next bucket in use, by the words of } \mathit{used} \text{, or } W \text{ if none} \cr 4 & \qquad \textbf{if}\ O \ne \emptyset\ \textbf{and}\ ( d = W \ \textbf{or}\ \mathrm{peekKey}( O ) < \ell + d )\ \textbf{then} \cr 5 & \qquad\quad \ell \gets \mathrm{peekKey}( O ) \cr 6 & \qquad\quad \text{move the items of } O \text{ of keys below } \ell + W \text{ to their buckets} \cr 7 & \qquad\quad d \gets \text{the distance of the next bucket in } \text{use, as above} \cr 8 & \qquad \ell \gets \ell + d \cr 9 & \quad x \gets \text{the item popped from } B[ \ell \bmod W ] \cr 10 & \quad \textbf{if}\ B[ \ell \bmod W ] = \emptyset\ \textbf{then} \ \mathit{used}[ \ell \bmod W ] \gets \textbf{false} \cr 11 & \quad n \gets n - 1;\ \textbf{return}\ x \end{array}} \]

Precondition
the queue is not empty

◆ push()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
void ADS::DialQueue< T, K, Policy >::push ( const T & x,
K k )

pushes \( x \) with the key \( k \), in \( O( 1 ) \) time if \( k < \ell + W \)

In pseudocode (the queue of Dial, beyond the book), \( \ell \) the last key extracted and \( \mathit{used} \) the bits of the buckets:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{push}( x , k ) \cr 2 & \quad \textbf{if}\ k - \ell < W\ \textbf{then}\ \text{push } x \text{ on } B[ k \bmod W ];\ \mathit{used}[ k \bmod W ] \gets \textbf{true} \cr 3 & \quad \textbf{else}\ \mathrm{push}( O , x , k )\quad \triangleright\ \text{the radix heap of the overflow} \cr 4 & \quad n \gets n + 1 \end{array}} \]

Precondition
\( k \) is not smaller than the last key extracted (any key before the first extraction and after clear())

◆ rebase()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
void ADS::DialQueue< T, K, Policy >::rebase ( K k)

the keys pushed next may start from \( k \), the items placed again for \( \ell = k \), in \( O( n + W ) \) time

In pseudocode (beyond the book), the bucket \( b \) holding the key \( \ell + ( ( b - \ell ) \bmod W ) \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{rebase}( k ) \cr 2 & \quad E \gets \text{the pairs } ( x , k' ) \text{ of the buckets} \text{ and of } O;\ \text{empty the buckets and } O \cr 3 & \quad \ell \gets k;\ n \gets 0 \cr 4 & \quad \textbf{foreach}\ ( x , k' ) \in E\ \textbf{do} \ \mathrm{push}( x , k' ) \end{array}} \]

Precondition
no key in the queue is below \( k \)

◆ size()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
std::size_t ADS::DialQueue< T, K, Policy >::size ( void ) const
inlinenodiscard

the number of items, \( n \)

◆ subject() [1/2]

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
Subject & ADS::DialQueue< T, K, Policy >::subject ( void )
inlinenodiscard

the subject, for ADS::batch() and ADS::quiet()

◆ subject() [2/2]

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
const Subject & ADS::DialQueue< T, K, Policy >::subject ( void ) const
inlinenodiscard

the subject

◆ top()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
const T & ADS::DialQueue< T, K, Policy >::top ( void )
nodiscard

an item of least key, the last pushed among those of its bucket that did not come through the overflow (equal keys in no given order)

Precondition
the queue is not empty

◆ topKey()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
K ADS::DialQueue< T, K, Policy >::topKey ( void )
nodiscard

the least key

Precondition
the queue is not empty

◆ window()

template<class T, std::integral K = std::uint32_t, class Policy = NoObservers>
std::size_t ADS::DialQueue< T, K, Policy >::window ( void ) const
inlinenodiscard

the number of buckets of the window, \( W \)


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