Struct boomphf::Mphf

source ·
pub struct Mphf<T> { /* private fields */ }
Expand description

A minimal perfect hash function over a set of objects of type T.

Implementations§

source§

impl<'a, T: 'a + Hash + Debug> Mphf<T>

source

pub fn from_chunked_iterator<I, N>( gamma: f64, objects: &'a I, n: u64 ) -> Mphf<T>where &'a I: IntoIterator<Item = N>, N: IntoIterator<Item = T> + Send, <N as IntoIterator>::IntoIter: ExactSizeIterator, <&'a I as IntoIterator>::IntoIter: Send, I: Sync,

Constructs an MPHF from a (possibly lazy) iterator over iterators. This allows construction of very large MPHFs without holding all the keys in memory simultaneously. objects is an IntoInterator yielding a stream of IntoIterators that must not contain any duplicate items. objects must be able to be iterated over multiple times and yield the same stream of items each time. gamma controls the tradeoff between the construction-time and run-time speed, and the size of the datastructure representing the hash function. See the paper for details. n is the total number of items that will be produced by iterating over all the input iterators. NOTE: the inner iterator N::IntoIter should override nth if there’s an efficient way to skip over items when iterating. This is important because later iterations of the MPHF construction algorithm skip most of the items.

source§

impl<T: Hash + Debug> Mphf<T>

source

pub fn new(gamma: f64, objects: &[T]) -> Mphf<T>

Generate a minimal perfect hash function for the set of objects. objects must not contain any duplicate items. gamma controls the tradeoff between the construction-time and run-time speed, and the size of the datastructure representing the hash function. See the paper for details. max_iters - None to never stop trying to find a perfect hash (safe if no duplicates).

source

pub fn hash(&self, item: &T) -> u64

Compute the hash value of item. This method should only be used with items known to be in construction set. Use try_hash if you cannot guarantee that item was in the construction set. If item was not present in the construction set this function may panic.

source

pub fn try_hash<Q>(&self, item: &Q) -> Option<u64>where T: Borrow<Q>, Q: ?Sized + Hash,

Compute the hash value of item. If item was not present in the set of objects used to construct the hash function, the return value will an arbitrary value Some(x), or None.

source§

impl<T: Hash + Debug + Sync + Send> Mphf<T>

source

pub fn new_parallel( gamma: f64, objects: &[T], starting_seed: Option<u64> ) -> Mphf<T>

Same as new, but parallelizes work on the rayon default Rayon threadpool. Configure the number of threads on that threadpool to control CPU usage.

source§

impl<'a, T: 'a + Hash + Debug + Send + Sync> Mphf<T>

source

pub fn from_chunked_iterator_parallel<I, N>( gamma: f64, objects: &'a I, max_iters: Option<u64>, n: u64, num_threads: usize ) -> Mphf<T>where &'a I: IntoIterator<Item = N>, N: IntoIterator<Item = T> + Send + Clone, <N as IntoIterator>::IntoIter: ExactSizeIterator, <&'a I as IntoIterator>::IntoIter: Send, I: Sync,

Same as to from_chunked_iterator but parallelizes work over num_threads threads.

Trait Implementations§

source§

impl<T: Clone> Clone for Mphf<T>

source§

fn clone(&self) -> Mphf<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Mphf<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Mphf<T>where T: RefUnwindSafe,

§

impl<T> Send for Mphf<T>where T: Send,

§

impl<T> Sync for Mphf<T>where T: Sync,

§

impl<T> Unpin for Mphf<T>where T: Unpin,

§

impl<T> UnwindSafe for Mphf<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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

§

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.