diff --git a/asparit/src/std/binary_heap.rs b/asparit/src/std/binary_heap.rs new file mode 100644 index 0000000..f734171 --- /dev/null +++ b/asparit/src/std/binary_heap.rs @@ -0,0 +1,32 @@ +use std::collections::BinaryHeap; +use std::iter::FromIterator; + +use crate::IntoParallelIterator; + +impl<'a, I> IntoParallelIterator<'a> for BinaryHeap +where + I: Send + 'a, +{ + type Iter = as IntoParallelIterator<'a>>::Iter; + type Item = I; + + fn into_par_iter(self) -> Self::Iter { + let vec = Vec::from_iter(self); + + vec.into_par_iter() + } +} + +impl<'a, I> IntoParallelIterator<'a> for &'a BinaryHeap +where + I: Send + Sync + 'a, +{ + type Iter = as IntoParallelIterator<'a>>::Iter; + type Item = &'a I; + + fn into_par_iter(self) -> Self::Iter { + let vec = Vec::<&'a I>::from_iter(self); + + vec.into_par_iter() + } +} diff --git a/asparit/src/std/hash_set.rs b/asparit/src/std/hash_set.rs new file mode 100644 index 0000000..85f99a4 --- /dev/null +++ b/asparit/src/std/hash_set.rs @@ -0,0 +1,35 @@ +use std::collections::HashSet; +use std::hash::BuildHasher; +use std::iter::FromIterator; + +use crate::IntoParallelIterator; + +impl<'a, I, S> IntoParallelIterator<'a> for HashSet +where + I: Send + 'a, + S: BuildHasher, +{ + type Iter = as IntoParallelIterator<'a>>::Iter; + type Item = I; + + fn into_par_iter(self) -> Self::Iter { + let vec = Vec::from_iter(self); + + vec.into_par_iter() + } +} + +impl<'a, I, S> IntoParallelIterator<'a> for &'a HashSet +where + I: Send + Sync + 'a, + S: BuildHasher, +{ + type Iter = as IntoParallelIterator<'a>>::Iter; + type Item = &'a I; + + fn into_par_iter(self) -> Self::Iter { + let vec = Vec::<&'a I>::from_iter(self); + + vec.into_par_iter() + } +} diff --git a/asparit/src/std/mod.rs b/asparit/src/std/mod.rs index 939bb9c..9ca659e 100644 --- a/asparit/src/std/mod.rs +++ b/asparit/src/std/mod.rs @@ -1,3 +1,5 @@ +mod binary_heap; +mod hash_set; mod range; mod slice; mod vec; diff --git a/asparit/src/std/vec.rs b/asparit/src/std/vec.rs index 6330504..5c00f3d 100644 --- a/asparit/src/std/vec.rs +++ b/asparit/src/std/vec.rs @@ -13,11 +13,7 @@ use crate::{ WithIndexedProducer, WithProducer, WithSetup, }; -/// Parallel iterator that moves out of a vector. -#[derive(Debug, Clone)] -pub struct IntoIter { - vec: Vec, -} +/* Vec */ impl<'a, T> IntoParallelIterator<'a> for Vec where @@ -94,6 +90,11 @@ where /* IntoIter */ +#[derive(Debug, Clone)] +pub struct IntoIter { + pub vec: Vec, +} + impl<'a, T> ParallelIterator<'a> for IntoIter where T: Send + 'a,