|
| | 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()
|
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
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 > && ... ) )
the empty queue, the static observers o...
template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
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
template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
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 \)
template<class T, std::integral K = int, BucketTie Tie = LargestSecondKey, class Policy = NoObservers>
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