pub struct BTreeMap<K: Ord + Clone + Sized, V: Sized> { /* private fields */ }btree only.Expand description
B+Tree Map for single-threaded usage, optimized for numeric type.
Implementations§
Source§impl<K: Ord + Sized + Clone, V: Sized> BTreeMap<K, V>
impl<K: Ord + Sized + Clone, V: Sized> BTreeMap<K, V>
Sourcepub fn leaf_count(&self) -> usize
pub fn leaf_count(&self) -> usize
Return the number of leaf nodes
Sourcepub fn get_fill_ratio(&self) -> f32
pub fn get_fill_ratio(&self) -> f32
Return the average fill ratio of leaf nodes
The range is [0.0, 100]
Sourcepub fn height(&self) -> u32
pub fn height(&self) -> u32
When root is leaf, returns 1, otherwise return the number of layers of inter node
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains the key
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert a key-value pair into the map Returns the old value if the key already existed
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Remove a key from the map, returning the value if it existed
Sourcepub fn remove_range<R>(&mut self, range: R) -> Option<(K, V)>where
R: RangeBounds<K>,
pub fn remove_range<R>(&mut self, range: R) -> Option<(K, V)>where
R: RangeBounds<K>,
Perform removal in batch mode and return the last item removed
NOTE: this function speed up by skipping the underflow of LeafNode until the last operation.
Sourcepub fn remove_range_with<R, F>(&mut self, range: R, cb: F) -> Option<(K, V)>
pub fn remove_range_with<R, F>(&mut self, range: R, cb: F) -> Option<(K, V)>
Perform removal in batch mode and return the last item removed
On each removal, callback function cb is invoke with (ref of key, ref of value)
NOTE: this function speed up by skipping the underflow of LeafNode until the last operation.
Sourcepub fn validate(&self)
pub fn validate(&self)
Validate the entire tree structure Uses the same traversal logic as Drop to avoid recursion
Sourcepub fn first_key_value(&self) -> Option<(&K, &V)>
pub fn first_key_value(&self) -> Option<(&K, &V)>
Returns the first key-value pair in the map
Returns None if the map is empty
Sourcepub fn last_key_value(&self) -> Option<(&K, &V)>
pub fn last_key_value(&self) -> Option<(&K, &V)>
Returns the last key-value pair in the map
Returns None if the map is empty
Sourcepub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
Returns an entry to the first key in the map
Returns None if the map is empty
Sourcepub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
Returns an entry to the last key in the map
Returns None if the map is empty
Sourcepub fn pop_first(&mut self) -> Option<(K, V)>
pub fn pop_first(&mut self) -> Option<(K, V)>
Removes and returns the first key-value pair in the map
Returns None if the map is empty
Sourcepub fn pop_last(&mut self) -> Option<(K, V)>
pub fn pop_last(&mut self) -> Option<(K, V)>
Removes and returns the last key-value pair in the map
Returns None if the map is empty
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Returns a mutable iterator over the map’s entries
Sourcepub fn into_iter_rev(self) -> IntoIter<K, V> ⓘ
pub fn into_iter_rev(self) -> IntoIter<K, V> ⓘ
Return a consuming iterator in reversed order
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
Returns a mutable iterator over the map’s values
Sourcepub fn range<R>(&self, range: R) -> Range<'_, K, V> ⓘwhere
R: RangeBounds<K>,
pub fn range<R>(&self, range: R) -> Range<'_, K, V> ⓘwhere
R: RangeBounds<K>,
Returns an iterator over a sub-range of entries in the map
Sourcepub fn range_mut<R>(&mut self, range: R) -> RangeMut<'_, K, V> ⓘwhere
R: RangeBounds<K>,
pub fn range_mut<R>(&mut self, range: R) -> RangeMut<'_, K, V> ⓘwhere
R: RangeBounds<K>,
Returns a mutable iterator over a sub-range of entries in the map
Trait Implementations§
impl<K: Ord + Clone + Sized, V: Sized> RefUnwindSafe for BTreeMap<K, V>
std only.