Skip to content

Commit

Permalink
Implement the length optimization for par_union
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jan 18, 2021
1 parent 2c66e28 commit af990b6
Showing 1 changed file with 9 additions and 2 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

0 comments on commit af990b6

Please sign in to comment.