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

Implement parallel Range<i64> and Range<u64> #144

Merged
merged 1 commit into from
Nov 16, 2016

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Nov 16, 2016

These couldn't be exact iterators, because they could exceed a usize
length on 32-bit targets. So this adds a bridge_unindexed helper
function to drive consumers directly with imprecise splits. 64-bit
ranges can use this while happily splitting in normal halves.

These couldn't be exact iterators, because they could exceed a `usize`
length on 32-bit targets.  So this adds a `bridge_unindexed` helper
function to drive consumers directly with imprecise splits.  64-bit
ranges can use this while happily splitting in normal halves.
@cuviper
Copy link
Member Author

cuviper commented Nov 16, 2016

I wrote bridge_unindexed while poking at #133, but this seems like an easy test bed for it.

@@ -83,6 +83,13 @@ pub trait UnindexedConsumer<ITEM>: Consumer<ITEM> {
fn to_reducer(&self) -> Self::Reducer;
}

/// An unindexed producer that doesn't know its exact length.
/// (or can't represent its known length in a `usize`)
pub trait UnindexedProducer: IntoIterator + Send + Sized {
Copy link
Member

Choose a reason for hiding this comment

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

Great! One nit: I've always imagined that we would have Producer: UnindexedProducer; but I guess it's just kind of a lot of boilerplate.

I would think something like this:

impl<T: Producer> UnindexedProducer for T {
    fn can_split(&self) -> bool { self.len() != 0 }
    fn split(&self) -> (Self, Self) { self.split_at(self.len() / 2) }
}

But I think we'd have to add the len method to Producer -- not that there is a good reason we don't have it.

Mostly I like the symmetry where you have:

  • Consumer and UnindexedConsumer: Consumed
  • UnindexedProducer and Producer: UnindexedProducer

@nikomatsakis nikomatsakis merged commit c4674db into rayon-rs:master Nov 16, 2016
@nikomatsakis
Copy link
Member

Going to merge this anyway. We can maybe refactor to give the producer traits more of a hierarchy later.

@cuviper
Copy link
Member Author

cuviper commented Nov 16, 2016

Thanks!

I agree that Producer: UnindexedProducer looks nice, but I'm not sure it's actually useful. Is there any case where you'd have a Producer and might prefer to use it unindexed anyway?

BTW, this should close #102. I had forgotten that issue existed when I wrote this, but it must have been floating in my subconscious already. :)

@nikomatsakis
Copy link
Member

@cuviper

I agree that Producer: UnindexedProducer looks nice, but I'm not sure it's actually useful. Is there any case where you'd have a Producer and might prefer to use it unindexed anyway?

Yeah, I can't think of any just now. =) I still like the idea of having the setup exposed (and it couldn't hurt), but I don't think it really matters, and if it does we can always do it then.

@cuviper cuviper deleted the range64 branch November 25, 2016 07:55
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.

2 participants