pub struct MapWithDict<K, V, const B: usize = 32, const S: usize = 8, ST = u8, H = WyHash>{ /* private fields */ }Expand description
An efficient, immutable hash map with values dictionary-packed for optimized space usage.
Implementations§
source§impl<K, V, const B: usize, const S: usize, ST, H> MapWithDict<K, V, B, S, ST, H>
impl<K, V, const B: usize, const S: usize, ST, H> MapWithDict<K, V, B, S, ST, H>
sourcepub fn from_iter_with_params<I>(iter: I, gamma: f32) -> Result<Self, MphfError>where
I: IntoIterator<Item = (K, V)>,
pub fn from_iter_with_params<I>(iter: I, gamma: f32) -> Result<Self, MphfError>where
I: IntoIterator<Item = (K, V)>,
Constructs a MapWithDict from an iterator of key-value pairs and MPHF function params.
sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key. Returns None if the key is
not present in the map.
§Examples
let map = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
assert_eq!(map.get(&1), Some(&2));
assert_eq!(map.get(&5), None);sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of key-value pairs in the map.
§Examples
let map = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
assert_eq!(map.len(), 2);sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
§Examples
let map = MapWithDict::try_from(HashMap::from([(0, 0); 0])).unwrap();
assert_eq!(map.is_empty(), true);
let map = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
assert_eq!(map.is_empty(), false);sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Checks if the map contains the specified key.
§Examples
let map = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);sourcepub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>
Returns an iterator over the map, yielding key-value pairs.
§Examples
let map = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
for (key, val) in map.iter() {
println!("key: {key} val: {val}");
}sourcepub fn keys(&self) -> impl Iterator<Item = &K>
pub fn keys(&self) -> impl Iterator<Item = &K>
Returns an iterator over the keys of the map.
§Examples
let map = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
for key in map.keys() {
println!("{key}");
}Trait Implementations§
source§impl<K, V> TryFrom<HashMap<K, V>> for MapWithDict<K, V>
impl<K, V> TryFrom<HashMap<K, V>> for MapWithDict<K, V>
Creates a MapWithDict from a HashMap.
Auto Trait Implementations§
impl<K, V, const B: usize, const S: usize, ST, H> Freeze for MapWithDict<K, V, B, S, ST, H>
impl<K, V, const B: usize, const S: usize, ST, H> RefUnwindSafe for MapWithDict<K, V, B, S, ST, H>
impl<K, V, const B: usize, const S: usize, ST, H> Send for MapWithDict<K, V, B, S, ST, H>
impl<K, V, const B: usize, const S: usize, ST, H> Sync for MapWithDict<K, V, B, S, ST, H>
impl<K, V, const B: usize, const S: usize, ST, H> Unpin for MapWithDict<K, V, B, S, ST, H>where
H: Unpin,
impl<K, V, const B: usize, const S: usize, ST, H> UnwindSafe for MapWithDict<K, V, B, S, ST, H>
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