//! Minimal support for `rustc-rayon`, not intended for general use. use crate::vec::Vec; use crate::{Bucket, Entries, IndexMap, IndexSet}; use rustc_rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer}; use rustc_rayon::iter::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator}; mod map { use super::*; impl IntoParallelIterator for IndexMap where K: Send, V: Send, { type Item = (K, V); type Iter = IntoParIter; fn into_par_iter(self) -> Self::Iter { IntoParIter { entries: self.into_entries(), } } } pub struct IntoParIter { entries: Vec>, } impl ParallelIterator for IntoParIter { type Item = (K, V); parallel_iterator_methods!(Bucket::key_value); } impl IndexedParallelIterator for IntoParIter { indexed_parallel_iterator_methods!(Bucket::key_value); } impl<'a, K, V, S> IntoParallelIterator for &'a IndexMap 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.as_entries(), } } } pub struct ParIter<'a, K, V> { entries: &'a [Bucket], } impl<'a, K: Sync, V: Sync> ParallelIterator for ParIter<'a, K, V> { type Item = (&'a K, &'a V); parallel_iterator_methods!(Bucket::refs); } impl IndexedParallelIterator for ParIter<'_, K, V> { indexed_parallel_iterator_methods!(Bucket::refs); } impl<'a, K, V, S> IntoParallelIterator for &'a mut IndexMap 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: self.as_entries_mut(), } } } pub struct ParIterMut<'a, K, V> { entries: &'a mut [Bucket], } impl<'a, K: Sync + Send, V: Send> ParallelIterator for ParIterMut<'a, K, V> { type Item = (&'a K, &'a mut V); parallel_iterator_methods!(Bucket::ref_mut); } impl IndexedParallelIterator for ParIterMut<'_, K, V> { indexed_parallel_iterator_methods!(Bucket::ref_mut); } } mod set { use super::*; impl IntoParallelIterator for IndexSet where T: Send, { type Item = T; type Iter = IntoParIter; fn into_par_iter(self) -> Self::Iter { IntoParIter { entries: self.into_entries(), } } } pub struct IntoParIter { entries: Vec>, } impl ParallelIterator for IntoParIter { type Item = T; parallel_iterator_methods!(Bucket::key); } impl IndexedParallelIterator for IntoParIter { indexed_parallel_iterator_methods!(Bucket::key); } impl<'a, T, S> IntoParallelIterator for &'a IndexSet where T: Sync, { type Item = &'a T; type Iter = ParIter<'a, T>; fn into_par_iter(self) -> Self::Iter { ParIter { entries: self.as_entries(), } } } pub struct ParIter<'a, T> { entries: &'a [Bucket], } impl<'a, T: Sync> ParallelIterator for ParIter<'a, T> { type Item = &'a T; parallel_iterator_methods!(Bucket::key_ref); } impl IndexedParallelIterator for ParIter<'_, T> { indexed_parallel_iterator_methods!(Bucket::key_ref); } }