Created
January 21, 2014 14:47
-
-
Save aristus/8541397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hashlib import md5 | |
bloom = 0b0 | |
num_bits = 512 | |
def add_to_bloom(s): | |
global bloom | |
# int representation of the hashed value | |
hash = int(md5(s.encode('utf8')).hexdigest(), 16) | |
# modulo that number against the length of the bloom filter | |
m = hash % num_bits | |
# flip the mth bit in the filter! | |
bit = 1 << m | |
bloom |= bit | |
return m | |
print bloom | |
print add_to_bloom('derp') | |
print add_to_bloom('foo') | |
print bloom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment