Переглянути джерело

Implemented parallel iterator for 'HashSet' and 'BinaryHeap'

master
Bergmann89 3 роки тому
джерело
коміт
e1ecc51627
4 змінених файлів з 75 додано та 5 видалено
  1. +32
    -0
      asparit/src/std/binary_heap.rs
  2. +35
    -0
      asparit/src/std/hash_set.rs
  3. +2
    -0
      asparit/src/std/mod.rs
  4. +6
    -5
      asparit/src/std/vec.rs

+ 32
- 0
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<I>
where
I: Send + 'a,
{
type Iter = <Vec<I> 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<I>
where
I: Send + Sync + 'a,
{
type Iter = <Vec<&'a I> 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()
}
}

+ 35
- 0
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<I, S>
where
I: Send + 'a,
S: BuildHasher,
{
type Iter = <Vec<I> 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<I, S>
where
I: Send + Sync + 'a,
S: BuildHasher,
{
type Iter = <Vec<&'a I> 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()
}
}

+ 2
- 0
asparit/src/std/mod.rs Переглянути файл

@@ -1,3 +1,5 @@
mod binary_heap;
mod hash_set;
mod range;
mod slice;
mod vec;

+ 6
- 5
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<T> {
vec: Vec<T>,
}
/* Vec */

impl<'a, T> IntoParallelIterator<'a> for Vec<T>
where
@@ -94,6 +90,11 @@ where

/* IntoIter */

#[derive(Debug, Clone)]
pub struct IntoIter<T> {
pub vec: Vec<T>,
}

impl<'a, T> ParallelIterator<'a> for IntoIter<T>
where
T: Send + 'a,


Завантаження…
Відмінити
Зберегти