a QUEUE of values of the monoid G with the aggregate of its values, each operation in \( O( 1 ) \) time, amortized or in the worst case by Policy
More...
#include <ADS/queue/SlidingAggregate.h>
|
| using | Value = typename G::Value |
| | the values
|
| using | Item = Value |
| | the items of the QUEUE
|
| using | Algebra = G |
| | their algebra
|
|
| bool | empty (void) const |
| | true if there is no item
|
| std::size_t | size (void) const |
| | the number \( n \) of items
|
| void | enqueue (const Value &x) |
| | \( x \) at the back
|
| Value | dequeue (void) |
| | removes the item at the front and returns it
|
| const Value & | top (void) const |
| | the item at the front
|
| Value | aggregate (void) const |
| | the aggregate \( x_1 \oplus \cdots \oplus x_n \) of the items from the front to the back, the identity if there is none
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( x ) on the items from the front to the back, \( O( n ) \)
|
| void | clear (void) |
| | removes all the items
|
| std::size_t | period (void) const |
| | the removals after which a group of floating point values is rebuilt from its items (subtract-on-evict only)
|
| void | period (std::size_t p) |
| | sets the period of the rebuilding to \( p \)
|
|
| static constexpr window_kind | kind = detail::windowKindOf< G , Policy >() |
| | the algorithm chosen by the algebra and the policy
|
template<Monoid G, class Policy = Amortized>
class ADS::SlidingAggregate< G, Policy >
a QUEUE of values of the monoid G with the aggregate of its values, each operation in \( O( 1 ) \) time, amortized or in the worst case by Policy
◆ Algebra
template<Monoid G, class Policy = Amortized>
◆ Item
template<Monoid G, class Policy = Amortized>
◆ Value
template<Monoid G, class Policy = Amortized>
◆ aggregate()
template<Monoid G, class Policy = Amortized>
the aggregate \( x_1 \oplus \cdots \oplus x_n \) of the items from the front to the back, the identity if there is none
◆ clear()
template<Monoid G, class Policy = Amortized>
◆ dequeue()
template<Monoid G, class Policy = Amortized>
removes the item at the front and returns it
In pseudocode (Two-Stacks Lite, beyond the book), \( q \) the items, \( m \) the length of the first part, \( S \) the aggregates of its suffixes and \( b \) that of the rest:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{dequeue}() \cr
2 & \quad \textbf{if}\ m = 0\ \textbf{then} \cr
3 & \qquad s \gets e;\ \textbf{for}\ k \gets |q| - 1\ \textbf{downto}
\ 0\ \textbf{do}\ s \gets q_k \oplus s;\ \mathrm{push}( S , s )
\cr
4 & \qquad m \gets |q|;\ b \gets e \cr
5 & \quad \mathrm{pop}( S );\ m \gets m - 1 \cr
6 & \quad \textbf{return}\ \text{the first item of } q,
\text{ removed}
\end{array}}
\]
and the aggregate is \( \mathrm{top}( S ) \oplus b \).
- Precondition
- the window is not empty
- Postcondition
- one item less
◆ empty()
template<Monoid G, class Policy = Amortized>
◆ enqueue()
template<Monoid G, class Policy = Amortized>
\( x \) at the back
In pseudocode (beyond the book), the monotone deque \( C \) of the candidates of a selective monoid:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{enqueue}( x ) \cr
2 & \quad \text{append } x \text{ to the items} \cr
3 & \quad \textbf{while}\ C \ne \emptyset\ \textbf{and}
\ \mathrm{last}( C ) \oplus x = x\ \textbf{do}
\ \text{remove } \mathrm{last}( C ) \cr
4 & \quad \text{append } x \text{ to } C
\end{array}}
\]
- Postcondition
- one item more
◆ forEach()
template<Monoid G, class Policy = Amortized>
template<class F>
f( x ) on the items from the front to the back, \( O( n ) \)
◆ period() [1/2]
template<Monoid G, class Policy = Amortized>
sets the period of the rebuilding to \( p \)
- Precondition
- \( p \ge 1 \)
◆ period() [2/2]
template<Monoid G, class Policy = Amortized>
the removals after which a group of floating point values is rebuilt from its items (subtract-on-evict only)
◆ size()
template<Monoid G, class Policy = Amortized>
the number \( n \) of items
◆ top()
template<Monoid G, class Policy = Amortized>
the item at the front
- Precondition
- the window is not empty
◆ kind
template<Monoid G, class Policy = Amortized>
the algorithm chosen by the algebra and the policy
The documentation for this class was generated from the following file: