pub enum WindowState {
EventCount {
timestamps: VecDeque<i64>,
},
ValueCount {
entries: VecDeque<(i64, String)>,
},
Temporal {
rule_hits: HashMap<String, VecDeque<i64>>,
},
NumericAgg {
entries: VecDeque<(i64, f64)>,
},
}Expand description
Per-group mutable state within a time window.
Each variant matches the type of aggregation being performed.
Variants§
EventCount
For event_count: timestamps of matching events.
ValueCount
For value_count: (timestamp, field_value) pairs.
Temporal
For temporal / temporal_ordered: rule_ref -> list of hit timestamps.
NumericAgg
For value_sum, value_avg, value_percentile, value_median:
(timestamp, numeric_value) pairs.
Implementations§
Source§impl WindowState
impl WindowState
Sourcepub fn new_for(corr_type: CorrelationType) -> Self
pub fn new_for(corr_type: CorrelationType) -> Self
Create a new empty window state for the given correlation type.
Sourcepub fn latest_timestamp(&self) -> Option<i64>
pub fn latest_timestamp(&self) -> Option<i64>
Returns the most recent timestamp in this window, or None if empty.
Sourcepub fn earliest_timestamp(&self) -> Option<i64>
pub fn earliest_timestamp(&self) -> Option<i64>
Returns the oldest timestamp in this window, or None if empty.
Entries are appended in arrival order, so the front of each deque holds the earliest timestamp. For temporal state the minimum is taken across all per-rule deques.
Sourcepub fn truncate_oldest(&mut self, cap: usize, preserve_front: bool)
pub fn truncate_oldest(&mut self, cap: usize, preserve_front: bool)
Enforce a per-group entry cap by dropping the oldest entries.
cap is the maximum number of retained entries (clamped to at least
1). For temporal state the cap applies to each referenced rule’s hit
deque independently, since the deques are what grow with event rate.
When preserve_front is set (session windows), the oldest entry is
kept and truncation happens behind it: the front entry anchors the
session’s total-span cap (timespan), so dropping it would silently
let the session extend past the cap. Truncation can only under-count;
it never extends a window.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all entries from the window state (used by CorrelationAction::Reset).
Sourcepub fn push_event_count(&mut self, ts: i64)
pub fn push_event_count(&mut self, ts: i64)
Record an event_count hit.
Sourcepub fn push_value_count(&mut self, ts: i64, value: String)
pub fn push_value_count(&mut self, ts: i64, value: String)
Record a value_count hit with the field value.
Sourcepub fn push_temporal(&mut self, ts: i64, rule_ref: &str)
pub fn push_temporal(&mut self, ts: i64, rule_ref: &str)
Record a temporal hit for a specific rule reference.
Sourcepub fn push_numeric(&mut self, ts: i64, value: f64)
pub fn push_numeric(&mut self, ts: i64, value: f64)
Record a numeric aggregation value.
Sourcepub fn check_condition(
&self,
condition: &CompiledCondition,
corr_type: CorrelationType,
rule_refs: &[String],
extended_expr: Option<&ConditionExpr>,
) -> Option<f64>
pub fn check_condition( &self, condition: &CompiledCondition, corr_type: CorrelationType, rule_refs: &[String], extended_expr: Option<&ConditionExpr>, ) -> Option<f64>
Evaluate the window state against the correlation condition.
Returns Some(aggregated_value) if the condition is satisfied,
None otherwise.
For temporal correlations with an extended expression, the expression is evaluated against the set of rules that have fired in the window.
Trait Implementations§
Source§impl Clone for WindowState
impl Clone for WindowState
Source§fn clone(&self) -> WindowState
fn clone(&self) -> WindowState
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more