Trait pthash::Phf

source ·
pub trait Phf: Sized + Send + Sync {
    const MINIMAL: bool;

    // Required methods
    fn build_in_internal_memory_from_bytes<Keys: IntoIterator>(
        &mut self,
        keys: Keys,
        config: &BuildConfiguration
    ) -> Result<BuildTimings, Exception>
       where <Keys as IntoIterator>::IntoIter: ExactSizeIterator + Clone,
             <<Keys as IntoIterator>::IntoIter as Iterator>::Item: Hashable;
    fn hash(&self, key: impl Hashable) -> u64;
    fn num_bits(&self) -> usize;
    fn num_keys(&self) -> u64;
    fn table_size(&self) -> u64;
    fn save(&mut self, path: impl AsRef<Path>) -> Result<usize, Exception>;
    fn load(path: impl AsRef<Path>) -> Result<Self, Exception>;
}
Expand description

A perfect-hash function implemented with the PTHash algorithm

Required Associated Constants§

source

const MINIMAL: bool

Whether instances of this function have their values in the range [0; num_keys).

Required Methods§

source

fn build_in_internal_memory_from_bytes<Keys: IntoIterator>( &mut self, keys: Keys, config: &BuildConfiguration ) -> Result<BuildTimings, Exception>

Builds the function from a set of keys

In plain English, this function’s trait bound on keys is that they should be a collection that can provide cloneable iterators of hashable values.

source

fn hash(&self, key: impl Hashable) -> u64

Returns the hash of the given key

If the key was not one of the keys passed to build_in_internal_memory_from_bytes when building the function, the hash will collide with another key’s

source

fn num_bits(&self) -> usize

Returns the number of bits needed to represent this perfect-hash function

source

fn num_keys(&self) -> u64

Returns the number of keys used to build this perfect-hash function

source

fn table_size(&self) -> u64

Largest value returned by Self::hash plus 1

source

fn save(&mut self, path: impl AsRef<Path>) -> Result<usize, Exception>

Dump this function to disk

source

fn load(path: impl AsRef<Path>) -> Result<Self, Exception>

Load this function from disk

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<M: Minimality, H: Hasher, E: Encoder> Phf for PartitionedPhf<M, H, E>

source§

const MINIMAL: bool = M::AS_BOOL

source§

impl<M: Minimality, H: Hasher, E: Encoder> Phf for SinglePhf<M, H, E>

source§

const MINIMAL: bool = M::AS_BOOL