3 use self::rayon::iter::plumbing::{Consumer, UnindexedConsumer};
4 use self::rayon::iter::plumbing::ProducerCallback;
5 use self::rayon::prelude::*;
12 /// Returns an iterator of shared references which can be used to iterate
13 /// over this arena in parallel with the `rayon` crate.
17 /// This API requires the `rayon` feature of this crate to be enabled.
18 pub fn par_iter(&self) -> ParIter<T, A>
24 arena_id: self.arena_id,
25 iter: self.items.par_iter().enumerate(),
26 _phantom: PhantomData,
30 /// Returns an iterator of mutable references which can be used to iterate
31 /// over this arena in parallel with the `rayon` crate.
35 /// This API requires the `rayon` feature of this crate to be enabled.
36 pub fn par_iter_mut(&mut self) -> ParIterMut<T, A>
42 arena_id: self.arena_id,
43 iter: self.items.par_iter_mut().enumerate(),
44 _phantom: PhantomData,
49 /// A parallel iterator over shared references in an arena.
51 /// See `Arena::par_iter` for more information.
53 pub struct ParIter<'a, T, A>
58 iter: rayon::iter::Enumerate<rayon::slice::Iter<'a, T>>,
59 _phantom: PhantomData<fn() -> A>,
62 impl<'a, T, A> ParallelIterator for ParIter<'a, T, A>
68 type Item = (A::Id, &'a T);
70 fn drive_unindexed<C>(self, consumer: C) -> C::Result
72 C: UnindexedConsumer<Self::Item>,
74 let arena_id = self.arena_id;
75 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
76 .drive_unindexed(consumer)
79 fn opt_len(&self) -> Option<usize> {
84 impl<'a, T, A> IndexedParallelIterator for ParIter<'a, T, A>
90 fn drive<C>(self, consumer: C) -> C::Result
92 C: Consumer<Self::Item>,
94 let arena_id = self.arena_id;
95 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
99 fn len(&self) -> usize {
103 fn with_producer<CB>(self, callback: CB) -> CB::Output
105 CB: ProducerCallback<Self::Item>,
107 let arena_id = self.arena_id;
108 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
109 .with_producer(callback)
113 impl<'data, T, A> IntoParallelIterator for &'data Arena<T, A>
114 where A: ArenaBehavior,
118 type Item = (A::Id, &'data T);
119 type Iter = ParIter<'data, T, A>;
121 fn into_par_iter(self) -> Self::Iter {
126 /// A parallel iterator over mutable references in an arena.
128 /// See `Arena::par_iter_mut` for more information.
130 pub struct ParIterMut<'a, T, A>
135 iter: rayon::iter::Enumerate<rayon::slice::IterMut<'a, T>>,
136 _phantom: PhantomData<fn() -> A>,
139 impl<'a, T, A> ParallelIterator for ParIterMut<'a, T, A>
145 type Item = (A::Id, &'a mut T);
147 fn drive_unindexed<C>(self, consumer: C) -> C::Result
149 C: UnindexedConsumer<Self::Item>,
151 let arena_id = self.arena_id;
152 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
153 .drive_unindexed(consumer)
156 fn opt_len(&self) -> Option<usize> {
161 impl<'a, T, A> IndexedParallelIterator for ParIterMut<'a, T, A>
167 fn drive<C>(self, consumer: C) -> C::Result
169 C: Consumer<Self::Item>,
171 let arena_id = self.arena_id;
172 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
176 fn len(&self) -> usize {
180 fn with_producer<CB>(self, callback: CB) -> CB::Output
182 CB: ProducerCallback<Self::Item>,
184 let arena_id = self.arena_id;
185 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
186 .with_producer(callback)
190 impl<'data, T, A> IntoParallelIterator for &'data mut Arena<T, A>
191 where A: ArenaBehavior,
195 type Item = (A::Id, &'data mut T);
196 type Iter = ParIterMut<'data, T, A>;
198 fn into_par_iter(self) -> Self::Iter {
203 /// A parallel iterator over items in an arena.
205 /// See `Arena::into_par_iter` for more information.
207 pub struct IntoParIter<T, A>
212 iter: rayon::iter::Enumerate<rayon::vec::IntoIter<T>>,
213 _phantom: PhantomData<fn() -> A>,
216 impl<T, A> ParallelIterator for IntoParIter<T, A>
222 type Item = (A::Id, T);
224 fn drive_unindexed<C>(self, consumer: C) -> C::Result
226 C: UnindexedConsumer<Self::Item>,
228 let arena_id = self.arena_id;
229 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
230 .drive_unindexed(consumer)
233 fn opt_len(&self) -> Option<usize> {
238 impl<T, A> IndexedParallelIterator for IntoParIter<T, A>
244 fn drive<C>(self, consumer: C) -> C::Result
246 C: Consumer<Self::Item>,
248 let arena_id = self.arena_id;
249 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
253 fn len(&self) -> usize {
257 fn with_producer<CB>(self, callback: CB) -> CB::Output
259 CB: ProducerCallback<Self::Item>,
261 let arena_id = self.arena_id;
262 self.iter.map(|(i, item)| (A::new_id(arena_id, i), item))
263 .with_producer(callback)
267 impl<T, A> IntoParallelIterator for Arena<T, A>
268 where A: ArenaBehavior,
272 type Item = (A::Id, T);
273 type Iter = IntoParIter<T, A>;
275 fn into_par_iter(self) -> Self::Iter {
277 arena_id: self.arena_id,
278 iter: self.items.into_par_iter().enumerate(),
279 _phantom: PhantomData,