summaryrefslogtreecommitdiffstats
path: root/vendor/indexmap/src/rayon
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/indexmap/src/rayon')
-rw-r--r--vendor/indexmap/src/rayon/map.rs116
-rw-r--r--vendor/indexmap/src/rayon/set.rs49
2 files changed, 147 insertions, 18 deletions
diff --git a/vendor/indexmap/src/rayon/map.rs b/vendor/indexmap/src/rayon/map.rs
index 8819f13ed..d5325f2ee 100644
--- a/vendor/indexmap/src/rayon/map.rs
+++ b/vendor/indexmap/src/rayon/map.rs
@@ -2,24 +2,23 @@
//!
//! You will rarely need to interact with this module directly unless you need to name one of the
//! iterator types.
-//!
-//! Requires crate feature `"rayon"`
use super::collect;
use rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
use rayon::prelude::*;
use crate::vec::Vec;
+use alloc::boxed::Box;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{BuildHasher, Hash};
use core::ops::RangeBounds;
+use crate::map::Slice;
use crate::Bucket;
use crate::Entries;
use crate::IndexMap;
-/// Requires crate feature `"rayon"`.
impl<K, V, S> IntoParallelIterator for IndexMap<K, V, S>
where
K: Send,
@@ -35,6 +34,21 @@ where
}
}
+impl<K, V> IntoParallelIterator for Box<Slice<K, V>>
+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(),
+ }
+ }
+}
+
/// A parallel owning iterator over the entries of a `IndexMap`.
///
/// This `struct` is created by the [`into_par_iter`] method on [`IndexMap`]
@@ -63,7 +77,6 @@ impl<K: Send, V: Send> IndexedParallelIterator for IntoParIter<K, V> {
indexed_parallel_iterator_methods!(Bucket::key_value);
}
-/// Requires crate feature `"rayon"`.
impl<'a, K, V, S> IntoParallelIterator for &'a IndexMap<K, V, S>
where
K: Sync,
@@ -79,6 +92,21 @@ where
}
}
+impl<'a, K, V> IntoParallelIterator for &'a Slice<K, V>
+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.entries,
+ }
+ }
+}
+
/// A parallel iterator over the entries of a `IndexMap`.
///
/// This `struct` is created by the [`par_iter`] method on [`IndexMap`]
@@ -113,7 +141,6 @@ impl<K: Sync, V: Sync> IndexedParallelIterator for ParIter<'_, K, V> {
indexed_parallel_iterator_methods!(Bucket::refs);
}
-/// Requires crate feature `"rayon"`.
impl<'a, K, V, S> IntoParallelIterator for &'a mut IndexMap<K, V, S>
where
K: Sync + Send,
@@ -129,6 +156,21 @@ where
}
}
+impl<'a, K, V> IntoParallelIterator for &'a mut Slice<K, V>
+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: &mut self.entries,
+ }
+ }
+}
+
/// A parallel mutable iterator over the entries of a `IndexMap`.
///
/// This `struct` is created by the [`par_iter_mut`] method on [`IndexMap`]
@@ -157,7 +199,6 @@ impl<K: Sync + Send, V: Send> IndexedParallelIterator for ParIterMut<'_, K, V> {
indexed_parallel_iterator_methods!(Bucket::ref_mut);
}
-/// Requires crate feature `"rayon"`.
impl<'a, K, V, S> ParallelDrainRange<usize> for &'a mut IndexMap<K, V, S>
where
K: Send,
@@ -225,6 +266,37 @@ where
}
}
+/// Parallel iterator methods and other parallel methods.
+///
+/// The following methods **require crate feature `"rayon"`**.
+///
+/// See also the `IntoParallelIterator` implementations.
+impl<K, V> Slice<K, V>
+where
+ K: Sync,
+ V: Sync,
+{
+ /// Return a parallel iterator over the keys of the map slice.
+ ///
+ /// While parallel iterators can process items in any order, their relative order
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
+ pub fn par_keys(&self) -> ParKeys<'_, K, V> {
+ ParKeys {
+ entries: &self.entries,
+ }
+ }
+
+ /// Return a parallel iterator over the values of the map slice.
+ ///
+ /// While parallel iterators can process items in any order, their relative order
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
+ pub fn par_values(&self) -> ParValues<'_, K, V> {
+ ParValues {
+ entries: &self.entries,
+ }
+ }
+}
+
impl<K, V, S> IndexMap<K, V, S>
where
K: Hash + Eq + Sync,
@@ -314,7 +386,6 @@ impl<K: Sync, V: Sync> IndexedParallelIterator for ParValues<'_, K, V> {
indexed_parallel_iterator_methods!(Bucket::value_ref);
}
-/// Requires crate feature `"rayon"`.
impl<K, V, S> IndexMap<K, V, S>
where
K: Send,
@@ -331,6 +402,22 @@ where
}
}
+impl<K, V> Slice<K, V>
+where
+ K: Send,
+ V: Send,
+{
+ /// Return a parallel iterator over mutable references to the the values of the map slice.
+ ///
+ /// While parallel iterators can process items in any order, their relative order
+ /// in the slice is still preserved for operations like `reduce` and `collect`.
+ pub fn par_values_mut(&mut self) -> ParValuesMut<'_, K, V> {
+ ParValuesMut {
+ entries: &mut self.entries,
+ }
+ }
+}
+
impl<K, V, S> IndexMap<K, V, S>
where
K: Hash + Eq + Send,
@@ -406,6 +493,18 @@ where
entries.par_sort_unstable_by(move |a, b| cmp(&a.key, &a.value, &b.key, &b.value));
IntoParIter { entries }
}
+
+ /// Sort the map’s key-value pairs in place and in parallel, using a sort-key extraction
+ /// function.
+ pub fn par_sort_by_cached_key<T, F>(&mut self, sort_key: F)
+ where
+ T: Ord + Send,
+ F: Fn(&K, &V) -> T + Sync,
+ {
+ self.with_entries(move |entries| {
+ entries.par_sort_by_cached_key(move |a| sort_key(&a.key, &a.value));
+ });
+ }
}
/// A parallel mutable iterator over the values of a `IndexMap`.
@@ -436,7 +535,6 @@ impl<K: Send, V: Send> IndexedParallelIterator for ParValuesMut<'_, K, V> {
indexed_parallel_iterator_methods!(Bucket::value_mut);
}
-/// Requires crate feature `"rayon"`.
impl<K, V, S> FromParallelIterator<(K, V)> for IndexMap<K, V, S>
where
K: Eq + Hash + Send,
@@ -457,7 +555,6 @@ where
}
}
-/// Requires crate feature `"rayon"`.
impl<K, V, S> ParallelExtend<(K, V)> for IndexMap<K, V, S>
where
K: Eq + Hash + Send,
@@ -474,7 +571,6 @@ where
}
}
-/// Requires crate feature `"rayon"`.
impl<'a, K: 'a, V: 'a, S> ParallelExtend<(&'a K, &'a V)> for IndexMap<K, V, S>
where
K: Copy + Eq + Hash + Send + Sync,
diff --git a/vendor/indexmap/src/rayon/set.rs b/vendor/indexmap/src/rayon/set.rs
index 6749dc0d7..0fc478ef0 100644
--- a/vendor/indexmap/src/rayon/set.rs
+++ b/vendor/indexmap/src/rayon/set.rs
@@ -2,25 +2,24 @@
//!
//! You will rarely need to interact with this module directly unless you need to name one of the
//! iterator types.
-//!
-//! Requires crate feature `"rayon"`.
use super::collect;
use rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
use rayon::prelude::*;
use crate::vec::Vec;
+use alloc::boxed::Box;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{BuildHasher, Hash};
use core::ops::RangeBounds;
+use crate::set::Slice;
use crate::Entries;
use crate::IndexSet;
type Bucket<T> = crate::Bucket<T, ()>;
-/// Requires crate feature `"rayon"`.
impl<T, S> IntoParallelIterator for IndexSet<T, S>
where
T: Send,
@@ -35,6 +34,20 @@ where
}
}
+impl<T> IntoParallelIterator for Box<Slice<T>>
+where
+ T: Send,
+{
+ type Item = T;
+ type Iter = IntoParIter<T>;
+
+ fn into_par_iter(self) -> Self::Iter {
+ IntoParIter {
+ entries: self.into_entries(),
+ }
+ }
+}
+
/// A parallel owning iterator over the items of a `IndexSet`.
///
/// This `struct` is created by the [`into_par_iter`] method on [`IndexSet`]
@@ -63,7 +76,6 @@ impl<T: Send> IndexedParallelIterator for IntoParIter<T> {
indexed_parallel_iterator_methods!(Bucket::key);
}
-/// Requires crate feature `"rayon"`.
impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S>
where
T: Sync,
@@ -78,6 +90,20 @@ where
}
}
+impl<'a, T> IntoParallelIterator for &'a Slice<T>
+where
+ T: Sync,
+{
+ type Item = &'a T;
+ type Iter = ParIter<'a, T>;
+
+ fn into_par_iter(self) -> Self::Iter {
+ ParIter {
+ entries: &self.entries,
+ }
+ }
+}
+
/// A parallel iterator over the items of a `IndexSet`.
///
/// This `struct` is created by the [`par_iter`] method on [`IndexSet`]
@@ -112,7 +138,6 @@ impl<T: Sync> IndexedParallelIterator for ParIter<'_, T> {
indexed_parallel_iterator_methods!(Bucket::key_ref);
}
-/// Requires crate feature `"rayon"`.
impl<'a, T, S> ParallelDrainRange<usize> for &'a mut IndexSet<T, S>
where
T: Send,
@@ -540,9 +565,19 @@ where
entries.par_sort_unstable_by(move |a, b| cmp(&a.key, &b.key));
IntoParIter { entries }
}
+
+ /// Sort the set’s values in place and in parallel, using a key extraction function.
+ pub fn par_sort_by_cached_key<K, F>(&mut self, sort_key: F)
+ where
+ K: Ord + Send,
+ F: Fn(&T) -> K + Sync,
+ {
+ self.with_entries(move |entries| {
+ entries.par_sort_by_cached_key(move |a| sort_key(&a.key));
+ });
+ }
}
-/// Requires crate feature `"rayon"`.
impl<T, S> FromParallelIterator<T> for IndexSet<T, S>
where
T: Eq + Hash + Send,
@@ -562,7 +597,6 @@ where
}
}
-/// Requires crate feature `"rayon"`.
impl<T, S> ParallelExtend<T> for IndexSet<T, S>
where
T: Eq + Hash + Send,
@@ -578,7 +612,6 @@ where
}
}
-/// Requires crate feature `"rayon"`.
impl<'a, T: 'a, S> ParallelExtend<&'a T> for IndexSet<T, S>
where
T: Copy + Eq + Hash + Send + Sync,