entropy_map::map_with_dict

Struct MapWithDict

source
pub struct MapWithDict<K, V, 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 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>
where K: Eq + Hash + Clone, V: Eq + Clone + Hash, ST: PrimInt + Unsigned, H: Hasher + Default,

source

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.

source

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

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

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

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);
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 = MapWithDict::try_from(HashMap::from([(1, 2), (3, 4)])).unwrap();
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
source

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

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

pub fn values(&self) -> impl Iterator<Item = &V>

Returns an iterator over the values of the map.

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

pub fn size(&self) -> usize

Returns the total number of bytes occupied by the structure.

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

Trait Implementations§

source§

impl<K, V> TryFrom<HashMap<K, V>> for MapWithDict<K, V>
where K: Eq + Hash + Clone, V: Eq + Clone + Hash,

Creates a MapWithDict from a HashMap.

source§

type Error = MphfError

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

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

Performs the conversion.

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>
where H: Send, K: Send, V: Send, ST: Send,

§

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

§

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