]>
git.proxmox.com Git - rustc.git/blob - vendor/rayon/src/iter/step_by.rs
4 use super::plumbing
::*;
6 use crate::math
::div_round_up
;
10 /// `StepBy` is an iterator that skips `n` elements between each yield, where `n` is the given step.
11 /// This struct is created by the [`step_by()`] method on [`IndexedParallelIterator`]
13 /// [`step_by()`]: trait.IndexedParallelIterator.html#method.step_by
14 /// [`IndexedParallelIterator`]: trait.IndexedParallelIterator.html
15 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
16 #[derive(Debug, Clone)]
17 pub struct StepBy
<I
: IndexedParallelIterator
> {
24 I
: IndexedParallelIterator
,
26 /// Creates a new `StepBy` iterator.
27 pub(super) fn new(base
: I
, step
: usize) -> Self {
32 impl<I
> ParallelIterator
for StepBy
<I
>
34 I
: IndexedParallelIterator
,
38 fn drive_unindexed
<C
>(self, consumer
: C
) -> C
::Result
40 C
: UnindexedConsumer
<Self::Item
>,
42 bridge(self, consumer
)
45 fn opt_len(&self) -> Option
<usize> {
50 impl<I
> IndexedParallelIterator
for StepBy
<I
>
52 I
: IndexedParallelIterator
,
54 fn drive
<C
: Consumer
<Self::Item
>>(self, consumer
: C
) -> C
::Result
{
55 bridge(self, consumer
)
58 fn len(&self) -> usize {
59 div_round_up(self.base
.len(), self.step
)
62 fn with_producer
<CB
>(self, callback
: CB
) -> CB
::Output
64 CB
: ProducerCallback
<Self::Item
>,
66 let len
= self.base
.len();
67 return self.base
.with_producer(Callback
{
79 impl<T
, CB
> ProducerCallback
<T
> for Callback
<CB
>
81 CB
: ProducerCallback
<T
>,
83 type Output
= CB
::Output
;
84 fn callback
<P
>(self, base
: P
) -> CB
::Output
86 P
: Producer
<Item
= T
>,
88 let producer
= StepByProducer
{
93 self.callback
.callback(producer
)
99 /// ////////////////////////////////////////////////////////////////////////
100 /// Producer implementation
102 struct StepByProducer
<P
> {
108 impl<P
> Producer
for StepByProducer
<P
>
113 type IntoIter
= iter
::StepBy
<P
::IntoIter
>;
115 fn into_iter(self) -> Self::IntoIter
{
116 self.base
.into_iter().step_by(self.step
)
119 fn split_at(self, index
: usize) -> (Self, Self) {
120 let elem_index
= min(index
* self.step
, self.len
);
122 let (left
, right
) = self.base
.split_at(elem_index
);
132 len
: self.len
- elem_index
,
137 fn min_len(&self) -> usize {
138 div_round_up(self.base
.min_len(), self.step
)
141 fn max_len(&self) -> usize {
142 self.base
.max_len() / self.step