CompressedBTreeMap

Struct CompressedBTreeMap 

Source
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>

Source

pub fn new() -> Self

Create a new empty compressed B-Tree using the global allocator.

§Panics

Panics if allocation fails.

Source§

impl<K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> CompressedBTreeMap<K, V, B, A>
where U2: Mul<B>, Prod<U2, B>: ArrayLength, U1: Add<Prod<U2, B>>, Sum<U1, Prod<U2, B>>: ArrayLength,

Source

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.

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 contains no elements.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: PartialOrd + Debug,

Returns true if the map contains a value for the specified key.

Source

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

Returns a reference to the value corresponding to the key.

Source

pub fn get_key_value<'s, Q>(&'s self, key: &'s Q) -> Option<(&'s K, &'s V)>
where K: Borrow<Q>, Q: PartialOrd + Debug,

Returns the key-value pair corresponding to the supplied key.

Source

pub fn get_mut<'s, Q>(&'s mut self, key: &'s Q) -> Option<&'s mut V>
where K: Borrow<Q>, Q: PartialOrd + Debug,

Returns a mutable reference to the value corresponding to the key.

Source

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.

Source

pub fn clear(&mut self) -> AllocResult<()>

Clears the map, removing all key-value pairs.

§Errors

Returns an error if allocation fails.

Source

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.

Source

pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, '_, A, K, V, B>>

Gets the first entry in the map for in-place manipulation.

Source

pub fn first_key_value(&self) -> Option<(&K, &V)>

Returns the first key-value pair in the map.

Source

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

Gets an iterator over the entries of the map, sorted by key.

Source

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

Gets an iterator over the keys of the map, in sorted order.

Source

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

Gets an iterator over the values of the map, in order by key.

Source

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

Gets a mutable iterator over the values of the map, in order by key.

Trait Implementations§

Source§

impl<K: PartialOrd + Debug, V> Default for CompressedBTreeMap<K, V>

Source§

fn default() -> Self

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

impl<K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> Drop for CompressedBTreeMap<K, V, B, A>
where U2: Mul<B>, Prod<U2, B>: ArrayLength, U1: Add<Prod<U2, B>>, Sum<U1, Prod<U2, B>>: ArrayLength,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'s, K: PartialOrd + Debug, V, B: ArrayLength, A: Allocator> IntoIterator for &'s CompressedBTreeMap<K, V, B, A>
where U2: Mul<B>, Prod<U2, B>: ArrayLength, U1: Add<Prod<U2, B>>, Sum<U1, Prod<U2, B>>: ArrayLength,

Source§

type IntoIter = Iter<'s, K, V, B>

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

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

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V, B = UInt<UInt<UInt<UTerm, B1>, B1>, B0>, A = Global> !Freeze for CompressedBTreeMap<K, V, B, A>

§

impl<K, V, B = UInt<UInt<UInt<UTerm, B1>, B1>, B0>, A = Global> !RefUnwindSafe for CompressedBTreeMap<K, V, B, A>

§

impl<K, V, B, A> Send for CompressedBTreeMap<K, V, B, A>
where <UInt<UTerm, B1> as Add<<UInt<UInt<UTerm, B1>, B0> as Mul<B>>::Output>>::Output: Sized, <UInt<UInt<UTerm, B1>, B0> as Mul<B>>::Output: Sized, A: Send, K: Send, V: Send,

§

impl<K, V, B, A> Sync for CompressedBTreeMap<K, V, B, A>
where <UInt<UTerm, B1> as Add<<UInt<UInt<UTerm, B1>, B0> as Mul<B>>::Output>>::Output: Sized, <UInt<UInt<UTerm, B1>, B0> as Mul<B>>::Output: Sized, A: Sync, K: Sync, V: Sync,

§

impl<K, V, B = UInt<UInt<UInt<UTerm, B1>, B1>, B0>, A = Global> !Unpin for CompressedBTreeMap<K, V, B, A>

§

impl<K, V, B = UInt<UInt<UInt<UTerm, B1>, B1>, B0>, A = Global> !UnwindSafe for CompressedBTreeMap<K, V, B, A>

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> Same for T

Source§

type Output = T

Should always be Self
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.