use hyperloglog::HyperLogLog;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut hll = HyperLogLog::new(14)?;
println!("Adding unique visitors...");
for i in 0..10000 {
hll.add_str(&format!("user_{}", i));
}
let count = hll.count();
let actual = 10000;
let error = ((count as f64 - actual as f64) / actual as f64).abs() * 100.0;
println!("Actual unique visitors: {}", actual);
println!("Estimated count: {}", count);
println!("Error: {:.2}%", error);
println!("\nAdding duplicates...");
for i in 0..5000 {
hll.add_str(&format!("user_{}", i));
}
let new_count = hll.count();
println!("Count after duplicates: {}", new_count);
println!("Change: {} visitors", new_count as i64 - count as i64);
Ok(())
}