mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-05-05 20:03:59 +00:00
Update data_structures/hashing/bloom_filter.py
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
313c80c369
commit
18e0dde13b
@ -5,15 +5,15 @@ The use of this data structure is to test membership in a set.
|
|||||||
Compared to Python's built-in set() it is more space-efficient.
|
Compared to Python's built-in set() it is more space-efficient.
|
||||||
In the following example, only 8 bits of memory will be used:
|
In the following example, only 8 bits of memory will be used:
|
||||||
>>> bloom = Bloom(size=8)
|
>>> bloom = Bloom(size=8)
|
||||||
>>> "Titanic" in bloom
|
|
||||||
False
|
|
||||||
|
|
||||||
Initially the filter contains all zeros:
|
Initially, the filter contains all zeros:
|
||||||
>>> bloom.bitstring
|
>>> bloom.bitstring
|
||||||
'00000000'
|
'00000000'
|
||||||
|
|
||||||
When an element is added, two bits are set to 1
|
When an element is added, two bits are set to 1
|
||||||
since there are 2 hash functions in this implementation:
|
since there are 2 hash functions in this implementation:
|
||||||
|
>>> "Titanic" in bloom
|
||||||
|
False
|
||||||
>>> bloom.add("Titanic")
|
>>> bloom.add("Titanic")
|
||||||
>>> bloom.bitstring
|
>>> bloom.bitstring
|
||||||
'01100000'
|
'01100000'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user