[][src]Trait asparit::IndexedParallelIterator

pub trait IndexedParallelIterator<'a>: ParallelIterator<'a> {
    pub fn drive_indexed<E, C, D, R>(
        self,
        executor: E,
        consumer: C
    ) -> E::Result
    where
        E: Executor<'a, D>,
        C: Consumer<Self::Item, Result = D, Reducer = R> + 'a,
        D: Send + 'a,
        R: Reducer<D> + Send + 'a
;
pub fn len_hint(&self) -> usize; pub fn zip<X>(self, other: X) -> Zip<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>
, { ... }
pub fn zip_eq<X>(self, other: X) -> Zip<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>
, { ... }
pub fn interleave<X>(self, other: X) -> Interleave<Self, X::Iter>
    where
        X: IntoParallelIterator<'a, Item = Self::Item>,
        X::Iter: IndexedParallelIterator<'a, Item = Self::Item>
, { ... }
pub fn interleave_shortest<X, I>(
        self,
        other: X
    ) -> Interleave<Take<Self>, Take<X::Iter>>
    where
        X: IntoParallelIterator<'a, Item = I>,
        X::Iter: IndexedParallelIterator<'a, Item = I> + WithIndexedProducer<'a, Item = I>,
        Self: IndexedParallelIterator<'a, Item = I> + WithIndexedProducer<'a, Item = I>,
        I: Send + 'a
, { ... }
pub fn chunks(self, chunk_size: usize) -> Chunks<Self> { ... }
pub fn cmp<X>(self, other: X) -> Cmp<Self, X::Iter>
    where
        X: IntoParallelIterator<'a, Item = Self::Item>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: Ord
, { ... }
pub fn partial_cmp<X>(self, other: X) -> PartialCmp<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialOrd<X::Item>
, { ... }
pub fn eq<X>(self, other: X) -> Equal<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialEq<X::Item>
, { ... }
pub fn ne<X>(self, other: X) -> Equal<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialEq<X::Item>
, { ... }
pub fn lt<X>(self, other: X) -> Compare<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialOrd<X::Item>
, { ... }
pub fn le<X>(self, other: X) -> Compare<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialOrd<X::Item>
, { ... }
pub fn gt<X>(self, other: X) -> Compare<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialOrd<X::Item>
, { ... }
pub fn ge<X>(self, other: X) -> Compare<Self, X::Iter>
    where
        X: IntoParallelIterator<'a>,
        X::Iter: IndexedParallelIterator<'a>,
        Self::Item: PartialOrd<X::Item>
, { ... }
pub fn enumerate(self) -> Enumerate<Self> { ... }
pub fn step_by(self, step: usize) -> StepBy<Self> { ... }
pub fn skip(self, n: usize) -> Skip<Self> { ... }
pub fn take(self, n: usize) -> Take<Self> { ... }
pub fn position_any<O>(self, operation: O) -> Position<Self, O>
    where
        O: Fn(Self::Item) -> bool + Clone + Send + 'a
, { ... }
pub fn position_first<O>(self, operation: O) -> Position<Self, O>
    where
        O: Fn(Self::Item) -> bool + Clone + Send + 'a
, { ... }
pub fn position_last<O>(self, operation: O) -> Position<Self, O>
    where
        O: Fn(Self::Item) -> bool + Clone + Send + 'a
, { ... }
pub fn rev(self) -> Rev<Self> { ... }
pub fn with_min_len(self, min: usize) -> SetupIter<Self> { ... }
pub fn with_max_len(self, max: usize) -> SetupIter<Self> { ... } }

An iterator that supports "random access" to its data, meaning that you can split it at arbitrary indices and draw data from those points.

Note: Not implemented for u64, i64, u128, or i128 ranges

Required methods

pub fn drive_indexed<E, C, D, R>(self, executor: E, consumer: C) -> E::Result where
    E: Executor<'a, D>,
    C: Consumer<Self::Item, Result = D, Reducer = R> + 'a,
    D: Send + 'a,
    R: Reducer<D> + Send + 'a, 

