Skip to main content

HyperLogLog

Struct HyperLogLog 

Source
pub struct HyperLogLog<T, H, W = usize> { /* private fields */ }
Expand description

Estimator logic implementing the HyperLogLog algorithm.

Instances are built using HyperLogLogBuilder, which provides convenient ways to set the internal parameters.

Note that T can be any type satisfying the Hash trait. The parameter H makes it possible to select a hashing algorithm, and W is the unsigned type used to store backends.

An important constraint is that W must be able to represent exactly the backend of an estimator. While usually usize will work (and it is the default type chosen by new), with odd register sizes and a small number of registers it might be necessary to select a smaller type, resulting in slower merges. For example, using 16 5-bit registers one needs to use u16, whereas for 16 6-bit registers u32 will be sufficient.

Formally, this means that W::BITS must divide (1 << log_2_num_registers) * register_size (using HyperLogLog::register_size(num_elements)). HyperLogLogBuilder::min_log_2_num_reg returns the minimum value for log_2_num_registers that satisfies this property.

Implementations§

Source§

impl HyperLogLog<(), (), ()>

Source

pub fn log_2_num_of_registers(rsd: f64) -> usize

Returns the logarithm of the number of registers per estimator that are necessary to attain a given relative standard deviation.

§Arguments
  • rsd: the relative standard deviation to be attained.
Source

pub fn rel_std(log_2_num_registers: usize) -> f64

Returns the relative standard deviation corresponding to a given number of registers per estimator.

§Arguments
  • log_2_num_registers: the logarithm of the number of registers per estimator.
Source

pub fn register_size(num_elements: usize) -> usize

Returns the register size in bits, given an upper bound on the number of distinct elements.

§Arguments
  • num_elements: an upper bound on the number of distinct elements.

Trait Implementations§

Source§

impl<T, H: Clone, W: Clone> Clone for HyperLogLog<T, H, W>

Source§

fn clone(&self) -> Self

Returns a duplicate 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, H: Debug, W: Debug> Debug for HyperLogLog<T, H, W>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, H, W> Display for HyperLogLog<T, H, W>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Hash, H: BuildHasher + Clone, W: Word> EstimationLogic for HyperLogLog<T, H, W>

Source§

type Item = T

The type of items.
Source§

type Backend = [W]

The type of the backend.
Source§

type Estimator<'a> = DefaultEstimator<HyperLogLog<T, H, W>, &'a HyperLogLog<T, H, W>, Box<[W]>> where T: 'a, W: 'a, H: 'a

The type of an estimator.
Source§

fn new_estimator(&self) -> Self::Estimator<'_>

Creates a new empty estimator using this logic.
Source§

fn add(&self, backend: &mut Self::Backend, element: impl Borrow<T>)

Adds an element to an estimator with the given backend.
Source§

fn estimate(&self, backend: &[W]) -> f64

Returns an estimation of the number of distinct elements that have been added to an estimator with the given backend so far.
Source§

fn clear(&self, backend: &mut [W])

Clears a backend, making it empty.
Source§

fn set(&self, dst: &mut [W], src: &[W])

Sets the contents of dst to the contents of src.
Source§

impl<T: Hash, H: BuildHasher + Clone, W: Word> MergeEstimationLogic for HyperLogLog<T, H, W>

Source§

type Helper = HyperLogLogHelper<W>

The type of the helper used in merge calculations. Read more
Source§

fn new_helper(&self) -> Self::Helper

Creates a new helper to use in merge operations.
Source§

fn merge_with_helper(&self, dst: &mut [W], src: &[W], helper: &mut Self::Helper)

Merges src into dst using the provided helper to avoid allocations.
Source§

fn merge(&self, dst: &mut Self::Backend, src: &Self::Backend)

Merges src into dst.
Source§

impl<T: PartialEq, H: PartialEq, W: PartialEq> PartialEq for HyperLogLog<T, H, W>

Source§

fn eq(&self, other: &HyperLogLog<T, H, W>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Hash, H: BuildHasher + Clone, W: Word> SliceEstimationLogic<W> for HyperLogLog<T, H, W>

Source§

fn backend_len(&self) -> usize

The number of elements of type T in a backend.
Source§

impl<T, H, W> StructuralPartialEq for HyperLogLog<T, H, W>

Auto Trait Implementations§

§

impl<T, H, W> Freeze for HyperLogLog<T, H, W>
where H: Freeze,

§

impl<T, H, W> RefUnwindSafe for HyperLogLog<T, H, W>

§

impl<T, H, W> Send for HyperLogLog<T, H, W>
where H: Send, T: Send, W: Send,

§

impl<T, H, W> Sync for HyperLogLog<T, H, W>
where H: Sync, T: Sync, W: Sync,

§

impl<T, H, W> Unpin for HyperLogLog<T, H, W>
where H: Unpin, T: Unpin,

§

impl<T, H, W> UnsafeUnpin for HyperLogLog<T, H, W>
where H: UnsafeUnpin,

§

impl<T, H, W> UnwindSafe for HyperLogLog<T, H, W>
where H: UnwindSafe, T: UnwindSafe, W: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 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> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.