Trait rustc_rayon::slice::ParallelSliceMut[][src]

pub trait ParallelSliceMut<T: Send> {
    fn as_parallel_slice_mut(&mut self) -> &mut [T]
Notable traits for &'_ mut [u8]
impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
; fn par_split_mut<P>(&mut self, separator: P) -> SplitMut<'_, T, P>
    where
        P: Fn(&T) -> bool + Sync + Send
, { ... }
fn par_chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> { ... }
fn par_sort(&mut self)
    where
        T: Ord
, { ... }
fn par_sort_by<F>(&mut self, compare: F)
    where
        F: Fn(&T, &T) -> Ordering + Sync
, { ... }
fn par_sort_by_key<B, F>(&mut self, f: F)
    where
        B: Ord,
        F: Fn(&T) -> B + Sync
, { ... }
fn par_sort_unstable(&mut self)
    where
        T: Ord
, { ... }
fn par_sort_unstable_by<F>(&mut self, compare: F)
    where
        F: Fn(&T, &T) -> Ordering + Sync
, { ... }
fn par_sort_unstable_by_key<B, F>(&mut self, f: F)
    where
        B: Ord,
        F: Fn(&T) -> B + Sync
, { ... } }
Expand description

Parallel extensions for mutable slices.

Required methods

Returns a plain mutable slice, which is used to implement the rest of the parallel methods.

Provided methods

Returns a parallel iterator over mutable subslices separated by elements that match the separator.

Examples
use rayon::prelude::*;
let mut array = [1, 2, 3, 0, 2, 4, 8, 0, 3, 6, 9];
array.par_split_mut(|i| *i == 0)
     .for_each(|slice| slice.reverse());
assert_eq!(array, [3, 2, 1, 0, 8, 4, 2, 0, 9, 6, 3]);

Returns a parallel iterator over at most chunk_size elements of self at a time. The chunks are mutable and 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 mut array = [1, 2, 3, 4, 5];
array.par_chunks_mut(2)
     .for_each(|slice| slice.reverse());
assert_eq!(array, [2, 1, 4, 3, 5]);

Sorts the slice in parallel.

This sort is stable (i.e. does not reorder equal elements) and O(n log n) worst-case.

When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See par_sort_unstable.

Current implementation

The current algorithm is an adaptive merge sort inspired by timsort. It is designed to be very fast in cases where the slice is nearly sorted, or consists of two or more sorted sequences concatenated one after another.

Also, it allocates temporary storage the same size as self, but for very short slices a non-allocating insertion sort is used instead.

In order to sort the slice in parallel, the slice is first divided into smaller chunks and all chunks are sorted in parallel. Then, adjacent chunks that together form non-descending or descending runs are concatenated. Finally, the remaining chunks are merged together using parallel subdivision of chunks and parallel merge operation.

Examples
use rayon::prelude::*;

let mut v = [-5, 4, 1, -3, 2];

v.par_sort();
assert_eq!(v, [-5, -3, 1, 2, 4]);

Sorts the slice in parallel with a comparator function.

This sort is stable (i.e. does not reorder equal elements) and O(n log n) worst-case.

When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See par_sort_unstable_by.

Current implementation

The current algorithm is an adaptive merge sort inspired by timsort. It is designed to be very fast in cases where the slice is nearly sorted, or consists of two or more sorted sequences concatenated one after another.

Also, it allocates temporary storage the same size as self, but for very short slices a non-allocating insertion sort is used instead.

In order to sort the slice in parallel, the slice is first divided into smaller chunks and all chunks are sorted in parallel. Then, adjacent chunks that together form non-descending or descending runs are concatenated. Finally, the remaining chunks are merged together using parallel subdivision of chunks and parallel merge operation.

Examples
use rayon::prelude::*;

let mut v = [5, 4, 1, 3, 2];
v.par_sort_by(|a, b| a.cmp(b));
assert_eq!(v, [1, 2, 3, 4, 5]);

