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

a two-level bucket queue: least \( f \) first, then largest (or, by the policy Tie, least) \( g \), then LIFO More...

#include <ADS/priority/BucketQueue.h>

Classes

struct  Entry
 an item with its keys More...
struct  TopEntry
 the item of top() with its keys, read in place More...
class  const_iterator

Public types

using Item = T
 the type of the items
using Key = K
 the type of the keys
using Ties = Tie
 the order among the items of one f
using modifications
 the events: an item inserted or erased with its keys \( f \) and \( g \), the queue emptied or rebuilt
using Subject = typename Policy::template bind< modifications , BucketQueue >
 the subject
using value_type = T
 the type of the items
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the distances of iterators
using reference = const T &
 a constant reference
using const_reference = const T &
 a constant reference
using iterator = const_iterator
 the same as const_iterator

Public member functions

 BucketQueue (void)=default
 the empty queue
template<class... O>
requires ( ( sizeof...( O ) > 0 ) && ( ! std::is_base_of_v< BucketQueue , O > && ... ) )
 BucketQueue (O &... o)
 the empty queue, the static observers o...
void push (const T &x, K f, K g)
 pushes \( x \) with the keys \( f \) and \( g \)
const T & top (void)
 an item of least \( f \) and, among those, of largest \( g \) (of least \( g \) with LeastSecondKey), the last pushed
K topF (void)
 the \( f \) of top(), i.e., the least \( f \) in the queue
K topG (void)
 the \( g \) of top(), i.e., the largest (by LeastSecondKey, the least) \( g \) of the least \( f \)
T pop (void)
 removes top() and returns it
Entry popEntry (void)
 removes top() and returns it with its keys \( f \) and \( g \), finding the top once instead of three times through topF(), topG() and pop()
TopEntry topEntry (void)
 top() with its keys \( f \) and \( g \), finding the top once instead of three times through top(), topF() and topG(); the queue is unchanged
bool empty (void) const
 whether the queue has no item
std::size_t size (void) const
 the number of items, the stale ones included
void clear (void)
 removes all the items and frees the layers
void extract (K theta, std::vector< T > &out)
 every item of first key at most \( \theta \) appended to out, in the order of pop(), each extracted as by it
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} \)
const_iterator begin (void) const
 on the item of top()
const_iterator end (void) const
 past the last item
const_iterator cbegin (void) const
 begin()
const_iterator cend (void) const
 end()

Static public attributes

static constexpr std::size_t D = 256
 the \( g \) below which the lists of a layer are always dense
static constexpr std::size_t R = 64
 the runs of \( g \ge D \) that a layer keeps sparse, at most

Detailed description

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
class ADS::BucketQueue< T, K, Tie, Policy >

a two-level bucket queue: least \( f \) first, then largest (or, by the policy Tie, least) \( g \), then LIFO

Member typedef documentation

◆ const_reference

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::const_reference = const T &

a constant reference

◆ difference_type

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::difference_type = std::ptrdiff_t

the distances of iterators

◆ Item

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::Item = T

the type of the items

◆ iterator

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::iterator = const_iterator

the same as const_iterator

◆ Key

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::Key = K

the type of the keys

◆ modifications

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, 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 keys \( f \) and \( g \), the queue emptied or rebuilt

◆ reference

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::reference = const T &

a constant reference

◆ size_type

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::size_type = std::size_t

the type of the sizes

◆ Subject

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::Subject = typename Policy::template bind< modifications , BucketQueue >

the subject

◆ Ties

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::Ties = Tie

the order among the items of one f

◆ value_type

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
using ADS::BucketQueue< T, K, Tie, Policy >::value_type = T

the type of the items

Constructor and destructor documentation

◆ BucketQueue() [1/2]

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
ADS::BucketQueue< T, K, Tie, Policy >::BucketQueue ( void )
default

the empty queue

◆ BucketQueue() [2/2]

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
template<class... O>
requires ( ( sizeof...( O ) > 0 ) && ( ! std::is_base_of_v< BucketQueue , O > && ... ) )
ADS::BucketQueue< T, K, Tie, Policy >::BucketQueue ( O &... o)
inlineexplicit

