Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information