Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/liballoc/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,8 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
unsafe { Some(self.next_unchecked()) }
}
}

// FIXME(#49205): Add size_hint.
}

#[stable(feature = "map_values_mut", since = "1.10.0")]
Expand Down Expand Up @@ -1612,6 +1614,8 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
unsafe { Some(self.next_unchecked()) }
}
}

// FIXME(#49205): Add size_hint.
}

impl<'a, K, V> RangeMut<'a, K, V> {
Expand Down Expand Up @@ -2549,4 +2553,19 @@ impl<K: Ord, V, I: Iterator<Item = (K, V)>> Iterator for MergeIter<K, V, I> {
}
}
}

// Currently unused. However, BTreeMap::from_sorted_iter may some day be
// rewritten to pre-allocate the correct amount of nodes, in which case
// having this will be helpful.
fn size_hint(&self) -> (usize, Option<usize>) {
let (left_lower, left_upper) = self.left.size_hint();
let (right_lower, right_upper) = self.right.size_hint();
let lower = left_lower.saturating_add(right_lower);
let upper = match (left_upper, right_upper) {
(Some(left), Some(right)) => left.checked_add(right),
(_, None) => None,
(None, _) => None
};
(lower, upper)
}
}
4 changes: 4 additions & 0 deletions src/liballoc/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,10 @@ impl<'a, T> Iterator for Range<'a, T> {
fn next(&mut self) -> Option<&'a T> {
self.iter.next().map(|(k, _)| k)
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}

#[stable(feature = "btree_range", since = "1.17.0")]
Expand Down