Skip to main content

Module fold

Module fold 

Source
Expand description

Parallel fold-reduce utilities using Rayon.

This module provides ergonomic patterns for parallel data processing using Rayon’s fold and reduce operations. These patterns are useful for batch operations like import, export, and statistics collection.

§Why Fold-Reduce?

The fold-reduce pattern provides:

  • No contention: Each thread has its own accumulator
  • Work-stealing: Rayon handles load balancing automatically
  • Composable: Easy to combine multiple aggregations

§Example

use grafeo_core::execution::parallel::fold::{parallel_count, parallel_sum};
use rayon::prelude::*;

let numbers: Vec<i32> = (0..1000).collect();

// Count even numbers
let even_count = parallel_count(numbers.par_iter(), |n| *n % 2 == 0);

// Sum all numbers
let total: f64 = parallel_sum(numbers.par_iter(), |n| *n as f64);

Traits§

Mergeable
Trait for types that can be merged in parallel fold-reduce operations.

Functions§

fold_reduce
Execute parallel fold-reduce with custom accumulator.
fold_reduce_with
Fold-reduce with a custom identity/factory function.
parallel_count
Count items matching a predicate in parallel.
parallel_max
Find maximum value in parallel.
parallel_min
Find minimum value in parallel.
parallel_partition
Partition items into groups based on a key extractor.
parallel_stats
Compute multiple aggregations in a single parallel pass.
parallel_sum
Sum values extracted from items in parallel.
parallel_sum_i64
Sum integers extracted from items in parallel.
parallel_try_collect
Collect results with errors separated.