pub struct PopulatedBTreeMap<K, V>(/* private fields */);Expand description
An ordered map based on a B-Tree that is guaranteed to have at least one key-value pair.
Implementations§
Source§impl<K: Ord, V> PopulatedBTreeMap<K, V>
impl<K: Ord, V> PopulatedBTreeMap<K, V>
Sourcepub fn new(key: K, value: V) -> PopulatedBTreeMap<K, V>
pub fn new(key: K, value: V) -> PopulatedBTreeMap<K, V>
Makes a new PopulatedBTreeMap with a single key-value pair.
Sourcepub fn get<Q: Ord + ?Sized>(&self, k: &Q) -> Option<&V>where
K: Borrow<Q>,
pub fn get<Q: Ord + ?Sized>(&self, k: &Q) -> Option<&V>where
K: Borrow<Q>,
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_key_value<Q: Ord + ?Sized>(&self, k: &Q) -> Option<(&K, &V)>where
K: Borrow<Q>,
pub fn get_key_value<Q: Ord + ?Sized>(&self, k: &Q) -> Option<(&K, &V)>where
K: Borrow<Q>,
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn first_key_value(&self) -> (&K, &V)
pub fn first_key_value(&self) -> (&K, &V)
Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.
Sourcepub fn pop_first(self) -> ((K, V), BTreeMap<K, V>)
pub fn pop_first(self) -> ((K, V), BTreeMap<K, V>)
Removes and returns the first element in the map. The key of this element is the minimum key that was in the map.
Sourcepub fn last_key_value(&self) -> (&K, &V)
pub fn last_key_value(&self) -> (&K, &V)
Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.
Sourcepub fn pop_last(self) -> (BTreeMap<K, V>, (K, V))
pub fn pop_last(self) -> (BTreeMap<K, V>, (K, V))
Removes and returns the last element in the map. The key of this element is the maximum key that was in the map.
Sourcepub fn contains_key<Q: Ord + ?Sized>(&self, k: &Q) -> boolwhere
K: Borrow<Q>,
pub fn contains_key<Q: Ord + ?Sized>(&self, k: &Q) -> boolwhere
K: Borrow<Q>,
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_mut<Q: Ord + ?Sized>(&mut self, k: &Q) -> Option<&mut V>where
K: Borrow<Q>,
pub fn get_mut<Q: Ord + ?Sized>(&mut self, k: &Q) -> Option<&mut V>where
K: Borrow<Q>,
Returns a mutable reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the map.
If the map did not have this key present, None is returned.
If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.
Sourcepub fn remove<Q: Ord + ?Sized>(
self,
k: &Q,
) -> Result<(V, BTreeMap<K, V>), PopulatedBTreeMap<K, V>>where
K: Borrow<Q>,
pub fn remove<Q: Ord + ?Sized>(
self,
k: &Q,
) -> Result<(V, BTreeMap<K, V>), PopulatedBTreeMap<K, V>>where
K: Borrow<Q>,
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn remove_entry<Q: Ord + ?Sized>(self, k: &Q) -> EntryRemovalResult<K, V>where
K: Borrow<Q>,
pub fn remove_entry<Q: Ord + ?Sized>(self, k: &Q) -> EntryRemovalResult<K, V>where
K: Borrow<Q>,
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn retain(self, predicate: impl FnMut(&K, &mut V) -> bool) -> BTreeMap<K, V>
pub fn retain(self, predicate: impl FnMut(&K, &mut V) -> bool) -> BTreeMap<K, V>
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v) for which f(&k, &mut v)
returns false. The elements are visited in ascending key order.
Sourcepub fn append(&mut self, other: &mut BTreeMap<K, V>)
pub fn append(&mut self, other: &mut BTreeMap<K, V>)
Moves all elements from other into self, leaving other empty.
If a key from other is already present in self, the respective value from self will be overwritten with the respective value from other.
Sourcepub fn range<T: Ord + ?Sized>(
&self,
range: impl RangeBounds<T>,
) -> Range<'_, K, V>where
K: Borrow<T>,
pub fn range<T: Ord + ?Sized>(
&self,
range: impl RangeBounds<T>,
) -> Range<'_, K, V>where
K: Borrow<T>,
Constructs a double-ended iterator over a sub-range of elements in
the map. The simplest way is to use the range syntax min..max,
thus range(min..max) will yield elements from min (inclusive) to
max (exclusive). The range may also be entered as
(Bound<T>, Bound<T>), so for example
range((Excluded(4), Included(10))) will yield a left-exclusive,
right-inclusive range from 4 to 10.
pub fn split_at<Q: Ord + ?Sized>(
self,
key: &Q,
) -> (BTreeMap<K, V>, BTreeMap<K, V>)where
K: Borrow<Q>,
Source§impl<K, V> PopulatedBTreeMap<K, V>
impl<K, V> PopulatedBTreeMap<K, V>
Source§impl<K, V> PopulatedBTreeMap<K, V>
impl<K, V> PopulatedBTreeMap<K, V>
pub fn iter(&self) -> PopulatedIter<'_, K, V>
pub fn iter_mut(&mut self) -> PopulatedIterMut<'_, K, V>
pub fn keys(&self) -> PopulatedKeys<'_, K, V>
pub fn values(&self) -> PopulatedValues<'_, K, V>
pub fn values_mut(&mut self) -> PopulatedValuesMut<'_, K, V>
pub fn into_keys(self) -> PopulatedIntoKeys<K, V>
pub fn into_values(self) -> PopulatedIntoValues<K, V>
Trait Implementations§
Source§impl<K: Clone, V: Clone> Clone for PopulatedBTreeMap<K, V>
impl<K: Clone, V: Clone> Clone for PopulatedBTreeMap<K, V>
Source§fn clone(&self) -> PopulatedBTreeMap<K, V>
fn clone(&self) -> PopulatedBTreeMap<K, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<K, V> From<PopulatedBTreeMap<K, V>> for BTreeMap<K, V>
impl<K, V> From<PopulatedBTreeMap<K, V>> for BTreeMap<K, V>
Source§fn from(populated_btree_map: PopulatedBTreeMap<K, V>) -> BTreeMap<K, V>
fn from(populated_btree_map: PopulatedBTreeMap<K, V>) -> BTreeMap<K, V>
Source§impl<K: Ord, V> FromPopulatedIterator<(K, V)> for PopulatedBTreeMap<K, V>
impl<K: Ord, V> FromPopulatedIterator<(K, V)> for PopulatedBTreeMap<K, V>
Source§fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = (K, V)>) -> Self
fn from_populated_iter(iter: impl IntoPopulatedIterator<Item = (K, V)>) -> Self
PopulatedIterator into Self.Source§impl<'a, K, V> IntoIterator for &'a PopulatedBTreeMap<K, V>
impl<'a, K, V> IntoIterator for &'a PopulatedBTreeMap<K, V>
Source§impl<'a, K, V> IntoIterator for &'a mut PopulatedBTreeMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut PopulatedBTreeMap<K, V>
Source§impl<K, V> IntoIterator for PopulatedBTreeMap<K, V>
impl<K, V> IntoIterator for PopulatedBTreeMap<K, V>
Source§impl<'a, K, V> IntoPopulatedIterator for &'a PopulatedBTreeMap<K, V>
impl<'a, K, V> IntoPopulatedIterator for &'a PopulatedBTreeMap<K, V>
type PopulatedIntoIter = PopulatedIter<'a, K, V>
Source§fn into_populated_iter(self) -> PopulatedIter<'a, K, V>
fn into_populated_iter(self) -> PopulatedIter<'a, K, V>
PopulatedIterator.Source§impl<'a, K, V> IntoPopulatedIterator for &'a mut PopulatedBTreeMap<K, V>
impl<'a, K, V> IntoPopulatedIterator for &'a mut PopulatedBTreeMap<K, V>
type PopulatedIntoIter = PopulatedIterMut<'a, K, V>
Source§fn into_populated_iter(self) -> PopulatedIterMut<'a, K, V>
fn into_populated_iter(self) -> PopulatedIterMut<'a, K, V>
PopulatedIterator.Source§impl<K, V> IntoPopulatedIterator for PopulatedBTreeMap<K, V>
impl<K, V> IntoPopulatedIterator for PopulatedBTreeMap<K, V>
type PopulatedIntoIter = IntoPopulatedIter<K, V>
Source§fn into_populated_iter(self) -> IntoPopulatedIter<K, V>
fn into_populated_iter(self) -> IntoPopulatedIter<K, V>
PopulatedIterator.