Crates.io | wnfs-namefilter |
lib.rs | wnfs-namefilter |
version | 0.1.23 |
source | src |
created_at | 2023-03-23 10:41:18.330703 |
updated_at | 2023-09-05 11:52:25.404165 |
description | Bloom filter for the Webnative Filesystem |
homepage | https://fission.codes |
repository | https://github.com/wnfs-wg/rs-wnfs/tree/wnfs-namefilter-release/wnfs-namefilter |
max_upload_size | |
id | 818199 |
size | 21,222 |
Namefilters are 2048-bit Bloom filters. They can hold 47 path segments with one-in-a-billion false positive rate using 30 hashes.
Many Bloom filter implementations are optimized for speed, not consistency. We have chosen the XXH32 (i.e. 32-bit) algorithm. It is about as fast as XXH64 for 256-bit (i.e. small) data. XXH32 is very portable. It can be implemented within JavaScript's number system (at time of writing, ES2021 and earlier). It also can be natively implemented on any 32-bit machine, or on common 64-bit machines with a 32-bit compatability mode, such as AMD64. However, for every element inserted into the Bloom filters we need k = 30 different hash functions.
We get these from the first two XXH32 invocations with seeds 0 and 1 and the enhanced double hashing scheme (ยง5.2, Algorithm 2) to generate more hash functions from the first two. In our case the enhanced double hashing scheme operates on 32-bit unsigned integer arithmetic. The resulting hashes are taken modulo m = 2048 to convert these hashes into an index in the accumulator.
use wnfs_namefilter::Namefilter;
let mut filter = Namefilter::default();
filter.add(&[0xF5u8; 32]);
filter.saturate();
assert!(filter.contains(&[0xF5u8; 32]));