pub fn fold_reduce<T, I, F, M>(items: I, fold_fn: F, merge_fn: M) -> TExpand description
Execute parallel fold-reduce with custom accumulator.
This is the most general form of parallel aggregation:
- Each thread gets its own accumulator (created by
T::default) fold_fnprocesses items into thread-local accumulatorsmerge_fncombines accumulators from different threads
ยงExample
use grafeo_core::execution::parallel::fold::fold_reduce;
use rayon::prelude::*;
let items = vec![1, 2, 3, 4, 5];
let sum: i32 = fold_reduce(
items.into_par_iter(),
|acc: i32, item| acc + item,
|a, b| a + b,
);
assert_eq!(sum, 15i32);