https://github.com/jettify/hyperbitbit
A native rust implementation of a HyperBitBit algorithm.
https://github.com/jettify/hyperbitbit
crates estimate-cardinality hyperbitbit
Last synced: 17 days ago
JSON representation
A native rust implementation of a HyperBitBit algorithm.
- Host: GitHub
- URL: https://github.com/jettify/hyperbitbit
- Owner: jettify
- License: apache-2.0
- Created: 2020-12-07T02:18:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-31T02:28:08.000Z (over 4 years ago)
- Last Synced: 2025-02-03T22:38:11.639Z (3 months ago)
- Topics: crates, estimate-cardinality, hyperbitbit
- Language: Rust
- Homepage:
- Size: 25.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HyperBitBit
[](https://github.com/jettify/hyperbitbit/actions?query=workflow%3ACI)
[](https://crates.io/crates/hyperbitbit)
[](https://docs.rs/hyperbitbit/)A native rust implementation of a HyperBitBit algorithm introduced by
by Robert Sedgewick in [AC11-Cardinality.pdf](https://www.cs.princeton.edu/~rs/talks/AC11-Cardinality.pdf)# Feature
* HyperBitBit, for N < 2^64
* Uses 128 + 8 bit of space
* Estimated cardinality withing 10% or actuals for large N.Consider HyperLogLog variants for productions usage, sine this data structure
extensively studied, merge able and more accurate. HyperBitBit is extremely
cheap and fast alternative in expense of accuracy.# Usage
This crate is [on crates.io](https://crates.io/crates/hyperbitbit) and
can be used by adding `hyperbitbit` to the dependencies in your
project's `Cargo.toml`.```toml
[dependencies]
hyperbitbit = "0.0.1-alpha.1"
```
If you want [serde](https://github.com/serde-rs/serde) support, include the feature like this:```toml
[dependencies]
hyperbitbit = { version = "0.0.1-alpha.1", features = ["serde_support"] }
```add this to your crate root:
```rust
extern crate hyperbitbit;
```# Example
Create a HyperBitBit, add more data and estimate cardinality
```rust
use hyperbitbit::HyperBitBit;
use rand::Rng;
use rand::SeedableRng;
use rand::distributions::Alphanumeric;
use rand_isaac::Isaac64Rng;
use std::collections::HashSet;fn main() {
let mut hbb = HyperBitBit::new();
let mut items = HashSet::new();
let mut rng = Isaac64Rng::seed_from_u64(42);let maxn = 100000;
for _ in 1..maxn {
let s = (&mut rng).sample_iter(&Alphanumeric).take(3).collect::();hbb.insert(&s);
items.insert(s);
}
let expected: i64 = items.len() as i64;
let rel: f64 = (100.0 * (expected - hbb.cardinality() as i64) as f64) / (expected as f64);println!("Cardinality: {:?}", expected);
println!("Estimated cardinality: {:?}", hbb.cardinality());
println!("Error % cardinality: {:.2}", rel);
}
```
# Lincese
Licensed under the Apache License, Version 2.0