pub struct BTreeMap<K, V, A: Tuning = DefaultTuning> { /* private fields */ }Expand description
BTreeMap similar to std::collections::BTreeMap.
General guide to implementation:
BTreeMap has a length and a Tree, where Tree is an enum that can be Leaf or NonLeaf.
The Entry API is implemented using CursorMut.
CursorMut is implemented using CursorMutKey which has a stack of raw pointer/index pairs
to keep track of non-leaf positions.
Roughly speaking, unsafe code is limited to the vecs module and the implementation of CursorMut and CursorMutKey.
Implementations§
Source§impl<K, V> BTreeMap<K, V>
impl<K, V> BTreeMap<K, V>
Sourcepub const fn new_in<AL>(a: AL) -> BTreeMap<K, V, CustomTuning<AL>>
pub const fn new_in<AL>(a: AL) -> BTreeMap<K, V, CustomTuning<AL>>
Returns a new, empty map with specified allocator.
§Example
use pstd::{ alloc::Global, collections::btree_map::{BTreeMap,CustomTuning} };
let a = Global;
let mut map = BTreeMap::new_in(a);
map.insert("England", "London");Source§impl<K, V, A: Tuning> BTreeMap<K, V, A>
impl<K, V, A: Tuning> BTreeMap<K, V, A>
Sourcepub const fn with_tuning(atune: A) -> Self
pub const fn with_tuning(atune: A) -> Self
Returns a new, empty map with specified allocation tuning.
§Example
use pstd::collections::btree_map::{BTreeMap,DefaultTuning};
let mut mymap = BTreeMap::with_tuning(DefaultTuning::new(8,2));
mymap.insert("England", "London");
mymap.insert("France", "Paris");
println!("The capital of France is {}", mymap["France"]);Sourcepub fn tuning_mut(&mut self) -> &mut A
pub fn tuning_mut(&mut self) -> &mut A
Get mut ref to tuning.
Sourcepub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V, A>>where
K: Ord,
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V, A>>where
K: Ord,
Get first Entry.
Sourcepub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V, A>>where
K: Ord,
pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V, A>>where
K: Ord,
Get last Entry.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Ord,
pub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Ord,
Insert key-value pair into map, or if key is already in map, replaces value and returns old value.
Sourcepub fn try_insert(
&mut self,
key: K,
value: V,
) -> Result<&mut V, OccupiedError<'_, K, V, A>>where
K: Ord,
pub fn try_insert(
&mut self,
key: K,
value: V,
) -> Result<&mut V, OccupiedError<'_, K, V, A>>where
K: Ord,
Tries to insert a key-value pair into the map, and returns a mutable reference to the value in the entry.
If the map already had this key present, nothing is updated, and an error containing the occupied entry and the value is returned.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Does the map have an entry for the specified key.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Remove key-value pair from map, returning just the value.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Remove key-value pair from map.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Remove all key-value pairs, visited in ascending order, for which f returns false.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Get 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>
Get a mutable reference to the value corresponding to the key.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Get references to the corresponding key and value.
Sourcepub fn first_key_value(&self) -> Option<(&K, &V)>
pub fn first_key_value(&self) -> Option<(&K, &V)>
Get references to first key and value.
Sourcepub fn last_key_value(&self) -> Option<(&K, &V)>
pub fn last_key_value(&self) -> Option<(&K, &V)>
Gets references to last key and value.
Sourcepub fn append(&mut self, other: &mut BTreeMap<K, V, A>)where
K: Ord,
pub fn append(&mut self, other: &mut BTreeMap<K, V, A>)where
K: Ord,
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 split_off<Q: ?Sized + Ord>(&mut self, key: &Q) -> Self
pub fn split_off<Q: ?Sized + Ord>(&mut self, key: &Q) -> Self
Splits the collection into two at the given key. Returns everything after the given key, including the key.
Sourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F, A> ⓘ
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F, A> ⓘ
Returns iterator that visits all elements (key-value pairs) in ascending key order and uses a closure to determine if an element should be removed.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Get iterator of mutable references to key-value pairs.
Sourcepub fn range<T, R>(&self, range: R) -> Range<'_, K, V> ⓘ
pub fn range<T, R>(&self, range: R) -> Range<'_, K, V> ⓘ
Get iterator for range of references to key-value pairs.
Sourcepub fn range_mut<T, R>(&mut self, range: R) -> RangeMut<'_, K, V> ⓘ
pub fn range_mut<T, R>(&mut self, range: R) -> RangeMut<'_, K, V> ⓘ
Get iterator for range of mutable references to key-value pairs.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
Get iterator of mutable references to values.
Sourcepub fn into_keys(self) -> IntoKeys<K, V, A> ⓘ
pub fn into_keys(self) -> IntoKeys<K, V, A> ⓘ
Get consuming iterator that returns all the keys, in sorted order.
Sourcepub fn into_values(self) -> IntoValues<K, V, A> ⓘ
pub fn into_values(self) -> IntoValues<K, V, A> ⓘ
Get consuming iterator that returns all the values, in sorted order.
Sourcepub fn lower_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V, A>
pub fn lower_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V, A>
Get cursor positioned just after bound.
Sourcepub fn upper_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V, A>
pub fn upper_bound<Q>(&self, bound: Bound<&Q>) -> Cursor<'_, K, V, A>
Get cursor positioned just before bound.
Sourcepub fn lower_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
pub fn lower_bound_mut<Q>(&mut self, bound: Bound<&Q>) -> CursorMut<'_, K, V, A>
Get a cursor positioned just after bound that permits map mutation.
Trait Implementations§
Source§impl<'a, K: Ord + Copy, V: Copy, A: Tuning> Extend<(&'a K, &'a V)> for BTreeMap<K, V, A>
impl<'a, K: Ord + Copy, V: Copy, A: Tuning> Extend<(&'a K, &'a V)> for BTreeMap<K, V, A>
Source§fn extend<I>(&mut self, iter: I)
fn extend<I>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: Ord, V, A: Tuning> Extend<(K, V)> for BTreeMap<K, V, A>
impl<K: Ord, V, A: Tuning> Extend<(K, V)> for BTreeMap<K, V, A>
Source§fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where
T: IntoIterator<Item = (K, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)