pub trait ParallelSlice<T>: AsRef<[T]>
where T: Sync,
{ // Provided methods fn par_chunk_map<F, R>( &self, task_pool: &TaskPool, chunk_size: usize, f: F ) -> Vec<R> where F: Fn(&[T]) -> R + Send + Sync, R: Send + 'static { ... } fn par_splat_map<F, R>( &self, task_pool: &TaskPool, max_tasks: Option<usize>, f: F ) -> Vec<R> where F: Fn(&[T]) -> R + Send + Sync, R: Send + 'static { ... } }
Expand description

Provides functions for mapping read-only slices across a provided TaskPool.

Provided Methods§

source

fn par_chunk_map<F, R>( &self, task_pool: &TaskPool, chunk_size: usize, f: F ) -> Vec<R>
where F: Fn(&[T]) -> R + Send + Sync, R: Send + 'static,

Splits the slice in chunks of size chunks_size or less and maps the chunks in parallel across the provided task_pool. One task is spawned in the task pool for every chunk.

Returns a Vec of the mapped results in the same order as the input.

Example
let task_pool = TaskPool::new();
let counts = (0..10000).collect::<Vec<u32>>();
let incremented = counts.par_chunk_map(&task_pool, 100, |chunk| {
  let mut results = Vec::new();
  for count in chunk {
    results.push(*count + 2);
  }
  results
});
See Also
source

fn par_splat_map<F, R>( &self, task_pool: &TaskPool, max_tasks: Option<usize>, f: F ) -> Vec<R>
where F: Fn(&[T]) -> R + Send + Sync, R: Send + 'static,

Splits the slice into a maximum of max_tasks chunks, and maps the chunks in parallel across the provided task_pool. One task is spawned in the task pool for every chunk.

If max_tasks is None, this function will attempt to use one chunk per thread in task_pool.

Returns a Vec of the mapped results in the same order as the input.

Example
let task_pool = TaskPool::new();
let counts = (0..10000).collect::<Vec<u32>>();
let incremented = counts.par_splat_map(&task_pool, None, |chunk| {
  let mut results = Vec::new();
  for count in chunk {
    results.push(*count + 2);
  }
  results
});
See Also

ParallelSliceMut::par_splat_map_mut for mapping mutable slices. ParallelSlice::par_chunk_map for mapping when a specific chunk size is desirable.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<S, T> ParallelSlice<T> for S
where T: Sync, S: AsRef<[T]>,