Skip to main content

Perfect

Struct Perfect 

Source
pub struct Perfect<SS: SeedSize, SC = SeedOnly, S = BuildDefaultSeededHasher> { /* private fields */ }
Expand description

PHast (Perfect Hashing made fast) - (K-)Perfect (not necessary minimal) Hash Function with very fast evaluation developed by Piotr Beling and Peter Sanders. Experimental.

Can be used with the following seed choosers (which specify a particular PHast variant): [ShiftOnlyWrapped], [ShiftSeedWrapped], SeedOnly, SeedOnlyK.

See: Piotr Beling, Peter Sanders, PHast - Perfect Hashing made fast, 2025, https://arxiv.org/abs/2504.17918

Implementations§

Source§

impl<SS: SeedSize, SC: SeedChooser, S: BuildSeededHasher> Perfect<SS, SC, S>

Source

pub fn get<K>(&self, key: &K) -> usize
where K: Hash + ?Sized,

Returns value assigned to the given key.

The returned value is in the range from 0 (inclusive) to the number of elements in the input key collection (exclusive). key must come from the input key collection given during construction.

Source

pub fn with_vec_p_hash_sc<K>( keys: Vec<K>, params: &Params<SS>, hasher: S, seed_chooser: SC, ) -> Self
where K: Hash,

Constructs Perfect function for given keys, using a single thread and given parameters: number of bits per seed, average bucket size (equals bucket_size100/100.0) and hasher.

bits_per_seed_to_100_bucket_size can be used to calculate good bucket_size100. keys cannot contain duplicates.

Source

pub fn with_vec_p_threads_hash_sc<K>( keys: Vec<K>, params: &Params<SS>, threads_num: usize, hasher: S, seed_chooser: SC, ) -> Self
where K: Hash + Sync + Send, S: Sync, SC: Sync,

Constructs Perfect function for given keys, using multiple (given number of) threads and given parameters: number of bits per seed, average bucket size (equals bucket_size100/100.0) and hasher.

bits_per_seed_to_100_bucket_size can be used to calculate good bucket_size100. keys cannot contain duplicates.

Source

pub fn with_slice_p_hash_sc<K>( keys: &[K], params: &Params<SS>, hasher: S, seed_chooser: SC, ) -> Self
where K: Hash + Clone,

Constructs Perfect function for given keys, using a single thread and given parameters: number of bits per seed, average bucket size (equals bucket_size100/100.0) and hasher.

bits_per_seed_to_100_bucket_size can be used to calculate good bucket_size100. keys cannot contain duplicates.

Source

pub fn with_slice_p_threads_hash_sc<K>( keys: &[K], params: &Params<SS>, threads_num: usize, hasher: S, seed_chooser: SC, ) -> Self
where K: Hash + Sync + Send + Clone, S: Sync, SC: Sync,

Constructs Perfect function for given keys, using multiple (given number of) threads and given parameters: number of bits per seed, average bucket size (equals bucket_size100/100.0) and hasher.

bits_per_seed_to_100_bucket_size can be used to calculate good bucket_size100. keys cannot contain duplicates.

Source

pub fn k(&self) -> u8

Returns maximum number of keys which can be mapped to the same value by k-Perfect function self.

Source

pub fn minimal_output_range(&self, num_of_keys: usize) -> usize

Returns output range of minimal (perfect or k-perfect) function for given number of keys, i.e. 1 + maximum value that minimal function can return.

Source

pub fn output_range(&self) -> usize

Returns output range of self, i.e. 1 + maximum value that self can return.

Source§

impl Perfect<Bits8, SeedOnly, BuildDefaultSeededHasher>

Source

pub fn from_vec_st<K>(keys: Vec<K>) -> Self
where K: Hash,

Constructs Perfect function for given keys, using a single thread.

keys cannot contain duplicates.

Source

pub fn from_vec_mt<K>(keys: Vec<K>) -> Self
where K: Hash + Send + Sync,

Constructs Perfect function for given keys, using multiple threads.

keys cannot contain duplicates.

Source

pub fn from_slice_st<K>(keys: &[K]) -> Self
where K: Hash + Clone,

Constructs Perfect function for given keys, using a single thread.

keys cannot contain duplicates.

Source

pub fn from_slice_mt<K>(keys: &[K]) -> Self
where K: Hash + Clone + Send + Sync,

Constructs Perfect function for given keys, using multiple threads.

keys cannot contain duplicates.

Source§

impl Perfect<Bits8, SeedOnlyK, BuildDefaultSeededHasher>

Source

pub fn k_from_vec_st<K>(k: u8, keys: Vec<K>) -> Self
where K: Hash,

Constructs k-Perfect function for given keys, using a single thread. k-Perfect function maps k or less different keys to each value.

keys cannot contain duplicates.

Source

pub fn k_from_vec_mt<K>(k: u8, keys: Vec<K>) -> Self
where K: Hash + Send + Sync,

Constructs k-Perfect function for given keys, using multiple threads. k-Perfect function maps k or less different keys to each value.

keys cannot contain duplicates.

Source

pub fn k_from_slice_st<K>(k: u8, keys: &[K]) -> Self
where K: Hash + Clone,

Constructs k-Perfect function for given keys, using a single thread. k-Perfect function maps k or less different keys to each value.

keys cannot contain duplicates.

Source

pub fn k_from_slice_mt<K>(k: u8, keys: &[K]) -> Self
where K: Hash + Clone + Send + Sync,

Constructs k-Perfect function for given keys, using multiple threads. k-Perfect function maps k or less different keys to each value.

keys cannot contain duplicates.

Trait Implementations§

Source§

impl<SC, SS: SeedSize, S> GetSize for Perfect<SS, SC, S>

Source§

const USES_DYN_MEM: bool = true

true if and only if the variables of this type can use dynamic (heap) memory.
Source§

fn size_bytes_dyn(&self) -> usize

Returns approximate number of bytes occupied by dynamic (heap) part of self. Same as self.size_bytes() - std::mem::size_of_val(self).
Source§

fn size_bytes_content_dyn(&self) -> usize

Returns approximate number of bytes occupied by dynamic (heap) part of self content. It usually equals to size_bytes_dyn(). However, sometimes it is smaller by the amount of memory reserved but not yet used (e.g., size_bytes_content_dyn() only takes into account the length of the vector and not its capacity).
Source§

fn size_bytes(&self) -> usize

Returns approximate, total (including heap memory) number of bytes occupied by self.

Auto Trait Implementations§

§

impl<SS, SC, S> Freeze for Perfect<SS, SC, S>
where S: Freeze, SC: Freeze, SS: Freeze,

§

impl<SS, SC, S> RefUnwindSafe for Perfect<SS, SC, S>

§

impl<SS, SC, S> Send for Perfect<SS, SC, S>
where S: Send, SC: Send, SS: Send,

§

impl<SS, SC, S> Sync for Perfect<SS, SC, S>
where S: Sync, SC: Sync,

§

impl<SS, SC, S> Unpin for Perfect<SS, SC, S>
where S: Unpin, SC: Unpin, SS: Unpin,

§

impl<SS, SC, S> UnsafeUnpin for Perfect<SS, SC, S>
where S: UnsafeUnpin, SC: UnsafeUnpin, SS: UnsafeUnpin,

§

impl<SS, SC, S> UnwindSafe for Perfect<SS, SC, S>

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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V