Skip to main content

BTreeMap

Struct BTreeMap 

Source
pub struct BTreeMap<K: Ord + Clone + Sized, V: Sized> { /* private fields */ }
Available on crate feature 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>

Source

pub fn new() -> Self

Create a new empty BTreeMap

Source

pub fn len(&self) -> usize

Returns the number of elements in the map

Source

pub fn is_empty(&self) -> bool

Returns true if the map is empty

Source

pub const fn cap() -> (u32, u32)

return (cap_of_inter_node, cap_of_leaf_node)

Source

pub fn leaf_count(&self) -> usize

Return the number of leaf nodes

Source

pub fn get_fill_ratio(&self) -> f32

Return the average fill ratio of leaf nodes

The range is [0.0, 100]

Source

pub fn height(&self) -> u32

When root is leaf, returns 1, otherwise return the number of layers of inter node

Source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>

Returns an entry to the key in the map

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Ord + ?Sized,

Returns true if the map contains the key

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Returns a reference to the value corresponding to the key

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Returns a mutable reference to the value corresponding to the key

Source

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

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Ord + ?Sized,

Remove a key from the map, returning the value if it existed

Source

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.

Source

pub fn remove_range_with<R, F>(&mut self, range: R, cb: F) -> Option<(K, V)>
where R: RangeBounds<K>, F: FnMut(&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.

Source

pub fn validate(&self)
where K: Debug, V: Debug,

Validate the entire tree structure Uses the same traversal logic as Drop to avoid recursion

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn iter(&self) -> Iter<'_, K, V>

Returns an iterator over the map’s entries

Source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Returns a mutable iterator over the map’s entries

Source

pub fn into_iter_rev(self) -> IntoIter<K, V>

Return a consuming iterator in reversed order

Source

pub fn keys(&self) -> Keys<'_, K, V>

Returns an iterator over the map’s keys

Source

pub fn values(&self) -> Values<'_, K, V>

Returns an iterator over the map’s values

Source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Returns a mutable iterator over the map’s values

Source

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

Source

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§

Source§

impl<K: Ord + Clone + Sized, V: Sized> Default for BTreeMap<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K: Ord + Clone + Sized, V: Sized> Drop for BTreeMap<K, V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, K: Ord + Clone + Sized, V: Sized> IntoIterator for &'a BTreeMap<K, V>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, K: Ord + Clone + Sized, V: Sized> IntoIterator for &'a mut BTreeMap<K, V>

Source§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: Ord + Clone + Sized, V: Sized> IntoIterator for BTreeMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: Ord + Clone + Sized, V: Sized> RefUnwindSafe for BTreeMap<K, V>

Available on crate feature std only.
Source§

impl<K: Ord + Clone + Sized + Send, V: Sized + Send> Send for BTreeMap<K, V>

Source§

impl<K: Ord + Clone + Sized + Send, V: Sized + Send> Sync for BTreeMap<K, V>

Auto Trait Implementations§

§

impl<K, V> !Freeze for BTreeMap<K, V>

§

impl<K, V> Unpin for BTreeMap<K, V>

§

impl<K, V> UnsafeUnpin for BTreeMap<K, V>

§

impl<K, V> UnwindSafe for BTreeMap<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.