implement cmp
, partial_cmp
, and friends for parallel iterator
#152
Labels
Milestone
cmp
, partial_cmp
, and friends for parallel iterator
#152
To achieve parity with sequential iterators, we need to support
cmp
and friends. These are methods which basically zip two iterators and compare corresponding elements; so long as the elements are equal, it proceeds to the next.We can parallelize this fairly easily by using the existing zip, map, and reduce combinators I think. Roughly speaking I would do something like
left.zip(right).map(Ord::cmp).reduce(|| Equal, |cmp_a, cmp_b| if cmp_a != Equal { cmp_b } else { cmp_a })
. This won't, however, be the most efficient thing, because it will do all the comparisons, even if it already knows the final answer.To support the most efficient thing, we probably want
find_first
(#151), I should think, so that we can basically search for the first "non-equal" result.Here are the full set of methods:
fn cmp<I>(self, other: I) -> Ordering where I: IntoIterator<Item=Self::Item>, Self::Item: Ord { ... }
fn partial_cmp<I>(self, other: I) -> Option<Ordering> where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
fn eq<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialEq<I::Item> { ... }
fn ne<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialEq<I::Item> { ... }
fn lt<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
fn le<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
fn gt<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
fn ge<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
If you've not hacked on Rayon before, also check out the guide to development.
The text was updated successfully, but these errors were encountered: