|
| 1 | +use alga::general::Operator; |
| 2 | +use std::ops::Range; |
| 3 | + |
| 4 | +/// An abstract data type which maintains a time-ordered sliding window. |
| 5 | +pub trait TimeWindow<Time, Value, BinOp> |
| 6 | +where |
| 7 | + Time: Ord, |
| 8 | + BinOp: Operator, |
| 9 | +{ |
| 10 | + /// Returns an empty window. |
| 11 | + fn new() -> Self; |
| 12 | + /// Inserts the tuple `(t,v)` at time `t` into the window. |
| 13 | + fn insert(&mut self, t: Time, v: Value); |
| 14 | + /// Removes the tuple `(t,v)` at time `t` from the window (if any). |
| 15 | + fn evict(&mut self, t: Time); |
| 16 | + /// Combines the values in time order and returns the result, e.g., `1+v1+v2+...+vn`. |
| 17 | + fn query(&self) -> Value; |
| 18 | +} |
| 19 | + |
| 20 | +/// An abstract data type which maintains a fifo-ordered sliding window. |
| 21 | +pub trait FifoWindow<Value, BinOp> |
| 22 | +where |
| 23 | + BinOp: Operator, |
| 24 | +{ |
| 25 | + /// Returns an empty window. |
| 26 | + fn new() -> Self; |
| 27 | + /// Inserts a value at the back of the window. |
| 28 | + fn push(&mut self, v: Value); |
| 29 | + /// Removes a value at the front of the window (if any). |
| 30 | + fn pop(&mut self); |
| 31 | + /// Combines the values in fifo order and returns the result, e.g., `1+v1+v2+...+vn`. |
| 32 | + fn query(&self) -> Value; |
| 33 | +} |
| 34 | + |
| 35 | +/// An abstract data type which maintains sliding sub-window aggregates. |
| 36 | +pub trait SubWindow<Time, Value> |
| 37 | +where |
| 38 | + Time: Ord, |
| 39 | +{ |
| 40 | + /// Returns the aggregate of a subwindow. |
| 41 | + fn range_query(&self, range: Range<Time>) -> Value; |
| 42 | +} |
0 commit comments