Set

Struct Set 

Source
pub struct Set<K, const B: usize = 32, const S: usize = 8, ST = u8, H = WyHash>
where ST: PrimInt + Unsigned, H: Hasher + Default,
{ /* private fields */ }
Expand description

An efficient, immutable set.

Implementations§

Source§

impl<K, const B: usize, const S: usize, ST, H> Set<K, B, S, ST, H>
where K: Eq + Hash, ST: PrimInt + Unsigned, H: Hasher + Default,

Source

pub fn from_iter_with_params<I>(iter: I, gamma: f32) -> Result<Self, MphfError>
where I: IntoIterator<Item = K>,

Constructs a Set from an iterator of keys and MPHF function parameters.

§Examples
use entropy_map::{Set, DEFAULT_GAMMA};

let set: Set<u32> = Set::from_iter_with_params([1, 2, 3], DEFAULT_GAMMA).unwrap();
assert!(set.contains(&1));
Source

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

Returns true if the set contains the value.

§Examples
let set = Set::try_from(HashSet::from([1, 2, 3])).unwrap();
assert_eq!(set.contains(&1), true);
assert_eq!(set.contains(&4), false);
Source

pub fn len(&self) -> usize

Returns the number of elements in the set.

§Examples
let set = Set::try_from(HashSet::from([1, 2, 3])).unwrap();
assert_eq!(set.len(), 3);
Source

pub fn is_empty(&self) -> bool

Returns true if the set contains no elements.

§Examples
let set = Set::try_from(HashSet::from([0u32; 0])).unwrap();
assert_eq!(set.is_empty(), true);
let set = Set::try_from(HashSet::from([1, 2, 3])).unwrap();
assert_eq!(set.is_empty(), false);
Source

pub fn iter(&self) -> impl Iterator<Item = &K>

Returns an iterator visiting set elements in arbitrary order.

§Examples
let set = Set::try_from(HashSet::from([1, 2, 3])).unwrap();
for x in set.iter() {
    println!("{x}");
}
Source

pub fn size(&self) -> usize

Returns the total number of bytes occupied by Set.

§Examples
let set = Set::try_from(HashSet::from([1, 2, 3])).unwrap();
assert_eq!(set.size(), 218);

Trait Implementations§

Source§

impl<K: Default, const B: usize, const S: usize, ST, H> Default for Set<K, B, S, ST, H>
where ST: PrimInt + Unsigned + Default, H: Hasher + Default + Default,

Source§

fn default() -> Set<K, B, S, ST, H>

Returns the “default value” for a type. Read more
Source§

impl<K> TryFrom<HashSet<K>> for Set<K>
where K: Eq + Hash,

Creates a Set from a HashSet.

Source§

type Error = MphfError

The type returned in the event of a conversion error.
Source§

fn try_from(value: HashSet<K>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<K, const B: usize, const S: usize, ST, H> Freeze for Set<K, B, S, ST, H>

§

impl<K, const B: usize, const S: usize, ST, H> RefUnwindSafe for Set<K, B, S, ST, H>

§

impl<K, const B: usize, const S: usize, ST, H> Send for Set<K, B, S, ST, H>
where H: Send, K: Send, ST: Send,

§

impl<K, const B: usize, const S: usize, ST, H> Sync for Set<K, B, S, ST, H>
where H: Sync, K: Sync, ST: Sync,

§

impl<K, const B: usize, const S: usize, ST, H> Unpin for Set<K, B, S, ST, H>
where H: Unpin,

§

impl<K, const B: usize, const S: usize, ST, H> UnwindSafe for Set<K, B, S, ST, H>
where H: UnwindSafe, K: UnwindSafe, ST: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.