Struct quickphf::set::PhfSet

source ·
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>

source

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

pub const fn is_empty(&self) -> bool

Returns true if the set does not contain any elements.

Examples
use quickphf::examples::*;

assert!(!DIGITS.is_empty());
assert!(EMPTY_SET.is_empty());
source

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

Returns an iterator over the elements of the set in no particular order.

Examples
use quickphf::examples::*;

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

assert_eq!(&items, &[0, 2, 4, 6, 8]);
source§

impl<K: Eq + Hash> PhfSet<K>

source

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));
source

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);
source

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]);
source

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());
source

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]);
source

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]);
source

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));
source

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));
source

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));

Trait Implementations§

source§

impl<K: Debug + 'static> Debug for PhfSet<K>

source§

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

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

impl<'a, K> IntoIterator for &'a PhfSet<K>

§

type Item = &'a K

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'a, K>

Creates an iterator from a value. Read more
source§

impl<K: Eq + Hash> PartialEq for PhfSet<K>

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: Eq + Hash> Eq for PhfSet<K>

Auto Trait Implementations§

§

impl<K> RefUnwindSafe for PhfSet<K>where K: RefUnwindSafe,

§

impl<K> Send for PhfSet<K>where K: Send + Sync,

§

impl<K> Sync for PhfSet<K>where K: Sync,

§

impl<K> Unpin for PhfSet<K>where K: Unpin,

§

impl<K> UnwindSafe for PhfSet<K>where K: UnwindSafe + 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.