Expand description
§Sliding Window Operators
Implementation of sliding (hopping) windows for stream processing.
Sliding windows are fixed-size windows that overlap. Each event can belong to multiple windows. The window size defines the duration, and the slide defines how much each window advances.
§Example
Window size: 1 hour, Slide: 15 minutes
Window 1: [00:00, 01:00)
Window 2: [00:15, 01:15)
Window 3: [00:30, 01:30)
Window 4: [00:45, 01:45)
An event at 00:40 belongs to windows 1, 2, 3§Performance
- Each event is assigned to
ceil(size / slide)windows - Uses
SmallVec<[WindowId; 4]>to avoid heap allocation for common cases - State is stored per-window, so memory usage scales with active windows
§Usage
use laminar_core::operator::sliding_window::{
SlidingWindowAssigner, SlidingWindowOperator,
};
use laminar_core::operator::window::CountAggregator;
use std::time::Duration;
// Create a 1-hour sliding window with 15-minute slide
let assigner = SlidingWindowAssigner::new(
Duration::from_secs(3600), // 1 hour window
Duration::from_secs(900), // 15 minute slide
);
let operator = SlidingWindowOperator::new(
assigner,
CountAggregator::new(),
Duration::from_secs(60), // 1 minute grace period
);Structs§
- Sliding
Window Assigner - Sliding window assigner.
- Sliding
Window Operator - Sliding window operator.