//! This module contains the parallel iterator types for double-ended queues //! (`VecDeque<T>`). You will rarely need to interact with it directly //! unless you have need to name one of the iterator types.
use std::collections::VecDeque; use std::ops::{Range, RangeBounds};
/// Parallel iterator over a double-ended queue #[derive(Debug, Clone)] pubstruct IntoIter<T: Send> {
inner: vec::IntoIter<T>,
}
impl<T: Send> IntoParallelIterator for VecDeque<T> { type Item = T; type Iter = IntoIter<T>;
fn into_par_iter(self) -> Self::Iter { // NOTE: requires data movement if the deque doesn't start at offset 0. let inner = Vec::from(self).into_par_iter();
IntoIter { inner }
}
}
/// Draining parallel iterator that moves a range out of a double-ended queue, /// but keeps the total capacity. #[derive(Debug)] pubstruct Drain<'a, T: Send> {
deque: &'a mut VecDeque<T>,
range: Range<usize>,
orig_len: usize,
}
impl<'a, T: Send> ParallelDrainRange<usize> for &'a mut VecDeque<T> { type Iter = Drain<'a, T>; type Item = T;
impl<'a, T: Send> IndexedParallelIterator for Drain<'a, T> { fn drive<C>(self, consumer: C) -> C::Result where
C: Consumer<Self::Item>,
{
bridge(self, consumer)
}
fn len(&self) -> usize { self.range.len()
}
fn with_producer<CB>(self, callback: CB) -> CB::Output where
CB: ProducerCallback<Self::Item>,
{ // NOTE: requires data movement if the deque doesn't start at offset 0. super::DrainGuard::new(self.deque)
.par_drain(self.range.clone())
.with_producer(callback)
}
}
impl<'a, T: Send> Drop for Drain<'a, T> { fn drop(&mutself) { ifself.deque.len() != self.orig_len - self.range.len() { // We must not have produced, so just call a normal drain to remove the items.
assert_eq!(self.deque.len(), self.orig_len); self.deque.drain(self.range.clone());
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-06-24)
¤
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.