Par

Struct Par 

Source
pub struct Par<I, R = RunnerWithPool<SequentialPool>>{ /* private fields */ }
Expand description

A parallel iterator.

Implementationsยง

Sourceยง

impl<I, R> Par<I, R>

Source

pub fn chain<C>( self, other: C, ) -> Par<ChainKnownLenI<I, <C as IntoConcurrentIter>::IntoIter>, R>

Creates a chain of this and other parallel iterators.

The first iterator is required to have a known length for chaining.

ยงExamples
use orx_parallel::*;

let a = vec!['a', 'b', 'c']; // with exact len
let b = vec!['d', 'e', 'f'].into_iter().filter(|x| *x != 'x');

let chain = a.into_par().chain(b.iter_into_par());
assert_eq!(
    chain.collect::<Vec<_>>(),
    vec!['a', 'b', 'c', 'd', 'e', 'f'],
);
Sourceยง

impl<E, T, R> Par<ConcurrentRecursiveIter<T, E>, R>
where T: Send + Sync, E: Fn(&T, &Queue<'_, T>) + Sync, R: ParallelRunner + Clone,

Source

pub fn linearize(self) -> Par<ConIterVec<T>, R>

Even with exact length, a recursive parallel iterator is much more dynamic than a flat parallel iterator. This dynamic nature of shrinking and growing concurrently requires a greater parallelization overhead. An alternative approach is to eagerly discover all tasks and then perform the parallel computation over the flattened input of tasks.

The linearize approach works in two parallelization phases:

  • first phase to linearize the inputs in parallel over the non-linear data, and
  • second phase to perform the computation in parallel over the linear data.

See into_par_rec and into_par_rec_exact for examples.

Trait Implementationsยง

Sourceยง

impl<I> IntoConcurrentIter for Par<I>
where I: ConcurrentIter,

Sourceยง

type Item = <I as ConcurrentIter>::Item

Type of the element that the concurrent iterator yields.
Sourceยง

type IntoIter = I

Type of the concurrent iterator that this type can be converted into.
Sourceยง

fn into_con_iter(self) -> <Par<I> as IntoConcurrentIter>::IntoIter

Trait to convert a source (collection or generator) into a concurrent iterator; i.e., ConcurrentIter, using its into_con_iter method. Read more
Sourceยง

impl<I, R> ParIter<R> for Par<I, R>

Sourceยง

type Item = <I as ConcurrentIter>::Item

Element type of the parallel iterator.
Sourceยง

fn con_iter(&self) -> &impl ConcurrentIter

Returns a reference to the input concurrent iterator.
Sourceยง

fn params(&self) -> Params

Parameters of the parallel iterator. Read more
Sourceยง

fn num_threads(self, num_threads: impl Into<NumThreads>) -> Par<I, R>

Sets the number of threads to be used in the parallel execution. Integers can be used as the argument with the following mapping: Read more
Sourceยง

fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Par<I, R>

Sets the number of elements to be pulled from the concurrent iterator during the parallel execution. When integers are used as argument, the following mapping applies: Read more
Sourceยง

fn iteration_order(self, collect: IterationOrder) -> Par<I, R>

Sets the iteration order of the parallel computation. Read more
Sourceยง

fn with_runner<Q>( self, orchestrator: Q, ) -> impl ParIter<Q, Item = <Par<I, R> as ParIter<R>>::Item>
where Q: ParallelRunner,

Rather than the DefaultRunner, uses the parallel runner Q which implements ParallelRunner. Read more
Sourceยง

fn using<U, F>( self, using: F, ) -> impl ParIterUsing<UsingFun<F, U>, R, Item = <Par<I, R> as ParIter<R>>::Item>
where U: 'static, F: Fn(usize) -> U + Sync,

Converts the ParIter into ParIterUsing which will have access to a mutable reference of the used variable throughout the computation. Read more
Sourceยง

fn using_clone<U>( self, value: U, ) -> impl ParIterUsing<UsingClone<U>, R, Item = <Par<I, R> as ParIter<R>>::Item>
where U: Clone + 'static,

Converts the ParIter into ParIterUsing which will have access to a mutable reference of the used variable throughout the computation. Read more
Sourceยง

fn map<Out, Map>(self, map: Map) -> impl ParIter<R, Item = Out>
where Map: Fn(<Par<I, R> as ParIter<R>>::Item) -> Out + Sync,

Takes a closure map and creates a parallel iterator which calls that closure on each element. Read more
Sourceยง

fn filter<Filter>( self, filter: Filter, ) -> impl ParIter<R, Item = <Par<I, R> as ParIter<R>>::Item>
where Filter: Fn(&<Par<I, R> as ParIter<R>>::Item) -> bool + Sync,

Creates an iterator which uses a closure filter to determine if an element should be yielded. Read more
Sourceยง

fn flat_map<IOut, FlatMap>( self, flat_map: FlatMap, ) -> impl ParIter<R, Item = <IOut as IntoIterator>::Item>
where IOut: IntoIterator, FlatMap: Fn(<Par<I, R> as ParIter<R>>::Item) -> IOut + Sync,

Creates an iterator that works like map, but flattens nested structure. Read more
Sourceยง

fn filter_map<Out, FilterMap>( self, filter_map: FilterMap, ) -> impl ParIter<R, Item = Out>
where FilterMap: Fn(<Par<I, R> as ParIter<R>>::Item) -> Option<Out> + Sync,

Creates an iterator that both filters and maps. Read more
Sourceยง

fn take_while<While>( self, take_while: While, ) -> impl ParIter<R, Item = <Par<I, R> as ParIter<R>>::Item>
where While: Fn(&<Par<I, R> as ParIter<R>>::Item) -> bool + Sync,

Creates an iterator that yields elements based on the predicate take_while. Read more
Sourceยง

fn into_fallible_result<Out, Err>( self, ) -> impl ParIterResult<R, Item = Out, Err = Err>
where <Par<I, R> as ParIter<R>>::Item: IntoResult<Out, Err>,

Transforms a parallel iterator where elements are of the result type; i.e., ParIter<R, Item = Result<T, E>>, into fallible parallel iterator with item type T and error type E; i.e., into ParIterResult<R, Item = T, Err = E>. Read more
Sourceยง

fn collect_into<C>(self, output: C) -> C
where C: ParCollectInto<<Par<I, R> as ParIter<R>>::Item>,

Collects all the items from an iterator into a collection. Read more
Sourceยง

fn reduce<Reduce>( self, reduce: Reduce, ) -> Option<<Par<I, R> as ParIter<R>>::Item>
where <Par<I, R> as ParIter<R>>::Item: Send, Reduce: Fn(<Par<I, R> as ParIter<R>>::Item, <Par<I, R> as ParIter<R>>::Item) -> <Par<I, R> as ParIter<R>>::Item + Sync,

Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more
Sourceยง

fn first(self) -> Option<<Par<I, R> as ParIter<R>>::Item>

Returns the first (or any) element of the iterator; returns None if it is empty. Read more
Sourceยง

fn with_pool<P>( self, pool: P, ) -> impl ParIter<RunnerWithPool<P, <R as ParallelRunner>::Executor>, Item = Self::Item>
where P: ParThreadPool,

Rather than DefaultPool, uses the parallel runner with the given pool implementing ParThreadPool. Read more
Sourceยง

fn into_fallible_option<T>(self) -> impl ParIterOption<R, Item = T>
where Self::Item: IntoOption<T>,

Transforms a parallel iterator where elements are of the option type; i.e., ParIter<R, Item = Option<T>>, into fallible parallel iterator with item type T; i.e., into ParIterOption<R, Item = T>. Read more
Sourceยง

fn inspect<Operation>( self, operation: Operation, ) -> impl ParIter<R, Item = Self::Item>
where Operation: Fn(&Self::Item) + Sync + Clone,

Does something with each element of an iterator, passing the value on. Read more
Sourceยง

fn map_while<Out, MapWhile>( self, map_while: MapWhile, ) -> impl ParIter<R, Item = Out>
where MapWhile: Fn(Self::Item) -> Option<Out> + Sync + Clone,

Creates an iterator that both yields elements based on the predicate map_while and maps. Read more
Sourceยง

fn copied<'a, T>(self) -> impl ParIter<R, Item = T>
where T: 'a + Copy, Self: ParIter<R, Item = &'a T>,

Creates an iterator which copies all of its elements. Read more
Sourceยง

fn cloned<'a, T>(self) -> impl ParIter<R, Item = T>
where T: 'a + Clone, Self: ParIter<R, Item = &'a T>,

Creates an iterator which clones all of its elements. Read more
Sourceยง

fn flatten(self) -> impl ParIter<R, Item = <Self::Item as IntoIterator>::Item>
where Self::Item: IntoIterator,

Creates an iterator that flattens nested structure. Read more
Sourceยง

fn collect<C>(self) -> C
where C: ParCollectInto<Self::Item>,

Transforms an iterator into a collection. Read more
Sourceยง

fn all<Predicate>(self, predicate: Predicate) -> bool
where Self::Item: Send, Predicate: Fn(&Self::Item) -> bool + Sync,

Tests if every element of the iterator matches a predicate. Read more
Sourceยง

fn any<Predicate>(self, predicate: Predicate) -> bool
where Self::Item: Send, Predicate: Fn(&Self::Item) -> bool + Sync,

Tests if any element of the iterator matches a predicate. Read more
Sourceยง

fn count(self) -> usize

Consumes the iterator, counting the number of iterations and returning it. Read more
Sourceยง

fn for_each<Operation>(self, operation: Operation)
where Operation: Fn(Self::Item) + Sync,

Calls a closure on each element of an iterator. Read more
Sourceยง

fn max(self) -> Option<Self::Item>
where Self::Item: Ord + Send,

Returns the maximum element of an iterator. Read more
Sourceยง

fn max_by<Compare>(self, compare: Compare) -> Option<Self::Item>
where Self::Item: Send, Compare: Fn(&Self::Item, &Self::Item) -> Ordering + Sync,

Returns the element that gives the maximum value with respect to the specified compare function. Read more
Sourceยง

fn max_by_key<Key, GetKey>(self, key: GetKey) -> Option<Self::Item>
where Self::Item: Send, Key: Ord, GetKey: Fn(&Self::Item) -> Key + Sync,

Returns the element that gives the maximum value from the specified function. Read more
Sourceยง

fn min(self) -> Option<Self::Item>
where Self::Item: Ord + Send,

Returns the minimum element of an iterator. Read more
Sourceยง

fn min_by<Compare>(self, compare: Compare) -> Option<Self::Item>
where Self::Item: Send, Compare: Fn(&Self::Item, &Self::Item) -> Ordering + Sync,

Returns the element that gives the minimum value with respect to the specified compare function. Read more
Sourceยง

fn min_by_key<Key, GetKey>(self, get_key: GetKey) -> Option<Self::Item>
where Self::Item: Send, Key: Ord, GetKey: Fn(&Self::Item) -> Key + Sync,

Returns the element that gives the minimum value from the specified function. Read more
Sourceยง

fn sum<Out>(self) -> Out
where Self::Item: Sum<Out>, Out: Send,

Sums the elements of an iterator. Read more
Sourceยง

fn find<Predicate>(self, predicate: Predicate) -> Option<Self::Item>
where Self::Item: Send, Predicate: Fn(&Self::Item) -> bool + Sync,

Searches for an element of an iterator that satisfies a predicate. Read more
Sourceยง

impl<I, R> Send for Par<I, R>

Sourceยง

impl<I, R> Sync for Par<I, R>

Auto Trait Implementationsยง

ยง

impl<I, R> Freeze for Par<I, R>
where R: Freeze, I: Freeze,

ยง

impl<I, R> RefUnwindSafe for Par<I, R>

ยง

impl<I, R> Unpin for Par<I, R>
where R: Unpin, I: Unpin,

ยง

impl<I, R> UnwindSafe for Par<I, R>
where R: UnwindSafe, I: UnwindSafe,

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<I> IntoParIter for I

Sourceยง

fn into_par(self) -> Par<<I as IntoConcurrentIter>::IntoIter>

Trait to convert a source (collection or generator) into a parallel iterator; i.e., ParIter, using its into_par method. Read more
Sourceยง

impl<T> SoM<T> for T

Sourceยง

fn get_ref(&self) -> &T

Returns a reference to self.
Sourceยง

fn get_mut(&mut self) -> &mut T

Returns a mutable reference to self.
Sourceยง

impl<T> SoR<T> for T

Sourceยง

fn get_ref(&self) -> &T

Returns a reference to self.
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.