pub fn parallel_partition<T, I, K, V, KeyFn, ValFn>(
items: I,
key_fn: KeyFn,
val_fn: ValFn,
) -> HashMap<K, Vec<V>>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, |(_, v)| v);
assert_eq!(groups[&1].len(), 2);
assert_eq!(groups[&2].len(), 2);