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

the combination by the commutative monoid G of the values of the pairs of a dictionary, kept by its events; for an abelian group of inexact values, recomputed from the structure bound every Period changes More...

#include <ADS/tree/MaterializedAggregate.h>

Public types

enum class  Kind { Group , Selective , Monoid }
 how the events update the aggregate More...
using Value = typename G::Value
 the type of the aggregate

Public member functions

 MaterializedAggregate (void)=default
 the identity, with no structure bound
template<detail::pair_visitable S>
 MaterializedAggregate (const S &s)
 the aggregate of \( s \), bound
template<detail::pair_visitable S>
void bind (const S &s)
 \( s \) bound, and the aggregate recomputed from it, in \( O( m ) \) (\( O( m \log m ) \) if selective)
template<class H, class K, class V>
void on (const mod::Inserted< H, K, V > &e)
 the pair \( ( k , v ) \) inserted: \( a \gets a \otimes \mathrm{from}( k , v ) \), or the value added to the multiset
template<class H, class K, class V>
void on (const mod::Erased< H, K, V > &e) noexcept
 the pair \( ( k , v ) \) erased: \( a \gets a \otimes \mathrm{from}( k , v )^{-1} \), or the value taken out of the multiset, or the aggregate stale
template<class H, class V>
void on (const mod::Assigned< H, V > &e)
 the value of the key \( h \) changed from \( v \) to \( w \): \( a \gets a \otimes \mathrm{from}( h , w ) \otimes \mathrm{from}( h , v )^{-1} \), or the two values exchanged in the multiset, or the aggregate stale
void on (const mod::Cleared &) noexcept
 the structure emptied: the identity
void on (const mod::Rebuilt &) noexcept
 anything may have changed: the aggregate stale
Value value (void) const
 the aggregate, recomputed from the structure bound if stale
bool stale (void) const
 whether the next value() recomputes
bool bound (void) const
 whether a structure is bound
std::size_t recomputations (void) const
 the recomputations made so far
template<detail::pair_visitable S>
bool audit (const S &s) const
 whether the aggregate (if not stale) is that of \( s \): equal for exact values, within a relative tolerance of \( 10^{-9} \) for those of a floating type

Static public attributes

static constexpr Kind kind
 the kind of G

Detailed description

template<class G, std::size_t Period = 1024>
requires CommutativeMonoid< G >
class ADS::MaterializedAggregate< G, Period >

the combination by the commutative monoid G of the values of the pairs of a dictionary, kept by its events; for an abelian group of inexact values, recomputed from the structure bound every Period changes

Member typedef documentation

◆ Value

template<class G, std::size_t Period = 1024>
using ADS::MaterializedAggregate< G, Period >::Value = typename G::Value

the type of the aggregate

Member enumeration documentation

◆ Kind

template<class G, std::size_t Period = 1024>
enum class ADS::MaterializedAggregate::Kind
strong

how the events update the aggregate

Enumerator
Group 

by the value and its inverse

Selective 

by the multiset of the values

Monoid 

by a combination, or a recomputation

Constructor and destructor documentation

◆ MaterializedAggregate() [1/2]

template<class G, std::size_t Period = 1024>
ADS::MaterializedAggregate< G, Period >::MaterializedAggregate ( void )
default

the identity, with no structure bound

◆ MaterializedAggregate() [2/2]

template<class G, std::size_t Period = 1024>
template<detail::pair_visitable S>
ADS::MaterializedAggregate< G, Period >::MaterializedAggregate ( const S & s)
inlineexplicit

the aggregate of \( s \), bound

Member function documentation

◆ audit()

template<class G, std::size_t Period = 1024>
template<detail::pair_visitable S>
bool ADS::MaterializedAggregate< G, Period >::audit ( const S & s) const
nodiscard

whether the aggregate (if not stale) is that of \( s \): equal for exact values, within a relative tolerance of \( 10^{-9} \) for those of a floating type

◆ bind()

template<class G, std::size_t Period = 1024>
template<detail::pair_visitable S>
void ADS::MaterializedAggregate< G, Period >::bind ( const S & s)

\( s \) bound, and the aggregate recomputed from it, in \( O( m ) \) (\( O( m \log m ) \) if selective)

◆ bound()

template<class G, std::size_t Period = 1024>
bool ADS::MaterializedAggregate< G, Period >::bound ( void ) const
inlinenodiscard

whether a structure is bound

◆ on() [1/5]

template<class G, std::size_t Period = 1024>
template<class H, class V>
void ADS::MaterializedAggregate< G, Period >::on ( const mod::Assigned< H, V > & e)

the value of the key \( h \) changed from \( v \) to \( w \): \( a \gets a \otimes \mathrm{from}( h , w ) \otimes \mathrm{from}( h , v )^{-1} \), or the two values exchanged in the multiset, or the aggregate stale

In pseudocode (beyond the book), with the names of on() of Inserted:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{assigned}( h , v , w ) \cr 2 & \quad \textbf{if}\ G \text{ is an abelian group}\ \textbf{then} \cr 3 & \qquad \textbf{if}\ \textbf{not}\ s\ \textbf{then}\ a \gets a \otimes \mathrm{from}( h , w ) \otimes \mathrm{from}( h , v )^{-1};\ \mathrm{changed}() \cr 4 & \quad \textbf{else if}\ G \text{ is selective}\ \textbf{then} \cr 5 & \qquad M \gets M \cup \{ \mathrm{from}( h , w ) \}; \ \text{take one copy of } \mathrm{from}( h , v ) \text{ out of } M \text{, if any};\ a \gets \min_\prec M \cr 6 & \quad \textbf{else}\ s \gets \textbf{true} \end{array}} \]

