ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Algebra.h File Reference

The algebra of the aggregates, beyond the book: the concepts by which a structure that keeps a combination of values (a prefix sum, the aggregate of a window, the augmentation of a tree) chooses its update rule at compile time (see The algebra of the aggregates). More...

#include <concepts>
#include <cstddef>
#include <limits>
#include <type_traits>

Go to the source code of this file.

Classes

struct  ADS::SumOf< T >
 the abelian group of the sums of T, of identity T() More...
struct  ADS::MinOf< T >
 the selective commutative monoid of the least value of T, of identity \( +\infty \) if T has it, its largest value otherwise More...
struct  ADS::MaxOf< T >
 the selective commutative monoid of the largest value of T, of identity \( -\infty \) if T has it, its least value otherwise More...

Namespaces

namespace  ADS

Concepts

concept  ADS::Monoid
 a monoid on G::Value: the identity G::identity() and the associative operation G::combine( a , b )
concept  ADS::CommutativeMonoid
 a monoid whose operation commutes, by the opt-in G::commutative
concept  ADS::Group
 a monoid with the inverse G::inverse( a ), i.e., combine( inverse( a ) , a ) and combine( a , inverse( a ) ) are the identity
concept  ADS::AbelianGroup
 a group whose operation commutes
concept  ADS::Selective
 a monoid whose combine( a , b ) is always \( a \) or \( b \), by the opt-in G::selective
concept  ADS::Action
 a monoid of the maps A::Map acting on the values of the monoid G: the identity map A::id(), the composition A::compose( f , g ) (first \( g \), then \( f \)), and A::apply( f , a , n ), the map applied to the aggregate \( a \) of \( n \) values

Variables

template<class G>
constexpr bool ADS::exact_v
 whether the values of G are exact, false for the floating point types, whose groups drift by rounding when a value leaves by its inverse

Detailed description

The algebra of the aggregates, beyond the book: the concepts by which a structure that keeps a combination of values (a prefix sum, the aggregate of a window, the augmentation of a tree) chooses its update rule at compile time (see The algebra of the aggregates).

An algebra G is a type with static members, as the augmentations of JoinTree [see JoinTree.h], of which these are refinements by opt-in members:

  • Monoid< G >: G::identity() and the associative G::combine( a , b ) on G::Value; a structure updates an aggregate by recombining the parts that a change touched;
  • CommutativeMonoid< G >: also G::commutative, true, so that a value may be combined into an aggregate wherever it stands;
  • Group< G >: also G::inverse( a ), so that a value leaves an aggregate by one combination with its inverse (subtract-on-evict, the point update of a prefix sum by its difference);
  • AbelianGroup< G >: both;
  • Selective< G >: also G::selective, true, when combine( a , b ) is always \( a \) or \( b \) (the least, the largest, the first), so that an aggregate of a window is kept by a monotone deque;
  • Action< A , G >: a monoid of maps A::Map on G::Value, of identity A::id(), composition A::compose( f , g ) (first \( g \), then \( f \)) and A::apply( f , a , n ), the map applied to the aggregate \( a \) of \( n \) values (the lazy updates of a range);
  • exact_v< G >: whether the values are exact, false for the floating point types, whose groups accumulate rounding errors and need a periodic recomputation.

SumOf< T > (the abelian group of the sums), MinOf< T > and MaxOf< T > (the selective commutative monoids of the least and of the largest value, of identity the largest and the least value of T) are the algebras that the structures of ADS use most. A type with the members from() of an augmentation of JoinTree and these is both.

See also
P. M. Fenwick, A new data structure for cumulative frequency tables, Software: Practice and Experience 24(3), 327-336, 1994, doi:10.1002/spe.4380240306
K. Tangwongsan, M. Hirzel, S. Schneider, In-order sliding-window aggregation in worst-case constant time, The VLDB Journal 30(6), 933-957, 2021, doi:10.1007/s00778-021-00668-3
M. Budiu, T. Chajed, F. McSherry, L. Ryzhyk, V. Tannen, DBSP: automatic incremental view maintenance for rich query languages, Proceedings of the VLDB Endowment 16(7), 1601-1614, 2023, doi:10.14778/3587136.3587137
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa