impl<U, I, ID, F> Fold<I, ID, F> where
I: ParallelIterator,
F: Fn(U, I::Item) -> U + Sync + Send,
ID: Fn() -> U + Sync + Send,
U: Send,
{ pub(super) fn new(base: I, identity: ID, fold_op: F) -> Self {
Fold {
base,
identity,
fold_op,
}
}
}
/// `Fold` is an iterator that applies a function over an iterator producing a single value. /// This struct is created by the [`fold()`] method on [`ParallelIterator`] /// /// [`fold()`]: trait.ParallelIterator.html#method.fold /// [`ParallelIterator`]: trait.ParallelIterator.html #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[derive(Clone)] pubstruct Fold<I, ID, F> {
base: I,
identity: ID,
fold_op: F,
}
impl<'r, U, T, C, ID, F> Consumer<T> for FoldConsumer<'r, C, ID, F> where
C: Consumer<U>,
F: Fn(U, T) -> U + Sync,
ID: Fn() -> U + Sync,
U: Send,
{ type Folder = FoldFolder<'r, C::Folder, U, F>; type Reducer = C::Reducer; type Result = C::Result;
let base = self.base; let item = iter
.into_iter() // stop iterating if another thread has finished
.take_while(not_full(&base))
.fold(self.item, self.fold_op);
impl<U, I, F> FoldWith<I, U, F> where
I: ParallelIterator,
F: Fn(U, I::Item) -> U + Sync + Send,
U: Send + Clone,
{ pub(super) fn new(base: I, item: U, fold_op: F) -> Self {
FoldWith {
base,
item,
fold_op,
}
}
}
/// `FoldWith` is an iterator that applies a function over an iterator producing a single value. /// This struct is created by the [`fold_with()`] method on [`ParallelIterator`] /// /// [`fold_with()`]: trait.ParallelIterator.html#method.fold_with /// [`ParallelIterator`]: trait.ParallelIterator.html #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[derive(Clone)] pubstruct FoldWith<I, U, F> {
base: I,
item: U,
fold_op: F,
}
impl<U, I, F> ParallelIterator for FoldWith<I, U, F> where
I: ParallelIterator,
F: Fn(U, I::Item) -> U + Sync + Send,
U: Send + Clone,
{ type Item = U;
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{ let consumer1 = FoldWithConsumer {
base: consumer,
item: self.item,
fold_op: &self.fold_op,
}; self.base.drive_unindexed(consumer1)
}
}
struct FoldWithConsumer<'c, C, U, F> {
base: C,
item: U,
fold_op: &'c F,
}
impl<'r, U, T, C, F> Consumer<T> for FoldWithConsumer<'r, C, U, F> where
C: Consumer<U>,
F: Fn(U, T) -> U + Sync,
U: Send + Clone,
{ type Folder = FoldFolder<'r, C::Folder, U, F>; type Reducer = C::Reducer; type Result = C::Result;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.