|
| | 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
|
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
template<class G, std::size_t Period = 1024>
template<class H, class V>
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}}
\]
template<class G, std::size_t Period = 1024>
template<class H, class K, class V>
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}}
\]
template<class G, std::size_t Period = 1024>
template<class H, class K, class V>
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}}
\]
template<class G, std::size_t Period = 1024>
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