HyperLogLogPlus

Struct HyperLogLogPlus 

Source
pub struct HyperLogLogPlus<H, B>
where H: Hash + ?Sized, B: BuildHasher,
{ /* private fields */ }
Expand description

Implements the HyperLogLog++ algorithm for cardinality estimation.

This implementation is based on the paper:

HyperLogLog in Practice: Algorithmic Engineering of a State of The Art Cardinality Estimation Algorithm.

  • Uses 6-bit registers, packed in a 32-bit unsigned integer. Thus, every five registers 2 bits are not used.
  • In small cardinalities, a sparse representation is used which allows for higher precision in estimations.
  • Performs bias correction using the empirical data provided by Google (can be found here).
  • Supports serialization/deserialization through serde.

§Examples

use std::collections::hash_map::RandomState;
use hyperloglogplus::{HyperLogLog, HyperLogLogPlus};

let mut hllp: HyperLogLogPlus<u32, _> =
    HyperLogLogPlus::new(16, RandomState::new()).unwrap();

hllp.insert(&12345);
hllp.insert(&23456);

assert_eq!(hllp.count().trunc() as u32, 2);

§References

Implementations§

Source§

impl<H, B> HyperLogLogPlus<H, B>
where H: Hash + ?Sized, B: BuildHasher,

Source

pub fn new(precision: u8, builder: B) -> Result<Self, HyperLogLogError>

Creates a new HyperLogLogPlus instance.

Source

pub fn merge<S, T>( &mut self, other: &HyperLogLogPlus<S, T>, ) -> Result<(), HyperLogLogError>
where S: Hash + ?Sized, T: BuildHasher,

Merges the other HyperLogLogPlus instance into self.

Both sketches must have the same precision. Merge can trigger the transition from sparse to normal representation.

Source

pub fn insert_any<R>(&mut self, value: &R)
where R: Hash + ?Sized,

Inserts a new value, of any type, to the multiset.

Trait Implementations§

Source§

impl<H, B> Clone for HyperLogLogPlus<H, B>
where H: Hash + ?Sized + Clone, B: BuildHasher + Clone,

Source§

fn clone(&self) -> HyperLogLogPlus<H, B>

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, B> Debug for HyperLogLogPlus<H, B>
where H: Hash + ?Sized + Debug, B: BuildHasher + Debug,

Source§

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

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

impl<'de, H, B> Deserialize<'de> for HyperLogLogPlus<H, B>
where H: Hash + ?Sized, B: BuildHasher + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<H, B> HyperLogLog<H> for HyperLogLogPlus<H, B>
where H: Hash + ?Sized, B: BuildHasher,

Source§

fn add(&mut self, value: &H)

👎Deprecated since 0.3.0: use insert() function instead.

Adds a new value to the multiset.

Source§

fn insert<Q>(&mut self, value: &Q)
where H: Borrow<Q>, Q: Hash + ?Sized,

Inserts a new value to the multiset.

Source§

fn count(&mut self) -> f64

Estimates the cardinality of the multiset.

Source§

impl<H, B> Serialize for HyperLogLogPlus<H, B>
where H: Hash + ?Sized, B: BuildHasher + Serialize,

Source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<H, B> Freeze for HyperLogLogPlus<H, B>
where B: Freeze, H: ?Sized,

§

impl<H, B> RefUnwindSafe for HyperLogLogPlus<H, B>

§

impl<H, B> Send for HyperLogLogPlus<H, B>
where B: Send, H: Send + ?Sized,

§

impl<H, B> Sync for HyperLogLogPlus<H, B>
where B: Sync, H: Sync + ?Sized,

§

impl<H, B> Unpin for HyperLogLogPlus<H, B>
where B: Unpin, H: Unpin + ?Sized,

§

impl<H, B> UnwindSafe for HyperLogLogPlus<H, B>
where B: UnwindSafe, H: UnwindSafe + ?Sized,

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,