1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use super::*;
use super::internal::*;
use std::ops::Range;
pub struct RangeIter<T> {
range: Range<T>
}
macro_rules! range_impl {
( $t:ty ) => {
impl IntoParallelIterator for Range<$t> {
type Item = $t;
type Iter = RangeIter<$t>;
fn into_par_iter(self) -> Self::Iter {
RangeIter { range: self }
}
}
impl ParallelIterator for RangeIter<$t> {
type Item = $t;
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where C: UnindexedConsumer<Self::Item>
{
bridge(self, consumer)
}
}
impl BoundedParallelIterator for RangeIter<$t> {
fn upper_bound(&mut self) -> usize {
ExactParallelIterator::len(self)
}
fn drive<C>(self, consumer: C) -> C::Result
where C: Consumer<Self::Item>
{
bridge(self, consumer)
}
}
impl ExactParallelIterator for RangeIter<$t> {
fn len(&mut self) -> usize {
self.range.len() as usize
}
}
impl IndexedParallelIterator for RangeIter<$t> {
fn with_producer<CB>(self, callback: CB) -> CB::Output
where CB: ProducerCallback<Self::Item>
{
callback.callback(self)
}
}
impl Producer for RangeIter<$t> {
fn cost(&mut self, len: usize) -> f64 {
len as f64
}
fn split_at(self, index: usize) -> (Self, Self) {
assert!(index <= self.range.len());
let mid = self.range.start.wrapping_add(index as $t);
let left = self.range.start .. mid;
let right = mid .. self.range.end;
(RangeIter { range: left }, RangeIter { range: right })
}
}
impl IntoIterator for RangeIter<$t> {
type Item = $t;
type IntoIter = Range<$t>;
fn into_iter(self) -> Self::IntoIter {
self.range
}
}
}
}
range_impl!{u8}
range_impl!{u16}
range_impl!{u32}
range_impl!{usize}
range_impl!{i8}
range_impl!{i16}
range_impl!{i32}
range_impl!{isize}