Struct quickphf::map::PhfMap

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

An immutable hash table constructed at compile time with perfect hashing.

Implementations§

source§

impl<K, V> PhfMap<K, V>

source

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

Returns references to the key and value corresponding to the supplied key, if present.

Examples
use quickphf::examples::*;

assert_eq!(FOURTH_POWERS_TO_ROOTS.get_key_value(&81), Some((&81, &3)));
assert_eq!(FOURTH_POWERS_TO_ROOTS.get_key_value(&8000), None);
source

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

Returns a reference to the value corresponding to the key, if present.

Examples
use quickphf::examples::*;

assert_eq!(FOURTH_POWERS_TO_ROOTS.get(&2401), Some(&7));
assert_eq!(FOURTH_POWERS_TO_ROOTS.get(&1729), None);
source

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

Returns a reference to the copy of the key stored in the map, if present.

Examples
use quickphf::examples::*;

assert_eq!(FOURTH_POWERS_TO_ROOTS.get_key(&4096), Some(&4096));
assert_eq!(FOURTH_POWERS_TO_ROOTS.get_key(&4830), None);
source

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

Returns true if the map contains the given key.

Examples
use quickphf::examples::*;
assert!(FOURTH_POWERS_TO_ROOTS.contains_key(&10_000));
assert!(!FOURTH_POWERS_TO_ROOTS.contains_key(&24));
source

pub const fn len(&self) -> usize

Returns the number of elements in the map.

Examples
use quickphf::examples::*;

assert_eq!(FOURTH_POWERS_TO_ROOTS.len(), 10);
assert_eq!(EMPTY_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!(!FOURTH_POWERS_TO_ROOTS.is_empty());
assert!(EMPTY_MAP.is_empty());
source

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

An iterator visiting all key-value pairs in arbitrary order.

Examples
use quickphf::examples::*;

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

let expected_entries = [
    (1, 1),
    (16, 2),
    (81, 3),
    (256, 4),
    (625, 5),
    (1296, 6),
    (2401, 7),
    (4096, 8),
    (6561, 9),
    (10000, 10),
];

assert_eq!(&entries, &expected_entries);
source

pub fn keys(&self) -> Keys<'_, K, V>

An iterator visiting all stored keys in arbitrary order.

Examples
use quickphf::examples::*;

let mut keys = FOURTH_POWERS_TO_ROOTS
    .keys()
    .copied()
    .collect::<Vec<_>>();
keys.sort();

let expected_keys = [1, 16, 81, 256, 625, 1296, 2401, 4096, 6561, 10000];

assert_eq!(&keys, &expected_keys);
source

pub fn values(&self) -> Values<'_, K, V>

An iterator visiting all stored values in arbitrary order.

Examples
use quickphf::examples::*;

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

let expected_values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

assert_eq!(&values, &expected_values);

Trait Implementations§

source§

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

source§

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

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

impl<K, V> PartialEq for PhfMap<K, V>where K: Eq + Hash, V: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> Eq for PhfMap<K, V>where K: Eq + Hash, V: Eq,

Auto Trait Implementations§

§

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

§

impl<K, V> Send for PhfMap<K, V>where K: Send + Sync, V: Sync,

§

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

§

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

§

impl<K, V> UnwindSafe for PhfMap<K, V>where K: UnwindSafe + RefUnwindSafe, 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.