Skip to main content

MapWithDictBitpacked

Struct MapWithDictBitpacked 

Source
pub struct MapWithDictBitpacked<K, const B: usize = 32, const S: usize = 8, ST = u8, H = WyHash>
where ST: PrimInt + Unsigned, H: Hasher + Default,
{ /* 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>
where K: Hash + PartialEq + Clone, ST: PrimInt + Unsigned, H: Hasher + Default,

Source

pub fn from_iter_with_params<I>(iter: I, gamma: f32) -> Result<Self, Error>
where I: IntoIterator<Item = (K, Vec<u32>)>,

Constructs a MapWithDictBitpacked from an iterator of key-value pairs and MPHF function params.

Source

pub fn get_values<Q>(&self, key: &Q, values: &mut [u32]) -> bool
where K: Borrow<Q> + PartialEq<Q>, Q: Hash + Eq + ?Sized,

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).

Source

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);
Source

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);
Source

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

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);
Source

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:?}");
}
Source

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}");
}
Source

pub fn values(&self, n: usize) -> impl Iterator<Item = Vec<u32>> + '_

Returns an iterator over the values of the map.

§Examples
let map = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![4])])).unwrap();
for val in map.values(1) {
    println!("{val:?}");
}
Source

pub fn size(&self) -> usize

Returns the total number of bytes occupied by the structure.

§Examples
let map = MapWithDictBitpacked::try_from(HashMap::from([(1, vec![2]), (3, vec![4])])).unwrap();
assert_eq!(map.size(), 394);

Trait Implementations§

Source§

impl<K: Default, const B: usize, const S: usize, ST, H> Default for MapWithDictBitpacked<K, B, S, ST, H>
where ST: PrimInt + Unsigned + Default, H: Hasher + Default + Default,

Source§

fn default() -> MapWithDictBitpacked<K, B, S, ST, H>

Returns the “default value” for a type. Read more
Source§

impl<K> TryFrom<HashMap<K, Vec<u32>>> for MapWithDictBitpacked<K>
where K: PartialEq + Hash + Clone,

Creates a MapWithDictBitpacked from a HashMap.

Source§

type Error = Error

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

fn try_from(value: HashMap<K, Vec<u32>>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<K, const B: usize, const S: usize, ST, H> Freeze for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: Freeze, Box<[K]>: Freeze,

§

impl<K, const B: usize, const S: usize, ST, H> RefUnwindSafe for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: RefUnwindSafe, Box<[K]>: RefUnwindSafe,

§

impl<K, const B: usize, const S: usize, ST, H> Send for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: Send, Box<[K]>: Send,

§

impl<K, const B: usize, const S: usize, ST, H> Sync for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: Sync, Box<[K]>: Sync,

§

impl<K, const B: usize, const S: usize, ST, H> Unpin for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: Unpin, Box<[K]>: Unpin,

§

impl<K, const B: usize, const S: usize, ST, H> UnsafeUnpin for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: UnsafeUnpin, Box<[K]>: UnsafeUnpin,

§

impl<K, const B: usize, const S: usize, ST, H> UnwindSafe for MapWithDictBitpacked<K, B, S, ST, H>
where Mphf<B, S, ST, H>: UnwindSafe, Box<[K]>: 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.