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 mut hll = HyperLogLog::new(16);
hll.insert("42");
hll.insert("🦀");
let count = hll.count();Implementations§
Source§impl<S: BuildHasher> HyperLogLog<S>
impl<S: BuildHasher> HyperLogLog<S>
Sourcepub fn with_hasher(precision: u8, hasher: S) -> Self
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§impl HyperLogLog
impl HyperLogLog
Sourcepub fn new(precision: u8) -> HyperLogLog<DefaultHasher>
pub fn new(precision: u8) -> HyperLogLog<DefaultHasher>
Returns a new Self with 1 << precision registers (1 byte each)
using the default hasher with a random seed.
Sourcepub fn seeded(precision: u8, seed: u128) -> HyperLogLog<DefaultHasher>
pub fn seeded(precision: u8, seed: u128) -> HyperLogLog<DefaultHasher>
Returns a new Self with 1 << precision registers (1 byte each)
using the default hasher seeded with seed.
Source§impl<S: BuildHasher> HyperLogLog<S>
impl<S: BuildHasher> HyperLogLog<S>
Source§impl<S: BuildHasher> HyperLogLog<S>
impl<S: BuildHasher> HyperLogLog<S>
Sourcepub fn iter(&self) -> impl Iterator<Item = u8> + '_
pub fn iter(&self) -> impl Iterator<Item = u8> + '_
Returns an iterator over the value of each register.
Sourcepub fn insert_hash(&mut self, hash: u64)
pub fn insert_hash(&mut self, hash: u64)
Inserts the hash of an item into the HyperLogLog.
Sourcepub fn insert_all<T: Hash, I: IntoIterator<Item = T>>(&mut self, iter: I)
pub fn insert_all<T: Hash, I: IntoIterator<Item = T>>(&mut self, iter: I)
Inserts all the items in iter into the self.
Sourcepub fn union(&mut self, other: &Self) -> Result<(), Error>
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 length (Self::len).
This does not verify that the HLLs use the same hasher or seed.
If they are different then self will be “corrupted”.
Sourcepub fn parts<'a>(&'a self) -> (&'a [u8], &'a S, usize, f64)
pub fn parts<'a>(&'a self) -> (&'a [u8], &'a S, usize, f64)
Low level method to expose de/serializable parts of self.
Sourcepub fn from_parts(
registers: Box<[u8]>,
hasher: S,
zeros: usize,
sum: f64,
) -> Self
pub fn from_parts( registers: Box<[u8]>, hasher: S, zeros: usize, sum: f64, ) -> Self
Low level method to construct Self de/serializable parts.
§Example
use hyperloglockless::HyperLogLog;
let mut before = HyperLogLog::seeded(16, 42);
before.extend(1000..=2000);
let (x, y, z, w) = before.parts();
let after = HyperLogLog::from_parts(x.into(), y.clone(), z, w);
assert_eq!(before, after);Trait Implementations§
Source§impl<S: Clone> Clone for HyperLogLog<S>
impl<S: Clone> Clone for HyperLogLog<S>
Source§fn clone(&self) -> HyperLogLog<S>
fn clone(&self) -> HyperLogLog<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<S: Debug> Debug for HyperLogLog<S>
impl<S: Debug> Debug for HyperLogLog<S>
Source§impl<T: Hash, S: BuildHasher> Extend<T> for HyperLogLog<S>
impl<T: Hash, S: BuildHasher> Extend<T> for HyperLogLog<S>
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)