Trait jobsteal::iter::Spliterator
[−]
[src]
pub trait Spliterator: Sized { type Item; type Base: Split; type Consumer: Consumer<Self::Base, Item = Self::Item>; fn destructure(self) -> (Self::Base, Self::Consumer); fn cloned<'a, T: 'a + Clone>(self) -> Cloned<Self>
where
Self: Spliterator<Item = &'a T>, { ... } fn enumerate(self) -> Enumerate<Self> { ... } fn filter<F: Sync>(self, pred: F) -> Filter<Self, F>
where
F: Fn(&Self::Item) -> bool, { ... } fn flat_map<U, F: Sync>(self, flat_map: F) -> FlatMap<Self, F>
where
U: IntoIterator,
F: Fn(Self::Item) -> U, { ... } fn map<F: Sync, U>(self, map: F) -> Map<Self, F>
where
F: Fn(Self::Item) -> U, { ... } fn zip<B: IntoSpliterator>(self, other: B) -> Zip<Self, B::SplitIter> { ... } fn any<P: Sync>(self, spawner: &Spawner, pred: P) -> bool
where
P: Fn(Self::Item) -> bool, { ... } fn all<P: Sync>(self, spawner: &Spawner, pred: P) -> bool
where
P: Fn(Self::Item) -> bool, { ... } fn for_each<F>(self, spawner: &Spawner, f: F)
where
F: Sync + Fn(Self::Item), { ... } fn collect<T: Send>(self, spawner: &Spawner) -> T
where
Self::Item: Send,
T: FromIterator<Self::Item> + Combine + Send, { ... } fn fold<F: Sync>(
self,
spawner: &Spawner,
initial: Self::Item,
folder: F
) -> Self::Item
where
F: Folder<Self::Item>,
Self::Item: Send, { ... } fn size_hint(&self) -> (usize, Option<usize>) { ... } fn with_cost_mul(self, mul: f32) -> CostMul<Self> { ... } }
A parallel iterator which works by splitting the underlying data and sharing it between threads.
Functions which consume the iterator will take a &Spawner
as an argument,
so that they can distribute their work in parallel.
These can be used almost exactly the same as Rust's regular Iterators
,
with adapters like enumerate
, map
, filter
, and more along with
consumers like for_each
and collect
.
This trait may seem complicated to implement, but fear not!
It is automatically implemented for data which implements Split
,
which is a lot easier to implement.
Spliterator
only needs to be manually implemented by those who are
trying to make their own adapters. Those individuals may want to look
at the source of iterator adapters like Map
and Filter
. The good news
is that all the Spliterator
adapers are implemented using only public
and safe jobsteal code, so anybody can create their own. The bad news is
that it does get fairly complex.
Associated Types
type Item
The item this iterator produces.
type Base: Split
The splittable base data which this consists of.
type Consumer: Consumer<Self::Base, Item = Self::Item>
A consumer which can act as an ad-hoc iterator adapter chain while being shared across threads.
Required Methods
fn destructure(self) -> (Self::Base, Self::Consumer)
Destructure this iterator into a splittable base and a shareable consumer of that base.
Provided Methods
fn cloned<'a, T: 'a + Clone>(self) -> Cloned<Self> where
Self: Spliterator<Item = &'a T>,
Self: Spliterator<Item = &'a T>,
Clone the items of this iterator to get owned copies.
fn enumerate(self) -> Enumerate<Self>
Enumerate items by their index.
fn filter<F: Sync>(self, pred: F) -> Filter<Self, F> where
F: Fn(&Self::Item) -> bool,
F: Fn(&Self::Item) -> bool,
Filter items by some predicate.
fn flat_map<U, F: Sync>(self, flat_map: F) -> FlatMap<Self, F> where
U: IntoIterator,
F: Fn(Self::Item) -> U,
U: IntoIterator,
F: Fn(Self::Item) -> U,
Produce an iterator for each element, and then yield the elements of those iterators.
fn map<F: Sync, U>(self, map: F) -> Map<Self, F> where
F: Fn(Self::Item) -> U,
F: Fn(Self::Item) -> U,
Map the items of this iterator to another type using the supplied function.
fn zip<B: IntoSpliterator>(self, other: B) -> Zip<Self, B::SplitIter>
Zip this iterator with another, combining their items in a tuple.
fn any<P: Sync>(self, spawner: &Spawner, pred: P) -> bool where
P: Fn(Self::Item) -> bool,
P: Fn(Self::Item) -> bool,
Whether any of the elements fulfill the supplied predicate.
fn all<P: Sync>(self, spawner: &Spawner, pred: P) -> bool where
P: Fn(Self::Item) -> bool,
P: Fn(Self::Item) -> bool,
Whether all of the elements fulfill the supplied predicate.
fn for_each<F>(self, spawner: &Spawner, f: F) where
F: Sync + Fn(Self::Item),
F: Sync + Fn(Self::Item),
Consume this iterator, performing an action for each item.
fn collect<T: Send>(self, spawner: &Spawner) -> T where
Self::Item: Send,
T: FromIterator<Self::Item> + Combine + Send,
Self::Item: Send,
T: FromIterator<Self::Item> + Combine + Send,
Collect the items of this iterator into a combinable collection.
Note that this works by repeatedly combining the results of from_iter
,
so this will probably lead to more allocations than a single-threaded
iterator collect
.
fn fold<F: Sync>(
self,
spawner: &Spawner,
initial: Self::Item,
folder: F
) -> Self::Item where
F: Folder<Self::Item>,
Self::Item: Send,
self,
spawner: &Spawner,
initial: Self::Item,
folder: F
) -> Self::Item where
F: Folder<Self::Item>,
Self::Item: Send,
Fold the items of the iterator together with the given operation and initial state.
Note: For this to work in parallel, the implementation assumes that the operation is commutative.
There will not be any safety issues caused by non-commutative operations, but there may be some incorrectness.
fn size_hint(&self) -> (usize, Option<usize>)
A lower bound and optional upper bound on the size of this iterator.
fn with_cost_mul(self, mul: f32) -> CostMul<Self>
Uses a cost multiplier for this iterator.
This takes the absolute value of the multiplier supplied.
This will affect how often the data backing this iterator is split in two.
with_cost_mul(1.0)
will have no effect.
with_cost_mul(2.0)
will cause twice as much splitting, while
with_cost_mul(0.5)
will cause half as much splitting.
with_cost_mul(0.0)
will cause the data to never split, and
with_cost_mul(f32::INFINITY)
will cause the data to split whenever
possible.
Implementors
impl<T: Spliterator> Spliterator for CostMul<T>
impl<T: ExactSizeSpliterator> Spliterator for Enumerate<T>
impl<T: Spliterator, F: Sync> Spliterator for Filter<T, F> where
F: Fn(&T::Item) -> bool,impl<T: Spliterator, F, U> Spliterator for FlatMap<T, F> where
F: Sync + Fn(T::Item) -> U,
U: IntoIterator,impl<T: Spliterator, F: Sync, U> Spliterator for Map<T, F> where
F: Fn(T::Item) -> U,impl<'a, T, U: Clone + 'a> Spliterator for Cloned<T> where
T: Spliterator<Item = &'a U>,impl<A: Spliterator, B: Spliterator> Spliterator for Zip<A, B>
impl<T: Split> Spliterator for T