|
| 1 | + |
| 2 | + |
| 3 | +use rayon::par_iter::ParallelIterator; |
| 4 | +use rayon::par_iter::IndexedParallelIterator; |
| 5 | +use rayon::par_iter::ExactParallelIterator; |
| 6 | +use rayon::par_iter::BoundedParallelIterator; |
| 7 | +use rayon::par_iter::internal::{Consumer, UnindexedConsumer}; |
| 8 | +use rayon::par_iter::internal::bridge; |
| 9 | +use rayon::par_iter::internal::ProducerCallback; |
| 10 | +use rayon::par_iter::internal::Producer; |
| 11 | + |
| 12 | +use super::AxisIter; |
| 13 | +use imp_prelude::*; |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +impl<'a, A, D> ParallelIterator for AxisIter<'a, A, D> |
| 18 | + where D: Dimension, |
| 19 | + A: Sync, |
| 20 | +{ |
| 21 | + type Item = <Self as Iterator>::Item; |
| 22 | + fn drive_unindexed<C>(self, consumer: C) -> C::Result |
| 23 | + where C: UnindexedConsumer<Self::Item> |
| 24 | + { |
| 25 | + bridge(self, consumer) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +impl<'a, A, D> IndexedParallelIterator for AxisIter<'a, A, D> |
| 30 | + where D: Dimension, |
| 31 | + A: Sync, |
| 32 | +{ |
| 33 | + fn with_producer<Cb>(self, callback: Cb) -> Cb::Output |
| 34 | + where Cb: ProducerCallback<Self::Item> |
| 35 | + { |
| 36 | + callback.callback(self) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +impl<'a, A, D> ExactParallelIterator for AxisIter<'a, A, D> |
| 41 | + where D: Dimension, |
| 42 | + A: Sync, |
| 43 | +{ |
| 44 | + fn len(&mut self) -> usize { |
| 45 | + self.size_hint().0 |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +impl<'a, A, D> BoundedParallelIterator for AxisIter<'a, A, D> |
| 50 | + where D: Dimension, |
| 51 | + A: Sync, |
| 52 | +{ |
| 53 | + fn upper_bound(&mut self) -> usize { |
| 54 | + ExactParallelIterator::len(self) |
| 55 | + } |
| 56 | + |
| 57 | + fn drive<C>(self, consumer: C) -> C::Result |
| 58 | + where C: Consumer<Self::Item> |
| 59 | + { |
| 60 | + bridge(self, consumer) |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +// This is the real magic, I guess |
| 65 | + |
| 66 | +impl<'a, A, D> Producer for AxisIter<'a, A, D> |
| 67 | + where D: Dimension, |
| 68 | + A: Sync, |
| 69 | +{ |
| 70 | + fn cost(&mut self, len: usize) -> f64 { |
| 71 | + // FIXME: No idea about what this is |
| 72 | + len as f64 |
| 73 | + } |
| 74 | + |
| 75 | + fn split_at(self, i: usize) -> (Self, Self) { |
| 76 | + self.split_at(i) |
| 77 | + } |
| 78 | +} |
0 commit comments