Struct quickphf::raw_map::RawPhfMap

source ·
pub struct RawPhfMap<K, V: 'static> { /* private fields */ }
Expand description

An immutable hash table constructed at compile time with perfect hashing which does not store its keys.

Implementations§

source§

impl<K, V> RawPhfMap<K, V>

source

pub fn get<Q>(&self, key: &Q) -> &Vwhere K: Borrow<Q>, Q: Hash + ?Sized,

Returns a reference to the value matching the given key.

If key is not one of the keys that was used when constructing the map, get will silently return an arbitrary value. If robustness to invalid keys is needed, use a PhfMap instead.

Panics

Panics if the RawPhfMap is empty.

Examples
use quickphf::examples::*;

assert_eq!(*HOLIDAYS_PER_MONTH.get("jan"), 2);

// Looking up an invalid key silently returns an incorrect value.
let result = HOLIDAYS_PER_MONTH.get("purple");
source

pub const fn len(&self) -> usize

Returns the number of elements in the map.

Examples
use quickphf::examples::*;

assert_eq!(HOLIDAYS_PER_MONTH.len(), 12);
assert_eq!(EMPTY_RAW_MAP.len(), 0);
source

pub const fn is_empty(&self) -> bool

Returns true if the map does not contain any elements.

Examples
use quickphf::examples::*;

assert!(!HOLIDAYS_PER_MONTH.is_empty());
assert!(EMPTY_RAW_MAP.is_empty())
source

pub fn iter(&self) -> Iter<'_, V>

An iterator visiting all the values stored in the map in an arbitrary order.

Examples
use quickphf::examples::*;

let mut values = HOLIDAYS_PER_MONTH
    .iter()
    .copied()
    .collect::<Vec<_>>();
values.sort();

assert_eq!(&values, &[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2]);

Trait Implementations§

source§

impl<K: Debug, V: Debug + 'static> Debug for RawPhfMap<K, V>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for RawPhfMap<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for RawPhfMap<K, V>where K: Send, V: Sync,

§

impl<K, V> Sync for RawPhfMap<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for RawPhfMap<K, V>where K: Unpin,

§

impl<K, V> UnwindSafe for RawPhfMap<K, V>where K: UnwindSafe, V: RefUnwindSafe,

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.