Skip to content

Commit

Permalink
Improve Set Difference size_hint
Browse files Browse the repository at this point in the history
This implementation isn't perfect, but it is spec compliant as far as I
can tell
  • Loading branch information
ToMe25 committed Jun 7, 2024
1 parent f540cb7 commit f4361bc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,7 @@ where
let (_, upper) = self.iter.size_hint();
(0, upper)
}

#[cfg_attr(feature = "inline-more", inline)]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Expand Down Expand Up @@ -1916,9 +1917,10 @@ where

#[cfg_attr(feature = "inline-more", inline)]
fn size_hint(&self) -> (usize, Option<usize>) {
let (_, upper) = self.iter.size_hint();
(0, upper)
let (lower, upper) = self.iter.size_hint();
(lower.saturating_sub(self.other.len()), upper)
}

#[cfg_attr(feature = "inline-more", inline)]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Expand Down Expand Up @@ -1975,10 +1977,12 @@ where
fn next(&mut self) -> Option<&'a T> {
self.iter.next()
}

#[cfg_attr(feature = "inline-more", inline)]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

#[cfg_attr(feature = "inline-more", inline)]
fn fold<B, F>(self, init: B, f: F) -> B
where
Expand Down Expand Up @@ -2048,10 +2052,12 @@ where
fn next(&mut self) -> Option<&'a T> {
self.iter.next()
}

#[cfg_attr(feature = "inline-more", inline)]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}

#[cfg_attr(feature = "inline-more", inline)]
fn fold<B, F>(self, init: B, f: F) -> B
where
Expand Down

0 comments on commit f4361bc

Please sign in to comment.