Skip to main content

parallel_partition

Function parallel_partition 

Source
pub fn parallel_partition<T, I, K, V, KeyFn, ValFn>(
    items: I,
    key_fn: KeyFn,
    val_fn: ValFn,
) -> HashMap<K, Vec<V>>
where T: Send, K: Send + Eq + Hash + Clone, V: Send, I: ParallelIterator<Item = T>, KeyFn: Fn(&T) -> K + Sync + Send, ValFn: Fn(T) -> V + Sync + Send,
Expand description

Partition items into groups based on a key extractor.

Groups items with the same key into separate vectors. The keys must be hashable and cloneable.

§Example

use grafeo_core::execution::parallel::fold::parallel_partition;
use rayon::prelude::*;

let items = vec![(1, "a"), (2, "b"), (1, "c"), (2, "d")];
let groups = parallel_partition(items.into_par_iter(), |(k, _)| *k);

assert_eq!(groups.get(&1).unwrap(), &vec!["a", "c"]);
assert_eq!(groups.get(&2).unwrap(), &vec!["b", "d"]);