pub struct HLL { /* private fields */ }
Expand description
The HLL
struct stores the underlying registers
of the HyperLogLog, with m
many registers.
The value for m
is derived from the desired error
of the estimation. The error is considered to be
1.04 / sqrt(2 ^ bits). So, given a desired 1% error
rate, we result in around 12 bits per register,
producing an underlying M of 2^12 bits (i.e. 4kb).
Implementations§
Source§impl HLL
impl HLL
Sourcepub fn one_hundred_twenty_eight() -> HLL
pub fn one_hundred_twenty_eight() -> HLL
Convenience function to produce a HLL with one hundred and twenty eight registers.
Sourcepub fn new(error: f64) -> HLL
pub fn new(error: f64) -> HLL
Create a new HLL with the desired standard error. Some examples might be:
bits size error
12 4096 0.0163
13 8192 0.0115
14 16384 0.0081
The error must be between 0.0 and 1.0. Beware using a stupidly small error size will grow beyond e.g. isize at less than 0.03 (if you need something that isn’t an estimate probably don’t use a hyperloglog).
Sourcepub fn insert<T: Hash>(&mut self, val: &T) -> bool
pub fn insert<T: Hash>(&mut self, val: &T) -> bool
Add an element into the hyperloglog estimate. We require the type of value to be able to be hashed. Returns whether the insertion altered the hyperloglog
Sourcepub fn registers(&self) -> Vec<u8> ⓘ
pub fn registers(&self) -> Vec<u8> ⓘ
Access a copy of the underlying registers (this is mainly here just for debugging/testing… its unlikely you’ll need this access typically).
Sourcepub fn empty() -> HLL
pub fn empty() -> HLL
A completely zeroed HLL. Not particularly useful
except as an identity element in Add
.
pub fn into_vec(self) -> Vec<u8> ⓘ
pub fn from_vec(data: Vec<u8>) -> HLL
Trait Implementations§
Source§impl<'a> Add for &'a HLL
Adding together two HLLs produces a new HLL where
the larger value of each register has been selected.
impl<'a> Add for &'a HLL
Adding together two HLLs produces a new HLL where the larger value of each register has been selected.