mirror of
https://github.com/openharmony/third_party_rust_indexmap.git
synced 2026-07-20 00:54:16 -04:00
impl ParallelDrainRange
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ bench = false
|
||||
autocfg = "1"
|
||||
[dependencies]
|
||||
serde = { version = "1.0", optional = true, default-features = false }
|
||||
rayon = { version = "1.2", optional = true }
|
||||
rayon = { version = "1.4.1", optional = true }
|
||||
|
||||
[dependencies.hashbrown]
|
||||
version = "0.11"
|
||||
|
||||
+2
-2
@@ -69,12 +69,12 @@ pub use self::core::{Entry, OccupiedEntry, VacantEntry};
|
||||
/// ```
|
||||
#[cfg(has_std)]
|
||||
pub struct IndexMap<K, V, S = RandomState> {
|
||||
core: IndexMapCore<K, V>,
|
||||
pub(crate) core: IndexMapCore<K, V>,
|
||||
hash_builder: S,
|
||||
}
|
||||
#[cfg(not(has_std))]
|
||||
pub struct IndexMap<K, V, S> {
|
||||
core: IndexMapCore<K, V>,
|
||||
pub(crate) core: IndexMapCore<K, V>,
|
||||
hash_builder: S,
|
||||
}
|
||||
|
||||
|
||||
@@ -166,6 +166,19 @@ impl<K, V> IndexMapCore<K, V> {
|
||||
self.entries.drain(range)
|
||||
}
|
||||
|
||||
#[cfg(feature = "rayon")]
|
||||
pub(crate) fn par_drain<R>(&mut self, range: R) -> rayon::vec::Drain<'_, Bucket<K, V>>
|
||||
where
|
||||
K: Send,
|
||||
V: Send,
|
||||
R: RangeBounds<usize>,
|
||||
{
|
||||
use rayon::iter::ParallelDrainRange;
|
||||
let range = simplify_range(range, self.entries.len());
|
||||
self.erase_indices(range.start, range.end);
|
||||
self.entries.par_drain(range)
|
||||
}
|
||||
|
||||
pub(crate) fn split_off(&mut self, at: usize) -> Self {
|
||||
assert!(at <= self.entries.len());
|
||||
self.erase_indices(at, self.entries.len());
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::vec::Vec;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
use core::ops::RangeBounds;
|
||||
|
||||
use crate::Bucket;
|
||||
use crate::Entries;
|
||||
@@ -149,6 +150,43 @@ 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,
|
||||
V: Send,
|
||||
{
|
||||
type Item = (K, V);
|
||||
type Iter = ParDrain<'a, K, V>;
|
||||
|
||||
fn par_drain<R: RangeBounds<usize>>(self, range: R) -> Self::Iter {
|
||||
ParDrain {
|
||||
entries: self.core.par_drain(range),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A parallel draining iterator over the entries of a `IndexMap`.
|
||||
///
|
||||
/// This `struct` is created by the [`par_drain`] method on [`IndexMap`]
|
||||
/// (provided by rayon's `ParallelDrainRange` trait). See its documentation for more.
|
||||
///
|
||||
/// [`par_drain`]: ../struct.IndexMap.html#method.par_drain
|
||||
/// [`IndexMap`]: ../struct.IndexMap.html
|
||||
pub struct ParDrain<'a, K: Send, V: Send> {
|
||||
entries: rayon::vec::Drain<'a, Bucket<K, V>>,
|
||||
}
|
||||
|
||||
impl<K: Send, V: Send> ParallelIterator for ParDrain<'_, K, V> {
|
||||
type Item = (K, V);
|
||||
|
||||
parallel_iterator_methods!(Bucket::key_value);
|
||||
}
|
||||
|
||||
impl<K: Send, V: Send> IndexedParallelIterator for ParDrain<'_, K, V> {
|
||||
indexed_parallel_iterator_methods!(Bucket::key_value);
|
||||
}
|
||||
|
||||
/// Parallel iterator methods and other parallel methods.
|
||||
///
|
||||
/// The following methods **require crate feature `"rayon"`**.
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::vec::Vec;
|
||||
use core::cmp::Ordering;
|
||||
use core::fmt;
|
||||
use core::hash::{BuildHasher, Hash};
|
||||
use core::ops::RangeBounds;
|
||||
|
||||
use crate::Entries;
|
||||
use crate::IndexSet;
|
||||
@@ -111,6 +112,42 @@ 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,
|
||||
{
|
||||
type Item = T;
|
||||
type Iter = ParDrain<'a, T>;
|
||||
|
||||
fn par_drain<R: RangeBounds<usize>>(self, range: R) -> Self::Iter {
|
||||
ParDrain {
|
||||
entries: self.map.core.par_drain(range),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A parallel draining iterator over the items of a `IndexSet`.
|
||||
///
|
||||
/// This `struct` is created by the [`par_drain`] method on [`IndexSet`]
|
||||
/// (provided by rayon's `ParallelDrainRange` trait). See its documentation for more.
|
||||
///
|
||||
/// [`par_drain`]: ../struct.IndexSet.html#method.par_drain
|
||||
/// [`IndexSet`]: ../struct.IndexSet.html
|
||||
pub struct ParDrain<'a, T: Send> {
|
||||
entries: rayon::vec::Drain<'a, Bucket<T>>,
|
||||
}
|
||||
|
||||
impl<T: Send> ParallelIterator for ParDrain<'_, T> {
|
||||
type Item = T;
|
||||
|
||||
parallel_iterator_methods!(Bucket::key);
|
||||
}
|
||||
|
||||
impl<T: Send> IndexedParallelIterator for ParDrain<'_, T> {
|
||||
indexed_parallel_iterator_methods!(Bucket::key);
|
||||
}
|
||||
|
||||
/// Parallel iterator methods and other parallel methods.
|
||||
///
|
||||
/// The following methods **require crate feature `"rayon"`**.
|
||||
|
||||
+2
-2
@@ -61,11 +61,11 @@ type Bucket<T> = super::Bucket<T, ()>;
|
||||
/// ```
|
||||
#[cfg(has_std)]
|
||||
pub struct IndexSet<T, S = RandomState> {
|
||||
map: IndexMap<T, (), S>,
|
||||
pub(crate) map: IndexMap<T, (), S>,
|
||||
}
|
||||
#[cfg(not(has_std))]
|
||||
pub struct IndexSet<T, S> {
|
||||
map: IndexMap<T, (), S>,
|
||||
pub(crate) map: IndexMap<T, (), S>,
|
||||
}
|
||||
|
||||
impl<T, S> Clone for IndexSet<T, S>
|
||||
|
||||
Reference in New Issue
Block a user