the empty queue, the static observers o...

Member function documentation

◆ attach()

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

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

Precondition
no batch is open

◆ begin()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
const_iterator ADS::BucketQueue< T, K, Tie, Policy >::begin ( void ) const
inlinenodiscard

on the item of top()

◆ cbegin()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
const_iterator ADS::BucketQueue< T, K, Tie, Policy >::cbegin ( void ) const
inlinenodiscard

◆ cend()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
const_iterator ADS::BucketQueue< T, K, Tie, Policy >::cend ( void ) const
inlinenodiscard

◆ clear()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
void ADS::BucketQueue< T, K, Tie, Policy >::clear ( void )

removes all the items and frees the layers

◆ detach()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
void ADS::BucketQueue< T, K, Tie, 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 = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
bool ADS::BucketQueue< T, K, Tie, Policy >::empty ( void ) const
nodiscard

whether the queue has no item

◆ end()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
const_iterator ADS::BucketQueue< T, K, Tie, Policy >::end ( void ) const
inlinenodiscard

past the last item

◆ extract()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
void ADS::BucketQueue< T, K, Tie, Policy >::extract ( K theta,
std::vector< T > & out )

every item of first key at most \( \theta \) appended to out, in the order of pop(), each extracted as by it

◆ pop()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
T ADS::BucketQueue< T, K, Tie, Policy >::pop ( void )

removes top() and returns it

In pseudocode, \( \ell \) the layer of top() found as there:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{pop}() \cr 2 & \quad \ell \gets \text{the layer of } \mathrm{top}() \cr 3 & \quad \textbf{if}\ \ell \text{ has runs}\ \textbf{then} \cr 4 & \qquad x \gets \text{the item unlinked from the head of the last run} \cr 5 & \qquad \textbf{if}\ \text{its list is empty}\ \textbf{then} \ \text{drop the run, and spare the vector if no run is left} \cr 6 & \quad \textbf{else}\ x \gets \text{the item unlinked from } \ell.\mathit{head}[ \ell.\mathit{topG} ] \cr 7 & \quad \text{its cell to the list of the free cells}; \ \ell.\mathit{count} \gets \ell.\mathit{count} - 1 \cr 8 & \quad \textbf{if}\ \ell.\mathit{count} = 0\ \textbf{then} \ \text{free the dense heads of } g \ge S;\ \ell.\mathit{topG} \gets 0 \cr 9 & \quad \textbf{return}\ x \end{array}} \]

Precondition
the queue is not empty

◆ popEntry()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
Entry ADS::BucketQueue< T, K, Tie, Policy >::popEntry ( void )

removes top() and returns it with its keys \( f \) and \( g \), finding the top once instead of three times through topF(), topG() and pop()

Precondition
the queue is not empty

◆ push()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
void ADS::BucketQueue< T, K, Tie, Policy >::push ( const T & x,
K f,
K g )

pushes \( x \) with the keys \( f \) and \( g \)

In pseudocode (the bucket queue of Dial nested as in Burns et al., beyond the book), \( \ell \) the layer of \( f \) and \( v \) its runs:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{push}( x , f , g ) \cr 2 & \quad \ell \gets \text{the layer of } f \cr 3 & \quad \textbf{if}\ g \ge D\ \textbf{and}\ \ell \text{ is sparse} \ \textbf{and}\ |v| = R\ \textbf{then}\quad \triangleright\ \text{to} \text{ dense} \cr 4 & \qquad \textbf{foreach}\ ( g' , h ) \in v\ \textbf{do} \ \ell.\mathit{head}[ g' ] \gets h \cr 5 & \qquad v \gets \emptyset;\ \ell.\mathit{topG} \gets \text{the } \text{largest } g' \cr 6 & \quad \textbf{if}\ g < D\ \textbf{or}\ \ell \text{ is dense} \ \textbf{then} \cr 7 & \qquad \text{prepend } x \text{ to the list of } \ell.\mathit{head}[ g ];\ \ell.\mathit{topG} \gets \max\{ \ell.\mathit{topG} , g \} \cr 8 & \quad \textbf{else if}\ v = \emptyset\ \textbf{or}\ g > \text{the } \text{last } g' \text{ of } v\ \textbf{then}\ \text{append the run } ( g , ( x ) ) \text{ to } v \cr 9 & \quad \textbf{else}\ \text{find the run of } g \text{ in } v \text{ by binary search, or insert it;}\ \text{prepend } x \text{ to it} \cr 10 & \quad \ell.\mathit{count} \gets \ell.\mathit{count} + 1; \ \mathit{minF} \gets \min\{ \mathit{minF} , f \} \end{array}} \]

