@@ -15,6 +15,7 @@ use core::fmt;
1515use core:: hash:: { BuildHasher , Hash } ;
1616use core:: ops:: RangeBounds ;
1717
18+ use crate :: map:: Slice ;
1819use crate :: Bucket ;
1920use crate :: Entries ;
2021use crate :: IndexMap ;
7980 }
8081}
8182
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+
8299/// A parallel iterator over the entries of a `IndexMap`.
83100///
84101/// This `struct` is created by the [`par_iter`] method on [`IndexMap`]
@@ -129,6 +146,22 @@ where
129146 }
130147}
131148
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+
132165/// A parallel mutable iterator over the entries of a `IndexMap`.
133166///
134167/// This `struct` is created by the [`par_iter_mut`] method on [`IndexMap`]
@@ -225,6 +258,37 @@ where
225258 }
226259}
227260
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+
228292impl < K , V , S > IndexMap < K , V , S >
229293where
230294 K : Hash + Eq + Sync ,
@@ -331,6 +395,23 @@ where
331395 }
332396}
333397
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+
334415impl < K , V , S > IndexMap < K , V , S >
335416where
336417 K : Hash + Eq + Send ,
0 commit comments