ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::SlidingAggregate< G, Policy > Class Template Reference

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>

Public types

using Value = typename G::Value
 the values
using Item = Value
 the items of the QUEUE
using Algebra = G
 their algebra

Public member functions

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 public attributes

static constexpr window_kind kind = detail::windowKindOf< G , Policy >()
 the algorithm chosen by the algebra and the policy

Detailed description

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

Member typedef documentation

◆ Algebra

template<Monoid G, class Policy = Amortized>
using ADS::SlidingAggregate< G, Policy >::Algebra = G

their algebra

◆ Item

template<Monoid G, class Policy = Amortized>
using ADS::SlidingAggregate< G, Policy >::Item = Value

the items of the QUEUE

◆ Value

template<Monoid G, class Policy = Amortized>
using ADS::SlidingAggregate< G, Policy >::Value = typename G::Value

the values

Member function documentation

◆ aggregate()

template<Monoid G, class Policy = Amortized>
Value ADS::SlidingAggregate< G, Policy >::aggregate ( void ) const
inlinenodiscard

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>
void ADS::SlidingAggregate< G, Policy >::clear ( void )
inline

removes all the items

◆ dequeue()

template<Monoid G, class Policy = Amortized>
Value ADS::SlidingAggregate< G, Policy >::dequeue ( void )
inline

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>
bool ADS::SlidingAggregate< G, Policy >::empty ( void ) const
inlinenodiscard

true if there is no item

◆ enqueue()

template<Monoid G, class Policy = Amortized>
void ADS::SlidingAggregate< G, Policy >::enqueue ( const Value & x)
inline

\( 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>
void ADS::SlidingAggregate< G, Policy >::forEach ( F && f) const
inline

f( x ) on the items from the front to the back, \( O( n ) \)

◆ period() [1/2]

template<Monoid G, class Policy = Amortized>
void ADS::SlidingAggregate< G, Policy >::period ( std::size_t p)
inline

sets the period of the rebuilding to \( p \)

Precondition
\( p \ge 1 \)

◆ period() [2/2]

template<Monoid G, class Policy = Amortized>
std::size_t ADS::SlidingAggregate< G, Policy >::period ( void ) const
inlinenodiscard

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>
std::size_t ADS::SlidingAggregate< G, Policy >::size ( void ) const
inlinenodiscard

the number \( n \) of items

◆ top()

template<Monoid G, class Policy = Amortized>
const Value & ADS::SlidingAggregate< G, Policy >::top ( void ) const
inlinenodiscard

the item at the front

Precondition
the window is not empty

Member data documentation

◆ kind

template<Monoid G, class Policy = Amortized>
window_kind ADS::SlidingAggregate< G, Policy >::kind = detail::windowKindOf< G , Policy >()
staticconstexpr

the algorithm chosen by the algebra and the policy


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