You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #531 - ToMe25:optimize_is_disjoint, r=Amanieu
Optimize Set is_disjoint
By using the `Intersection` iterator in `HashSet::is_Disjoint` its performance can be significantly improved in some cases.
This is because `intersection()` always uses the shorter set as its iterator.
It would also be possible to replicate this "Iterate over the smaller set and check in the larger set" logic in the is_disjoint method.
However in my benchmarks the approach I chose is faster than that.
This change only causes a significant improvement when called on the larger of two disjoint sets.
My benchmark results:
Name | Before | After | Diff (%)
-- | -- | -- | --
disjoint_is_disjoint_large_small | 1,147.43 | 535.25 | -53,35 %
disjoint_is_disjoint_small_large | 535.66 | 527.59 | -1,51 %
subset_is_disjoint | 9.90 | 10.44 | 5,45 %
superset_is_disjoint | 9.80 | 10.43 | 6,43 %
0 commit comments