pub trait UnorderedFold<M, K, V, R>{
// Required methods
fn add(&mut self, acc: R, key: &K, value: &V) -> R;
fn remove(&mut self, acc: R, key: &K, value: &V) -> R;
fn revert_to_init_when_empty(&self) -> bool;
// Provided methods
fn update(&mut self, acc: R, key: &K, old: &V, new: &V) -> R { ... }
fn initial_fold(&mut self, acc: R, input: &M) -> R { ... }
}
Expand description
Defines an unordered fold for a given map, key, value and output type.
Used with IncrMap::incr_unordered_fold_with.
Implementations get &mut access to self. So you can store things in the type that implements this.
Required Methods§
Sourcefn add(&mut self, acc: R, key: &K, value: &V) -> R
fn add(&mut self, acc: R, key: &K, value: &V) -> R
How to add a key/value pair to the fold value
E.g. |acc, _, value| acc + value
for a signed integer.
Sourcefn remove(&mut self, acc: R, key: &K, value: &V) -> R
fn remove(&mut self, acc: R, key: &K, value: &V) -> R
How to remove a key/value pair from the fold value
E.g. |acc, _, value| acc - value
for a signed integer.
Sourcefn revert_to_init_when_empty(&self) -> bool
fn revert_to_init_when_empty(&self) -> bool
If we have emptied the map, can we just reset to the initial value? Or do we have to call remove() on everything that was removed?
Provided Methods§
Sourcefn update(&mut self, acc: R, key: &K, old: &V, new: &V) -> R
fn update(&mut self, acc: R, key: &K, old: &V, new: &V) -> R
Default implementation is self.add(self.remove(acc, key, old), key, new)
Sourcefn initial_fold(&mut self, acc: R, input: &M) -> R
fn initial_fold(&mut self, acc: R, input: &M) -> R
Optimize the initial fold