Expand description
§Rolling Max
A rolling accumulator that tracks the largest value in a fixed size window.
- Push is amortized O(1).
- Max is O(1).
- There are no heap allocations.
Like std::collections::BinaryHeap, RollingMax exposes
a “maximum only” API. A rolling minimum can be found by using
core::cmp::Reverse within a RollingMax.
use core::cmp::Reverse;
use high_roller::rolling_max::RollingMax;
type RollingMin<T, const WINDOW: usize> = RollingMax<Reverse<T>, WINDOW>;The example below shows how this might be used to publish telemetry for the highest latency event among the 100 most recent samples.
let events = stream.map(|event| network_latency_us(&event));
let mut window: RollingMax<u32, 100> = RollingMax::new();
for latency in events {
window.push(latency);
window.max().copied().map(emit_network_telemetry);
}
Structs§
- Rolling
Max - Rolling Max