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>
impl<K, V> BudgetedMap<K, V>
pub fn new(memory: &MemoryBudget) -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn budget(&self) -> &MemoryBudget
pub fn prepare_entry( &self, key: K, value: V, ) -> Result<PreparedMapEntry<K, V>, MemoryError>
Sourcepub fn for_each_mut(&mut self, visit: impl FnMut(&K, &mut V))
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.
pub fn iter(&self) -> BudgetedMapIter<'_, K, V> ⓘ
Source§impl<K: Ord, V> BudgetedMap<K, V>
impl<K: Ord, V> BudgetedMap<K, V>
pub fn get<Q: Ord + ?Sized>(&self, key: &Q) -> Option<&V>where
K: Borrow<Q>,
pub fn get_mut<Q: Ord + ?Sized>(&mut self, key: &Q) -> Option<&mut V>where
K: Borrow<Q>,
pub fn contains_key<Q: Ord + ?Sized>(&self, key: &Q) -> boolwhere
K: Borrow<Q>,
Sourcepub fn insert_prepared(&mut self, entry: PreparedMapEntry<K, V>) -> Option<V>
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.
Sourcepub fn insert(&mut self, key: K, value: V) -> Result<Option<V>, MemoryError>
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.
pub fn remove<Q: Ord + ?Sized>(&mut self, key: &Q) -> Option<V>where
K: Borrow<Q>,
Trait Implementations§
Source§impl<'a, K, V> IntoIterator for &'a BudgetedMap<K, V>
impl<'a, K, V> IntoIterator for &'a BudgetedMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for BudgetedMap<K, V>
impl<K, V> RefUnwindSafe for BudgetedMap<K, V>where
Option<OwnedNode<K, V>>: RefUnwindSafe,
impl<K, V> Send for BudgetedMap<K, V>
impl<K, V> Sync for BudgetedMap<K, V>
impl<K, V> Unpin for BudgetedMap<K, V>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more