Simple, fast and self-contained structs for tracking whether a newly observed
u64) is greater than the largest previously observed value.
Use cases include message sequence numbers, timestamps, and other situations that present a need to quickly assess whether incoming data is "new", i.e. its numbering is larger than any previous value.
All of the structs include an
is_new function that returns
true if the
passed value is a new maximum, while simultaneously storing the new value to
check against future values.
Two of the
is_new implementations (
Map) require an
AtomicMap require only
RcIncr's interior mutability and
AtomicIncr's thread safe syncrhonization.
The cost of checking a new value is minimal: 0-2ns for the single-threaded
implementations, and ~5-10ns for
AtomicIncr, except in cases of pathological
contention. In a worst-case, nightmare scenrio benchmark for the
it's possible to induce delays of hundreds of nanoseconds. A more realistic
case of 24 threads contending to increment the atomic but yielding each iteration
resulted in checks in the ~5-10ns range.
Enabling the "nightly" feature (on by default) allows the use of
as the backing storage for
AtomicUsize otherwise). Also,
nightly is required to run the benchmarks.
Enabling the "fnv" feature will use a Fowler-Noll-Vo hash function from the
crate for the
HashMap used by
AtomicMap. FNV is faster than the
default hasher but provides no protection against malicious inputs.
A self-contained struct for quickly checking whether a newly observed value is greater than any previously observed value.
A map interface allowing fast checks of whether a newly observed value is greater than any previously observed value for a given key.