Skip to main content

BudgetedMap

Struct BudgetedMap 

Source
pub struct BudgetedMap<K, V> { /* private fields */ }
Expand description

An ordered map with logarithmic lookup, insertion and removal. Each node reserves its entire allocation before construction; keys and values retain their own separately allocated payloads. Removing a node frees its allocation before releasing that reservation. The map never clones elements or retains unused nodes.

Implementations§

Source§

impl<K, V> BudgetedMap<K, V>

Source

pub fn new(memory: &MemoryBudget) -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn budget(&self) -> &MemoryBudget

Source

pub fn prepare_entry( &self, key: K, value: V, ) -> Result<PreparedMapEntry<K, V>, MemoryError>

Source

pub fn for_each_mut(&mut self, visit: impl FnMut(&K, &mut V))

Visit mutable values in key order without allocating a traversal buffer or allowing keys to change.

Source

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

Source§

impl<K: Ord, V> BudgetedMap<K, V>

Source

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

Source

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

Source

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

Source

pub fn insert_prepared(&mut self, entry: PreparedMapEntry<K, V>) -> Option<V>

Publish an already reserved entry without allocation. A matching key retains its original key and returns the replaced value. Panics before mutation if the entry belongs to a different allowance.

Source

pub fn insert(&mut self, key: K, value: V) -> Result<Option<V>, MemoryError>

Reserve a node only for a new key. Failure preserves the map, its entries and its reservations.

Source

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

Trait Implementations§

Source§

impl<K: Ord + Borrow<Q>, V, Q: Ord + ?Sized> Index<&Q> for BudgetedMap<K, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, key: &Q) -> &V

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, K, V> IntoIterator for &'a BudgetedMap<K, V>

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = BudgetedMapIter<'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

Auto Trait Implementations§

§

impl<K, V> Freeze for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: Freeze,

§

impl<K, V> RefUnwindSafe for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: RefUnwindSafe,

§

impl<K, V> Send for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: Send,

§

impl<K, V> Sync for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: Sync,

§

impl<K, V> Unpin for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: Unpin,

§

impl<K, V> UnsafeUnpin for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: UnsafeUnpin,

§

impl<K, V> UnwindSafe for BudgetedMap<K, V>
where Option<OwnedNode<K, V>>: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.