Struct HyperLogLog

Source
pub struct HyperLogLog<T, H, W> { /* 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 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.

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(n: usize) -> usize

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

§Arguments
  • n: 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 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, 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 + UpcastableInto<u64> + CastableFrom<u64>> 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 + UpcastableInto<u64> + CastableFrom<u64>> MergeEstimationLogic for HyperLogLog<T, H, W>

Source§

type Helper = HyperLogLogHelper<W>

The type of the helper use 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 + UpcastableInto<u64> + CastableFrom<u64>> 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> 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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
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> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V