summaryrefslogtreecommitdiffstats
path: root/third_party/rust/indexmap/src/rustc.rs
blob: b843858b325d71cc359c81e5fb7ef5ee91f6cdb3 (plain)
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
//! Minimal support for `rustc-rayon`, not intended for general use.

use crate::vec::Vec;
use crate::{Bucket, Entries, IndexMap, IndexSet};

use rustc_rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
use rustc_rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};

mod map {
    use super::*;

    impl<K, V, S> IntoParallelIterator for IndexMap<K, V, S>
    where
        K: Send,
        V: Send,
    {
        type Item = (K, V);
        type Iter = IntoParIter<K, V>;

        fn into_par_iter(self) -> Self::Iter {
            IntoParIter {
                entries: self.into_entries(),
            }
        }
    }

    pub struct IntoParIter<K, V> {
        entries: Vec<Bucket<K, V>>,
    }

    impl<K: Send, V: Send> ParallelIterator for IntoParIter<K, V> {
        type Item = (K, V);

        parallel_iterator_methods!(Bucket::key_value);
    }

    impl<K: Send, V: Send> IndexedParallelIterator for IntoParIter<K, V> {
        indexed_parallel_iterator_methods!(Bucket::key_value);
    }

    impl<'a, K, V, S> IntoParallelIterator for &'a IndexMap<K, V, S>
    where
        K: Sync,
        V: Sync,
    {
        type Item = (&'a K, &'a V);
        type Iter = ParIter<'a, K, V>;

        fn into_par_iter(self) -> Self::Iter {
            ParIter {
                entries: self.as_entries(),
            }
        }
    }

    pub struct ParIter<'a, K, V> {
        entries: &'a [Bucket<K, V>],
    }

    impl<'a, K: Sync, V: Sync> ParallelIterator for ParIter<'a, K, V> {
        type Item = (&'a K, &'a V);

        parallel_iterator_methods!(Bucket::refs);
    }

    impl<K: Sync, V: Sync> IndexedParallelIterator for ParIter<'_, K, V> {
        indexed_parallel_iterator_methods!(Bucket::refs);
    }

    impl<'a, K, V, S> IntoParallelIterator for &'a mut IndexMap<K, V, S>
    where
        K: Sync + Send,
        V: Send,
    {
        type Item = (&'a K, &'a mut V);
        type Iter = ParIterMut<'a, K, V>;

        fn into_par_iter(self) -> Self::Iter {
            ParIterMut {
                entries: self.as_entries_mut(),
            }
        }
    }

    pub struct ParIterMut<'a, K, V> {
        entries: &'a mut [Bucket<K, V>],
    }

    impl<'a, K: Sync + Send, V: Send> ParallelIterator for ParIterMut<'a, K, V> {
        type Item = (&'a K, &'a mut V);

        parallel_iterator_methods!(Bucket::ref_mut);
    }

    impl<K: Sync + Send, V: Send> IndexedParallelIterator for ParIterMut<'_, K, V> {
        indexed_parallel_iterator_methods!(Bucket::ref_mut);
    }
}

mod set {
    use super::*;

    impl<T, S> IntoParallelIterator for IndexSet<T, S>
    where
        T: Send,
    {
        type Item = T;
        type Iter = IntoParIter<T>;

        fn into_par_iter(self) -> Self::Iter {
            IntoParIter {
                entries: self.into_entries(),
            }
        }
    }

    pub struct IntoParIter<T> {
        entries: Vec<Bucket<T, ()>>,
    }

    impl<T: Send> ParallelIterator for IntoParIter<T> {
        type Item = T;

        parallel_iterator_methods!(Bucket::key);
    }

    impl<T: Send> IndexedParallelIterator for IntoParIter<T> {
        indexed_parallel_iterator_methods!(Bucket::key);
    }

    impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S>
    where
        T: Sync,
    {
        type Item = &'a T;
        type Iter = ParIter<'a, T>;

        fn into_par_iter(self) -> Self::Iter {
            ParIter {
                entries: self.as_entries(),
            }
        }
    }

    pub struct ParIter<'a, T> {
        entries: &'a [Bucket<T, ()>],
    }

    impl<'a, T: Sync> ParallelIterator for ParIter<'a, T> {
        type Item = &'a T;

        parallel_iterator_methods!(Bucket::key_ref);
    }

    impl<T: Sync> IndexedParallelIterator for ParIter<'_, T> {
        indexed_parallel_iterator_methods!(Bucket::key_ref);
    }
}