Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add traits ParallelDrainRange and ParallelDrainFull #787

Merged
merged 2 commits into from Sep 15, 2020

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Aug 16, 2020

These define methods of the same name, so only one is expected to be
implemented for any given collection type. Collections that support
ranges can always call par_drain(..) for a full drain.

pub trait ParallelDrainRange<Idx = usize> {
    type Iter: ParallelIterator<Item = Self::Item>;
    type Item: Send;
    fn par_drain<R: RangeBounds<Idx>>(self, range: R) -> Self::Iter;
}

pub trait ParallelDrainFull {
    type Iter: ParallelIterator<Item = Self::Item>;
    type Item: Send;
    fn par_drain(self) -> Self::Iter;
}

This was linked to issues Aug 16, 2020
These define methods of the same name, so only one is expected to be
implemented for any given collection type. Collections that support
ranges can always call `par_drain(..)` for a full drain.

```rust
pub trait ParallelDrainRange<Idx = usize> {
    type Iter: ParallelIterator<Item = Self::Item>;
    type Item: Send;
    fn par_drain<R: RangeBounds<Idx>>(self, range: R) -> Self::Iter;
}

pub trait ParallelDrainFull {
    type Iter: ParallelIterator<Item = Self::Item>;
    type Item: Send;
    fn par_drain(self) -> Self::Iter;
}
```
@cuviper
Copy link
Member Author

cuviper commented Aug 16, 2020

These define methods of the same name,

I did this so these traits can be seen as extension traits mirroring par_drain to each collection's inherent drain, but some take an argument (like ParallelDrainRange) and some always drain everything (like ParallelDrainFull).

Copy link
Member

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one nit but overall this PR reads great, good idea to support drain

src/math.rs Show resolved Hide resolved
@nikomatsakis
Copy link
Member

bors r+

@bors bors bot merged commit 4a26ac4 into rayon-rs:master Sep 15, 2020
@cuviper cuviper deleted the par_drain branch February 25, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement par_drain for Vec Vec::truncate_par
2 participants