Skip to content

Commit 3b051d0

Browse files
committed
BTreeMap: comment why drain_filter's size_hint is somewhat pessimistictid
1 parent 90c8b43 commit 3b051d0

File tree

1 file changed

+4
-0
lines changed
  • library/alloc/src/collections/btree

1 file changed

+4
-0
lines changed

library/alloc/src/collections/btree/map.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,10 @@ impl<'a, K: 'a, V: 'a> DrainFilterInner<'a, K, V> {
17481748

17491749
/// Implementation of a typical `DrainFilter::size_hint` method.
17501750
pub(super) fn size_hint(&self) -> (usize, Option<usize>) {
1751+
// In most of the btree iterators, `self.length` is the number of elements
1752+
// yet to be visited. Here, it includes elements that were visited and that
1753+
// the predicate decided not to drain. Making this upper bound more accurate
1754+
// requires maintaining an extra field and is not worth while.
17511755
(0, Some(*self.length))
17521756
}
17531757
}

0 commit comments

Comments
 (0)