pub struct MapWithDictBitpacked<K, const B: usize = 32, const S: usize = 8, ST = u8, H = WyHash>{ /* private fields */ }Expand description
An efficient, immutable hash map with bit-packed Vec<u32> values for optimized space usage.
§Serde and untrusted input
Deserialization performs best-effort consistency checks (key/MPHF alignment, value index
bounds, num_bits <= 32), but does not verify that every dictionary entry covers its
packed blocks. A crafted payload can therefore pass deserialization and later panic in
get_values/values/iter. Only
deserialize payloads you trust; do not treat this type as a security boundary.
Implementations§
Source§impl<K, const B: usize, const S: usize, ST, H> MapWithDictBitpacked<K, B, S, ST, H>
impl<K, const B: usize, const S: usize, ST, H> MapWithDictBitpacked<K, B, S, ST, H>
Sourcepub fn from_iter_with_params<I>(iter: I, gamma: f32) -> Result<Self, Error>
pub fn from_iter_with_params<I>(iter: I, gamma: f32) -> Result<Self, Error>
Constructs a MapWithDictBitpacked from an iterator of key-value pairs and MPHF function params.
Sourcepub fn get_values<Q>(&self, key: &Q, values: &mut [u32]) -> bool
pub fn get_values<Q>(&self, key: &Q, values: &mut [u32]) -> bool
Updates values to the array of values corresponding to the key. Returns false if the
key is not not present in the map.
§Examples
let map = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![4])])).unwrap();
let mut values = [0];
assert_eq!(map.get_values(&1, &mut values), true);
assert_eq!(values, [2]);
assert_eq!(map.get_values(&2, &mut values), false);§Panics
Panics if self was deserialized from a crafted payload whose dictionary entry is
truncated (see the type-level note about untrusted input).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of keys in the map.
§Examples
let map = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![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 = MapWithDictBitpacked::try_from(HashMap::from([(0, vec![0]); 0])).unwrap();
assert_eq!(map.is_empty(), true);
let map = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![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 = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![4])])).unwrap();
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);Sourcepub fn iter(&self, n: usize) -> impl Iterator<Item = (&K, Vec<u32>)>
pub fn iter(&self, n: usize) -> impl Iterator<Item = (&K, Vec<u32>)>
Returns an iterator over the map, yielding key-value pairs.
§Examples
let map = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![4])])).unwrap();
for (key, val) in map.iter(1) {
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 = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![4])])).unwrap();
for key in map.keys() {
println!("{key}");
}