pub struct AllocatedBTreeMap<K: PartialOrd + Debug, V, B: ArrayLength = U6>where
U2: Mul<B>,
Prod<U2, B>: ArrayLength,
U1: Add<Prod<U2, B>>,
Sum<U1, Prod<U2, B>>: ArrayLength,{ /* private fields */ }Expand description
A compressed B-Tree map implementation using the allocated pattern.
This is the low-level “allocated” type that requires manual allocator passing.
For most use cases, prefer the CompressedBTreeMap wrapper which owns its allocator
and provides a safe, ergonomic API.
This implementation uses ~30% less memory than the naive implementation by using specialized node types:
- Leaf nodes: Store only keys and values (no child pointers)
- Interior nodes: Store keys, values, and child pointers
§Type Parameters
K: Key type, must bePartialOrd + DebugV: Value typeB: Branching factor (defaults toU6for 6-way tree). Controls the number of keys per node (2*B keys maximum).
§Examples
use allocated_btree::AllocatedCompressedBTreeMap;
use allocated::CountingAllocator;
let alloc = CountingAllocator::default();
let mut map = AllocatedCompressedBTreeMap::<u32, String>::new_in(&alloc)?;
unsafe {
map.insert_in(&alloc, 1, "one".to_string())?;
map.insert_in(&alloc, 2, "two".to_string())?;
}
assert_eq!(map.len(), 2);Implementations§
Source§impl<K: PartialOrd + Debug, V, B: ArrayLength> AllocatedBTreeMap<K, V, B>
impl<K: PartialOrd + Debug, V, B: ArrayLength> AllocatedBTreeMap<K, V, B>
Sourcepub fn new_in<A: Allocator>(alloc: &A) -> DropGuardResult<Self, &A>
pub fn new_in<A: Allocator>(alloc: &A) -> DropGuardResult<Self, &A>
§Errors
Will return Err if the 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 unsafe fn insert_in<A: Allocator>(
&mut self,
alloc: &A,
key: K,
value: V,
) -> AllocResult<Option<V>>
pub unsafe fn insert_in<A: Allocator>( &mut self, alloc: &A, 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.
§Safety
alloc MUST be the allocator used to allocate this object.
§Errors
Will return Err if the allocation fails.
Sourcepub fn get<'s, Q>(&'s self, key: &Q) -> Option<&'s V>
pub fn get<'s, Q>(&'s self, key: &Q) -> Option<&'s 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 iter(&self) -> Iter<'_, K, V, B> ⓘ
pub fn iter(&self) -> Iter<'_, K, V, B> ⓘ
Returns an iterator over the key-value pairs of the map, in sorted order by key.
Sourcepub fn keys(&self) -> Keys<'_, K, V, B> ⓘ
pub fn keys(&self) -> Keys<'_, K, V, B> ⓘ
Returns 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> ⓘ
Returns 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> ⓘ
Returns a mutable iterator over the values of the map, in order by key.
Sourcepub unsafe fn entry_in<'a, 's, A: Allocator>(
&'s mut self,
alloc: &'a A,
key: K,
) -> Entry<'a, 's, A, K, V, B>
pub unsafe fn entry_in<'a, 's, A: Allocator>( &'s mut self, alloc: &'a A, key: K, ) -> Entry<'a, 's, A, K, V, B>
§Safety
alloc MUST be the allocator used to allocate this object.
Sourcepub unsafe fn first_entry_in<'a, 's, A: Allocator>(
&'s mut self,
alloc: &'a A,
) -> Option<OccupiedEntry<'a, 's, A, K, V, B>>
pub unsafe fn first_entry_in<'a, 's, A: Allocator>( &'s mut self, alloc: &'a A, ) -> Option<OccupiedEntry<'a, 's, A, K, V, B>>
§Safety
alloc MUST be the allocator used to allocate this object.
Sourcepub fn first_key_value<'s>(&'s self) -> Option<(&'s K, &'s V)>
pub fn first_key_value<'s>(&'s self) -> Option<(&'s K, &'s V)>
Returns a reference to the first key-value pair in the map. The key in this pair is the minimum key in the map.
Trait Implementations§
Source§impl<K: PartialOrd + Debug, V, B: ArrayLength> DropIn for AllocatedBTreeMap<K, V, B>
impl<K: PartialOrd + Debug, V, B: ArrayLength> DropIn for AllocatedBTreeMap<K, V, B>
Source§impl<'a, K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> FromIteratorIn<'a, (K, V), A> for AllocatedBTreeMap<K, V, B>
impl<'a, K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> FromIteratorIn<'a, (K, V), A> for AllocatedBTreeMap<K, V, B>
Source§fn from_iter_in<T>(alloc: &'a A, iter: T) -> DropGuardResult<Self, &'a A>where
T: IntoIterator<Item = (K, V)>,
fn from_iter_in<T>(alloc: &'a A, iter: T) -> DropGuardResult<Self, &'a A>where
T: IntoIterator<Item = (K, V)>,
alloc. The instance
of Self MUST be drop_in using the same instance of the
allocator.