◆ on() [2/5]

template<class G, std::size_t Period = 1024>
void ADS::MaterializedAggregate< G, Period >::on ( const mod::Cleared & )
noexcept

the structure emptied: the identity

◆ on() [3/5]

template<class G, std::size_t Period = 1024>
template<class H, class K, class V>
void ADS::MaterializedAggregate< G, Period >::on ( const mod::Erased< H, K, V > & e)
noexcept

the pair \( ( k , v ) \) erased: \( a \gets a \otimes \mathrm{from}( k , v )^{-1} \), or the value taken out of the multiset, or the aggregate stale

In pseudocode (beyond the book), with the names of on() of Inserted:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{erased}( k , v ) \cr 2 & \quad \textbf{if}\ G \text{ is an abelian group}\ \textbf{then} \cr 3 & \qquad \textbf{if}\ \textbf{not}\ s\ \textbf{then}\ a \gets a \otimes \mathrm{from}( k , v )^{-1};\ \mathrm{changed}() \cr 4 & \quad \textbf{else if}\ G \text{ is selective}\ \textbf{then} \cr 5 & \qquad \text{take one copy of } \mathrm{from}( k , v ) \text{ out } \text{of } M \text{, if any};\ a \gets \min_\prec M \text{, or the identity if } M = \emptyset \cr 6 & \quad \textbf{else}\ s \gets \textbf{true} \end{array}} \]

◆ on() [4/5]

template<class G, std::size_t Period = 1024>
template<class H, class K, class V>
void ADS::MaterializedAggregate< G, Period >::on ( const mod::Inserted< H, K, V > & e)

the pair \( ( k , v ) \) inserted: \( a \gets a \otimes \mathrm{from}( k , v ) \), or the value added to the multiset

In pseudocode (beyond the book), \( a \) the aggregate, \( M \) the multiset of a selective G in the order \( \prec \) of Before, \( s \) whether \( a \) is stale and \( d \) the changes since the last recomputation:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{inserted}( k , v ) \cr 2 & \quad \textbf{if}\ G \text{ is selective}\ \textbf{then} \ M \gets M \cup \{ \mathrm{from}( k , v ) \};\ a \gets \min_\prec M \cr 3 & \quad \textbf{else if}\ \textbf{not}\ s\ \textbf{then}\ a \gets a \otimes \mathrm{from}( k , v );\ \mathrm{changed}() \cr 4 & \textbf{procedure}\ \mathrm{changed}()\quad \triangleright \ \text{a group of inexact values, } \mathit{Period} > 0 \cr 5 & \quad d \gets d + 1 \cr 6 & \quad \textbf{if}\ d \ge \mathit{Period}\ \textbf{and} \ \text{a structure is bound}\ \textbf{then}\ s \gets \textbf{true} \end{array}} \]

◆ on() [5/5]

template<class G, std::size_t Period = 1024>
void ADS::MaterializedAggregate< G, Period >::on ( const mod::Rebuilt & )
inlinenoexcept

anything may have changed: the aggregate stale

◆ recomputations()

template<class G, std::size_t Period = 1024>
std::size_t ADS::MaterializedAggregate< G, Period >::recomputations ( void ) const
inlinenodiscard

the recomputations made so far

◆ stale()

template<class G, std::size_t Period = 1024>
bool ADS::MaterializedAggregate< G, Period >::stale ( void ) const
inlinenodiscard

whether the next value() recomputes

◆ value()

template<class G, std::size_t Period = 1024>
Value ADS::MaterializedAggregate< G, Period >::value ( void ) const
nodiscard

the aggregate, recomputed from the structure bound if stale

In pseudocode (beyond the book), with the names of on() of Inserted and \( S \) the structure bound:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{value}() \cr 2 & \quad \textbf{if}\ s\ \textbf{then} \cr 3 & \qquad \textbf{if}\ G \text{ is selective}\ \textbf{then}\ M \gets \{ \mathrm{from}( k , v ) : ( k , v ) \in S \};\ a \gets \min_\prec M \text{, or the identity} \cr 4 & \qquad \textbf{else}\ a \gets \text{the identity}; \ \textbf{foreach}\ ( k , v ) \in S\ \textbf{do}\ a \gets a \otimes \mathrm{from}( k , v ) \cr 5 & \qquad s \gets \textbf{false};\ d \gets 0 \cr 6 & \quad \textbf{return}\ a \end{array}} \]

Precondition
a structure is bound, if stale

Member data documentation

◆ kind

template<class G, std::size_t Period = 1024>
Kind ADS::MaterializedAggregate< G, Period >::kind
staticconstexpr
Initial value:
=
: ( Selective< G > && std::equality_comparable< Value > ) ? Kind::Selective
Kind
how the events update the aggregate
Definition MaterializedAggregate.h:116
@ Group
by the value and its inverse
Definition MaterializedAggregate.h:117
@ Selective
by the multiset of the values
Definition MaterializedAggregate.h:118
a group whose operation commutes
Definition Algebra.h:137
a monoid on G::Value: the identity G::identity() and the associative operation G::combine( a ,...
Definition Algebra.h:117
a monoid whose combine( a , b ) is always or , by the opt-in G::selective
Definition Algebra.h:142

the kind of G


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