|
| | RadixHeap (void)=default |
| | the empty heap
|
| | RadixHeap (const A &alloc) |
| | the empty heap, its buckets from alloc
|
template<class... O>
requires ( ( sizeof...( O ) > 0 ) && ( ! std::is_convertible_v< O & , const A & > && ... ) && ( ! std::is_base_of_v< RadixHeap ,
O > && ... ) ) |
| | RadixHeap (O &... o) |
| | the empty heap, the static observers o...
|
| template<class... O> |
| | RadixHeap (std::allocator_arg_t, const A &alloc, O &... o) |
| | the empty heap, its buckets from alloc, the static observers o...
|
| allocator_type | get_allocator (void) const |
| | the allocator of the buckets
|
| void | push (const T &x, K k) |
| | pushes \( x \) with the key \( k \), in \( O( 1 ) \) time
|
| const T & | top (void) |
| | an item of least key, the last pushed among those
|
| K | topKey (void) |
| | the least key
|
| K | peekKey (void) const |
| | the least key, read from the least key of the first bucket in use, which does not move the buckets: the keys pushed next need only be not smaller than the last one extracted, as if topKey() were not called
|
| T | pop (void) |
| | removes top() and returns it, in \( O( W / B + 2^B W / ( 64 B ) ) \) amortized time
|
| template<class F> |
| void | extractBelow (K limit, F &&f) |
| | removes the items of keys below limit, calling f( item , key ) for each of them in no given order, which count as extracted: the buckets whose keys are all below limit are emptied whole, with no move, and the first one that holds a key not below it is moved to the rows below for its least key, as by pop(), until the limit falls between two buckets or within one of the row 0
|
| 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
|
| void | rebase (K k) |
| | the keys pushed next may start from \( k \), the items placed again for \( \ell = k \), in \( O( n + 2^B W / B ) \) 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} \)
|
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
class ADS::RadixHeap< T, K, B, A, Policy >
a monotone queue of items with integer keys of the type K, the least key first, in buckets by digits of \( B \) bits
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
template<class... O>
requires ( ( sizeof...( O ) > 0 ) && ( ! std::is_convertible_v< O & , const A & > && ... ) && ( ! std::is_base_of_v< RadixHeap ,
O > && ... ) )
the empty heap, the static observers o...
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
template<class... O>
| ADS::RadixHeap< T, K, B, A, Policy >::RadixHeap |
( |
std::allocator_arg_t | , |
|
|
const A & | alloc, |
|
|
O &... | o ) |
|
inline |
the empty heap, its buckets from alloc, the static observers o...
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
template<class O>
requires ( Subject::dynamic )
attaches the observer \( o \) and gives its number
- Precondition
- no batch is open
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
| void ADS::RadixHeap< T, K, B, A, 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()
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
template<class F>
| void ADS::RadixHeap< T, K, B, A, Policy >::extractBelow |
( |
K | limit, |
|
|
F && | f ) |
removes the items of keys below limit, calling f( item , key ) for each of them in no given order, which count as extracted: the buckets whose keys are all below limit are emptied whole, with no move, and the first one that holds a key not below it is moved to the rows below for its least key, as by pop(), until the limit falls between two buckets or within one of the row 0
In pseudocode (beyond the book), \( \lambda \) the limit and \( \mathit{hi}( b ) \) the largest key that the bucket \( b \) may hold for \( \ell \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{extractBelow}( \lambda , f ) \cr
2 & \quad \textbf{while}\ n > 0\ \textbf{do} \cr
3 & \qquad b \gets \text{the first bucket in use} \cr
4 & \qquad \textbf{if}\ \mathit{lo}[ b ] \ge \lambda
\ \textbf{then}\ \textbf{break} \cr
5 & \qquad \textbf{if}\ \mathit{hi}( b ) < \lambda\ \textbf{then}
\ f( x , k ) \text{ for each } ( k , x ) \in B[ b ];\ \text{empty }
b \cr
6 & \qquad \textbf{else if}\ b \ge 2^B\ \textbf{then}\ \ell \gets
\mathit{lo}[ b ];\ \text{move the items of } B[ b ] \text{ to}
\text{ their buckets} \cr
7 & \qquad \textbf{else} \cr
8 & \qquad\quad f( x , k ) \text{ for each } ( k , x ) \in B[ b ]
\text{ with } k < \lambda \text{, the others kept in } B[ b ] \cr
9 & \qquad\quad \textbf{if}\ B[ b ] \ne \emptyset\ \textbf{then}
\ \textbf{break}
\end{array}}
\]
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
the least key, read from the least key of the first bucket in use, which does not move the buckets: the keys pushed next need only be not smaller than the last one extracted, as if topKey() were not called
- Precondition
- the queue is not empty
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
removes top() and returns it, in \( O( W / B + 2^B W / ( 64 B ) ) \) amortized time
In pseudocode (Ahuja, Mehlhorn, Orlin and Tarjan, beyond the book), with \( \mathrm{bucket}() \) of push():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{pop}() \cr
2 & \quad b \gets \text{the first bucket in use, by the lowest bit}
\text{ of the mask} \cr
3 & \quad \textbf{if}\ b \ge 2^B\ \textbf{then}\quad \triangleright
\ \text{above the row 0} \cr
4 & \qquad \ell \gets \mathit{lo}[ b ];\ \mathit{lo}[ b ] \gets
\infty;\ \text{mark } b \text{ not in use} \cr
5 & \qquad \textbf{foreach}\ ( k , x ) \in B[ b ]\ \textbf{do}
\ \text{push } ( k , x ) \text{ on } B[ \mathrm{bucket}( k ) ]
\text{, updating } \mathit{lo} \text{ and the mask} \cr
6 & \qquad B[ b ] \gets \emptyset;\ b \gets \mathrm{bucket}( \ell )
\cr
7 & \quad \textbf{else}\ \ell \gets \ell \text{ with its last digit}
\text{ set to } b \cr
8 & \quad ( k , x ) \gets \text{the pair popped from } B[ b ] \cr
9 & \quad \textbf{if}\ B[ b ] = \emptyset\ \textbf{then}
\ \mathit{lo}[ b ] \gets \infty;\ \text{mark } b \text{ not in use}
\cr
10 & \quad n \gets n - 1;\ \textbf{return}\ x
\end{array}}
\]
- Precondition
- the queue is not empty
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
pushes \( x \) with the key \( k \), in \( O( 1 ) \) time
In pseudocode (Ahuja, Mehlhorn, Orlin and Tarjan, beyond the book), \( \mathit{lo}[ b ] \) the least key of the bucket \( b \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{push}( x , k ) \cr
2 & \quad b \gets \mathrm{bucket}( k );\ \text{push } ( k , x )
\text{ on } B[ b ];\ \text{mark } b \text{ in use} \cr
3 & \quad \mathit{lo}[ b ] \gets \min\{ \mathit{lo}[ b ] , k \};\ n
\gets n + 1 \cr
4 & \textbf{function}\ \mathrm{bucket}( k ) \cr
5 & \quad r \gets \text{the digit of the highest bit of } k \oplus
\ell \text{, 0 if } k = \ell \cr
6 & \quad \textbf{return}\ 2^B r + \text{the digit } r \text{ of } k
\end{array}}
\]
- Precondition
- \( k \) is not smaller than any key extracted, by pop() or extractBelow(), or read by top() and topKey() (any key before the first of them and after clear())
template<class T, std::integral K = std::uint32_t, unsigned B = 4, class A = std::allocator< T >, class Policy = NoObservers>
the keys pushed next may start from \( k \), the items placed again for \( \ell = k \), in \( O( n + 2^B W / B ) \) time
In pseudocode (beyond the book), with \( \mathrm{bucket}() \) of push():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{rebase}( k ) \cr
2 & \quad E \gets \text{the pairs } ( k' , x ) \text{ of all the}
\text{ buckets};\ \text{empty the buckets} \cr
3 & \quad \ell \gets k;\ \text{the largest key extracted} \gets
k \cr
4 & \quad \textbf{foreach}\ ( k' , x ) \in E\ \textbf{do}\ \text{push }
( k' , x ) \text{ on } B[ \mathrm{bucket}( k' ) ]
\end{array}}
\]
- Precondition
- no key in the heap is below \( k \)