use cl_tds::ClTds;
fn main() {
let sketch = ClTds::new();
let traffic = [
("attacker", 10_000u64),
("user_a", 500),
("user_b", 200),
("user_c", 50),
];
for &(label, count) in &traffic {
let id = hash(label);
for _ in 0..count {
sketch.increment(id);
}
}
println!("╔══════════════════════════════════════╗");
println!("║ CL-TDS Basic Example ║");
println!("╠══════════════════════════════════════╣");
for &(label, real_count) in &traffic {
let est = sketch.query(hash(label));
println!(
"║ {:<12} real={:<6} est={:<6} {} ║",
label,
real_count,
est,
if est as u64 == real_count {
"✅"
} else {
"≈"
}
);
}
println!("║ ║");
println!("║ Memory: {} bytes (1 MB) ║", sketch.memory_bytes());
println!("╚══════════════════════════════════════╝");
}
fn hash(s: &str) -> u64 {
let mut h: u64 = 0xcbf29ce484222325;
for b in s.bytes() {
h ^= b as u64;
h = h.wrapping_mul(0x100000001b3);
}
h
}