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

The aggregate of a sliding window, beyond the book: a QUEUE of values of the monoid G [see Algebra.h] with aggregate(), the combination \( x_1 \oplus \cdots \oplus x_n \) of its values from the front to the back, in \( O( 1 ) \) time per operation, by the algorithm that the algebra and the policy allow (see The aggregate of a sliding window): More...

#include "ADS/Algebra.h"
#include "ADS/Contract.h"
#include "ADS/Portable.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <memory>
#include <type_traits>
#include <utility>
#include <vector>
#include "ADS/queue/impl/SlidingAggregate.tpp"

Go to the source code of this file.

Classes

struct  ADS::Amortized
 the policy of a sliding window whose operations cost \( O( 1 ) \) amortized time, by the algorithm that suits the algebra More...
struct  ADS::WorstCase
 the policy of a sliding window whose operations cost \( O( 1 ) \) time in the worst case More...
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 More...

Namespaces

namespace  ADS

Enumerations

enum class  ADS::window_kind { ADS::window_kind::subtract_on_evict , ADS::window_kind::monotone_deque , ADS::window_kind::two_stacks , ADS::window_kind::real_time }
 the algorithm of a sliding window [see SlidingAggregate] More...

Detailed description

The aggregate of a sliding window, beyond the book: a QUEUE of values of the monoid G [see Algebra.h] with aggregate(), the combination \( x_1 \oplus \cdots \oplus x_n \) of its values from the front to the back, in \( O( 1 ) \) time per operation, by the algorithm that the algebra and the policy allow (see The aggregate of a sliding window):

  • with Amortized, the default, and a group G the aggregate is kept whole, an item entering by \( s \gets s \oplus x \) and leaving by \( s \gets x^{-1} \oplus s \) (subtract-on-evict, \( O( 1 ) \)), and rebuilt from the items every period() removals when the values are not exact (floating point), \( O( 1 ) \) amortized;
  • with Amortized and a selective G whose values compare by == (the least, the largest), a deque of the candidates keeps those items that no later item absorbs, so that the front candidate is the aggregate (the monotone deque, \( O( 1 ) \) amortized);
  • with Amortized and any other monoid, the items are in one deque whose first part has the aggregates of its suffixes, the rest one aggregate, and a removal from an empty first part makes all the items the first part (Two-Stacks Lite of Tangwongsan, Hirzel and Schneider, \( O( 1 ) \) amortized, one combination per item and per move);
  • with WorstCase, for any monoid, the real-time queue of Hood and Melville [see RealTimeMinQueue.h] on stacks whose cells hold the aggregate of the cells below them, its rotation three moves per operation, so that every operation costs \( O( 1 ) \) in the worst case (the guarantee of DABA Lite by another route).

kind tells which one was chosen. MinQueue< T > and RealTimeMinQueue< T > [see MinQueue.h, RealTimeMinQueue.h] compute what SlidingAggregate< MinOf< T > > and SlidingAggregate< MinOf< T > , WorstCase > do, and stay as they are, since they also take an order that is an object rather than a type and give the least item by reference.

The contracts [see Contract.h]: top() and dequeue() need a window that is not empty; enqueue() ensures one item more, dequeue() one less. The operations are defined in SlidingAggregate.tpp.

See also
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
R. Hood, R. Melville, Real-time queue operations in pure LISP, Information Processing Letters 13(2), 50-54, 1981, doi:10.1016/0020-0190(81)90030-2
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa