This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am diogodanielsoaresferreira on github. | |
* I am diogosoaresferre (https://keybase.io/diogosoaresferre) on keybase. | |
* I have a public key ASCTFDFWY1NVZFPnHKmc3hkJ5xWelssWgAjW48zBu_Y9HAo | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from bitarray import bitarray | |
class BloomFilter(object): | |
def __init__(self, size, number_expected_elements=100000): | |
self.size = size | |
self.number_expected_elements = number_expected_elements | |
self.bloom_filter = bitarray(self.size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _hash_djb2(self, s): | |
hash = 5381 | |
for x in s: | |
hash = ((hash << 5) + hash) + ord(x) | |
return hash % self.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _hash(self, item, K): | |
return self._hash_djb2(str(K) + item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_to_filter(self, item): | |
for i in range(self.number_hash_functions): | |
self.bloom_filter[self._hash(item, i)] = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_is_not_in_filter(self, item): | |
for i in range(self.number_hash_functions): | |
if self.bloom_filter[self._hash(item, i)] == 0: | |
return True | |
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bloom_filter = BloomFilter(1000000, 100000) | |
base_ip = "192.168.1." | |
bloom_filter.add_to_filter(base_ip + str(1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1, 100000): | |
if not bloom_filter.check_is_not_in_filter(base_ip + str(i)): | |
print(base_ip+str(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from bitarray import bitarray | |
class BloomFilter(object): | |
def __init__(self, size, number_expected_elements=100000): | |
self.size = size | |
self.number_expected_elements = number_expected_elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terms | dialogue 1 | dialogue 2 | dialogue 3 | ... | |
---|---|---|---|---|---|
cancel | 0.26 | 0 | 0 |