Internal method used to define the behavior of this parallel iterator. You should not need to call this directly.

This method causes the iterator self to start producing items and to feed them to the consumer consumer one by one. It may split the consumer before doing so to create the opportunity to produce in parallel. If a split does happen, it will inform the consumer of the index where the split should occur (unlike ParallelIterator::drive_unindexed()).

See the README for more details on the internals of parallel iterators.

pub fn len_hint(&self) -> usize

Produces an exact count of how many items this iterator will produce, presuming no panic occurs.

Examples

use asparit::*;

let par_iter = (0..100).into_par_iter().zip(vec![0; 10]);
assert_eq!(par_iter.len_hint(), 10);

let vec: Vec<_> = par_iter.collect().exec();
assert_eq!(vec.len(), 10);
Loading content...

Provided methods

pub fn zip<X>(self, other: X) -> Zip<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>, 

Iterates over tuples (A, B), where the items A are from this iterator and B are from the iterator given as argument. Like the zip method on ordinary iterators, if the two iterators are of unequal length, you only get the items they have in common.

Examples

use asparit::*;

let result: Vec<_> = (1..4)
    .into_par_iter()
    .zip(vec!['a', 'b', 'c'])
    .collect()
    .exec();

assert_eq!(result, [(1, 'a'), (2, 'b'), (3, 'c')]);

pub fn zip_eq<X>(self, other: X) -> Zip<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>, 

The same as Zip, but requires that both iterators have the same length.

Panics

Will panic if self and other are not the same length.

This example panics
use asparit::*;

let one = [1u8];
let two = [2u8, 2];
let one_iter = one.par_iter();
let two_iter = two.par_iter();

// this will panic
let zipped: Vec<(&u8, &u8)> = one_iter.zip_eq(two_iter).collect().exec();

// we should never get here
assert_eq!(1, zipped.len());

pub fn interleave<X>(self, other: X) -> Interleave<Self, X::Iter> where
    X: IntoParallelIterator<'a, Item = Self::Item>,
    X::Iter: IndexedParallelIterator<'a, Item = Self::Item>, 

Interleaves elements of this iterator and the other given iterator. Alternately yields elements from this iterator and the given iterator, until both are exhausted. If one iterator is exhausted before the other, the last elements are provided from the other.

Examples

use asparit::*;
let (x, y) = (vec![1, 2], vec![3, 4, 5, 6]);
let r: Vec<i32> = x.into_par_iter().interleave(y).collect().exec();
assert_eq!(r, vec![1, 3, 2, 4, 5, 6]);

pub fn interleave_shortest<X, I>(
    self,
    other: X
) -> Interleave<Take<Self>, Take<X::Iter>> where
    X: IntoParallelIterator<'a, Item = I>,
    X::Iter: IndexedParallelIterator<'a, Item = I> + WithIndexedProducer<'a, Item = I>,
    Self: IndexedParallelIterator<'a, Item = I> + WithIndexedProducer<'a, Item = I>,
    I: Send + 'a, 

Interleaves elements of this iterator and the other given iterator, until one is exhausted.

Examples

use asparit::*;
let (x, y) = (vec![1, 2, 3, 4], vec![5, 6]);
let r: Vec<i32> = x.into_par_iter().interleave_shortest(y).collect().exec();
assert_eq!(r, vec![1, 5, 2, 6, 3]);

pub fn chunks(self, chunk_size: usize) -> Chunks<Self>

Splits an iterator up into fixed-size chunks.

Returns an iterator that returns Vecs of the given number of elements. If the number of elements in the iterator is not divisible by chunk_size, the last chunk may be shorter than chunk_size.

See also par_chunks() and par_chunks_mut() for similar behavior on slices, without having to allocate intermediate Vecs for the chunks.

Examples

