Struct accumulator::Accumulator
[−]
[src]
pub struct Accumulator<Key, Value> where
Key: PartialOrd + Ord + Clone,
Value: Clone, { /* fields omitted */ }
A key-value store limited by size or time, allowing accumulation of multiple values under a single key.
Methods
impl<Key: PartialOrd + Ord + Clone, Value: Clone + Eq + Hash> Accumulator<Key, Value>
[src]
fn with_capacity(quorum: usize, capacity: usize) -> Accumulator<Key, Value>
Constructor for capacity based Accumulator
.
quorum
defines the count at and above which add()
will return Some()
.
fn with_duration(quorum: usize, duration: Duration) -> Accumulator<Key, Value>
Constructor for time based Accumulator
.
quorum
defines the count at and above which add()
will return Some()
.
fn contains_key(&self, key: &Key) -> bool
Returns whether key
exists in the accumulator or not.
fn is_quorum_reached(&self, key: &Key) -> bool
Returns whether key
exists and has accumulated quorum
or more corresponding values.
fn add(&mut self, key: Key, value: Value) -> Option<&HashSet<Value>>
Adds a key-value pair.
Returns the corresponding values for key
if quorum
or more values have been accumulated,
otherwise returns None
.
fn get(&self, key: &Key) -> Option<&HashSet<Value>>
Returns the values accumulated under key
, or None
if key
doesn't exist.
fn delete(&mut self, key: &Key)
Removes key
and all corresponding accumulated values.
fn cache_size(&mut self) -> usize
Returns the size of the accumulator, i.e. the number of keys held.
fn set_quorum(&mut self, new_size: usize)
Sets a new value for quorum
.
This has immediate effect, even for existing key-value entries.
fn quorum(&self) -> usize
Returns the current value for quorum
.