Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<T: Send, const N: usize> IntoParallelIterator for [T; N] {

/// Parallel iterator that moves out of an array.
#[derive(Debug, Clone)]
pub struct IntoIter<T: Send, const N: usize> {
pub struct IntoIter<T, const N: usize> {
array: [T; N],
}

Expand Down
24 changes: 13 additions & 11 deletions src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::vec;

/// Parallel iterator over a binary heap
#[derive(Debug, Clone)]
pub struct IntoIter<T: Ord + Send> {
pub struct IntoIter<T> {
inner: vec::IntoIter<T>,
}

impl<T: Ord + Send> IntoParallelIterator for BinaryHeap<T> {
impl<T: Send> IntoParallelIterator for BinaryHeap<T> {
type Item = T;
type Iter = IntoIter<T>;

Expand All @@ -29,24 +29,24 @@ impl<T: Ord + Send> IntoParallelIterator for BinaryHeap<T> {

delegate_indexed_iterator! {
IntoIter<T> => T,
impl<T: Ord + Send>
impl<T: Send>
}

/// Parallel iterator over an immutable reference to a binary heap
#[derive(Debug)]
pub struct Iter<'a, T: Ord + Sync> {
pub struct Iter<'a, T> {
inner: slice::Iter<'a, T>,
}

impl<'a, T: Ord + Sync> Clone for Iter<'a, T> {
impl<T> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Iter {
inner: self.inner.clone(),
}
}
}

impl<'a, T: Ord + Sync> IntoParallelIterator for &'a BinaryHeap<T> {
impl<'a, T: Sync> IntoParallelIterator for &'a BinaryHeap<T> {
type Item = &'a T;
type Iter = Iter<'a, T>;

Expand All @@ -59,18 +59,20 @@ impl<'a, T: Ord + Sync> IntoParallelIterator for &'a BinaryHeap<T> {

delegate_indexed_iterator! {
Iter<'a, T> => &'a T,
impl<'a, T: Ord + Sync + 'a>
impl<'a, T: Sync + 'a>
}

// `BinaryHeap` doesn't have a mutable `Iterator`

/// Draining parallel iterator that moves out of a binary heap,
/// but keeps the total capacity.
#[derive(Debug)]
pub struct Drain<'a, T: Ord + Send> {
pub struct Drain<'a, T> {
heap: &'a mut BinaryHeap<T>,
}

// NB: The only reason we require `T: Ord` is for `DrainGuard` to reconstruct
// the heap `From<Vec<T>>` afterward, even though that will actually be empty.
impl<'a, T: Ord + Send> ParallelDrainFull for &'a mut BinaryHeap<T> {
type Iter = Drain<'a, T>;
type Item = T;
Expand All @@ -80,7 +82,7 @@ impl<'a, T: Ord + Send> ParallelDrainFull for &'a mut BinaryHeap<T> {
}
}

impl<'a, T: Ord + Send> ParallelIterator for Drain<'a, T> {
impl<T: Ord + Send> ParallelIterator for Drain<'_, T> {
type Item = T;

fn drive_unindexed<C>(self, consumer: C) -> C::Result
Expand All @@ -95,7 +97,7 @@ impl<'a, T: Ord + Send> ParallelIterator for Drain<'a, T> {
}
}

impl<'a, T: Ord + Send> IndexedParallelIterator for Drain<'a, T> {
impl<T: Ord + Send> IndexedParallelIterator for Drain<'_, T> {
fn drive<C>(self, consumer: C) -> C::Result
where
C: Consumer<Self::Item>,
Expand All @@ -117,7 +119,7 @@ impl<'a, T: Ord + Send> IndexedParallelIterator for Drain<'a, T> {
}
}

impl<'a, T: Ord + Send> Drop for Drain<'a, T> {
impl<T> Drop for Drain<'_, T> {
fn drop(&mut self) {
if !self.heap.is_empty() {
// We must not have produced, so just call a normal drain to remove the items.
Expand Down
20 changes: 10 additions & 10 deletions src/collections/btree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ use crate::vec;

/// Parallel iterator over a B-Tree map
#[derive(Debug)] // std doesn't Clone
pub struct IntoIter<K: Ord + Send, V: Send> {
pub struct IntoIter<K, V> {
inner: vec::IntoIter<(K, V)>,
}

into_par_vec! {
BTreeMap<K, V> => IntoIter<K, V>,
impl<K: Ord + Send, V: Send>
impl<K: Send, V: Send>
}

delegate_iterator! {
IntoIter<K, V> => (K, V),
impl<K: Ord + Send, V: Send>
impl<K: Send, V: Send>
}

/// Parallel iterator over an immutable reference to a B-Tree map
#[derive(Debug)]
pub struct Iter<'a, K: Ord + Sync, V: Sync> {
pub struct Iter<'a, K, V> {
inner: vec::IntoIter<(&'a K, &'a V)>,
}

impl<'a, K: Ord + Sync, V: Sync> Clone for Iter<'a, K, V> {
impl<K, V> Clone for Iter<'_, K, V> {
fn clone(&self) -> Self {
Iter {
inner: self.inner.clone(),
Expand All @@ -41,26 +41,26 @@ impl<'a, K: Ord + Sync, V: Sync> Clone for Iter<'a, K, V> {

into_par_vec! {
&'a BTreeMap<K, V> => Iter<'a, K, V>,
impl<'a, K: Ord + Sync, V: Sync>
impl<'a, K: Sync, V: Sync>
}

delegate_iterator! {
Iter<'a, K, V> => (&'a K, &'a V),
impl<'a, K: Ord + Sync + 'a, V: Sync + 'a>
impl<'a, K: Sync + 'a, V: Sync + 'a>
}

/// Parallel iterator over a mutable reference to a B-Tree map
#[derive(Debug)]
pub struct IterMut<'a, K: Ord + Sync, V: Send> {
pub struct IterMut<'a, K, V> {
inner: vec::IntoIter<(&'a K, &'a mut V)>,
}

into_par_vec! {
&'a mut BTreeMap<K, V> => IterMut<'a, K, V>,
impl<'a, K: Ord + Sync, V: Send>
impl<'a, K: Sync, V: Send>
}

delegate_iterator! {
IterMut<'a, K, V> => (&'a K, &'a mut V),
impl<'a, K: Ord + Sync + 'a, V: Send + 'a>
impl<'a, K: Sync + 'a, V: Send + 'a>
}
14 changes: 7 additions & 7 deletions src/collections/btree_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ use crate::vec;

/// Parallel iterator over a B-Tree set
#[derive(Debug)] // std doesn't Clone
pub struct IntoIter<T: Ord + Send> {
pub struct IntoIter<T> {
inner: vec::IntoIter<T>,
}

into_par_vec! {
BTreeSet<T> => IntoIter<T>,
impl<T: Ord + Send>
impl<T: Send>
}

delegate_iterator! {
IntoIter<T> => T,
impl<T: Ord + Send>
impl<T: Send>
}

/// Parallel iterator over an immutable reference to a B-Tree set
#[derive(Debug)]
pub struct Iter<'a, T: Ord + Sync> {
pub struct Iter<'a, T> {
inner: vec::IntoIter<&'a T>,
}

impl<'a, T: Ord + Sync + 'a> Clone for Iter<'a, T> {
impl<T> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Iter {
inner: self.inner.clone(),
Expand All @@ -41,12 +41,12 @@ impl<'a, T: Ord + Sync + 'a> Clone for Iter<'a, T> {

into_par_vec! {
&'a BTreeSet<T> => Iter<'a, T>,
impl<'a, T: Ord + Sync>
impl<'a, T: Sync>
}

delegate_iterator! {
Iter<'a, T> => &'a T,
impl<'a, T: Ord + Sync + 'a>
impl<'a, T: Sync + 'a>
}

// `BTreeSet` doesn't have a mutable `Iterator`
29 changes: 13 additions & 16 deletions src/collections/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! unless you have need to name one of the iterator types.

use std::collections::HashMap;
use std::hash::{BuildHasher, Hash};
use std::marker::PhantomData;

use crate::iter::plumbing::*;
Expand All @@ -13,27 +12,27 @@ use crate::vec;

/// Parallel iterator over a hash map
#[derive(Debug)] // std doesn't Clone
pub struct IntoIter<K: Hash + Eq + Send, V: Send> {
pub struct IntoIter<K, V> {
inner: vec::IntoIter<(K, V)>,
}

into_par_vec! {
HashMap<K, V, S> => IntoIter<K, V>,
impl<K: Hash + Eq + Send, V: Send, S: BuildHasher>
impl<K: Send, V: Send, S>
}

delegate_iterator! {
IntoIter<K, V> => (K, V),
impl<K: Hash + Eq + Send, V: Send>
impl<K: Send, V: Send>
}

/// Parallel iterator over an immutable reference to a hash map
#[derive(Debug)]
pub struct Iter<'a, K: Hash + Eq + Sync, V: Sync> {
pub struct Iter<'a, K, V> {
inner: vec::IntoIter<(&'a K, &'a V)>,
}

impl<'a, K: Hash + Eq + Sync, V: Sync> Clone for Iter<'a, K, V> {
impl<K, V> Clone for Iter<'_, K, V> {
fn clone(&self) -> Self {
Iter {
inner: self.inner.clone(),
Expand All @@ -43,41 +42,39 @@ impl<'a, K: Hash + Eq + Sync, V: Sync> Clone for Iter<'a, K, V> {

into_par_vec! {
&'a HashMap<K, V, S> => Iter<'a, K, V>,
impl<'a, K: Hash + Eq + Sync, V: Sync, S: BuildHasher>
impl<'a, K: Sync, V: Sync, S>
}

delegate_iterator! {
Iter<'a, K, V> => (&'a K, &'a V),
impl<'a, K: Hash + Eq + Sync + 'a, V: Sync + 'a>
impl<'a, K: Sync, V: Sync>
}

/// Parallel iterator over a mutable reference to a hash map
#[derive(Debug)]
pub struct IterMut<'a, K: Hash + Eq + Sync, V: Send> {
pub struct IterMut<'a, K, V> {
inner: vec::IntoIter<(&'a K, &'a mut V)>,
}

into_par_vec! {
&'a mut HashMap<K, V, S> => IterMut<'a, K, V>,
impl<'a, K: Hash + Eq + Sync, V: Send, S: BuildHasher>
impl<'a, K: Sync, V: Send, S>
}

delegate_iterator! {
IterMut<'a, K, V> => (&'a K, &'a mut V),
impl<'a, K: Hash + Eq + Sync + 'a, V: Send + 'a>
impl<'a, K: Sync, V: Send>
}

/// Draining parallel iterator that moves out of a hash map,
/// but keeps the total capacity.
#[derive(Debug)]
pub struct Drain<'a, K: Hash + Eq + Send, V: Send> {
pub struct Drain<'a, K, V> {
inner: vec::IntoIter<(K, V)>,
marker: PhantomData<&'a mut HashMap<K, V>>,
}

impl<'a, K: Hash + Eq + Send, V: Send, S: BuildHasher> ParallelDrainFull
for &'a mut HashMap<K, V, S>
{
impl<'a, K: Send, V: Send, S> ParallelDrainFull for &'a mut HashMap<K, V, S> {
type Iter = Drain<'a, K, V>;
type Item = (K, V);

Expand All @@ -92,5 +89,5 @@ impl<'a, K: Hash + Eq + Send, V: Send, S: BuildHasher> ParallelDrainFull

delegate_iterator! {
Drain<'_, K, V> => (K, V),
impl<K: Hash + Eq + Send, V: Send>
impl<K: Send, V: Send>
}
21 changes: 10 additions & 11 deletions src/collections/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! unless you have need to name one of the iterator types.

use std::collections::HashSet;
use std::hash::{BuildHasher, Hash};
use std::marker::PhantomData;

use crate::iter::plumbing::*;
Expand All @@ -13,27 +12,27 @@ use crate::vec;

/// Parallel iterator over a hash set
#[derive(Debug)] // std doesn't Clone
pub struct IntoIter<T: Hash + Eq + Send> {
pub struct IntoIter<T> {
inner: vec::IntoIter<T>,
}

into_par_vec! {
HashSet<T, S> => IntoIter<T>,
impl<T: Hash + Eq + Send, S: BuildHasher>
impl<T: Send, S>
}

delegate_iterator! {
IntoIter<T> => T,
impl<T: Hash + Eq + Send>
impl<T: Send>
}

/// Parallel iterator over an immutable reference to a hash set
#[derive(Debug)]
pub struct Iter<'a, T: Hash + Eq + Sync> {
pub struct Iter<'a, T> {
inner: vec::IntoIter<&'a T>,
}

impl<'a, T: Hash + Eq + Sync> Clone for Iter<'a, T> {
impl<T> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Iter {
inner: self.inner.clone(),
Expand All @@ -43,25 +42,25 @@ impl<'a, T: Hash + Eq + Sync> Clone for Iter<'a, T> {

into_par_vec! {
&'a HashSet<T, S> => Iter<'a, T>,
impl<'a, T: Hash + Eq + Sync, S: BuildHasher>
impl<'a, T: Sync, S>
}

delegate_iterator! {
Iter<'a, T> => &'a T,
impl<'a, T: Hash + Eq + Sync + 'a>
impl<'a, T: Sync>
}

// `HashSet` doesn't have a mutable `Iterator`

/// Draining parallel iterator that moves out of a hash set,
/// but keeps the total capacity.
#[derive(Debug)]
pub struct Drain<'a, T: Hash + Eq + Send> {
pub struct Drain<'a, T> {
inner: vec::IntoIter<T>,
marker: PhantomData<&'a mut HashSet<T>>,
}

impl<'a, T: Hash + Eq + Send, S: BuildHasher> ParallelDrainFull for &'a mut HashSet<T, S> {
impl<'a, T: Send, S> ParallelDrainFull for &'a mut HashSet<T, S> {
type Iter = Drain<'a, T>;
type Item = T;

Expand All @@ -76,5 +75,5 @@ impl<'a, T: Hash + Eq + Send, S: BuildHasher> ParallelDrainFull for &'a mut Hash

delegate_iterator! {
Drain<'_, T> => T,
impl<T: Hash + Eq + Send>
impl<T: Send>
}
Loading