pub struct HyperLogLog<T, H, W = usize> { /* private fields */ }Expand description
Estimator logic implementing the HyperLogLog algorithm.
Instances are built using HyperLogLogBuilder, which provides convenient
ways to set the internal parameters.
Note that T can be any type satisfying the Hash trait. The parameter
H makes it possible to select a hashing algorithm, and W is the unsigned
type used to store backends.
An important constraint is that W must be able to represent exactly the
backend of an estimator. While usually usize will work (and it is the default
type chosen by new), with odd register sizes
and a small number of registers it might be necessary to select a smaller
type, resulting in slower merges. For example, using 16 5-bit registers one
needs to use u16, whereas for 16 6-bit registers u32 will be sufficient.
Formally, this means that W::BITS must divide
(1 << log_2_num_registers) * register_size (using
HyperLogLog::register_size(num_elements)).
HyperLogLogBuilder::min_log_2_num_reg returns the minimum value for
log_2_num_registers that satisfies this property.
Implementations§
Source§impl HyperLogLog<(), (), ()>
impl HyperLogLog<(), (), ()>
Sourcepub fn log_2_num_of_registers(rsd: f64) -> usize
pub fn log_2_num_of_registers(rsd: f64) -> usize
Returns the logarithm of the number of registers per estimator that are necessary to attain a given relative standard deviation.
§Arguments
rsd: the relative standard deviation to be attained.
Sourcepub fn rel_std(log_2_num_registers: usize) -> f64
pub fn rel_std(log_2_num_registers: usize) -> f64
Returns the relative standard deviation corresponding to a given number of registers per estimator.
§Arguments
log_2_num_registers: the logarithm of the number of registers per estimator.
Sourcepub fn register_size(num_elements: usize) -> usize
pub fn register_size(num_elements: usize) -> usize
Returns the register size in bits, given an upper bound on the number of distinct elements.
§Arguments
num_elements: an upper bound on the number of distinct elements.
Trait Implementations§
Source§impl<T, H, W> Display for HyperLogLog<T, H, W>
impl<T, H, W> Display for HyperLogLog<T, H, W>
Source§impl<T: Hash, H: BuildHasher + Clone, W: Word> EstimationLogic for HyperLogLog<T, H, W>where
u32: PrimitiveNumberAs<W>,
impl<T: Hash, H: BuildHasher + Clone, W: Word> EstimationLogic for HyperLogLog<T, H, W>where
u32: PrimitiveNumberAs<W>,
Source§type Estimator<'a> = DefaultEstimator<HyperLogLog<T, H, W>, &'a HyperLogLog<T, H, W>, Box<[W]>>
where
T: 'a,
W: 'a,
H: 'a
type Estimator<'a> = DefaultEstimator<HyperLogLog<T, H, W>, &'a HyperLogLog<T, H, W>, Box<[W]>> where T: 'a, W: 'a, H: 'a
Source§fn new_estimator(&self) -> Self::Estimator<'_>
fn new_estimator(&self) -> Self::Estimator<'_>
Source§fn add(&self, backend: &mut Self::Backend, element: impl Borrow<T>)
fn add(&self, backend: &mut Self::Backend, element: impl Borrow<T>)
Source§impl<T: Hash, H: BuildHasher + Clone, W: Word> MergeEstimationLogic for HyperLogLog<T, H, W>where
u32: PrimitiveNumberAs<W>,
impl<T: Hash, H: BuildHasher + Clone, W: Word> MergeEstimationLogic for HyperLogLog<T, H, W>where
u32: PrimitiveNumberAs<W>,
Source§type Helper = HyperLogLogHelper<W>
type Helper = HyperLogLogHelper<W>
Source§fn new_helper(&self) -> Self::Helper
fn new_helper(&self) -> Self::Helper
Source§impl<T: Hash, H: BuildHasher + Clone, W: Word> SliceEstimationLogic<W> for HyperLogLog<T, H, W>where
u32: PrimitiveNumberAs<W>,
impl<T: Hash, H: BuildHasher + Clone, W: Word> SliceEstimationLogic<W> for HyperLogLog<T, H, W>where
u32: PrimitiveNumberAs<W>,
Source§fn backend_len(&self) -> usize
fn backend_len(&self) -> usize
T in a backend.