Feature gate: #![feature(map_first_last)]
Public API
impl<T> BTreeSet<T> {
pub fn first(&self) -> Option<&T> where T: Ord;
pub fn last(&self) -> Option<&T> where T: Ord;
pub fn pop_first(&mut self) -> Option<T> where T: Ord;
pub fn pop_last(&mut self) -> Option<T> where T: Ord;
}
impl<K, V> BTreeMap<K, V> {
pub fn first_key_value(&self) -> Option<(&K, &V)> where K: Ord;
pub fn last_key_value(&self) -> Option<(&K, &V)> where K: Ord;
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord;
pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>> where K: Ord;
pub fn pop_first(&mut self) -> Option<(K, V)> where K: Ord;
pub fn pop_last(&mut self) -> Option<(K, V)> where K: Ord;
}
Steps / History
Unresolved Questions
Original issue title: Finding minimum/maximum element in BTreeMap does twice the required amount of computation
Original issue text:
The standard way of finding the minimum element in BTreeMap is tree_map.iter().next()
The iter() function creates a btree_map::Iter, which finds both the minimum and maximum element to create its internal instance of btree_map::Range.
This is unnecessary, and a BTreeMap::get_min or similar function could be provided, which would just internally call the first_leaf_edge private function, without needing to call last_leaf_edge.
Ditto for finding the maximum element.
Feature gate:
#![feature(map_first_last)]Public API
Steps / History
Unresolved Questions
Original issue title: Finding minimum/maximum element in BTreeMap does twice the required amount of computation
Original issue text:
The standard way of finding the minimum element in BTreeMap is
tree_map.iter().next()The
iter()function creates abtree_map::Iter, which finds both the minimum and maximum element to create its internal instance ofbtree_map::Range.This is unnecessary, and a
BTreeMap::get_minor similar function could be provided, which would just internally call thefirst_leaf_edgeprivate function, without needing to calllast_leaf_edge.Ditto for finding the maximum element.