Skip to content

xzeck/HyperLogLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HyperLogLog

This is a rust implementation of Google's HyperLogLog algorithm

Features

  • Support for primitive data types
  • Support for custom data types
  • Pluggable hasher
  • Save state
  • Load state
  • Merge
  • Reset

Usage:

use hyperloglog::HyperLogLog;
use std::{collections::HashSet, time::Instant};

fn main() {
    let mut hll: HyperLogLog<i64> = HyperLogLog::new(4);



    for i in -1_000_000i64..1_000_000 {
        hll.insert(i);
    }

    // getting an estimate    
    let estimate = hll.calculate_cardinality();

    // serializing the data
    let serialized = serde_json::to_string(&hll).unwrap();
    // output: {"p":4,"m":16,"buckets":[17,17,20,17,19,18,21,18,19,18,18,17,17,19,17,17],"fingerprint":17010847314131961531}
    println!("{}", serialized);

    // rebuild the data
    let desserialized: HyperLogLog<i64> = serde_json::from_str(&serialized).unwrap();

    println!("{}, {}", hll.calculate_cardinality(), desserialized.calculate_cardinality());
}

More examples can be found in examples/

About

A rust implementation of google's HyperLogLog for cardinality estimation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages