pub struct Function2<SS, SC = ShiftOnlyWrapped, 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.
The last layer (when the number of keys is small) is constructed using regular PHast.
This makes Function2 compatible with almost all SeedChoosers (including non-wrapping ShiftOnly).
It can be used with the following SeedChooser (which specify a particular PHast variant):
[ShiftOnly] (PHast+ without wrapping),
ShiftOnlyWrapped (PHast+ with wrapping),
[ShiftSeedWrapped] (PHast/PHast+ hybrid),
SeedOnly (regular PHast).
Note that some SeedChoosers can also be used with Function.
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> Function2<SS, SC, CA, S>
impl<SS: SeedSize, SC: SeedChooser, CA: CompressedArray, S: BuildSeededHasher> Function2<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 must come from the input key collection given during construction.
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> Function2<SS, ShiftOnlyWrapped, DefaultCompressedArray, BuildDefaultSeededHasher>
impl<SS: SeedSize> Function2<SS, ShiftOnlyWrapped, DefaultCompressedArray, BuildDefaultSeededHasher>
Source§impl Function2<Bits8, ShiftOnlyWrapped, DefaultCompressedArray, BuildDefaultSeededHasher>
impl Function2<Bits8, ShiftOnlyWrapped, 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 Function2<SS, SC, CA, S>where
CA: GetSize,
impl<SC, SS: SeedSize, CA, S> GetSize for Function2<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 Function2<SS, SC, CA, S>
impl<SS, SC, CA, S> RefUnwindSafe for Function2<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 Function2<SS, SC, CA, S>
impl<SS, SC, CA, S> Sync for Function2<SS, SC, CA, S>
impl<SS, SC, CA, S> Unpin for Function2<SS, SC, CA, S>
impl<SS, SC, CA, S> UnsafeUnpin for Function2<SS, SC, CA, S>
impl<SS, SC, CA, S> UnwindSafe for Function2<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