use asparit::*;
let a = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let r: Vec<Vec<i32>> = a.into_par_iter().chunks(3).collect().exec();
assert_eq!(
    r,
    vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9], vec![10]]
);

pub fn cmp<X>(self, other: X) -> Cmp<Self, X::Iter> where
    X: IntoParallelIterator<'a, Item = Self::Item>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: Ord

Lexicographically compares the elements of this ParallelIterator with those of another.

Examples

use asparit::*;
use std::cmp::Ordering::*;

let x = vec![1, 2, 3];
assert_eq!(x.par_iter().cmp(&vec![1, 3, 0]).exec(), Less);
assert_eq!(x.par_iter().cmp(&vec![1, 2, 3]).exec(), Equal);
assert_eq!(x.par_iter().cmp(&vec![1, 2]).exec(), Greater);

pub fn partial_cmp<X>(self, other: X) -> PartialCmp<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialOrd<X::Item>, 

Lexicographically compares the elements of this ParallelIterator with those of another.

Examples

use asparit::*;
use std::cmp::Ordering::*;
use std::f64::NAN;

let x = vec![1.0, 2.0, 3.0];
assert_eq!(
    x.par_iter().partial_cmp(&vec![1.0, 3.0, 0.0]).exec(),
    Some(Less)
);
assert_eq!(
    x.par_iter().partial_cmp(&vec![1.0, 2.0, 3.0]).exec(),
    Some(Equal)
);
assert_eq!(
    x.par_iter().partial_cmp(&vec![1.0, 2.0]).exec(),
    Some(Greater)
);
assert_eq!(x.par_iter().partial_cmp(&vec![1.0, NAN]).exec(), None);

pub fn eq<X>(self, other: X) -> Equal<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialEq<X::Item>, 

Determines if the elements of this ParallelIterator are equal to those of another

pub fn ne<X>(self, other: X) -> Equal<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialEq<X::Item>, 

Determines if the elements of this ParallelIterator are unequal to those of another

pub fn lt<X>(self, other: X) -> Compare<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialOrd<X::Item>, 

Determines if the elements of this ParallelIterator are lexicographically less than those of another.

pub fn le<X>(self, other: X) -> Compare<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialOrd<X::Item>, 

Determines if the elements of this ParallelIterator are less or equal to those of another.

pub fn gt<X>(self, other: X) -> Compare<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialOrd<X::Item>, 

Determines if the elements of this ParallelIterator are lexicographically greater than those of another.

pub fn ge<X>(self, other: X) -> Compare<Self, X::Iter> where
    X: IntoParallelIterator<'a>,
    X::Iter: IndexedParallelIterator<'a>,
    Self::Item: PartialOrd<X::Item>, 

Determines if the elements of this ParallelIterator are less or equal to those of another.

pub fn enumerate(self) -> Enumerate<Self>

Yields an index along with each item.

Examples

use asparit::*;

let chars = vec!['a', 'b', 'c'];
let result: Vec<_> = chars.into_par_iter().enumerate().collect().exec();

assert_eq!(result, [(0, 'a'), (1, 'b'), (2, 'c')]);

pub fn step_by(self, step: usize) -> StepBy<Self>

Creates an iterator that steps by the given amount

Examples

use asparit::*;

let range = (3..10);
let result: Vec<i32> = range.into_par_iter().step_by(3).collect().exec();

assert_eq!(result, [3, 6, 9])

pub fn skip(self, n: usize) -> Skip<Self>

Creates an iterator that skips the first n elements.

Examples

use asparit::*;

let result: Vec<_> = (0..100).into_par_iter().skip(95).collect().exec();

assert_eq!(result, [95, 96, 97, 98, 99]);

pub fn take(self, n: usize) -> Take<Self>

Creates an iterator that yields the first n elements.

Examples

use asparit::*;

let result: Vec<_> = (0..100).into_par_iter().take(5).collect().exec();

