Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
'Refactored by Sourcery'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI committed Nov 27, 2023
1 parent 6798d1e commit 5200cdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
45 changes: 21 additions & 24 deletions fastBloomFilter/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def shannon_entropy(data, iterator=None):
def display(digest):
str_i = "Display: "
for i in digest:
str_i += str(i) + " "
str_i += f"{str(i)} "
sys.stderr.write(str_i)


Expand Down Expand Up @@ -157,7 +157,7 @@ def calc_hashid(self):
data = self.bfilter.tobytes()
self.hashid = self.hashfunc(data)
del data
sys.stderr.write("BLOOM: HASHID: %s\n" % self.hashid.hexdigest()[0:8])
sys.stderr.write("BLOOM: HASHID: %s\n" % self.hashid.hexdigest()[:8])

def _raw_merge(self, bfilter):
"""
Expand Down Expand Up @@ -197,14 +197,13 @@ def _hash(self, value):
# value = value.__str__() # Comment out line if you're filtering strings()
if self.do_hashes:
digest = int.from_bytes(self.hashfunc(value.encode("utf8")).digest(), "big")
elif self.data_is_hex:
digest = int(value, 16)
else:
if self.data_is_hex:
digest = int(value, 16)
else:
try:
digest = int(value.hex(), 16)
except:
digest = int(binascii.hexlify(value), 16)
try:
digest = int(value.hex(), 16)
except:
digest = int(binascii.hexlify(value), 16)
if self.fast:
yield (digest % self.bitcount)
else:
Expand Down Expand Up @@ -244,10 +243,7 @@ def _add(self, __hash):
# The purpose here is to spread out the hashes to create a unique
# hash with unique locations in the filter array,
# rather than just a big long hash blob.
if self.fast:
self.bitset += 1
else:
self.bitset += self.slices
self.bitset += 1 if self.fast else self.slices

def query(self, value):
"""
Expand Down Expand Up @@ -304,17 +300,18 @@ def load(self, filename):
return True

def save(self, filename = None):
if not self.saving:
if filename is None and self.filename is None:
sys.stderr.write("A Filename must be provided\n")
return False
else:
self.saving = True
if filename is not None:
self.filename = filename
compress_pickle(self.filename, self)
self.saving = False
return True
if self.saving:
return
if filename is None and self.filename is None:
sys.stderr.write("A Filename must be provided\n")
return False
else:
self.saving = True
if filename is not None:
self.filename = filename
compress_pickle(self.filename, self)
self.saving = False
return True

def stat(self):
if self.bitcalc:
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
author_email="[email protected]",
install_requires=[x.strip() for x in open("requirements.txt").readlines()],
url=BASE_CVS_URL,
download_url="{}/tarball/{}".format(BASE_CVS_URL, VERSION),
download_url=f"{BASE_CVS_URL}/tarball/{VERSION}",
test_suite="tests",
tests_require=[x.strip() for x in open("requirements_test.txt").readlines()],
tests_require=[
x.strip() for x in open("requirements_test.txt").readlines()
],
keywords=[],
classifiers=[
"Development Status :: 1 - Planning",
Expand Down

0 comments on commit 5200cdf

Please sign in to comment.