With LeastSecondKey the runs are kept by decreasing \( g \) (line 8 appends a run of a \( g \) less than the last), and line 7 lowers \( \ell.\mathit{topG} \) to \( g \) instead of raising it.

Precondition
\( f \ge 0 \) and \( g \ge 0 \)

◆ size()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
std::size_t ADS::BucketQueue< T, K, Tie, Policy >::size ( void ) const
nodiscard

the number of items, the stale ones included

◆ subject() [1/2]

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
Subject & ADS::BucketQueue< T, K, Tie, Policy >::subject ( void )
inlinenodiscard

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

◆ subject() [2/2]

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
const Subject & ADS::BucketQueue< T, K, Tie, Policy >::subject ( void ) const
inlinenodiscard

the subject

◆ top()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
const T & ADS::BucketQueue< T, K, Tie, Policy >::top ( void )
nodiscard

an item of least \( f \) and, among those, of largest \( g \) (of least \( g \) with LeastSecondKey), the last pushed

In pseudocode, the two scans moving only forward in \( f \) and backward in \( g \) between two pushes:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{top}() \cr 2 & \quad \textbf{while}\ \text{the layer of } \mathit{minF} \text{ is } \text{empty}\ \textbf{do}\ \mathit{minF} \gets \mathit{minF} + 1 \cr 3 & \quad \ell \gets \text{the layer of } \mathit{minF} \cr 4 & \quad \textbf{if}\ \ell \text{ has runs}\ \textbf{then return} \ \text{the head of its last run} \cr 5 & \quad \textbf{while}\ \ell.\mathit{head}[ \ell.\mathit{topG} ] = \textbf{nil}\ \textbf{do}\ \ell.\mathit{topG} \gets \ell.\mathit{topG} - 1 \cr 6 & \quad \textbf{return}\ \text{the item of } \ell.\mathit{head}[ \ell.\mathit{topG} ] \end{array}} \]

With LeastSecondKey, line 5 moves \( \ell.\mathit{topG} \) forward, up to the dense lists' end, and the runs are looked at, line 4, only if no dense list has items.

Precondition
the queue is not empty

◆ topEntry()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
TopEntry ADS::BucketQueue< T, K, Tie, Policy >::topEntry ( void )
nodiscard

top() with its keys \( f \) and \( g \), finding the top once instead of three times through top(), topF() and topG(); the queue is unchanged

Precondition
the queue is not empty

◆ topF()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
K ADS::BucketQueue< T, K, Tie, Policy >::topF ( void )
nodiscard

the \( f \) of top(), i.e., the least \( f \) in the queue

Precondition
the queue is not empty

◆ topG()

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
K ADS::BucketQueue< T, K, Tie, Policy >::topG ( void )
nodiscard

the \( g \) of top(), i.e., the largest (by LeastSecondKey, the least) \( g \) of the least \( f \)

Precondition
the queue is not empty

Member data documentation

◆ D

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
std::size_t ADS::BucketQueue< T, K, Tie, Policy >::D = 256
staticconstexpr

the \( g \) below which the lists of a layer are always dense

◆ R

template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
std::size_t ADS::BucketQueue< T, K, Tie, Policy >::R = 64
staticconstexpr

the runs of \( g \ge D \) that a layer keeps sparse, at most


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