pub struct PhfSet<K: 'static> { /* private fields */ }
Expand description
An immutable set constructed at compile time with perfect hashing.
Implementations§
source§impl<K> PhfSet<K>
impl<K> PhfSet<K>
sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of elements in the set.
Examples
use quickphf::examples::*;
assert_eq!(EVEN_DIGITS.len(), 5);
assert_eq!(EMPTY_SET.len(), 0);
source§impl<K: Eq + Hash> PhfSet<K>
impl<K: Eq + Hash> PhfSet<K>
sourcepub fn contains(&self, element: &K) -> bool
pub fn contains(&self, element: &K) -> bool
Returns true
if the set contains the given element.
Examples
use quickphf::examples::*;
assert!(PRIME_DIGITS.contains(&2));
assert!(!PRIME_DIGITS.contains(&1));
sourcepub fn get(&self, element: &K) -> Option<&K>
pub fn get(&self, element: &K) -> Option<&K>
Returns a reference to the copy of the element stored in the set, if present.
Examples
use quickphf::examples::*;
assert_eq!(EVEN_DIGITS.get(&2), Some(&2));
assert_eq!(EVEN_DIGITS.get(&3), None);
sourcepub fn difference<'a>(&'a self, other: &'a PhfSet<K>) -> Difference<'a, K> ⓘ
pub fn difference<'a>(&'a self, other: &'a PhfSet<K>) -> Difference<'a, K> ⓘ
Returns an iterator over the set difference in no particular order.
The iterator yields all items that are in self
but not in other
.
Examples
use quickphf::examples::*;
let mut difference = EVEN_DIGITS
.difference(&PRIME_DIGITS)
.copied()
.collect::<Vec<_>>();
difference.sort();
assert_eq!(&difference, &[0, 4, 6, 8]);
sourcepub fn intersection<'a>(&'a self, other: &'a PhfSet<K>) -> Intersection<'a, K> ⓘ
pub fn intersection<'a>(&'a self, other: &'a PhfSet<K>) -> Intersection<'a, K> ⓘ
Returns an iterator over the intersection in no particular order.
The iterator yields all items that are in both self
and other
.
Examples
use quickphf::examples::*;
let mut intersection = PRIME_DIGITS.intersection(&EVEN_DIGITS);
assert_eq!(intersection.next(), Some(&2));
assert!(intersection.next().is_none());
sourcepub fn symmetric_difference<'a>(
&'a self,
other: &'a PhfSet<K>
) -> SymmetricDifference<'a, K> ⓘ
pub fn symmetric_difference<'a>( &'a self, other: &'a PhfSet<K> ) -> SymmetricDifference<'a, K> ⓘ
Returns an iterator over the symmetric difference of the two sets in no particular order.
The iterator yields all items that are in self
but not in other
, or vice versa.
Examples
use quickphf::examples::*;
let mut symmetric_difference = PRIME_DIGITS
.symmetric_difference(&EVEN_DIGITS)
.copied()
.collect::<Vec<_>>();
symmetric_difference.sort();
assert_eq!(&symmetric_difference, &[0, 3, 4, 5, 6, 7, 8]);
sourcepub fn union<'a>(&'a self, other: &'a PhfSet<K>) -> Union<'a, K> ⓘ
pub fn union<'a>(&'a self, other: &'a PhfSet<K>) -> Union<'a, K> ⓘ
Returns an iterator over the union in no particular order.
The iterator yields all items that are in self
or other
.
Examples
use quickphf::examples::*;
let mut union = PRIME_DIGITS
.union(&EVEN_DIGITS)
.copied()
.collect::<Vec<_>>();
union.sort();
assert_eq!(&union, &[0, 2, 3, 4, 5, 6, 7, 8]);
sourcepub fn is_disjoint(&self, other: &PhfSet<K>) -> bool
pub fn is_disjoint(&self, other: &PhfSet<K>) -> bool
Returns true
if self
and other
have no elements in common.
Examples
use quickphf::examples::*;
assert!(!EVEN_DIGITS.is_disjoint(&PRIME_DIGITS));
sourcepub fn is_subset(&self, other: &PhfSet<K>) -> bool
pub fn is_subset(&self, other: &PhfSet<K>) -> bool
Returns true
if there are no elements in self
that are not in other
as well.
Examples
use quickphf::examples::*;
assert!(EVEN_DIGITS.is_subset(&DIGITS));
sourcepub fn is_superset(&self, other: &PhfSet<K>) -> bool
pub fn is_superset(&self, other: &PhfSet<K>) -> bool
Returns true
if there are no elements of other
that are not in self
.
Examples
use quickphf::examples::*;
assert!(DIGITS.is_superset(&EVEN_DIGITS));