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>
impl<K, V> RawPhfMap<K, V>
sourcepub fn get<Q>(&self, key: &Q) -> &Vwhere
K: Borrow<Q>,
Q: Hash + ?Sized,
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");
sourcepub const fn len(&self) -> usize
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);
sourcepub const fn is_empty(&self) -> bool
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())
sourcepub fn iter(&self) -> Iter<'_, V> ⓘ
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more