@@ -17,6 +17,7 @@ use core::hash::{BuildHasher, Hash};
17
17
use crate :: Bucket ;
18
18
use crate :: Entries ;
19
19
use crate :: IndexMap ;
20
+ use crate :: map:: Slice ;
20
21
21
22
/// Requires crate feature `"rayon"`.
22
23
impl < K , V , S > IntoParallelIterator for IndexMap < K , V , S >
78
79
}
79
80
}
80
81
82
+ /// Requires crate feature `"rayon"`.
83
+ impl < ' a , K , V > IntoParallelIterator for & ' a Slice < K , V >
84
+ where
85
+ K : Sync ,
86
+ V : Sync ,
87
+ {
88
+ type Item = ( & ' a K , & ' a V ) ;
89
+ type Iter = ParIter < ' a , K , V > ;
90
+
91
+ fn into_par_iter ( self ) -> Self :: Iter {
92
+ ParIter {
93
+ entries : & self . entries ,
94
+ }
95
+ }
96
+ }
97
+
81
98
/// A parallel iterator over the entries of a `IndexMap`.
82
99
///
83
100
/// This `struct` is created by the [`par_iter`] method on [`IndexMap`]
@@ -128,6 +145,22 @@ where
128
145
}
129
146
}
130
147
148
+ /// Requires crate feature `"rayon"`.
149
+ impl < ' a , K , V > IntoParallelIterator for & ' a mut Slice < K , V >
150
+ where
151
+ K : Sync + Send ,
152
+ V : Send ,
153
+ {
154
+ type Item = ( & ' a K , & ' a mut V ) ;
155
+ type Iter = ParIterMut < ' a , K , V > ;
156
+
157
+ fn into_par_iter ( self ) -> Self :: Iter {
158
+ ParIterMut {
159
+ entries : & mut self . entries ,
160
+ }
161
+ }
162
+ }
163
+
131
164
/// A parallel mutable iterator over the entries of a `IndexMap`.
132
165
///
133
166
/// This `struct` is created by the [`par_iter_mut`] method on [`IndexMap`]
@@ -180,6 +213,37 @@ where
180
213
}
181
214
}
182
215
216
+ /// Parallel iterator methods and other parallel methods.
217
+ ///
218
+ /// The following methods **require crate feature `"rayon"`**.
219
+ ///
220
+ /// See also the `IntoParallelIterator` implementations.
221
+ impl < K , V > Slice < K , V >
222
+ where
223
+ K : Sync ,
224
+ V : Sync ,
225
+ {
226
+ /// Return a parallel iterator over the keys of the map slice.
227
+ ///
228
+ /// While parallel iterators can process items in any order, their relative order
229
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
230
+ pub fn par_keys ( & self ) -> ParKeys < ' _ , K , V > {
231
+ ParKeys {
232
+ entries : & self . entries ,
233
+ }
234
+ }
235
+
236
+ /// Return a parallel iterator over the values of the map slice.
237
+ ///
238
+ /// While parallel iterators can process items in any order, their relative order
239
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
240
+ pub fn par_values ( & self ) -> ParValues < ' _ , K , V > {
241
+ ParValues {
242
+ entries : & self . entries ,
243
+ }
244
+ }
245
+ }
246
+
183
247
impl < K , V , S > IndexMap < K , V , S >
184
248
where
185
249
K : Hash + Eq + Sync ,
@@ -286,6 +350,23 @@ where
286
350
}
287
351
}
288
352
353
+ /// Requires crate feature `"rayon"`.
354
+ impl < K , V > Slice < K , V >
355
+ where
356
+ K : Send ,
357
+ V : Send ,
358
+ {
359
+ /// Return a parallel iterator over mutable references to the the values of the map slice.
360
+ ///
361
+ /// While parallel iterators can process items in any order, their relative order
362
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
363
+ pub fn par_values_mut ( & mut self ) -> ParValuesMut < ' _ , K , V > {
364
+ ParValuesMut {
365
+ entries : & mut self . entries ,
366
+ }
367
+ }
368
+ }
369
+
289
370
impl < K , V , S > IndexMap < K , V , S >
290
371
where
291
372
K : Hash + Eq + Send ,
0 commit comments