pub struct CDict<K: Copy, V: Compact + Clone, A: Allocator = DefaultHeap> { /* private fields */ }Expand description
A simple linear-search key-value dictionary,
implemented using two CompactVec’s, one for keys, one for values.
The API loosely follows that of std::collections::HashMap.
Spilling behaviour using Allocator is equivalent to CompactVec.
Implementations§
Source§impl<K: Eq + Copy, V: Compact + Clone, A: Allocator> CompactDict<K, V, A>
impl<K: Eq + Copy, V: Compact + Clone, A: Allocator> CompactDict<K, V, A>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create new, empty dictionary with a given capactity
Sourcepub fn get_mut(&mut self, query: K) -> Option<&mut V>
pub fn get_mut(&mut self, query: K) -> Option<&mut V>
Look up the value for keu query mutably, if it exists
Sourcepub fn get_mru(&mut self, query: K) -> Option<&V>
pub fn get_mru(&mut self, query: K) -> Option<&V>
Lookup up the value for key query, if it exists, but also swap the entry
to the beginning of the key/value vectors, so a repeated lookup for that item will be faster
Sourcepub fn get_mfu(&mut self, query: K) -> Option<&V>
pub fn get_mfu(&mut self, query: K) -> Option<&V>
Lookup up the value for key query, if it exists, but also swap the entry
one index towards the beginning of the key/value vectors, so frequently repeated lookups
for that item will be faster
Sourcepub fn contains_key(&self, query: K) -> bool
pub fn contains_key(&self, query: K) -> bool
Does the dictionary contain a value for query?
Sourcepub fn insert(&mut self, query: K, new_value: V) -> Option<V>
pub fn insert(&mut self, query: K, new_value: V) -> Option<V>
Insert new value at key query and return the previous value at that key, if any existed
Sourcepub fn remove(&mut self, query: K) -> Option<V>
pub fn remove(&mut self, query: K) -> Option<V>
Remove value at key query and return it, if it existed
Sourcepub fn values_mut(&mut self) -> IterMut<'_, V>
pub fn values_mut(&mut self) -> IterMut<'_, V>
Iterator over mutable references to all values in the dictionary
Source§impl<K: Eq + Copy, I: Compact, A1: Allocator, A2: Allocator> CompactDict<K, CompactVec<I, A1>, A2>
impl<K: Eq + Copy, I: Compact, A1: Allocator, A2: Allocator> CompactDict<K, CompactVec<I, A1>, A2>
Trait Implementations§
Source§impl<K: Copy, V: Compact + Clone, A: Allocator> Compact for CompactDict<K, V, A>
impl<K: Copy, V: Compact + Clone, A: Allocator> Compact for CompactDict<K, V, A>
Source§fn is_still_compact(&self) -> bool
fn is_still_compact(&self) -> bool
Source§fn dynamic_size_bytes(&self) -> usize
fn dynamic_size_bytes(&self) -> usize
Source§unsafe fn compact(source: *mut Self, dest: *mut Self, new_dynamic_part: *mut u8)
unsafe fn compact(source: *mut Self, dest: *mut Self, new_dynamic_part: *mut u8)
source to dest and compactly store
the dynamic part of source as the new dynamic part of dest at new_dynamic_part.
This semantically moves source into dest.Source§unsafe fn decompact(source: *const Self) -> CompactDict<K, V, A>
unsafe fn decompact(source: *const Self) -> CompactDict<K, V, A>
Source§fn total_size_bytes(&self) -> usize
fn total_size_bytes(&self) -> usize
Source§unsafe fn behind(ptr: *mut Self) -> *mut u8
unsafe fn behind(ptr: *mut Self) -> *mut u8
self (commonly used place for the dynamic part)Source§unsafe fn compact_behind(source: *mut Self, dest: *mut Self)
unsafe fn compact_behind(source: *mut Self, dest: *mut Self)
compact with new_dynamic_part set to dest.behind()Source§impl<K, V, A> Debug for CompactDict<K, V, A>
impl<K, V, A> Debug for CompactDict<K, V, A>
Source§impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> Extend<(K, V)> for CompactDict<K, V, A>
impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> Extend<(K, V)> for CompactDict<K, V, A>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
Extend a compact dictionary from an iterator over key-value pairs
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> FromIterator<(K, V)> for CompactDict<K, V, A>
impl<K: Copy + Eq, V: Compact + Clone, A: Allocator> FromIterator<(K, V)> for CompactDict<K, V, A>
Source§fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
Construct a compact dictionary from an interator over key-value pairs