/// Creates a parallel iterator that endlessly repeats `elt` (by /// cloning it). Note that this iterator has "infinite" length, so /// typically you would want to use `zip` or `take` or some other /// means to shorten it, or consider using /// [the `repeatn()` function](fn.repeatn.html) instead. /// /// # Examples /// /// ``` /// use rayon::prelude::*; /// use rayon::iter::repeat; /// let x: Vec<(i32, i32)> = repeat(22).zip(0..3).collect(); /// assert_eq!(x, vec![(22, 0), (22, 1), (22, 2)]); /// ``` pubfn repeat<T: Clone + Send>(elt: T) -> Repeat<T> {
Repeat { element: elt }
}
impl<T> Repeat<T> where
T: Clone + Send,
{ /// Takes only `n` repeats of the element, similar to the general /// [`take()`](trait.IndexedParallelIterator.html#method.take). /// /// The resulting `RepeatN` is an `IndexedParallelIterator`, allowing /// more functionality than `Repeat` alone. pubfn take(self, n: usize) -> RepeatN<T> {
repeatn(self.element, n)
}
/// Iterates tuples, repeating the element with items from another /// iterator, similar to the general /// [`zip()`](trait.IndexedParallelIterator.html#method.zip). pubfn zip<Z>(self, zip_op: Z) -> Zip<RepeatN<T>, Z::Iter> where
Z: IntoParallelIterator,
Z::Iter: IndexedParallelIterator,
{ let z = zip_op.into_par_iter(); let n = z.len(); self.take(n).zip(z)
}
}
impl<T> ParallelIterator for Repeat<T> where
T: Clone + Send,
{ type Item = T;
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{ let producer = RepeatProducer {
element: self.element,
};
bridge_unindexed(producer, consumer)
}
}
/// Iterator for `RepeatN`. /// /// This is conceptually like `std::iter::Take<std::iter::Repeat<T>>`, but /// we need `DoubleEndedIterator` and unconditional `ExactSizeIterator`. struct Iter<T: Clone> {
element: T,
count: usize,
}
impl<T: Clone> Iterator for Iter<T> { type Item = T;
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.