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.

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

§

impl<K, const B: usize, const S: usize, ST, H> RefUnwindSafe for MapWithDictBitpacked<K, B, S, ST, H>

§

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

§

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

§

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

§

impl<K, const B: usize, const S: usize, ST, H> UnwindSafe for MapWithDictBitpacked<K, B, S, ST, H>
where H: UnwindSafe, K: UnwindSafe, ST: 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.