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
use super::*;
use super::internal::*;
pub struct SliceIterMut<'data, T: 'data + Send> {
slice: &'data mut [T]
}
impl<'data, T: Send + 'data> IntoParallelIterator for &'data mut [T] {
type Item = &'data mut T;
type Iter = SliceIterMut<'data, T>;
fn into_par_iter(self) -> Self::Iter {
SliceIterMut { slice: self }
}
}
impl<'data, T: Send + 'data> IntoParallelIterator for &'data mut Vec<T> {
type Item = &'data mut T;
type Iter = SliceIterMut<'data, T>;
fn into_par_iter(self) -> Self::Iter {
SliceIterMut { slice: self }
}
}
impl<'data, T: Send + 'data> IntoParallelRefMutIterator<'data> for [T] {
type Item = T;
type Iter = SliceIterMut<'data, T>;
fn par_iter_mut(&'data mut self) -> Self::Iter {
self.into_par_iter()
}
}
impl<'data, T: Send + 'data> ParallelIterator for SliceIterMut<'data, T> {
type Item = &'data mut T;
fn drive_unindexed<C>(self, consumer: C) -> C::Result
where C: UnindexedConsumer<Self::Item>
{
bridge(self, consumer)
}
}
impl<'data, T: Send + 'data> BoundedParallelIterator for SliceIterMut<'data, 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<'data, T: Send + 'data> ExactParallelIterator for SliceIterMut<'data, T> {
fn len(&mut self) -> usize {
self.slice.len()
}
}
impl<'data, T: Send + 'data> IndexedParallelIterator for SliceIterMut<'data, T> {
fn with_producer<CB>(self, callback: CB) -> CB::Output
where CB: ProducerCallback<Self::Item>
{
callback.callback(SliceMutProducer { slice: self.slice })
}
}
pub struct SliceMutProducer<'data, T: 'data + Send> {
slice: &'data mut [T]
}
impl<'data, T: 'data + Send> Producer for SliceMutProducer<'data, T>
{
fn cost(&mut self, len: usize) -> f64 {
len as f64
}
fn split_at(self, index: usize) -> (Self, Self) {
let (left, right) = self.slice.split_at_mut(index);
(SliceMutProducer { slice: left }, SliceMutProducer { slice: right })
}
}
impl<'data, T: 'data + Send> IntoIterator for SliceMutProducer<'data, T> {
type Item = &'data mut T;
type IntoIter = ::std::slice::IterMut<'data, T>;
fn into_iter(self) -> Self::IntoIter {
self.slice.into_iter()
}
}