Skip to content

sjf25/bloom-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Bloom Filter

What is a Bloom Filter?

A bloom filter is a space-efficient probablistic data structure used to check set membership. For more information, see: https://en.wikipedia.org/wiki/Bloom_filter

How to use

from bloom_filter import BloomFilter

# the constructor takes the expected number of elements and the desired error probability
number_of_elements = 1000
desired_error = 0.005
filter = BloomFilter(number_of_elements, desired_error)

# add items to the filter
filter.add("some element")
filter.add("another")

# returns True if might be in filter, False otherwise
# note: the bloom filter can return false positives, but not false negatives
filter.maybe_element("some element")
filter.maybe_element("something")

# save the bloom filter in to file for later use
out_file = open('/path/to/some/file/some_file', 'wb')
filter.write(out_file)

# read in a bloom filter that was saved to a file
in_file = open('/path/to/some/file/other_file', 'rb')
other_filter = BloomFilter.open(in_file)

Uses

The bloom filter can be used to check if a given password is in a set of breached passwords (can be obtained from https://haveibeenpwned.com/).

The following are some example queries applied to the set of passwords:

?- password
True
?- correcthorsebatterystaple
True
?- qwertyuiop
True
?- sdfghjkl
True
?- qwfgfddfgfgfdff
False
?- zxokggty
False
?- bW9vY293Z29lc21vbw==
False
?- anypasswordheretotest
False
?- 123456789
True
?- 12624120720
True
?- 10195748
False
?- bloomfiltersarecool
False

About

Implementation of a Bloom FIlter in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages