Skip to content

Commit

Permalink
Auto merge of #228 - cuviper:union-length, r=Amanieu
Browse files Browse the repository at this point in the history
Fix the union length comparision, and implement it for par_union

The `(smaller, larger)` comparison in `union` was backwards. It flipped in commit 80ce422 syncing with `std`, but the comparison is used differently there.

While we're at it, `par_union` can use the same trick.
  • Loading branch information
bors committed Jan 19, 2021
2 parents 496b1bc + af990b6 commit def8aba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/external_trait_impls/rayon/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,16 @@ where
where
C: UnindexedConsumer<Self::Item>,
{
self.a
// We'll iterate one set in full, and only the remaining difference from the other.
// Use the smaller set for the difference in order to reduce hash lookups.
let (smaller, larger) = if self.a.len() <= self.b.len() {
(self.a, self.b)
} else {
(self.b, self.a)
};
larger
.into_par_iter()
.chain(self.b.par_difference(self.a))
.chain(smaller.par_difference(larger))
.drive_unindexed(consumer)
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,9 @@ where
/// ```
#[cfg_attr(feature = "inline-more", inline)]
pub fn union<'a>(&'a self, other: &'a Self) -> Union<'a, T, S, A> {
let (smaller, larger) = if self.len() >= other.len() {
// We'll iterate one set in full, and only the remaining difference from the other.
// Use the smaller set for the difference in order to reduce hash lookups.
let (smaller, larger) = if self.len() <= other.len() {
(self, other)
} else {
(other, self)
Expand Down

0 comments on commit def8aba

Please sign in to comment.