Skip to main content

parallel_count

Function parallel_count 

Source
pub fn parallel_count<T, I, P>(items: I, predicate: P) -> usize
where T: Send, I: ParallelIterator<Item = T>, P: Fn(&T) -> bool + Sync + Send,
Expand description

Count items matching a predicate in parallel.

Efficiently counts matching items using fold-reduce, with no lock contention between threads.

§Example

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

let numbers: Vec<i32> = (0..1000).collect();
let even_count = parallel_count(numbers.par_iter(), |n| *n % 2 == 0);
assert_eq!(even_count, 500);