@@ -15,6 +15,7 @@ use core::fmt;
15
15
use core:: hash:: { BuildHasher , Hash } ;
16
16
use core:: ops:: RangeBounds ;
17
17
18
+ use crate :: map:: Slice ;
18
19
use crate :: Bucket ;
19
20
use crate :: Entries ;
20
21
use crate :: IndexMap ;
79
80
}
80
81
}
81
82
83
+ /// Requires crate feature `"rayon"`.
84
+ impl < ' a , K , V > IntoParallelIterator for & ' a Slice < K , V >
85
+ where
86
+ K : Sync ,
87
+ V : Sync ,
88
+ {
89
+ type Item = ( & ' a K , & ' a V ) ;
90
+ type Iter = ParIter < ' a , K , V > ;
91
+
92
+ fn into_par_iter ( self ) -> Self :: Iter {
93
+ ParIter {
94
+ entries : & self . entries ,
95
+ }
96
+ }
97
+ }
98
+
82
99
/// A parallel iterator over the entries of a `IndexMap`.
83
100
///
84
101
/// This `struct` is created by the [`par_iter`] method on [`IndexMap`]
@@ -129,6 +146,22 @@ where
129
146
}
130
147
}
131
148
149
+ /// Requires crate feature `"rayon"`.
150
+ impl < ' a , K , V > IntoParallelIterator for & ' a mut Slice < K , V >
151
+ where
152
+ K : Sync + Send ,
153
+ V : Send ,
154
+ {
155
+ type Item = ( & ' a K , & ' a mut V ) ;
156
+ type Iter = ParIterMut < ' a , K , V > ;
157
+
158
+ fn into_par_iter ( self ) -> Self :: Iter {
159
+ ParIterMut {
160
+ entries : & mut self . entries ,
161
+ }
162
+ }
163
+ }
164
+
132
165
/// A parallel mutable iterator over the entries of a `IndexMap`.
133
166
///
134
167
/// This `struct` is created by the [`par_iter_mut`] method on [`IndexMap`]
@@ -225,6 +258,37 @@ where
225
258
}
226
259
}
227
260
261
+ /// Parallel iterator methods and other parallel methods.
262
+ ///
263
+ /// The following methods **require crate feature `"rayon"`**.
264
+ ///
265
+ /// See also the `IntoParallelIterator` implementations.
266
+ impl < K , V > Slice < K , V >
267
+ where
268
+ K : Sync ,
269
+ V : Sync ,
270
+ {
271
+ /// Return a parallel iterator over the keys of the map slice.
272
+ ///
273
+ /// While parallel iterators can process items in any order, their relative order
274
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
275
+ pub fn par_keys ( & self ) -> ParKeys < ' _ , K , V > {
276
+ ParKeys {
277
+ entries : & self . entries ,
278
+ }
279
+ }
280
+
281
+ /// Return a parallel iterator over the values of the map slice.
282
+ ///
283
+ /// While parallel iterators can process items in any order, their relative order
284
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
285
+ pub fn par_values ( & self ) -> ParValues < ' _ , K , V > {
286
+ ParValues {
287
+ entries : & self . entries ,
288
+ }
289
+ }
290
+ }
291
+
228
292
impl < K , V , S > IndexMap < K , V , S >
229
293
where
230
294
K : Hash + Eq + Sync ,
@@ -331,6 +395,23 @@ where
331
395
}
332
396
}
333
397
398
+ /// Requires crate feature `"rayon"`.
399
+ impl < K , V > Slice < K , V >
400
+ where
401
+ K : Send ,
402
+ V : Send ,
403
+ {
404
+ /// Return a parallel iterator over mutable references to the the values of the map slice.
405
+ ///
406
+ /// While parallel iterators can process items in any order, their relative order
407
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
408
+ pub fn par_values_mut ( & mut self ) -> ParValuesMut < ' _ , K , V > {
409
+ ParValuesMut {
410
+ entries : & mut self . entries ,
411
+ }
412
+ }
413
+ }
414
+
334
415
impl < K , V , S > IndexMap < K , V , S >
335
416
where
336
417
K : Hash + Eq + Send ,
0 commit comments