Trait rayon::slice::ParallelSliceMut [] [src]

pub trait ParallelSliceMut<T: Send> {
    fn as_parallel_slice_mut(&mut self) -> &mut [T];

    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
, { ... } }

Parallel extensions for mutable slices.

Required Methods

Important traits for &'a mut [u8]

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 size elements of self at a time. The chunks are mutable and do not overlap.

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

impl<T: Send> ParallelSliceMut<T> for [T]
[src]

Important traits for &'a mut [u8]
[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

[src]

Implementors