impl<T, A> Arena<T, A> where
A: ArenaBehavior,
{ /// Returns an iterator of shared references which can be used to iterate /// over this arena in parallel with the `rayon` crate. /// /// # Features /// /// This API requires the `rayon` feature of this crate to be enabled. pubfn par_iter(&self) -> ParIter<T, A> where
T: Sync,
A::Id: Send,
{
ParIter {
arena_id: self.arena_id,
iter: self.items.par_iter().enumerate(),
_phantom: PhantomData,
}
}
/// Returns an iterator of mutable references which can be used to iterate /// over this arena in parallel with the `rayon` crate. /// /// # Features /// /// This API requires the `rayon` feature of this crate to be enabled. pubfn par_iter_mut(&mutself) -> ParIterMut<T, A> where
T: Send + Sync,
A::Id: Send,
{
ParIterMut {
arena_id: self.arena_id,
iter: self.items.par_iter_mut().enumerate(),
_phantom: PhantomData,
}
}
}
/// A parallel iterator over shared references in an arena. /// /// See `Arena::par_iter` for more information. #[derive(Debug)] pubstruct ParIter<'a, T, A> where
T: Sync,
{
arena_id: u32,
iter: rayon::iter::Enumerate<rayon::slice::Iter<'a, T>>,
_phantom: PhantomData<fn() -> A>,
}
impl<'a, T, A> ParallelIterator for ParIter<'a, T, A> where
T: Sync,
A: ArenaBehavior,
A::Id: Send,
{ type Item = (A::Id, &'a T);
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{ let arena_id = self.arena_id; self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
.drive_unindexed(consumer)
}
impl<'data, T, A> IntoParallelIterator for &'data Arena<T, A> where A: ArenaBehavior,
A::Id: Send,
T: Sync,
{ type Item = (A::Id, &'data T); type Iter = ParIter<'data, T, A>;
/// A parallel iterator over mutable references in an arena. /// /// See `Arena::par_iter_mut` for more information. #[derive(Debug)] pubstruct ParIterMut<'a, T, A> where
T: Send + Sync,
{
arena_id: u32,
iter: rayon::iter::Enumerate<rayon::slice::IterMut<'a, T>>,
_phantom: PhantomData<fn() -> A>,
}
impl<'a, T, A> ParallelIterator for ParIterMut<'a, T, A> where
T: Send + Sync,
A: ArenaBehavior,
A::Id: Send,
{ type Item = (A::Id, &'a mut T);
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{ let arena_id = self.arena_id; self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
.drive_unindexed(consumer)
}
impl<'data, T, A> IntoParallelIterator for &'data mut Arena<T, A> where A: ArenaBehavior,
A::Id: Send,
T: Send + Sync,
{ type Item = (A::Id, &'data mut T); type Iter = ParIterMut<'data, T, A>;
/// A parallel iterator over items in an arena. /// /// See `Arena::into_par_iter` for more information. #[derive(Debug)] pubstruct IntoParIter<T, A> where
T: Send,
{
arena_id: u32,
iter: rayon::iter::Enumerate<rayon::vec::IntoIter<T>>,
_phantom: PhantomData<fn() -> A>,
}
impl<T, A> ParallelIterator for IntoParIter<T, A> where
T: Send,
A: ArenaBehavior,
A::Id: Send,
{ type Item = (A::Id, T);
fn drive_unindexed<C>(self, consumer: C) -> C::Result where
C: UnindexedConsumer<Self::Item>,
{ let arena_id = self.arena_id; self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
.drive_unindexed(consumer)
}
impl<T, A> IndexedParallelIterator for IntoParIter<T, A> where
T: Send,
A: ArenaBehavior,
A::Id: Send,
{ fn drive<C>(self, consumer: C) -> C::Result where
C: Consumer<Self::Item>,
{ let arena_id = self.arena_id; self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
.drive(consumer)
}
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.