Skip to main content

Bloom Filter

Implemented in Python 3.

  • The price we pay for efficiency through bloom filters is that it is probabilistic in nature that means, there might be some False Positive results. False positive means, it might tell that given username is already taken but actually it’s not.
  • Not being False Negative such that telling that username doesn't exist while it is there, i.e., if exists it reports it's existenece in terms of maybe, else if not present it is 100% confident to report the same.
  • Deleting elements from filter is not possible because, if we delete a single element by clearing bits at indices generated by k hash functions, it might cause deletion of few other elements.

Installation

pip install bloomf==0.2

Distributed as a PyPi Package.

Usage

You can use this bloom filter as follows -

from bloomf import BloomFilter

n = 10  # number of items to be added
p = 0.04  # FP Probablity

filter = BloomFilter(n, p)

print("Size of bit array: {}" . format(filter.size))
print("False positive Probability: {}" . format(filter.fp_prob))
print("Number of hash functions: {}" . format(filter.hash_count))

word_present = ['abound', 'abounds', 'abundance', 'abundant', 'accessable', 'bloom', 'blossom', 'bolster', 'bonny', 'bonus', 'bonuses']
word_absent = ['bluff', 'cheater', 'hate', 'war', 'humanity', 'racism', 'hurt', 'facebook', 'sambhav', 'twitter']

for i in word_present:
    filter.add(i)

test_words = word_present[:5] + word_absent

for word in test_words:
    if filter.check(word):
        if word in word_absent:
            print("'{}' is a false positive!" . format(word))
        else:
            print("'{}' is a probably present!" . format(word))
    else:
        print("'{}' is 100% not present!" . format(word))

Dependencies

  • bitarray
  • mmh3

Metadata

Release files for bloomf 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bloomf 0.3
File Size Uploaded
bloomf-0.3.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bloomf 0.3
File Interpreter ABI Platform
bloomf-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 kB

Release files / bloomf-0.3.tar.gz

Download URL bloomf-0.3.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
be3f1a00814e327034c2125da71230a785577280e3c76c977a74df34c0e0c937
BLAKE2b-256 checksum
How to use checksums
e729be629fb306722944f6f599993a49545c10e77e2073159a1c307e58444b62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / bloomf-0.3-py3-none-any.whl

Download URL bloomf-0.3-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef97b6d720241d482dbd8bbf433e7a99f91589d9f5afeee82e35050fca5e3db0
BLAKE2b-256 checksum
How to use checksums
888f408cf8f074034f91e3f40512e8abb2fb694ae73b886f201487875715b139
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page