Skip to main content

A fast bloom filter implemented by Rust for Python and Rust!

Project description

fastbloom

rust docs Test Rust Test Python Benchmark Crates Latest Release PyPI Latest Release

A fast bloom filter implemented by Rust for Python and Rust!

setup

Python

requirements

Python >= 3.7

install

Install the latest fastbloom version with:

pip install fastbloom-rs

Rust

fastbloom-rs = "0.2.1"

Examples

Python

basic usage

from fastbloom_rs import BloomFilter

bloom = BloomFilter(100_000_000, 0.01)

bloom.add_str('hello')
bloom.add_bytes(b'world')
bloom.add_int(9527)

assert bloom.contains('hello')
assert bloom.contains(b'world')
assert bloom.contains(9527)

assert not bloom.contains('hello world')

build bloom filter from bytes or list

from fastbloom_rs import BloomFilter

bloom = BloomFilter(100_000_000, 0.01)
bloom.add_str('hello')
assert bloom.contains('hello')

bloom2 = BloomFilter.from_bytes(bloom.get_bytes(), bloom.hashes())
assert bloom2.contains('hello')

bloom3 = BloomFilter.from_int_array(bloom.get_int_array(), bloom.hashes())
assert bloom3.contains('hello')

Rust

use fastbloom_rs::{BloomFilter, FilterBuilder};

let mut bloom = FilterBuilder::new(100_000_000, 0.01).build_bloom_filter();

bloom.add(b"helloworld");
assert_eq!(bloom.contains(b"helloworld"), true);
assert_eq!(bloom.contains(b"helloworld!"), false);

more examples at docs.rs

benchmark

computer info

CPU Memory OS
AMD Ryzen 7 5800U with Radeon Graphics 16G Windows 10

bloom add

Benchmark insert str to bloom filter:

PDF of Slope Regression

Additional Statistics:

Lower bound Estimate Upper bound
Slope 41.095 ns 41.146 ns 41.203 ns
0.9959495 0.9961648 0.9959083
Mean 41.157 ns 41.207 ns 41.257 ns
Std. Dev. 226.07 ps 261.59 ps 294.01 ps
Median 41.132 ns 41.184 ns 41.247 ns
MAD 201.13 ps 277.13 ps 335.05 ps

bloom add one million

Benchmark loop insert (1..1_000_000).map(|n| { n.to_string() }) to bloom filter:

PDF of Slope Regression

Additional Statistics:

Lower bound Estimate Upper bound
0.0002895 0.0002964 0.0002822
Mean 237.57 ms 240.25 ms 244.15 ms
Std. Dev. 2.4341 ms 17.400 ms 28.072 ms
Median 236.83 ms 237.27 ms 237.75 ms
MAD 1.5867 ms 2.2701 ms 2.8268 ms

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastbloom_rs-0.2.1.tar.gz (62.6 kB view hashes)

Uploaded Source

Built Distributions

fastbloom_rs-0.2.1-cp37-abi3-win_amd64.whl (143.7 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

fastbloom_rs-0.2.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (198.9 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

fastbloom_rs-0.2.1-cp37-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.whl (215.4 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.5+ x86-64

fastbloom_rs-0.2.1-cp37-abi3-macosx_11_0_arm64.whl (185.6 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

fastbloom_rs-0.2.1-cp37-abi3-macosx_10_7_x86_64.whl (197.1 kB view hashes)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page