Trait orx_parallel::IntoPar

source ·
pub trait IntoPar {
    type ConIter: ConcurrentIter;

    // Required method
    fn into_par(self) -> ParEmpty<Self::ConIter>;
}
Expand description

Conversion into a parallel iterator.

Every type implementing orx_concurrent_iter::ConcurrentIter or orx_concurrent_iter::IntoConcurrentIter also implements IntoPar. These types include common collections/views such as range, vector or slice.

See crate::IterIntoPar for conversion of any regular iterator into parallel iterator.

Converting into a parallel iterator is achieved using the into_par() method.

§Examples

use orx_parallel::*;

let seq: usize = (0..1024).sum();
let par = (0..1024).into_par().sum();
assert_eq!(par, seq);

let seq = vec![10; 42].into_iter().sum();
let par = vec![10; 42].into_par().sum();
assert_eq!(par, seq);

let seq = (10..420).filter(|x| x % 2 == 1).map(|x| 2 * x).sum();
let par = (10..420).into_par().filter(|x| x % 2 == 1).map(|x| 2 * x).sum();
assert_eq!(par, seq);

let names = ["john", "doe", "foo", "bar"].map(String::from);
let seq = names.iter().map(|x| x.len()).reduce(|a, b| a + b);
let par = names.as_slice().into_par().map(|x| x.len()).reduce(|a, b| a + b);
assert_eq!(par, seq);

Required Associated Types§

source

type ConIter: ConcurrentIter

Underlying concurrent iterator which provides the input elements to the defined parallel computation.

Required Methods§

source

fn into_par(self) -> ParEmpty<Self::ConIter>

Conversion into a parallel iterator.

Every type implementing orx_concurrent_iter::ConcurrentIter or orx_concurrent_iter::IntoConcurrentIter also implements IntoPar. These types include common collections/views such as range, vector or slice.

See crate::IterIntoPar for conversion of any regular iterator into parallel iterator.

Converting into a parallel iterator is achieved using the into_par() method.

§Examples
use orx_parallel::*;

let seq = vec![10; 42].into_iter().sum();
let par = vec![10; 42].into_par().sum();
assert_eq!(par, seq);

let seq = (10..420).filter(|x| x % 2 == 1).map(|x| 2 * x).sum();
let par = (10..420).into_par().filter(|x| x % 2 == 1).map(|x| 2 * x).sum();
assert_eq!(par, seq);

let names = ["john", "doe", "foo", "bar"].map(String::from);
let seq = names.iter().map(|x| x.len()).reduce(|a, b| a + b);
let par = names.as_slice().into_par().map(|x| x.len()).reduce(|a, b| a + b);
assert_eq!(par, seq);

Implementations on Foreign Types§

source§

impl<'a, T: Send + Sync + Clone, C: AtomicIter<&'a T> + ConcurrentIter<Item = &'a T>> IntoPar for Cloned<'a, T, C>

source§

type ConIter = Cloned<'a, T, C>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<'a, T: Send + Sync> IntoPar for &'a [T]

source§

type ConIter = ConIterOfSlice<'a, T>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<'a, T: Send + Sync> IntoPar for ConIterOfSlice<'a, T>

source§

type ConIter = ConIterOfSlice<'a, T>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<Idx> IntoPar for Range<Idx>
where Idx: Send + Sync + Clone + Copy + From<usize> + Into<usize> + Add<Idx, Output = Idx> + Sub<Idx, Output = Idx> + Ord, Range<Idx>: Iterator<Item = Idx>,

source§

type ConIter = ConIterOfRange<Idx>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<Idx> IntoPar for ConIterOfRange<Idx>
where Idx: Send + Sync + Clone + Copy + From<usize> + Into<usize> + Add<Idx, Output = Idx> + Sub<Idx, Output = Idx> + Ord, Range<Idx>: Iterator<Item = Idx>,

source§

type ConIter = ConIterOfRange<Idx>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<K: Send + Sync, V: Send + Sync> IntoPar for BTreeMap<K, V>

source§

type ConIter = ConIterOfIter<(K, V), IntoIter<K, V>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<K: Send + Sync, V: Send + Sync> IntoPar for HashMap<K, V>

source§

type ConIter = ConIterOfIter<(K, V), IntoIter<K, V>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for BinaryHeap<T>

source§

type ConIter = ConIterOfIter<T, IntoIter<T>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for BTreeSet<T>

source§

type ConIter = ConIterOfIter<T, IntoIter<T>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for LinkedList<T>

source§

type ConIter = ConIterOfIter<T, IntoIter<T>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for VecDeque<T>

source§

type ConIter = ConIterOfIter<T, IntoIter<T>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for Vec<T>

source§

type ConIter = ConIterOfVec<T>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for HashSet<T>

source§

type ConIter = ConIterOfIter<T, IntoIter<T>>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync> IntoPar for ConIterOfVec<T>

source§

type ConIter = ConIterOfVec<T>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<T: Send + Sync, Iter> IntoPar for ConIterOfIter<T, Iter>
where Iter: Iterator<Item = T>,

source§

type ConIter = ConIterOfIter<T, Iter>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<const N: usize, T: Send + Sync + Default> IntoPar for [T; N]

source§

type ConIter = ConIterOfArray<N, T>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

source§

impl<const N: usize, T: Send + Sync + Default> IntoPar for ConIterOfArray<N, T>

source§

type ConIter = ConIterOfArray<N, T>

source§

fn into_par(self) -> ParEmpty<Self::ConIter>

Implementors§