usesuper::plumbing::*; usesuper::*; use rayon_core::join; use std::iter;
/// `Chain` is an iterator that joins `b` after `a` in one continuous iterator. /// This struct is created by the [`chain()`] method on [`ParallelIterator`] /// /// [`chain()`]: trait.ParallelIterator.html#method.chain /// [`ParallelIterator`]: trait.ParallelIterator.html #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] #[derive(Debug, Clone)] pubstruct Chain<A, B> where
A: ParallelIterator,
B: ParallelIterator<Item = A::Item>,
{
a: A,
b: B,
}
impl<A, B> Chain<A, B> where
A: ParallelIterator,
B: ParallelIterator<Item = A::Item>,
{ /// Creates a new `Chain` iterator. pub(super) fn new(a: A, b: B) -> Self {
Chain { a, b }
}
}
impl<A, B> ParallelIterator for Chain<A, B> where
A: ParallelIterator,
B: ParallelIterator<Item = A::Item>,
{ type Item = A::Item;
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{ let Chain { a, b } = self;
// If we returned a value from our own `opt_len`, then the collect consumer in particular // will balk at being treated like an actual `UnindexedConsumer`. But when we do know the // length, we can use `Consumer::split_at` instead, and this is still harmless for other // truly-unindexed consumers too. let (left, right, reducer) = iflet Some(len) = a.opt_len() {
consumer.split_at(len)
} else { let reducer = consumer.to_reducer();
(consumer.split_off_left(), consumer, reducer)
};
let (a, b) = join(|| a.drive_unindexed(left), || b.drive_unindexed(right));
reducer.reduce(a, b)
}
impl<A, B> IndexedParallelIterator for Chain<A, B> where
A: IndexedParallelIterator,
B: IndexedParallelIterator<Item = A::Item>,
{ fn drive<C>(self, consumer: C) -> C::Result where
C: Consumer<Self::Item>,
{ let Chain { a, b } = self; let (left, right, reducer) = consumer.split_at(a.len()); let (a, b) = join(|| a.drive(left), || b.drive(right));
reducer.reduce(a, b)
}
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.