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
Query: Democrats win republicans in election. | |
5 most similar descriptions using TF-IDF | |
Democrat Richard Cordray will face Republican Mike DeWine in November. | |
Ohio state Sen. Troy Balderson now will face a Democrat in an Aug. 7 special election. | |
Republican Morrisey will face Sen. Joe Manchin, a conservative Democrat who has voted for the president's agenda 61 percent of the time. | |
Haspel looks all but assured to win confirmation in a vote before the full Senate. | |
"I win either way," second-place finisher Caleb Lee Hutchinson said. | |
5 most similar descriptions using Doc2Vec |
OlderNewer