assert_eq!(result, [0, 1, 2, 3, 4]);

pub fn position_any<O>(self, operation: O) -> Position<Self, O> where
    O: Fn(Self::Item) -> bool + Clone + Send + 'a, 

Searches for some item in the parallel iterator that matches the given operation, and returns its index. Like ParallelIterator::find_any, the parallel search will not necessarily find the first match, and once a match is found we'll attempt to stop processing any more.

Examples

use asparit::*;

let a = [1, 2, 3, 3];

let i = a
    .par_iter()
    .position_any(|&x| x == 3)
    .exec()
    .expect("found");
assert!(i == 2 || i == 3);

assert_eq!(a.par_iter().position_any(|&x| x == 100).exec(), None);

pub fn position_first<O>(self, operation: O) -> Position<Self, O> where
    O: Fn(Self::Item) -> bool + Clone + Send + 'a, 

Searches for the sequentially first item in the parallel iterator that matches the given operation, and returns its index.

Like ParallelIterator::find_first, once a match is found, all attempts to the right of the match will be stopped, while attempts to the left must continue in case an earlier match is found.

Note that not all parallel iterators have a useful order, much like sequential HashMap iteration, so "first" may be nebulous. If you just want the first match that discovered anywhere in the iterator, position_any is a better choice.

Examples

use asparit::*;

let a = [1, 2, 3, 3];

assert_eq!(a.par_iter().position_first(|&x| x == 3).exec(), Some(2));

assert_eq!(a.par_iter().position_first(|&x| x == 100).exec(), None);

pub fn position_last<O>(self, operation: O) -> Position<Self, O> where
    O: Fn(Self::Item) -> bool + Clone + Send + 'a, 

Searches for the sequentially last item in the parallel iterator that matches the given operation, and returns its index.

Like ParallelIterator::find_last, once a match is found, all attempts to the left of the match will be stopped, while attempts to the right must continue in case a later match is found.

Note that not all parallel iterators have a useful order, much like sequential HashMap iteration, so "last" may be nebulous. When the order doesn't actually matter to you, position_any is a better choice.

Examples

use asparit::*;

let a = [1, 2, 3, 3];

assert_eq!(a.par_iter().position_last(|&x| x == 3).exec(), Some(3));

assert_eq!(a.par_iter().position_last(|&x| x == 100).exec(), None);

pub fn rev(self) -> Rev<Self>

Produces a new iterator with the elements of this iterator in reverse order.

Examples

use asparit::*;

let result: Vec<_> = (0..5).into_par_iter().rev().collect().exec();

assert_eq!(result, [4, 3, 2, 1, 0]);

pub fn with_min_len(self, min: usize) -> SetupIter<Self>

Sets the minimum length of iterators desired to process in each thread. Rayon will not split any smaller than this length, but of course an iterator could already be smaller to begin with.

Producers like zip and interleave will use greater of the two minimums. Chained iterators and iterators inside flat_map may each use their own minimum length.

Examples

use asparit::*;

let min = (0..1_000_000)
    .into_par_iter()
    .with_min_len(1234)
    .fold(|| 0, |acc, _| acc + 1) // count how many are in this segment
    .min()
    .exec()
    .unwrap();

assert!(min >= 1234);

pub fn with_max_len(self, max: usize) -> SetupIter<Self>

Sets the maximum length of iterators desired to process in each thread. Rayon will try to split at least below this length, unless that would put it below the length from with_min_len(). For example, given min=10 and max=15, a length of 16 will not be split any further.

Producers like zip and interleave will use lesser of the two maximums. Chained iterators and iterators inside flat_map may each use their own maximum length.

Examples

use asparit::*;

let max = (0..1_000_000)
    .into_par_iter()
    .with_max_len(1234)
    .fold(|| 0, |acc, _| acc + 1) // count how many are in this segment
    .max()
    .exec()
    .unwrap();

assert!(max <= 1234);
Loading content...

Implementors

Loading content...