pub struct Function<SS, SC = SeedOnly, CA = DefaultCompressedArray, S = BuildDefaultSeededHasher>where
SS: SeedSize,{ /* private fields */ }Expand description
PHast (Perfect Hashing made fast) - Minimal Perfect Hash Function with very fast evaluation and size below 2 bits/key developed by Piotr Beling and Peter Sanders.
It can be used with the following SeedChooser (which specify a particular PHast variant):
[ShiftOnlyWrapped] (PHast+ with wrapping),
[ShiftSeedWrapped] (PHast/PHast+ hybrid),
SeedOnly (regular PHast).
Note that some SeedChoosers can be used only with Function2.
See: Piotr Beling, Peter Sanders, PHast - Perfect Hashing made fast, 2025, https://arxiv.org/abs/2504.17918
Implementations§
Source§impl<SS: SeedSize, SC: SeedChooser, CA: CompressedArray, S: BuildSeededHasher> Function<SS, SC, CA, S>
impl<SS: SeedSize, SC: SeedChooser, CA: CompressedArray, S: BuildSeededHasher> Function<SS, SC, CA, S>
Sourcepub fn get<K>(&self, key: &K) -> usize
pub fn get<K>(&self, key: &K) -> usize
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 should come from the input key collection given during construction.
For keys not in the collection, returns usize::MAX.
Sourcepub fn with_vec_p_hash_sc<K>(
keys: Vec<K>,
params: &Params<SS>,
hasher: S,
seed_chooser: SC,
) -> Selfwhere
K: Hash,
pub fn with_vec_p_hash_sc<K>(
keys: Vec<K>,
params: &Params<SS>,
hasher: S,
seed_chooser: SC,
) -> Selfwhere
K: Hash,
Constructs 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.
Sourcepub fn with_vec_p_threads_hash_sc<K>(
keys: Vec<K>,
params: &Params<SS>,
threads_num: usize,
hasher: S,
seed_chooser: SC,
) -> Self
pub fn with_vec_p_threads_hash_sc<K>( keys: Vec<K>, params: &Params<SS>, threads_num: usize, hasher: S, seed_chooser: SC, ) -> Self
Constructs 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.
Sourcepub fn with_slice_p_hash_sc<K>(
keys: &[K],
params: &Params<SS>,
hasher: S,
seed_chooser: SC,
) -> Self
pub fn with_slice_p_hash_sc<K>( keys: &[K], params: &Params<SS>, hasher: S, seed_chooser: SC, ) -> Self
Constructs 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.
Sourcepub fn with_slice_p_threads_hash_sc<K>(
keys: &[K],
params: &Params<SS>,
threads_num: usize,
hasher: S,
seed_chooser: SC,
) -> Self
pub fn with_slice_p_threads_hash_sc<K>( keys: &[K], params: &Params<SS>, threads_num: usize, hasher: S, seed_chooser: SC, ) -> Self
Constructs 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.
Sourcepub fn minimal_output_range(&self, num_of_keys: usize) -> usize
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.
Sourcepub fn output_range(&self) -> usize
pub fn output_range(&self) -> usize
Returns output range of self, i.e. 1 + maximum value that self can return.
Sourcepub fn write_bytes(&self) -> usize
pub fn write_bytes(&self) -> usize
Returns number of bytes which write will write.
Sourcepub fn read_with_hasher_sc(
input: &mut dyn Read,
hasher: S,
seed_chooser: SC,
) -> Result<Self>
pub fn read_with_hasher_sc( input: &mut dyn Read, hasher: S, seed_chooser: SC, ) -> Result<Self>
Read Self from the input. hasher and seed_chooser must be the same as used by the structure written.
Source§impl<SS: SeedSize> Function<SS, SeedOnly, DefaultCompressedArray, BuildDefaultSeededHasher>
impl<SS: SeedSize> Function<SS, SeedOnly, DefaultCompressedArray, BuildDefaultSeededHasher>
Source§impl Function<Bits8, SeedOnly, DefaultCompressedArray, BuildDefaultSeededHasher>
impl Function<Bits8, SeedOnly, DefaultCompressedArray, BuildDefaultSeededHasher>
Sourcepub fn from_vec_st<K>(keys: Vec<K>) -> Selfwhere
K: Hash,
pub fn from_vec_st<K>(keys: Vec<K>) -> Selfwhere
K: Hash,
Constructs Function for given keys, using a single thread.
keys cannot contain duplicates.
Sourcepub fn from_vec_mt<K>(keys: Vec<K>) -> Self
pub fn from_vec_mt<K>(keys: Vec<K>) -> Self
Constructs Function for given keys, using multiple threads.
keys cannot contain duplicates.
Sourcepub fn from_slice_st<K>(keys: &[K]) -> Self
pub fn from_slice_st<K>(keys: &[K]) -> Self
Constructs Function for given keys, using a single thread.
keys cannot contain duplicates.
Trait Implementations§
Source§impl<SC, SS: SeedSize, CA, S> GetSize for Function<SS, SC, CA, S>where
CA: GetSize,
impl<SC, SS: SeedSize, CA, S> GetSize for Function<SS, SC, CA, S>where
CA: GetSize,
Source§const USES_DYN_MEM: bool = true
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
fn size_bytes_dyn(&self) -> usize
self.
Same as self.size_bytes() - std::mem::size_of_val(self).Source§fn size_bytes_content_dyn(&self) -> usize
fn size_bytes_content_dyn(&self) -> usize
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
fn size_bytes(&self) -> usize
self.Auto Trait Implementations§
impl<SS, SC, CA, S> Freeze for Function<SS, SC, CA, S>
impl<SS, SC, CA, S> RefUnwindSafe for Function<SS, SC, CA, S>where
CA: RefUnwindSafe,
S: RefUnwindSafe,
SC: RefUnwindSafe,
SS: RefUnwindSafe,
<SS as SeedSize>::VecElement: RefUnwindSafe,
impl<SS, SC, CA, S> Send for Function<SS, SC, CA, S>
impl<SS, SC, CA, S> Sync for Function<SS, SC, CA, S>
impl<SS, SC, CA, S> Unpin for Function<SS, SC, CA, S>
impl<SS, SC, CA, S> UnsafeUnpin for Function<SS, SC, CA, S>
impl<SS, SC, CA, S> UnwindSafe for Function<SS, SC, CA, S>where
CA: UnwindSafe,
S: UnwindSafe,
SC: UnwindSafe,
SS: UnwindSafe,
<SS as SeedSize>::VecElement: UnwindSafe,
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
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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