UnorderedFold

Trait UnorderedFold 

Source
pub trait UnorderedFold<M, K, V, R>
where M: SymmetricFoldMap<K, V>, K: Value + Ord, V: Value,
{ // 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§

Source

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.

Source

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.

Source

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§

Source

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)

Source

fn initial_fold(&mut self, acc: R, input: &M) -> R

Optimize the initial fold

Implementors§

Source§

impl<M, K, V, R, FAdd, FRemove, FUpdate, FInitial> UnorderedFold<M, K, V, R> for ClosureFold<M, K, V, R, FAdd, FRemove, FUpdate, FInitial>
where M: SymmetricFoldMap<K, V>, K: Value + Ord, V: Value, R: Value, FAdd: for<'a> FnMut(R, &'a K, &'a V) -> R + 'static + NotObserver, FRemove: for<'a> FnMut(R, &'a K, &'a V) -> R + 'static + NotObserver, FUpdate: for<'a> FnMut(R, &'a K, &'a V, &'a V) -> R + 'static + NotObserver, FInitial: for<'a> FnMut(R, &'a M) -> R + 'static + NotObserver,