Skip to main content

HyperLogLogPlus

Struct HyperLogLogPlus 

Source
pub struct HyperLogLogPlus<S = DefaultHasher> { /* private fields */ }
Expand description

An implementation of the the HyperLogLog++ data structure.

For small cardinalities, a “sparse” representation is used. The sparse representation is more accurate and uses less memory, but has slower insert speed. The error and memory usage of the sparse representation scales roughly linearly with the number of items inserted. When the memory of the sparse representation equals the memory of the dense representation, it switches to dense automatically. This happens inside the insert/insert_hash call (which is why it needs &mut self). The error of the sparse representation never exceeds that of the dense.

Implementations§

Source§

impl HyperLogLogPlus

Source

pub fn new(precision: u8) -> Self

Returns a new Self using the default hasher with a random seed. Self is initialized to use the compact and dynamically sized sparse representation, but later switches to the dense representation when it uses equal memory (1 << precision registers (1 byte each)).

Source

pub fn seeded(precision: u8, seed: u128) -> Self

Returns a new Self using the default hasher seeded with seed. Self is initialized to use the compact and dynamically sized sparse representation, but later switches to the dense representation when it uses equal memory (1 << precision registers, 1 byte each).

Source§

impl<S: BuildHasher> HyperLogLogPlus<S>

Source

pub fn with_hasher(precision: u8, hasher: S) -> Self

Returns a new Self using the provided hasher. Self is initialized to use the compact and dynamically sized sparse representation, but later switches to the dense representation when it uses equal memory (1 << precision registers, 1 byte each).

Source

pub fn insert_hash(&mut self, hash: u64)

Inserts the hash of an item into the HyperLogLogPlus. self switches to dense mode if sparse mode exceeds memory usage of dense mode.

Source

pub fn insert<T: Hash + ?Sized>(&mut self, value: &T)

Inserts the item into the HyperLogLogPlus. self switches to dense mode if sparse mode exceeds memory usage of dense mode.

Source

pub fn insert_all<T: Hash, I: IntoIterator<Item = T>>(&mut self, iter: I)

Inserts all the items in iter into the self.

Source

pub fn count(&mut self) -> usize

Returns the approximate number of elements in self.

Source

pub fn raw_count(&mut self) -> f64

Returns the approximate number of elements in self.

Source

pub fn is_sparse(&self) -> bool

Returns true if the current internal representation is sparse, false if using classic dense (HyperLogLog) representation.

Source

pub fn precision(&self) -> u8

Returns the precision of self.

Source

pub fn union(&mut self, other: &Self) -> Result<(), Error>

Merges another HyperLogLog into self, updating the count. Returns Err(Error::IncompatibleLength) if the two HyperLogLogs have different precision (Self::precision).

This does not verify that the HLLs use equal hashers or seeds. If they are different then self will be “corrupted”.

Trait Implementations§

Source§

impl<S: Clone> Clone for HyperLogLogPlus<S>

Source§

fn clone(&self) -> HyperLogLogPlus<S>

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<S: Debug> Debug for HyperLogLogPlus<S>

Source§

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

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

impl<T: Hash, S: BuildHasher> Extend<T> for HyperLogLogPlus<S>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<S: BuildHasher> PartialEq for HyperLogLogPlus<S>

Source§

fn eq(&self, other: &Self) -> 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<S: BuildHasher> Eq for HyperLogLogPlus<S>

Auto Trait Implementations§

§

impl<S> Freeze for HyperLogLogPlus<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for HyperLogLogPlus<S>
where S: RefUnwindSafe,

§

impl<S> Send for HyperLogLogPlus<S>
where S: Send,

§

impl<S> Sync for HyperLogLogPlus<S>
where S: Sync,

§

impl<S> Unpin for HyperLogLogPlus<S>
where S: Unpin,

§

impl<S> UnwindSafe for HyperLogLogPlus<S>
where S: 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.
Source§

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

Source§

fn vzip(self) -> V