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 #530 - ToMe25:fix_set_diff_size_hint, r=Amanieu
Improve Set Difference size_hint lower bound
This PR makes the Set `Difference` iterator generate a non-zero lower bound in some situations.
Specifically, it now returns a non-zero lower bound if the `difference` method is called on a larger set with a smaller set.
That is because in those cases the fact that sets can't really contains duplicates\* guarantees that a minimum of `self.len() - other.len()` items will be returned by the iterator.
\* Well, they can, but that is already documented to be causing a random mess
This implementation has the disadvantage that a single `next()` call may reduce the lower bound by more than one.
Every size hint generated, even the first largest one, is guaranteed to be correct, but it may be confusing if one `next()` call causes the lower bound to drop by more than one.
This could be avoided by storing the minimum number of resulting elements in the iterator and subtracting one each time `next()` is called, but I don't think its worth the added complexity.
0 commit comments