Created
September 6, 2016 00:48
-
-
Save cuviper/b8d7a42fe7a901c298e2fb12c4f3a73c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use super::IntoParallelIterator; | |
use super::vec::VecIter; | |
use std::collections::{BinaryHeap, BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque}; | |
macro_rules! vectorized { | |
( impl<$($c:tt),*> IntoParallelIterator for $t:ty ) => { | |
impl<$($c),*> IntoParallelIterator for $t | |
where $t: IntoIterator, | |
<$t as IntoIterator>::Item: Send | |
{ | |
type Item = <Self as IntoIterator>::Item; | |
type Iter = VecIter<Self::Item>; | |
fn into_par_iter(self) -> Self::Iter { | |
let v: Vec<_> = self.into_iter().collect(); | |
v.into_par_iter() | |
} | |
} | |
} | |
} | |
impl<T: Send> IntoParallelIterator for BinaryHeap<T> { | |
type Item = T; | |
type Iter = VecIter<T>; | |
fn into_par_iter(self) -> Self::Iter { | |
let v: Vec<_> = self.into(); | |
v.into_par_iter() | |
} | |
} | |
vectorized!{ impl<'a, T> IntoParallelIterator for &'a BinaryHeap<T> } | |
vectorized!{ impl<K, V> IntoParallelIterator for BTreeMap<K, V> } | |
vectorized!{ impl<'a, K, V> IntoParallelIterator for &'a BTreeMap<K, V> } | |
vectorized!{ impl<'a, K, V> IntoParallelIterator for &'a mut BTreeMap<K, V> } | |
vectorized!{ impl<T> IntoParallelIterator for BTreeSet<T> } | |
vectorized!{ impl<'a, T> IntoParallelIterator for &'a BTreeSet<T> } | |
// `BTreeSet` doesn't have a mutable `Iterator` | |
vectorized!{ impl<K, V, S> IntoParallelIterator for HashMap<K, V, S> } | |
vectorized!{ impl<'a, K, V, S> IntoParallelIterator for &'a HashMap<K, V, S> } | |
vectorized!{ impl<'a, K, V, S> IntoParallelIterator for &'a mut HashMap<K, V, S> } | |
vectorized!{ impl<T, S> IntoParallelIterator for HashSet<T, S> } | |
vectorized!{ impl<'a, T, S> IntoParallelIterator for &'a HashSet<T, S> } | |
// `HashSet` doesn't have a mutable `Iterator` | |
vectorized!{ impl<T> IntoParallelIterator for LinkedList<T> } | |
vectorized!{ impl<'a, T> IntoParallelIterator for &'a LinkedList<T> } | |
vectorized!{ impl<'a, T> IntoParallelIterator for &'a mut LinkedList<T> } | |
vectorized!{ impl<T> IntoParallelIterator for VecDeque<T> } | |
vectorized!{ impl<'a, T> IntoParallelIterator for &'a VecDeque<T> } | |
vectorized!{ impl<'a, T> IntoParallelIterator for &'a mut VecDeque<T> } | |
// could potentionally do these directly with `as_slices` and `as_mut_slices` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment