Skip to content

Commit 2fd7196

Browse files
committed
estimated error
1 parent 28e6691 commit 2fd7196

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

data_structures/hashing/bloom_filter.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'00000000'
1414
1515
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:
1717
>>> b.add("Titanic")
1818
>>> b.bitstring
1919
'01100000'
@@ -35,19 +35,31 @@
3535
'00011000'
3636
>>> "Interstellar" in b
3737
False
38+
>>> b.format_hash("Interstellar")
39+
'00000011'
3840
>>> "Parasite" in b
3941
False
42+
>>> b.format_hash("Parasite")
43+
'00010010'
4044
>>> "Pulp Fiction" in b
4145
False
46+
>>> b.format_hash("Pulp Fiction")
47+
'10000100'
4248
4349
but sometimes there are false positives:
4450
>>> "Ratatouille" in b
4551
True
4652
>>> b.format_hash("Ratatouille")
4753
'01100000'
4854
55+
The probability increases with the number of added elements
4956
>>> b.estimated_error_rate()
5057
0.140625
58+
>>> b.add("The Goodfather")
59+
>>> b.estimated_error_rate()
60+
0.390625
61+
>>> b.bitstring
62+
'01111100'
5163
"""
5264
from hashlib import md5, sha256
5365

0 commit comments

Comments
 (0)