use hyperloglog::{HyperLogLog, storage::FileStorage, Storage};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let storage_path = std::env::temp_dir().join("hll_example");
let storage = FileStorage::new(&storage_path).await?;
println!("Using file storage at: {}", storage_path.display());
let mut hll = HyperLogLog::new(14)?;
for i in 0..1000 {
hll.add_str(&format!("user_{}", i));
}
let count_before = hll.count();
println!("Created HLL with estimated count: {}", count_before);
storage.store("daily_visitors", &hll).await?;
println!("Stored HLL to disk");
let exists = storage.exists("daily_visitors").await?;
println!("Key exists: {}", exists);
let loaded_hll = storage.load("daily_visitors").await?;
let count_after = loaded_hll.count();
println!("Loaded HLL with estimated count: {}", count_after);
println!("Counts match: {}", count_before == count_after);
let keys = storage.list_keys().await?;
println!("All keys in storage: {:?}", keys);
storage.delete("daily_visitors").await?;
println!("Cleaned up storage");
Ok(())
}