pub struct IncrementalSlidingWindow { /* private fields */ }Expand description
A sliding window optimized for aggregations with O(1) updates
Instead of recomputing aggregations over all events on each emit, this window maintains running totals that are updated incrementally:
- Adding an event: O(1) update to aggregates
- Removing expired events: O(k) where k is expired count
- Getting aggregates: O(1)
This is ~10-100x faster than recomputing for large windows.
Implementations§
Source§impl IncrementalSlidingWindow
impl IncrementalSlidingWindow
Sourcepub fn new(
window_size: Duration,
slide_interval: Duration,
field: impl Into<String>,
) -> Self
pub fn new( window_size: Duration, slide_interval: Duration, field: impl Into<String>, ) -> Self
Create a new incremental sliding window
Sourcepub fn add(&mut self, event: SharedEvent) -> Option<IncrementalAggregates>
pub fn add(&mut self, event: SharedEvent) -> Option<IncrementalAggregates>
Add an event, returning aggregates if slide interval reached
Sourcepub fn current_aggregates(&mut self) -> IncrementalAggregates
pub fn current_aggregates(&mut self) -> IncrementalAggregates
Get current aggregates without emitting
Sourcepub fn events(&self) -> impl Iterator<Item = &SharedEvent>
pub fn events(&self) -> impl Iterator<Item = &SharedEvent>
Get events in the current window (for patterns that need event access)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for IncrementalSlidingWindow
impl RefUnwindSafe for IncrementalSlidingWindow
impl Send for IncrementalSlidingWindow
impl Sync for IncrementalSlidingWindow
impl Unpin for IncrementalSlidingWindow
impl UnsafeUnpin for IncrementalSlidingWindow
impl UnwindSafe for IncrementalSlidingWindow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more