@@ -17,6 +17,7 @@ use core::hash::{BuildHasher, Hash};
1717use crate :: Bucket ;
1818use crate :: Entries ;
1919use crate :: IndexMap ;
20+ use crate :: map:: Slice ;
2021
2122/// Requires crate feature `"rayon"`.
2223impl < K , V , S > IntoParallelIterator for IndexMap < K , V , S >
7879 }
7980}
8081
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+
8198/// A parallel iterator over the entries of a `IndexMap`.
8299///
83100/// This `struct` is created by the [`par_iter`] method on [`IndexMap`]
@@ -128,6 +145,22 @@ where
128145 }
129146}
130147
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+
131164/// A parallel mutable iterator over the entries of a `IndexMap`.
132165///
133166/// This `struct` is created by the [`par_iter_mut`] method on [`IndexMap`]
@@ -180,6 +213,37 @@ where
180213 }
181214}
182215
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+
183247impl < K , V , S > IndexMap < K , V , S >
184248where
185249 K : Hash + Eq + Sync ,
@@ -286,6 +350,23 @@ where
286350 }
287351}
288352
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+
289370impl < K , V , S > IndexMap < K , V , S >
290371where
291372 K : Hash + Eq + Send ,
0 commit comments