File tree Expand file tree Collapse file tree 4 files changed +32
-24
lines changed Expand file tree Collapse file tree 4 files changed +32
-24
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ use std::sync::atomic::{AtomicUsize, Ordering};
8
8
/// [`skip_any()`]: trait.ParallelIterator.html#method.skip_any
9
9
/// [`ParallelIterator`]: trait.ParallelIterator.html
10
10
#[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
11
- #[ derive( Debug ) ]
11
+ #[ derive( Clone , Debug ) ]
12
12
pub struct SkipAny < I : ParallelIterator > {
13
13
base : I ,
14
- count : AtomicUsize ,
14
+ count : usize ,
15
15
}
16
16
17
17
impl < I > SkipAny < I >
@@ -20,27 +20,23 @@ where
20
20
{
21
21
/// Creates a new `SkipAny` iterator.
22
22
pub ( super ) fn new ( base : I , count : usize ) -> Self {
23
- SkipAny {
24
- base,
25
- count : AtomicUsize :: new ( count) ,
26
- }
23
+ SkipAny { base, count }
27
24
}
28
25
}
29
26
30
- impl < I , T > ParallelIterator for SkipAny < I >
27
+ impl < I > ParallelIterator for SkipAny < I >
31
28
where
32
- I : ParallelIterator < Item = T > ,
33
- T : Send ,
29
+ I : ParallelIterator ,
34
30
{
35
- type Item = T ;
31
+ type Item = I :: Item ;
36
32
37
33
fn drive_unindexed < C > ( self , consumer : C ) -> C :: Result
38
34
where
39
35
C : UnindexedConsumer < Self :: Item > ,
40
36
{
41
37
let consumer1 = SkipAnyConsumer {
42
38
base : consumer,
43
- count : & self . count ,
39
+ count : & AtomicUsize :: new ( self . count ) ,
44
40
} ;
45
41
self . base . drive_unindexed ( consumer1)
46
42
}
Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ use std::sync::atomic::{AtomicUsize, Ordering};
8
8
/// [`take_any()`]: trait.ParallelIterator.html#method.take_any
9
9
/// [`ParallelIterator`]: trait.ParallelIterator.html
10
10
#[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
11
- #[ derive( Debug ) ]
11
+ #[ derive( Clone , Debug ) ]
12
12
pub struct TakeAny < I : ParallelIterator > {
13
13
base : I ,
14
- count : AtomicUsize ,
14
+ count : usize ,
15
15
}
16
16
17
17
impl < I > TakeAny < I >
@@ -20,27 +20,23 @@ where
20
20
{
21
21
/// Creates a new `TakeAny` iterator.
22
22
pub ( super ) fn new ( base : I , count : usize ) -> Self {
23
- TakeAny {
24
- base,
25
- count : AtomicUsize :: new ( count) ,
26
- }
23
+ TakeAny { base, count }
27
24
}
28
25
}
29
26
30
- impl < I , T > ParallelIterator for TakeAny < I >
27
+ impl < I > ParallelIterator for TakeAny < I >
31
28
where
32
- I : ParallelIterator < Item = T > ,
33
- T : Send ,
29
+ I : ParallelIterator ,
34
30
{
35
- type Item = T ;
31
+ type Item = I :: Item ;
36
32
37
33
fn drive_unindexed < C > ( self , consumer : C ) -> C :: Result
38
34
where
39
35
C : UnindexedConsumer < Self :: Item > ,
40
36
{
41
37
let consumer1 = TakeAnyConsumer {
42
38
base : consumer,
43
- count : & self . count ,
39
+ count : & AtomicUsize :: new ( self . count ) ,
44
40
} ;
45
41
self . base . drive_unindexed ( consumer1)
46
42
}
Original file line number Diff line number Diff line change 10
10
assert_eq ! ( a, b) ;
11
11
}
12
12
13
+ fn check_count < I > ( iter : I )
14
+ where
15
+ I : ParallelIterator + Clone ,
16
+ {
17
+ assert_eq ! ( iter. clone( ) . count( ) , iter. count( ) ) ;
18
+ }
19
+
13
20
#[ test]
14
21
fn clone_binary_heap ( ) {
15
22
use std:: collections:: BinaryHeap ;
@@ -150,8 +157,8 @@ fn clone_adaptors() {
150
157
check ( v. par_iter ( ) . panic_fuse ( ) ) ;
151
158
check ( v. par_iter ( ) . positions ( |_| true ) ) ;
152
159
check ( v. par_iter ( ) . rev ( ) ) ;
153
- check ( v. par_iter ( ) . skip ( 1 ) ) ;
154
- check ( v. par_iter ( ) . take ( 1 ) ) ;
160
+ check ( v. par_iter ( ) . skip ( 42 ) ) ;
161
+ check ( v. par_iter ( ) . take ( 42 ) ) ;
155
162
check ( v. par_iter ( ) . cloned ( ) . while_some ( ) ) ;
156
163
check ( v. par_iter ( ) . with_max_len ( 1 ) ) ;
157
164
check ( v. par_iter ( ) . with_min_len ( 1 ) ) ;
@@ -160,6 +167,13 @@ fn clone_adaptors() {
160
167
check ( v. par_iter ( ) . step_by ( 2 ) ) ;
161
168
}
162
169
170
+ #[ test]
171
+ fn clone_counted_adaptors ( ) {
172
+ let v: Vec < _ > = ( 0 ..1000 ) . collect ( ) ;
173
+ check_count ( v. par_iter ( ) . skip_any ( 42 ) ) ;
174
+ check_count ( v. par_iter ( ) . take_any ( 42 ) ) ;
175
+ }
176
+
163
177
#[ test]
164
178
fn clone_empty ( ) {
165
179
check ( rayon:: iter:: empty :: < i32 > ( ) ) ;
Original file line number Diff line number Diff line change @@ -172,7 +172,9 @@ fn debug_adaptors() {
172
172
check ( v. par_iter ( ) . positions ( |_| true ) ) ;
173
173
check ( v. par_iter ( ) . rev ( ) ) ;
174
174
check ( v. par_iter ( ) . skip ( 1 ) ) ;
175
+ check ( v. par_iter ( ) . skip_any ( 1 ) ) ;
175
176
check ( v. par_iter ( ) . take ( 1 ) ) ;
177
+ check ( v. par_iter ( ) . take_any ( 1 ) ) ;
176
178
check ( v. par_iter ( ) . map ( Some ) . while_some ( ) ) ;
177
179
check ( v. par_iter ( ) . with_max_len ( 1 ) ) ;
178
180
check ( v. par_iter ( ) . with_min_len ( 1 ) ) ;
You can’t perform that action at this time.
0 commit comments