Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srinivasreddy/rust-bloomfilter
🦀 Bloom filter implementation in Rust 🦀
https://github.com/srinivasreddy/rust-bloomfilter
bloom-filter probabilistic-data-structures rust
Last synced: 2 months ago
JSON representation
🦀 Bloom filter implementation in Rust 🦀
- Host: GitHub
- URL: https://github.com/srinivasreddy/rust-bloomfilter
- Owner: srinivasreddy
- License: mit
- Created: 2019-10-18T09:23:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-18T05:47:38.000Z (about 4 years ago)
- Last Synced: 2024-11-28T11:16:31.190Z (3 months ago)
- Topics: bloom-filter, probabilistic-data-structures, rust
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 18
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
## rust-bloomfilter
Bloom filters are defined by 4 interdependent values:
* n - Number of items in the filter
* p - Probability of false positives, float between 0 and 1 or a number indicating 1-in-p
* m - Number of bits in the filter
* k - Number of hash functions## Guide for selecting the parameters
The values are interdependent as shown in the following calculations:```
m = ceil((n * log(p)) / log(1.0 / (pow(2.0, log(2.0)))));k = round(log(2.0) * m / n);
```
## Design
I use murmur3 hash to generate 128 bit hash integer, and then i split it into two integers of 64 bits each.
Following is the pseudo-code written for the design of bloom filter.````
let hash_128 = murmur3_hash(data);
let first_64 = (hash_128 & (2_u128.pow(64) - 1));
let second_64 = hash >> 64;
for i 0..num_of_hashfuncs{
first_64 += i* second_64;
index = fist_64 % number_of_bits
self.bitvec.set(index, true);
}
````
## Usage
````rust
extern crate rust_bloomfilter;use rust_bloomfilter::BloomFilter;
let mut b = BloomFilter(20000, 0.01, true);
b.add("Helloworld");
assert!(b.contains("Helloworld"));````