Created
May 31, 2023 07:32
-
-
Save jiacai2050/88dabe0e288db61dc0be2835528cd277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[dependencies] | |
rand = "0.8.5" | |
xorfilter-rs = { git = "https://github.com/datafuse-extras/xorfilter", features = [ | |
"cbordata", | |
], tag = "databend-alpha.4" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashSet; | |
use rand::Rng; | |
use xorfilter::{BuildHasherDefault, Xor8Builder}; | |
fn random() -> Vec<u8> { | |
let mut rng = rand::thread_rng(); | |
let bytes: Vec<u8> = (0..100).map(|_| rng.gen()).collect(); | |
bytes | |
} | |
fn run(value_num: usize) { | |
let mut b = Xor8Builder::<BuildHasherDefault>::default(); | |
let mut set = HashSet::with_capacity(value_num); | |
for _ in 0..value_num { | |
let key = random(); | |
set.insert(key.clone()); | |
b.insert(&key); | |
// b.populate(&[random(), random()]); | |
} | |
let filter = b.build().unwrap(); | |
let bs = filter.to_bytes(); | |
println!( | |
"key_num:{}, len:{}, byte_per_key:{}", | |
set.len(), | |
bs.len(), | |
bs.len() as f64 / value_num.max(1) as f64 | |
) | |
} | |
pub fn main() { | |
run(0); | |
run(1); | |
run(5); | |
run(10); | |
run(100); | |
run(1000); | |
run(2000); | |
run(3000); | |
run(4000); | |
run(8000); | |
} |
Author
jiacai2050
commented
May 31, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment