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>
impl<K, V> PhfMap<K, V>
sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
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);
sourcepub fn get<Q>(&self, key: &Q) -> Option<&V>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
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);
sourcepub fn get_key<Q>(&self, key: &Q) -> Option<&K>where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
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);
sourcepub fn contains_key<Q>(&self, key: &Q) -> boolwhere
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
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));
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!(FOURTH_POWERS_TO_ROOTS.len(), 10);
assert_eq!(EMPTY_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!(!FOURTH_POWERS_TO_ROOTS.is_empty());
assert!(EMPTY_MAP.is_empty());
sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
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);
sourcepub fn keys(&self) -> Keys<'_, K, V> ⓘ
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);
sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
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, V> PartialEq for PhfMap<K, V>where
K: Eq + Hash,
V: PartialEq,
impl<K, V> PartialEq for PhfMap<K, V>where K: Eq + Hash, V: PartialEq,
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> 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