Git Product home page Git Product logo

simple_hll's Introduction

simple_hll โ€ƒ Build Status Latest Version

simple_hll is a simple HyperLogLog implementation in rust. It is designed to be simple to use and less bytes to store (with Sparse HyperLogLog).

Quick Start

use simple_hll::HyperLogLog;

let mut hll = HyperLogLog::<14>::new();
hll.add_object("hello");
hll.add_object("world");
hll.add_object("simple_hll");

println!("cardinality: {}", hll.count());

Serde

simple_hll supports serde and borsh with feature serde_borsh enabled, so you can serialize and deserialize the HyperLogLog instance.

   let val = serde_json::to_vec(hll)?;

Notice that in order to reduce the serialized size, we introduce a sparse intermediate struct for the HyperLogLog instance. When the non-zero registers are less than a threshold, we will use the sparse mode to serialize the HyperLogLog instance.

enum HyperLogLogVariant<const P: usize> {
    Empty,
    Sparse { data: Vec<(u16, u8)> },
    Full(Vec<u8>),
}

None-Fixed type

Different from other hyperloglog implementation, we don't use fixed type HyperLogLog<T> for the HyperLogLog instance, but we use a const generic parameter to specify the precision. The precision P is the number of bits to use for the register index. The number of registers is 2^P. The precision P is a trade-off between the accuracy and the memory usage. The default precision is 14, which means the memory usage is about 16KB.

The reason is that in databend or other dbms, we will store the HyperLogLog inside the metadata. We don't want to use HyperLogLog<Datum> for simplicity and less overhead to hash the enum.

Contributing

Check out the CONTRIBUTING.md guide for more details on getting started with contributing to this project.

Acknowledgements

Some codes and tests are borrowed and inspired from:

Reference papers:

Thanks for the great work of the authors and contributors.

License

Licensed under Apache License, Version 2.0.

simple_hll's People

Contributors

sundy-li avatar

Stargazers

xudong.w avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.