Skip to main content

HyperLogLogBuilder

Struct HyperLogLogBuilder 

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

Builder for HyperLogLog cardinality-estimation logic.

The builder lets you configure:

Call build to obtain the configured HyperLogLog logic.

Implementations§

Source§

impl HyperLogLogBuilder<BuildHasherDefault<DefaultHasher>>

Source

pub const fn new(num_elements: usize) -> Self

Creates a new builder for a HyperLogLog logic with the default word type (the fixed-size equivalent of usize).

§Panics

If num_elements is zero.

Source§

impl<H, W: Word, const BETA: bool> HyperLogLogBuilder<H, W, BETA>

Source

pub fn rsd(self, rsd: f64) -> Self

Sets the desired relative standard deviation.

This is a high-level alternative to Self::log2_num_regs. Calling one after the other invalidates the work done by the first one.

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

If the resulting number of registers is less than 16 (i.e., rsd is too large).

Source

pub const fn log2_num_regs(self, log2_num_regs: u32) -> Self

Sets the base-2 logarithm of the number of registers.

This is a low-level alternative to Self::rsd. Calling one after the other invalidates the work done by the first one.

§Arguments
  • log2_num_regs: the logarithm of the number of registers per estimator.
§Panics

If log2_num_regs is less than 4.

Source

pub fn min_log2_num_regs(&self) -> u32

Returns the minimum value allowed for Self::log2_num_regs given the current value of Self::num_elements.

Source

pub fn word_type<W2>(self) -> HyperLogLogBuilder<H, W2, BETA>

Sets the type W to use to represent backends.

Note that the returned builder will have a different type if W2 is different from W.

See the logic documentation for the limitations on the choice of W2.

Source

pub fn beta<const BETA2: bool>(self) -> HyperLogLogBuilder<H, W, BETA2>

Enables or disables the LogLog-β bias correction in the estimate.

When enabled (the default), the estimate uses the LogLog-β formula for log_num_regs 4–18, which provides better accuracy across the full cardinality range without a separate linear-counting correction, at the cost of roughly 20ns per estimate call when some registers are still zero. When all registers are populated, the correction is skipped and performance is identical to the classic formula.

When disabled, the classic HyperLogLog formula with linear-counting fallback is used.

// Disable LogLog-β correction
let logic = HyperLogLogBuilder::new(1_000_000)
    .log2_num_regs(8)
    .beta::<false>()
    .build::<usize>().unwrap();
Source

pub const fn num_elements(self, num_elements: usize) -> Self

Sets the upper bound on the number of elements.

§Panics

If n is zero.

Source

pub fn build_hasher<H2>( self, build_hasher: H2, ) -> HyperLogLogBuilder<H2, W, BETA>

Sets the BuildHasher to use.

Using this method you can select a specific hasher based on one or more seeds.

Source

pub fn build<T>(self) -> Result<HyperLogLog<T, H, W, BETA>, HyperLogLogError>

Builds the logic.

The type of objects the estimators keep track of is defined here by T, but it is usually inferred by the compiler.

§Errors

Returns HyperLogLogError::RegisterSizeTooLarge if the register size derived from num_elements exceeds the maximum supported by the hash type.

Returns HyperLogLogError::UnalignedBackend if the estimator size in bits is not divisible by the bit width of W.

Trait Implementations§

Source§

impl<H: Clone, W: Clone, const BETA: bool> Clone for HyperLogLogBuilder<H, W, BETA>

Source§

fn clone(&self) -> HyperLogLogBuilder<H, W, BETA>

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<H, W, const BETA: bool> Freeze for HyperLogLogBuilder<H, W, BETA>
where H: Freeze,

§

impl<H, W, const BETA: bool> RefUnwindSafe for HyperLogLogBuilder<H, W, BETA>

§

impl<H, W, const BETA: bool> Send for HyperLogLogBuilder<H, W, BETA>
where H: Send, W: Send,

§

impl<H, W, const BETA: bool> Sync for HyperLogLogBuilder<H, W, BETA>
where H: Sync, W: Sync,

§

impl<H, W, const BETA: bool> Unpin for HyperLogLogBuilder<H, W, BETA>
where H: Unpin, W: Unpin,

§

impl<H, W, const BETA: bool> UnsafeUnpin for HyperLogLogBuilder<H, W, BETA>
where H: UnsafeUnpin,

§

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