pub struct HyperLogLogPlusPlus {
    pub registers: Box<[u8; 1048576]>,
}
Expand description

An enhanced HyperLogLog data structure, often termed HyperLogLog++, for estimating the cardinality of a dataset without storing individual elements.

Fields§

§registers: Box<[u8; 1048576]>

Registers used for maintaining the cardinality estimate. The number of registers (M) impacts precision and memory usage.

Implementations§

source§

impl HyperLogLogPlusPlus

source

pub fn new() -> Self

Constructs a new instance of HyperLogLog++ with all registers initialized to zero.

Returns

A new HyperLogLogPlusPlus instance.

source

pub fn add<T: Hash>(&mut self, item: T)

Adds an item to the HyperLogLog++. This will update the registers based on the hash of the item but won’t store the item itself.

Parameters
  • item: The item to be added. It should implement the Hash trait.
source

pub fn estimate(&self) -> f64

Estimates the cardinality or unique count of the items added to the HyperLogLog++.

Returns

An approximate count (as f64) of unique items added.

source

pub fn merge(&mut self, other: &HyperLogLogPlusPlus)

Merges the state of another HyperLogLog++ instance into this one. This is useful for combining the cardinality estimates of two separate datasets.

Parameters
  • other: The other HyperLogLogPlusPlus instance whose state is to be merged into this one.

Trait Implementations§

source§

impl Clone for HyperLogLogPlusPlus

source§

fn clone(&self) -> HyperLogLogPlusPlus

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 Debug for HyperLogLogPlusPlus

source§

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

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

impl Default for HyperLogLogPlusPlus

source§

fn default() -> Self

Creates a default instance of HyperLogLogPlusPlus.

This is equivalent to calling HyperLogLogPlusPlus::new().

Examples
let hll = HyperLogLogPlusPlus::default();
// ... use the `hll` instance ...
source§

impl<'de> Deserialize<'de> for HyperLogLogPlusPlus

source§

fn deserialize<D>(deserializer: D) -> Result<HyperLogLogPlusPlus, D::Error>where D: Deserializer<'de>,

Deserializes data to construct a HyperLogLogPlusPlus instance.

The data is expected to contain a registers field in a specific serialized format. The CompressedRegistersVisitor is used to assist in this deserialization process.

source§

impl From<[u8; 1048576]> for HyperLogLogPlusPlus

source§

fn from(registers: [u8; 1048576]) -> Self

Creates a HyperLogLogPlusPlus instance from a given array of registers.

Arguments
  • registers: An array of u8 representing the internal state of the HyperLogLogPlusPlus.
source§

impl Serialize for HyperLogLogPlusPlus

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serializes the HyperLogLogPlusPlus instance.

The registers field will be serialized in a format suitable for transmission or storage using the serialize_registers function.

Auto Trait Implementations§

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, U> Cast<U> for Twhere U: FromCast<T>,

source§

fn cast(self) -> U

Numeric cast from self to T.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromBits<T> for T

source§

fn from_bits(t: T) -> T

Safe lossless bitwise transmute from T to Self.
source§

impl<T> FromCast<T> for T

source§

fn from_cast(t: T) -> T

Numeric cast from T to Self.
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.

source§

impl<T, U> IntoBits<U> for Twhere U: FromBits<T>,

source§

fn into_bits(self) -> U

Safe lossless bitwise transmute from self to T.
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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,