-
-
Notifications
You must be signed in to change notification settings - Fork 49.1k
Bloom Filter #8615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bloom Filter #8615
Changes from 1 commit
173ab0e
08bc970
0448109
486dcbc
4111807
e6ce098
e4d39db
7629686
3926167
280ffa0
5d460aa
cc54095
78d19fd
8b1bec0
28e6691
2fd7196
314237d
9b01472
c132d50
313c80c
18e0dde
54041ff
483a2a0
174ce08
00cc60e
35fa5f5
5cd20ea
7617143
799171a
1a71f4c
4e0263f
e746746
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,103 @@ | ||||||||||||||||||
| """ | ||||||||||||||||||
| See https://en.wikipedia.org/wiki/Bloom_filter | ||||||||||||||||||
| """ | ||||||||||||||||||
| from hashlib import sha256, md5 | ||||||||||||||||||
| from random import randint, choices | ||||||||||||||||||
| import string | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class Bloom: | ||||||||||||||||||
| def __init__(self, size=8): | ||||||||||||||||||
| self.bitstring = 0b0 | ||||||||||||||||||
| self.size = size | ||||||||||||||||||
|
|
||||||||||||||||||
| def add(self, value): | ||||||||||||||||||
| h = self.hash(value) | ||||||||||||||||||
| self.bitstring |= h | ||||||||||||||||||
| print( | ||||||||||||||||||
| f"""\ | ||||||||||||||||||
| [add] value = {value} | ||||||||||||||||||
| hash = {self.format_bin(h)} | ||||||||||||||||||
| filter = {self.format_bin(self.bitstring)} | ||||||||||||||||||
| """ | ||||||||||||||||||
| ) | ||||||||||||||||||
|
||||||||||||||||||
| print( | |
| f"""\ | |
| [add] value = {value} | |
| hash = {self.format_bin(h)} | |
| filter = {self.format_bin(self.bitstring)} | |
| """ | |
| ) |
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| print( | |
| f"""\ | |
| [exists] value = {value} | |
| hash = {self.format_bin(h)} | |
| filter = {self.format_bin(self.bitstring)} | |
| res = {res} | |
| """ | |
| ) |
In the CONTRIBUTING it says
- return all calculation results instead of printing or plotting them
I don't think these prints are necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to method and called in doctest
Uh oh!
There was an error while loading. Please reload this page.