File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 13
13
'00000000'
14
14
15
15
When an element is added, two bits are set to 1
16
- since there are 2 hash functions:
16
+ since there are 2 hash functions in this implementation :
17
17
>>> b.add("Titanic")
18
18
>>> b.bitstring
19
19
'01100000'
35
35
'00011000'
36
36
>>> "Interstellar" in b
37
37
False
38
+ >>> b.format_hash("Interstellar")
39
+ '00000011'
38
40
>>> "Parasite" in b
39
41
False
42
+ >>> b.format_hash("Parasite")
43
+ '00010010'
40
44
>>> "Pulp Fiction" in b
41
45
False
46
+ >>> b.format_hash("Pulp Fiction")
47
+ '10000100'
42
48
43
49
but sometimes there are false positives:
44
50
>>> "Ratatouille" in b
45
51
True
46
52
>>> b.format_hash("Ratatouille")
47
53
'01100000'
48
54
55
+ The probability increases with the number of added elements
49
56
>>> b.estimated_error_rate()
50
57
0.140625
58
+ >>> b.add("The Goodfather")
59
+ >>> b.estimated_error_rate()
60
+ 0.390625
61
+ >>> b.bitstring
62
+ '01111100'
51
63
"""
52
64
from hashlib import md5 , sha256
53
65
You can’t perform that action at this time.
0 commit comments