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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use super::iter::GenericIterator;
use crate::ParIter;
use core::cmp::Ordering;
impl<T, S, R, O> GenericIterator<T, S, R, O>
where
T: Send + Sync,
S: Iterator<Item = T>,
R: rayon::iter::ParallelIterator<Item = T>,
O: ParIter<Item = T>,
{
/// Reduction for the generic iterator.
///
/// See [`reduce`] for details.
///
/// [`reduce`]: crate::ParIter::reduce
pub fn reduce<Reduce>(self, reduce: Reduce) -> Option<T>
where
Reduce: Fn(T, T) -> T + Send + Sync,
{
match self {
GenericIterator::Sequential(x) => x.reduce(reduce),
GenericIterator::Rayon(x) => x.reduce_with(reduce),
GenericIterator::Orx(x) => x.reduce(reduce),
}
}
/// Count reduction for the generic iterator.
///
/// See [`count`] for details.
///
/// [`count`]: crate::ParIter::count
pub fn count(self) -> usize {
match self {
GenericIterator::Sequential(x) => x.count(),
GenericIterator::Rayon(x) => x.count(),
GenericIterator::Orx(x) => x.count(),
}
}
/// For-each iteration for the generic iterator.
///
/// See [`for_each`] for details.
///
/// [`for_each`]: crate::ParIter::for_each
pub fn for_each<Operation>(self, operation: Operation)
where
Operation: Fn(T) + Sync + Send,
{
match self {
GenericIterator::Sequential(x) => x.for_each(operation),
GenericIterator::Rayon(x) => x.for_each(operation),
GenericIterator::Orx(x) => x.for_each(operation),
}
}
/// Max reduction for the generic iterator.
///
/// See [`max`] for details.
///
/// [`max`]: crate::ParIter::max
pub fn max(self) -> Option<T>
where
T: Ord,
{
match self {
GenericIterator::Sequential(x) => x.max(),
GenericIterator::Rayon(x) => x.max(),
GenericIterator::Orx(x) => x.max(),
}
}
/// Max-by reduction for the generic iterator.
///
/// See [`max_by`] for details.
///
/// [`max_by`]: crate::ParIter::max_by
pub fn max_by<Compare>(self, compare: Compare) -> Option<T>
where
Compare: Fn(&T, &T) -> Ordering + Sync + Send,
{
match self {
GenericIterator::Sequential(x) => x.max_by(compare),
GenericIterator::Rayon(x) => x.max_by(compare),
GenericIterator::Orx(x) => x.max_by(compare),
}
}
/// Max-by-key reduction for the generic iterator.
///
/// See [`max_by_key`] for details.
///
/// [`max_by_key`]: crate::ParIter::max_by_key
pub fn max_by_key<Key, GetKey>(self, key: GetKey) -> Option<T>
where
Key: Ord + Send,
GetKey: Fn(&T) -> Key + Sync + Send,
{
match self {
GenericIterator::Sequential(x) => x.max_by_key(key),
GenericIterator::Rayon(x) => x.max_by_key(key),
GenericIterator::Orx(x) => x.max_by_key(key),
}
}
/// Min reduction for the generic iterator.
///
/// See [`min`] for details.
///
/// [`min`]: crate::ParIter::min
pub fn min(self) -> Option<T>
where
T: Ord,
{
match self {
GenericIterator::Sequential(x) => x.min(),
GenericIterator::Rayon(x) => x.min(),
GenericIterator::Orx(x) => x.min(),
}
}
/// Min-by reduction for the generic iterator.
///
/// See [`min_by`] for details.
///
/// [`min_by`]: crate::ParIter::min_by
pub fn min_by<Compare>(self, compare: Compare) -> Option<T>
where
Compare: Fn(&T, &T) -> Ordering + Sync + Send,
{
match self {
GenericIterator::Sequential(x) => x.min_by(compare),
GenericIterator::Rayon(x) => x.min_by(compare),
GenericIterator::Orx(x) => x.min_by(compare),
}
}
/// Min-by-key reduction for the generic iterator.
///
/// See [`min_by_key`] for details.
///
/// [`min_by_key`]: crate::ParIter::min_by_key
pub fn min_by_key<Key, GetKey>(self, key: GetKey) -> Option<T>
where
Key: Ord + Send,
GetKey: Fn(&T) -> Key + Sync + Send,
{
match self {
GenericIterator::Sequential(x) => x.min_by_key(key),
GenericIterator::Rayon(x) => x.min_by_key(key),
GenericIterator::Orx(x) => x.min_by_key(key),
}
}
/// Sum reduction for the generic iterator.
///
/// See [`sum`] for details.
///
/// [`sum`]: crate::ParIter::sum
pub fn sum(self) -> T
where
T: crate::special_type_sets::Sum<T> + core::iter::Sum<T>,
{
match self {
GenericIterator::Sequential(x) => x.sum(),
GenericIterator::Rayon(x) => x.sum(),
GenericIterator::Orx(x) => x.sum(),
}
}
}