File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
See https://en.wikipedia.org/wiki/Bloom_filter
3
3
"""
4
- import string
5
4
from hashlib import md5 , sha256
6
5
from random import choices
6
+ from string import ascii_lowercase
7
7
8
8
9
9
class Bloom :
@@ -15,7 +15,7 @@ def __init__(self, size=8):
15
15
self .size = size
16
16
17
17
def add (self , value ):
18
- h = self .hash (value )
18
+ h = self .hash_ (value )
19
19
self .bitstring |= h
20
20
print (
21
21
f"""\
@@ -26,7 +26,7 @@ def add(self, value):
26
26
)
27
27
28
28
def exists (self , value ):
29
- h = self .hash (value )
29
+ h = self .hash_ (value )
30
30
res = (h & self .bitstring ) == h
31
31
32
32
print (
@@ -43,7 +43,7 @@ def format_bin(self, value):
43
43
res = bin (value )[2 :]
44
44
return res .zfill (self .size )
45
45
46
- def hash (self , value ):
46
+ def hash_ (self , value ):
47
47
res = 0b0
48
48
for func in self .HASH_FUNCTIONS :
49
49
b = func (value .encode ()).digest ()
@@ -67,7 +67,7 @@ def test_movies():
67
67
68
68
69
69
def random_string (size ):
70
- return "" .join (choices (string . ascii_lowercase + " " , k = size ))
70
+ return "" .join (choices (ascii_lowercase + " " , k = size ))
71
71
72
72
73
73
def test_probability (m = 64 , n = 20 ):
You can’t perform that action at this time.
0 commit comments