// reverse sorting
v.par_sort_by(|a, b| b.cmp(a));
assert_eq!(v, [5, 4, 3, 2, 1]);

Sorts the slice in parallel with a key extraction function.

This sort is stable (i.e. does not reorder equal elements) and O(n log n) worst-case.

When applicable, unstable sorting is preferred because it is generally faster than stable sorting and it doesn’t allocate auxiliary memory. See par_sort_unstable_by_key.

Current implementation

The current algorithm is an adaptive merge sort inspired by timsort. It is designed to be very fast in cases where the slice is nearly sorted, or consists of two or more sorted sequences concatenated one after another.

Also, it allocates temporary storage the same size as self, but for very short slices a non-allocating insertion sort is used instead.

In order to sort the slice in parallel, the slice is first divided into smaller chunks and all chunks are sorted in parallel. Then, adjacent chunks that together form non-descending or descending runs are concatenated. Finally, the remaining chunks are merged together using parallel subdivision of chunks and parallel merge operation.

Examples
use rayon::prelude::*;

let mut v = [-5i32, 4, 1, -3, 2];

v.par_sort_by_key(|k| k.abs());
assert_eq!(v, [1, 2, -3, 4, -5]);

Sorts the slice in parallel, but may not preserve the order of equal elements.

This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate), and O(n log n) worst-case.

Current implementation

The current algorithm is based on Orson Peters’ pattern-defeating quicksort, which is a quicksort variant designed to be very fast on certain kinds of patterns, sometimes achieving linear time. It is randomized but deterministic, and falls back to heapsort on degenerate inputs.

It is generally faster than stable sorting, except in a few special cases, e.g. when the slice consists of several concatenated sorted sequences.

All quicksorts work in two stages: partitioning into two halves followed by recursive calls. The partitioning phase is sequential, but the two recursive calls are performed in parallel.

Examples
use rayon::prelude::*;

let mut v = [-5, 4, 1, -3, 2];

v.par_sort_unstable();
assert_eq!(v, [-5, -3, 1, 2, 4]);

Sorts the slice in parallel with a comparator function, but may not preserve the order of equal elements.

This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate), and O(n log n) worst-case.

Current implementation

The current algorithm is based on Orson Peters’ pattern-defeating quicksort, which is a quicksort variant designed to be very fast on certain kinds of patterns, sometimes achieving linear time. It is randomized but deterministic, and falls back to heapsort on degenerate inputs.

It is generally faster than stable sorting, except in a few special cases, e.g. when the slice consists of several concatenated sorted sequences.

All quicksorts work in two stages: partitioning into two halves followed by recursive calls. The partitioning phase is sequential, but the two recursive calls are performed in parallel.

Examples
use rayon::prelude::*;

let mut v = [5, 4, 1, 3, 2];
v.par_sort_unstable_by(|a, b| a.cmp(b));
assert_eq!(v, [1, 2, 3, 4, 5]);

// reverse sorting
v.par_sort_unstable_by(|a, b| b.cmp(a));
assert_eq!(v, [5, 4, 3, 2, 1]);

Sorts the slice in parallel with a key extraction function, but may not preserve the order of equal elements.

This sort is unstable (i.e. may reorder equal elements), in-place (i.e. does not allocate), and O(n log n) worst-case.

Current implementation

The current algorithm is based on Orson Peters’ pattern-defeating quicksort, which is a quicksort variant designed to be very fast on certain kinds of patterns, sometimes achieving linear time. It is randomized but deterministic, and falls back to heapsort on degenerate inputs.

It is generally faster than stable sorting, except in a few special cases, e.g. when the slice consists of several concatenated sorted sequences.

All quicksorts work in two stages: partitioning into two halves followed by recursive calls. The partitioning phase is sequential, but the two recursive calls are performed in parallel.

Examples
use rayon::prelude::*;

let mut v = [-5i32, 4, 1, -3, 2];

v.par_sort_unstable_by_key(|k| k.abs());
assert_eq!(v, [1, 2, -3, 4, -5]);

Implementations on Foreign Types

Implementors