Skip to main content

Bloom filter implemented in zig

Project description

bloom-zig

Bloom filters written in Zig with Python bindings.

NOTE that this software is under development and it's not completely functional!

How to install

Right now, there's only a wheel for Macos. To install it, you can run the usual

pip install bloom-zig

If you need to install this package for another architecture, refer to the section about building from source.

Building from source

To build this package from source, you'll need:

  • Zig (version 0.11.0)
  • Python (version used is 3.9, but it should work with lower versions)
  • Python development header
  • make (not mandatory, but handy)

If everything correctly installed, you can run zig build test to double check that everything works.

Then, go inside code_binding directory. You can create a Python env with the requirements.txt installed or install the requirements in your current env. With everything in place, run

make install

This should install the bloom package in your environment. To test that the package has been correctly installed, run make test.

How it works

The src folder contains the Zig code for the Bloom filter. It internally uses an ArrayList of u32, where each bit in a u32 element represents an element in the set. I'd preferred to use a more efficient structure or directly an array of u64, but I'm not aware of the compile-time functionality of Zig and if they integrate well with Python code. So I decided to stick with the basics.

The code_binding folder contains the code used to generate the Python wheel package and the Python bindings directly written in Zig. There's a Makefile to reproduce the building steps. The Zig code is a blind translation of the C code for writing Python bindings.

The exposed functionalities inside Python are a class called BloomFilter with 3 methods: add, present and count. There's also a function called fnv to compute a 64 bit non-cryptographic hash.

Why?

Never written an extension for Python so far. Just a beginner with Zig. How to conciliate these two aspects? A Python extension in Zig! The great interop that Zig has with C libraries made the process (not-so-much) simple.

TODOs

  • make wheels for manylinux
  • Pypi package(s)
  • examples and benchmark

Resources

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zig_bloom-0.0.7-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (112.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.5+ x86-64

zig_bloom-0.0.7-cp39-cp39-macosx_11_0_universal2.whl (50.5 kB view details)

Uploaded CPython 3.9macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file zig_bloom-0.0.7-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for zig_bloom-0.0.7-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f167391bdbc8b657c1ef0c7bf766450fb44d9fd296413a84dd3f7e738215b596
MD5 f29cd1870c2a62496d72eded5273c546
BLAKE2b-256 938762bb87896ca4f88f1356792a31c61a7793453120bbec2e59fbc06bf52473

See more details on using hashes here.

File details

Details for the file zig_bloom-0.0.7-cp39-cp39-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for zig_bloom-0.0.7-cp39-cp39-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 d1ccf13e394dbbf363ff60def5310b6b946b5eaf702384d053a790ae0629a609
MD5 a9de1bc1958a1e9f311cd7e678b66441
BLAKE2b-256 d2b91e426e424bb6d1337d65bb7d906a8bfa4dfdd41b0c5025ddb00916d34755

See more details on using hashes here.

Supported by

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