pub struct ZeroHashMap<'a, K, V>where
    K: ZeroMapKV<'a> + ?Sized,
    V: ZeroMapKV<'a> + ?Sized,{ /* private fields */ }
Expand description

A perfect zerohashmap optimized for lookups over immutable keys.

Examples

use zerovec::ZeroHashMap;

let hashmap =
    ZeroHashMap::<i32, str>::from_iter([(0, "a"), (1, "b"), (2, "c")]);
assert_eq!(hashmap.get(&0), Some("a"));
assert_eq!(hashmap.get(&2), Some("c"));
assert_eq!(hashmap.get(&4), None);

Implementations§

source§

impl<'a, K, V> ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + ?Sized, V: ZeroMapKV<'a> + ?Sized,

source

pub fn len(&self) -> usize

The number of elements in the ZeroHashMap.

source

pub fn is_empty(&self) -> bool

Whether the ZeroHashMap is empty.

source§

impl<'a, K, V> ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + ?Sized + Hash + Eq, V: ZeroMapKV<'a> + ?Sized,

source

pub fn get<'b, A>(&'b self, key: &A) -> Option<&'b V::GetType>where A: Borrow<K> + ?Sized + 'b,

Get the value corresponding to key. If absent None is returned.

Example
use zerovec::ZeroHashMap;

let hashmap = ZeroHashMap::<str, str>::from_iter([("a", "A"), ("z", "Z")]);

assert_eq!(hashmap.get("a"), Some("A"));
assert_eq!(hashmap.get("z"), Some("Z"));
assert_eq!(hashmap.get("0"), None);
source

pub fn contains_key(&self, key: &K) -> bool

Returns whether key is contained in this hashmap

Example
use zerovec::ZeroHashMap;

let hashmap = ZeroHashMap::<str, str>::from_iter([("a", "A"), ("z", "Z")]);

assert!(hashmap.contains_key("a"));
assert!(!hashmap.contains_key("p"));
source§

impl<'a, K, V> ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + ?Sized, V: ZeroMapKV<'a> + ?Sized,

source

pub fn iter<'b>( &'b self ) -> impl ExactSizeIterator<Item = (&'b <K as ZeroMapKV<'a>>::GetType, &'b <V as ZeroMapKV<'a>>::GetType)>

source

pub fn iter_keys<'b>( &'b self ) -> impl ExactSizeIterator<Item = &'b <K as ZeroMapKV<'a>>::GetType>

source

pub fn iter_values<'b>( &'b self ) -> impl ExactSizeIterator<Item = &'b <V as ZeroMapKV<'a>>::GetType>

Trait Implementations§

source§

impl<'a, K, V> Debug for ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + ?Sized + Debug, V: ZeroMapKV<'a> + ?Sized + Debug, K::Container: Debug, V::Container: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, 'a, K, V> Deserialize<'de> for ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + ?Sized, V: ZeroMapKV<'a> + ?Sized, K::Container: Deserialize<'de>, V::Container: Deserialize<'de>, 'de: 'a,

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a, K, V, A, B> FromIterator<(A, B)> for ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + ?Sized + Hash + Eq, V: ZeroMapKV<'a> + ?Sized, B: Borrow<V>, A: Borrow<K>,

source§

fn from_iter<T: IntoIterator<Item = (A, B)>>(iter: T) -> Self

Build a ZeroHashMap from an iterator returning (K, V) tuples.

Example
use zerovec::ZeroHashMap;

let hashmap = ZeroHashMap::<i32, str>::from_iter([
    (1, "a"),
    (2, "b"),
    (3, "c"),
    (4, "d"),
]);
assert_eq!(hashmap.get(&1), Some("a"));
assert_eq!(hashmap.get(&2), Some("b"));
assert_eq!(hashmap.get(&3), Some("c"));
assert_eq!(hashmap.get(&4), Some("d"));
source§

impl<'a, K, V> Serialize for ZeroHashMap<'a, K, V>where K: ZeroMapKV<'a> + Serialize + ?Sized, V: ZeroMapKV<'a> + Serialize + ?Sized, K::Container: Serialize, V::Container: Serialize,

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a, K: ?Sized, V: ?Sized> RefUnwindSafe for ZeroHashMap<'a, K, V>where <K as ZeroMapKV<'a>>::Container: RefUnwindSafe, <V as ZeroMapKV<'a>>::Container: RefUnwindSafe,

§

impl<'a, K: ?Sized, V: ?Sized> Send for ZeroHashMap<'a, K, V>where <K as ZeroMapKV<'a>>::Container: Send, <V as ZeroMapKV<'a>>::Container: Send,

§

impl<'a, K: ?Sized, V: ?Sized> Sync for ZeroHashMap<'a, K, V>where <K as ZeroMapKV<'a>>::Container: Sync, <V as ZeroMapKV<'a>>::Container: Sync,

§

impl<'a, K: ?Sized, V: ?Sized> Unpin for ZeroHashMap<'a, K, V>where <K as ZeroMapKV<'a>>::Container: Unpin, <V as ZeroMapKV<'a>>::Container: Unpin,

§

impl<'a, K: ?Sized, V: ?Sized> UnwindSafe for ZeroHashMap<'a, K, V>where <K as ZeroMapKV<'a>>::Container: UnwindSafe, <V as ZeroMapKV<'a>>::Container: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> ErasedDestructor for Twhere T: 'static,