use core::hash::Hash;
use crate::prelude::*;
pub trait EstimateIterCardinality {
fn estimate_cardinality<P: Precision + WordType<BITS>, const BITS: usize>(self) -> f32;
}
impl<I, T: Hash> EstimateIterCardinality for I
where
I: Iterator<Item = T>,
{
fn estimate_cardinality<P: Precision + WordType<BITS>, const BITS: usize>(self) -> f32 {
let hll: HyperLogLog<P, BITS> = self.collect();
hll.estimate_cardinality()
}
}
pub trait HyperLogLogIterator<P: Precision + WordType<BITS>, const BITS: usize> {
fn union(self) -> HyperLogLog<P, BITS>;
}
impl<P: Precision + WordType<BITS>, const BITS: usize, I, C> HyperLogLogIterator<P, BITS> for I
where
I: Iterator<Item = C>,
HyperLogLog<P, BITS>: BitOr<C, Output = HyperLogLog<P, BITS>>,
{
#[inline(always)]
fn union(self) -> HyperLogLog<P, BITS> {
self.fold(HyperLogLog::default(), |acc, hll| acc | hll)
}
}