running_buffer.rs
Data types for variables of which you want to monitor their changing state.
RunningBuffer
a RunningBuffer is a non-allocated fixed-length FILO container. Useful for example if you want to keep track of the N most recent values something has had.
It keeps track of the most recent N entries.
let a = new;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let single_entry = a.pushed;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let two_entries = single_entry.pushed;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
If more entries are added than it is long, then it starts discarding old entries.
History
a History keeps track of how a value changes over time.
Its focus is on giving the ability to compare recent history with longer-duration history.
It saves N_MOST_RECENT values in a RunningBuffer exactly, and in addition keeps cumulative and total amount of value as well.
This way both recent and total historical values can be assessed and compared.
let mut s = new;
assert_eq!;
assert_eq!;
assert_eq!;
s.push;
assert_eq!;
assert_eq!;
assert_eq!;
s.push;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// Only keeps 2 most recent, other only as cumulative.
s.push;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
the CUM type.
As keeping a very long history might run out of bounds of the variable type T, a separate type CUM is used to store long-term cumulative data.
The only requirement is for T to be transformable into CUM.
For example, I want to record instances of u32. If I record history.pushed(4_294_967_200).pushed(500000), u32 would overflow.
By taking the CUM type as u64, you can keep the size of the History smaller than if you were to store all instances as u64, while still having an accurate cumulative number.