Struct hydroflow::util::monotonic_map::MonotonicMap
source · pub struct MonotonicMap<K, V>where
K: PartialOrd,{ /* private fields */ }
Expand description
A map-like interface which in reality only stores one value at a time. The keys must be
monotonically increasing (i.e. timestamps). For Hydroflow, this allows state to be stored which
resets each tick by using the tick counter as the key. In the generic Map
case it can be
swapped out for a true map to allow processing of multiple ticks of data at once.
Implementations§
source§impl<K, V> MonotonicMap<K, V>where
K: PartialOrd,
impl<K, V> MonotonicMap<K, V>where
K: PartialOrd,
sourcepub fn new_init(val: V) -> Self
pub fn new_init(val: V) -> Self
Creates a new MonotonicMap
initialized with the given value. The
vaue will be Clear
ed before it is accessed.
sourcepub fn get_mut_with(&mut self, key: K, init: impl FnOnce() -> V) -> &mut V
pub fn get_mut_with(&mut self, key: K, init: impl FnOnce() -> V) -> &mut V
Inserts the value using the function if new key
is strictly later than the current key.
source§impl<K, V> MonotonicMap<K, V>where
K: PartialOrd,
V: Default,
impl<K, V> MonotonicMap<K, V>where
K: PartialOrd,
V: Default,
sourcepub fn get_mut_default(&mut self, key: K) -> &mut V
pub fn get_mut_default(&mut self, key: K) -> &mut V
Gets a mutable reference to the inner value. If key
is strictly later than the existing
key, the value will be reset to Default::default
.
source§impl<K, V> MonotonicMap<K, V>where
K: PartialOrd,
V: Clear,
impl<K, V> MonotonicMap<K, V>where
K: PartialOrd,
V: Clear,
sourcepub fn get_mut_clear(&mut self, key: K) -> &mut V
pub fn get_mut_clear(&mut self, key: K) -> &mut V
Gets a mutable reference to the inner value. If key
is strictly later than the existing
key, the value will be cleared via the Clear
trait.
Trait Implementations§
source§impl<K, V: Clone> Clone for MonotonicMap<K, V>where
K: PartialOrd + Clone,
impl<K, V: Clone> Clone for MonotonicMap<K, V>where
K: PartialOrd + Clone,
source§fn clone(&self) -> MonotonicMap<K, V>
fn clone(&self) -> MonotonicMap<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more