Created
January 21, 2014 14:47
-
-
Save aristus/8541397 to your computer and use it in GitHub Desktop.
Revisions
-
aristus created this gist
Jan 21, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ 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