diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /third_party/rust/indexmap/src/rayon/set.rs | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/indexmap/src/rayon/set.rs')
-rw-r--r-- | third_party/rust/indexmap/src/rayon/set.rs | 111 |
1 files changed, 63 insertions, 48 deletions
diff --git a/third_party/rust/indexmap/src/rayon/set.rs b/third_party/rust/indexmap/src/rayon/set.rs index 6749dc0d7f..3904234b20 100644 --- a/third_party/rust/indexmap/src/rayon/set.rs +++ b/third_party/rust/indexmap/src/rayon/set.rs @@ -1,26 +1,25 @@ -//! Parallel iterator types for `IndexSet` with [rayon](https://docs.rs/rayon/1.0/rayon). +//! Parallel iterator types for [`IndexSet`] with [rayon][::rayon]. //! //! 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,13 +34,24 @@ where } } -/// A parallel owning iterator over the items of a `IndexSet`. -/// -/// This `struct` is created by the [`into_par_iter`] method on [`IndexSet`] -/// (provided by rayon's `IntoParallelIterator` trait). See its documentation for more. +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 an [`IndexSet`]. /// -/// [`IndexSet`]: ../struct.IndexSet.html -/// [`into_par_iter`]: ../struct.IndexSet.html#method.into_par_iter +/// This `struct` is created by the [`IndexSet::into_par_iter`] method +/// (provided by rayon's [`IntoParallelIterator`] trait). See its documentation for more. pub struct IntoParIter<T> { entries: Vec<Bucket<T>>, } @@ -63,7 +73,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,13 +87,26 @@ where } } -/// A parallel iterator over the items of a `IndexSet`. +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 an [`IndexSet`]. /// -/// This `struct` is created by the [`par_iter`] method on [`IndexSet`] -/// (provided by rayon's `IntoParallelRefIterator` trait). See its documentation for more. +/// This `struct` is created by the [`IndexSet::par_iter`] method +/// (provided by rayon's [`IntoParallelRefIterator`] trait). See its documentation for more. /// -/// [`IndexSet`]: ../struct.IndexSet.html -/// [`par_iter`]: ../struct.IndexSet.html#method.par_iter +/// [`IndexSet::par_iter`]: ../struct.IndexSet.html#method.par_iter pub struct ParIter<'a, T> { entries: &'a [Bucket<T>], } @@ -112,7 +134,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, @@ -127,13 +148,12 @@ where } } -/// A parallel draining iterator over the items of a `IndexSet`. +/// A parallel draining iterator over the items of an [`IndexSet`]. /// -/// This `struct` is created by the [`par_drain`] method on [`IndexSet`] -/// (provided by rayon's `ParallelDrainRange` trait). See its documentation for more. +/// This `struct` is created by the [`IndexSet::par_drain`] method +/// (provided by rayon's [`ParallelDrainRange`] trait). See its documentation for more. /// -/// [`par_drain`]: ../struct.IndexSet.html#method.par_drain -/// [`IndexSet`]: ../struct.IndexSet.html +/// [`IndexSet::par_drain`]: ../struct.IndexSet.html#method.par_drain pub struct ParDrain<'a, T: Send> { entries: rayon::vec::Drain<'a, Bucket<T>>, } @@ -269,13 +289,10 @@ where } } -/// A parallel iterator producing elements in the difference of `IndexSet`s. +/// A parallel iterator producing elements in the difference of [`IndexSet`]s. /// -/// This `struct` is created by the [`par_difference`] method on [`IndexSet`]. +/// This `struct` is created by the [`IndexSet::par_difference`] method. /// See its documentation for more. -/// -/// [`IndexSet`]: ../struct.IndexSet.html -/// [`par_difference`]: ../struct.IndexSet.html#method.par_difference pub struct ParDifference<'a, T, S1, S2> { set1: &'a IndexSet<T, S1>, set2: &'a IndexSet<T, S2>, @@ -320,13 +337,10 @@ where } } -/// A parallel iterator producing elements in the intersection of `IndexSet`s. +/// A parallel iterator producing elements in the intersection of [`IndexSet`]s. /// -/// This `struct` is created by the [`par_intersection`] method on [`IndexSet`]. +/// This `struct` is created by the [`IndexSet::par_intersection`] method. /// See its documentation for more. -/// -/// [`IndexSet`]: ../struct.IndexSet.html -/// [`par_intersection`]: ../struct.IndexSet.html#method.par_intersection pub struct ParIntersection<'a, T, S1, S2> { set1: &'a IndexSet<T, S1>, set2: &'a IndexSet<T, S2>, @@ -371,13 +385,10 @@ where } } -/// A parallel iterator producing elements in the symmetric difference of `IndexSet`s. -/// -/// This `struct` is created by the [`par_symmetric_difference`] method on -/// [`IndexSet`]. See its documentation for more. +/// A parallel iterator producing elements in the symmetric difference of [`IndexSet`]s. /// -/// [`IndexSet`]: ../struct.IndexSet.html -/// [`par_symmetric_difference`]: ../struct.IndexSet.html#method.par_symmetric_difference +/// This `struct` is created by the [`IndexSet::par_symmetric_difference`] method. +/// See its documentation for more. pub struct ParSymmetricDifference<'a, T, S1, S2> { set1: &'a IndexSet<T, S1>, set2: &'a IndexSet<T, S2>, @@ -422,13 +433,10 @@ where } } -/// A parallel iterator producing elements in the union of `IndexSet`s. +/// A parallel iterator producing elements in the union of [`IndexSet`]s. /// -/// This `struct` is created by the [`par_union`] method on [`IndexSet`]. +/// This `struct` is created by the [`IndexSet::par_union`] method. /// See its documentation for more. -/// -/// [`IndexSet`]: ../struct.IndexSet.html -/// [`par_union`]: ../struct.IndexSet.html#method.par_union pub struct ParUnion<'a, T, S1, S2> { set1: &'a IndexSet<T, S1>, set2: &'a IndexSet<T, S2>, @@ -476,8 +484,7 @@ where /// The following methods **require crate feature `"rayon"`**. impl<T, S> IndexSet<T, S> where - T: Hash + Eq + Send, - S: BuildHasher + Send, + T: Send, { /// Sort the set’s values in parallel by their default ordering. pub fn par_sort(&mut self) @@ -540,9 +547,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 +579,6 @@ where } } -/// Requires crate feature `"rayon"`. impl<T, S> ParallelExtend<T> for IndexSet<T, S> where T: Eq + Hash + Send, @@ -578,7 +594,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, |