Struct HyperLogLog

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

HyperLogLog is a data structure for the “count-distinct problem”, approximating the number of distinct elements in a multiset.

§Example

use hyperloglockless::HyperLogLog;

let hll = HyperLogLog::new(16);
hll.insert("42");
hll.insert("🦀");

let count = hll.count();

Implementations§

Source§

impl HyperLogLog

Source

pub fn new(precision: u8) -> Self

Returns a new HyperLogLog with 1 << precision registers (1 byte each) using the default hasher with a random seed.

Source

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

Returns a new HyperLogLog with 1 << precision registers (1 byte each) using the default hasher seeded with seed.

Source§

impl<S: BuildHasher> HyperLogLog<S>

Source

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

Returns a new HyperLogLog with 1 << precision registers (1 byte each) using the provided hasher.

Source

pub fn len(&self) -> usize

Returns the number registers in self.

Source

pub fn iter(&self) -> impl Iterator<Item = u8> + use<'_, S>

Returns an iterator over the value of each register.

Source

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

Inserts the item into the HyperLogLog.

Source

pub fn insert_hash(&self, hash: u64)

Inserts the hash of an item into the HyperLogLog.

Source

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

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

Source

pub fn count(&self) -> usize

Returns the approximate number of items in self.

Source

pub fn raw_count(&self) -> f64

Returns the approximate number of items in self.

Trait Implementations§

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<S> UnwindSafe for HyperLogLog<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> 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, 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