pub struct CompressedBTreeMap<K: PartialOrd + Debug, V, B: ArrayLength = U6, A: Allocator = Global>where
U2: Mul<B>,
Prod<U2, B>: ArrayLength,
U1: Add<Prod<U2, B>>,
Sum<U1, Prod<U2, B>>: ArrayLength,{ /* private fields */ }Expand description
An ergonomic compressed B-Tree map that owns its allocator.
This is a memory-optimized B-Tree that uses specialized leaf nodes without child pointers, reducing memory usage by approximately 30% compared to the naive implementation.
This is the recommended type for most use cases. It wraps the allocated
B-Tree and provides safe methods without requiring unsafe blocks or
passing allocators manually.
§Example
use allocated_btree::CompressedBTreeMap;
let mut map = CompressedBTreeMap::new();
map.insert(1, "one").unwrap();
map.insert(2, "two").unwrap();
assert_eq!(map.get(&1), Some(&"one"));
assert_eq!(map.len(), 2);Implementations§
Source§impl<K: PartialOrd + Debug, V> CompressedBTreeMap<K, V>
impl<K: PartialOrd + Debug, V> CompressedBTreeMap<K, V>
Source§impl<K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> CompressedBTreeMap<K, V, B, A>
impl<K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> CompressedBTreeMap<K, V, B, A>
Sourcepub fn new_in(alloc: A) -> AllocResult<Self>
pub fn new_in(alloc: A) -> AllocResult<Self>
Create a new empty compressed B-Tree using the provided allocator.
§Errors
Returns an error if allocation fails.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains a value for the specified 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_key_value<'s, Q>(&'s self, key: &'s Q) -> Option<(&'s K, &'s V)>
pub fn get_key_value<'s, Q>(&'s self, key: &'s Q) -> Option<(&'s K, &'s V)>
Returns the key-value pair corresponding to the supplied key.
Sourcepub fn get_mut<'s, Q>(&'s mut self, key: &'s Q) -> Option<&'s mut V>
pub fn get_mut<'s, Q>(&'s mut self, key: &'s Q) -> Option<&'s mut V>
Returns a mutable reference to the value corresponding to the key.
Sourcepub fn insert(&mut self, key: K, value: V) -> AllocResult<Option<V>>
pub fn insert(&mut self, key: K, value: V) -> AllocResult<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.
§Errors
Returns an error if allocation fails during tree rebalancing.
Sourcepub fn clear(&mut self) -> AllocResult<()>
pub fn clear(&mut self) -> AllocResult<()>
Sourcepub fn entry(&mut self, key: K) -> Entry<'_, '_, A, K, V, B>
pub fn entry(&mut self, key: K) -> Entry<'_, '_, A, K, V, B>
Gets the given key’s corresponding entry in the map for in-place manipulation.
Sourcepub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, '_, A, K, V, B>>
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, '_, A, K, V, B>>
Gets the first entry in the map for in-place manipulation.
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.
Sourcepub fn iter(&self) -> Iter<'_, K, V, B> ⓘ
pub fn iter(&self) -> Iter<'_, K, V, B> ⓘ
Gets an iterator over the entries of the map, sorted by key.
Sourcepub fn keys(&self) -> Keys<'_, K, V, B> ⓘ
pub fn keys(&self) -> Keys<'_, K, V, B> ⓘ
Gets an iterator over the keys of the map, in sorted order.
Sourcepub fn values(&self) -> Values<'_, K, V, B> ⓘ
pub fn values(&self) -> Values<'_, K, V, B> ⓘ
Gets an iterator over the values of the map, in order by key.
Sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V, B> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V, B> ⓘ
Gets a mutable iterator over the values of the map, in order by key.