Skip to main content

HyperLogLog8

Struct HyperLogLog8 

Source
pub struct HyperLogLog8<T, H, const BETA: bool = true> { /* private fields */ }
Expand description

Estimation logic implementing the HyperLogLog algorithm with byte-sized registers.

This implementation uses a full byte for each register instead of packed 5– or 6-bit registers. This approach trades 60% (for 5-bit registers) or 33.3% (for 6-bit registers) extra space with respect to HyperLogLog for:

  • fast register access (byte indexing instead of bit-field extraction);
  • no backend alignment constraints;
  • SIMD-accelerated merge using platform-specific byte-wise maximum instructions (SSE2 on x86/x86_64, NEON on aarch64);
  • no temporary allocations for merge operations.

The choice between the two logics should be guided by the specific use case and constraints of your application. Please try the included benchmarks to have an idea of the difference in performance between the two logics in your environment.

Instances are created through HyperLogLog8Builder:

// Default: LogLog-β correction enabled
let logic = HyperLogLog8Builder::new()
    .log2_num_regs(8)
    .build::<String>();

// Disable LogLog-β, use classic HLL + linear-counting fallback
let logic = HyperLogLog8Builder::new()
    .log2_num_regs(8)
    .beta::<false>()
    .build::<String>();

§Type parameters

  • T: the type of elements to count (must implement Hash).

  • H: the BuildHasher used to hash elements.

  • BETA: when true (the default), the LogLog-β bias correction is used during estimation. See HyperLogLog for details.

Implementations§

Source§

impl<T, H: Clone, const BETA: bool> HyperLogLog8<T, H, BETA>

Source

pub fn log2_num_regs(&self) -> u32

Returns the base-2 logarithm of the number of registers per estimator.

Trait Implementations§

Source§

impl<T, H: Clone, const BETA: bool> Clone for HyperLogLog8<T, H, BETA>

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, const BETA: bool> Debug for HyperLogLog8<T, H, BETA>

Source§

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

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

impl<T, H, const BETA: bool> Display for HyperLogLog8<T, H, BETA>

Source§

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

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

impl<T: Hash, H: BuildHasher + Clone, const BETA: bool> EstimationLogic for HyperLogLog8<T, H, BETA>

Source§

type Item = T

The type of items.
Source§

type Backend = [u8]

The type of the backend.
Source§

type Estimator<'a> = DefaultEstimator<HyperLogLog8<T, H, BETA>, &'a HyperLogLog8<T, H, BETA>, Box<[u8]>> where T: '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: &[u8]) -> 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 [u8])

Clears a backend, making it empty.
Source§

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

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

impl<T: Hash, H: BuildHasher + Clone, const BETA: bool> MergeEstimationLogic for HyperLogLog8<T, H, BETA>

Source§

type Helper = ()

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 [u8], src: &[u8], _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, const BETA: bool> PartialEq for HyperLogLog8<T, H, BETA>

Source§

fn eq(&self, other: &HyperLogLog8<T, H, BETA>) -> 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, const BETA: bool> SliceEstimationLogic<u8> for HyperLogLog8<T, H, BETA>

Source§

fn backend_len(&self) -> usize

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

impl<T, H, const BETA: bool> StructuralPartialEq for HyperLogLog8<T, H, BETA>

Auto Trait Implementations§

§

impl<T, H, const BETA: bool> Freeze for HyperLogLog8<T, H, BETA>
where H: Freeze,

§

impl<T, H, const BETA: bool> RefUnwindSafe for HyperLogLog8<T, H, BETA>

§

impl<T, H, const BETA: bool> Send for HyperLogLog8<T, H, BETA>
where H: Send, T: Send,

§

impl<T, H, const BETA: bool> Sync for HyperLogLog8<T, H, BETA>
where H: Sync, T: Sync,

§

impl<T, H, const BETA: bool> Unpin for HyperLogLog8<T, H, BETA>
where H: Unpin, T: Unpin,

§

impl<T, H, const BETA: bool> UnsafeUnpin for HyperLogLog8<T, H, BETA>
where H: UnsafeUnpin,

§

impl<T, H, const BETA: bool> UnwindSafe for HyperLogLog8<T, H, BETA>
where H: UnwindSafe, T: 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.