Trait rayon::slice::ParallelSlice
source · [−]pub trait ParallelSlice<T: Sync> {
fn as_parallel_slice(&self) -> &[T]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
;
fn par_split<P>(&self, separator: P) -> Split<'_, T, P>
where
P: Fn(&T) -> bool + Sync + Send,
{ ... }
fn par_split_inclusive<P>(&self, separator: P) -> SplitInclusive<'_, T, P>
where
P: Fn(&T) -> bool + Sync + Send,
{ ... }
fn par_windows(&self, window_size: usize) -> Windows<'_, T> { ... }
fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T> { ... }
fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> { ... }
fn par_rchunks(&self, chunk_size: usize) -> RChunks<'_, T> { ... }
fn par_rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> { ... }
fn par_chunk_by<F>(&self, pred: F) -> ChunkBy<'_, T, F>
where
F: Fn(&T, &T) -> bool + Send + Sync,
{ ... }
}
Expand description
Parallel extensions for slices.
Required Methods
Provided Methods
sourcefn par_split<P>(&self, separator: P) -> Split<'_, T, P>where
P: Fn(&T) -> bool + Sync + Send,
fn par_split<P>(&self, separator: P) -> Split<'_, T, P>where
P: Fn(&T) -> bool + Sync + Send,
Returns a parallel iterator over subslices separated by elements that match the separator.
Examples
use rayon::prelude::*;
let products: Vec<_> = [1, 2, 3, 0, 2, 4, 8, 0, 3, 6, 9]
.par_split(|i| *i == 0)
.map(|numbers| numbers.iter().product::<i32>())
.collect();
assert_eq!(products, [6, 64, 162]);
sourcefn par_split_inclusive<P>(&self, separator: P) -> SplitInclusive<'_, T, P>where
P: Fn(&T) -> bool + Sync + Send,
fn par_split_inclusive<P>(&self, separator: P) -> SplitInclusive<'_, T, P>where
P: Fn(&T) -> bool + Sync + Send,
Returns a parallel iterator over subslices separated by elements that match the separator, including the matched part as a terminator.
Examples
use rayon::prelude::*;
let lengths: Vec<_> = [1, 2, 3, 0, 2, 4, 8, 0, 3, 6, 9]
.par_split_inclusive(|i| *i == 0)
.map(|numbers| numbers.len())
.collect();
assert_eq!(lengths, [4, 4, 3]);
sourcefn par_windows(&self, window_size: usize) -> Windows<'_, T>
fn par_windows(&self, window_size: usize) -> Windows<'_, T>
Returns a parallel iterator over all contiguous windows of length
window_size
. The windows overlap.
Examples
use rayon::prelude::*;
let windows: Vec<_> = [1, 2, 3].par_windows(2).collect();
assert_eq!(vec![[1, 2], [2, 3]], windows);
sourcefn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T>
fn par_chunks(&self, chunk_size: usize) -> Chunks<'_, T>
Returns a parallel iterator over at most chunk_size
elements of
self
at a time. The chunks do not overlap.
If the number of elements in the iterator is not divisible by
chunk_size
, the last chunk may be shorter than chunk_size
. All
other chunks will have that exact length.
Examples
use rayon::prelude::*;
let chunks: Vec<_> = [1, 2, 3, 4, 5].par_chunks(2).collect();
assert_eq!(chunks, vec![&[1, 2][..], &[3, 4], &[5]]);
sourcefn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T>
fn par_chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T>
Returns a parallel iterator over chunk_size
elements of
self
at a time. The chunks do not overlap.
If chunk_size
does not divide the length of the slice, then the
last up to chunk_size-1
elements will be omitted and can be
retrieved from the remainder function of the iterator.
Examples
use rayon::prelude::*;
let chunks: Vec<_> = [1, 2, 3, 4, 5].par_chunks_exact(2).collect();
assert_eq!(chunks, vec![&[1, 2][..], &[3, 4]]);
sourcefn par_rchunks(&self, chunk_size: usize) -> RChunks<'_, T>
fn par_rchunks(&self, chunk_size: usize) -> RChunks<'_, T>
Returns a parallel iterator over at most chunk_size
elements of self
at a time,
starting at the end. The chunks do not overlap.
If the number of elements in the iterator is not divisible by
chunk_size
, the last chunk may be shorter than chunk_size
. All
other chunks will have that exact length.
Examples
use rayon::prelude::*;
let chunks: Vec<_> = [1, 2, 3, 4, 5].par_rchunks(2).collect();
assert_eq!(chunks, vec![&[4, 5][..], &[2, 3], &[1]]);
sourcefn par_rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T>
fn par_rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T>
Returns a parallel iterator over chunk_size
elements of self
at a time,
starting at the end. The chunks do not overlap.
If chunk_size
does not divide the length of the slice, then the
last up to chunk_size-1
elements will be omitted and can be
retrieved from the remainder function of the iterator.
Examples
use rayon::prelude::*;
let chunks: Vec<_> = [1, 2, 3, 4, 5].par_rchunks_exact(2).collect();
assert_eq!(chunks, vec![&[4, 5][..], &[2, 3]]);
sourcefn par_chunk_by<F>(&self, pred: F) -> ChunkBy<'_, T, F>where
F: Fn(&T, &T) -> bool + Send + Sync,
fn par_chunk_by<F>(&self, pred: F) -> ChunkBy<'_, T, F>where
F: Fn(&T, &T) -> bool + Send + Sync,
Returns a parallel iterator over the slice producing non-overlapping runs of elements using the predicate to separate them.
The predicate is called on two elements following themselves,
it means the predicate is called on slice[0]
and slice[1]
then on slice[1]
and slice[2]
and so on.
Examples
use rayon::prelude::*;
let chunks: Vec<_> = [1, 2, 2, 3, 3, 3].par_chunk_by(|&x, &y| x == y).collect();
assert_eq!(chunks[0], &[1]);
assert_eq!(chunks[1], &[2, 2]);
assert_eq!(chunks[2], &[3, 3, 3]);