Skip to content

Commit a259242

Browse files
authored
v0.5.5 (#97)
* remove unnecessary int casts * remove unnecessary float casts * more pylint requests * version bump
1 parent 43973f9 commit a259242

File tree

10 files changed

+32
-21
lines changed

10 files changed

+32
-21
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ max-attributes=20
349349
min-public-methods=2
350350

351351
# Maximum number of public methods for a class (see R0904).
352-
max-public-methods=20
352+
max-public-methods=25
353353

354354
# Maximum number of boolean expressions in a if statement
355355
max-bool-expr=5

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# PyProbables Changelog
22

3+
### Version 0.5.5
4+
* Bloom Filters:
5+
* Re-implemented the entire Bloom Filter data structure to reduce complexity and code duplication
6+
* Removed un-unsed imports
7+
* Removed unnecessary casts
8+
* Pylint Requested Style Changes:
9+
* Use python 3 `super()`
10+
* Use python 3 classes
11+
* Remove use of temporary variables if possible and still clear
12+
313
### Version 0.5.4
414
* All Probablistic Data Structures:
515
* Added ability to load each `frombytes()`

probables/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
__maintainer__ = "Tyler Barrus"
2828
__email__ = "[email protected]"
2929
__license__ = "MIT"
30-
__version__ = "0.5.4"
30+
__version__ = "0.5.5"
3131
__credits__ = [] # type: ignore
3232
__url__ = "https://github.com/barrust/pyprobables"
3333
__bugtrack_url__ = "https://github.com/barrust/pyprobables/issues"

probables/blooms/bloom.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" BloomFilter, python implementation
1+
""" BloomFilter and BloomFiter on Disk, python implementation
22
License: MIT
33
Author: Tyler Barrus ([email protected])
44
URL: https://github.com/barrust/bloom
@@ -243,9 +243,9 @@ def add_alt(self, hashes: HashResultsT) -> None:
243243
Args:
244244
hashes (list): A list of integers representing the key to insert"""
245245
for i in range(0, self._number_hashes):
246-
k = int(hashes[i]) % self._num_bits
246+
k = hashes[i] % self._num_bits
247247
idx = k // 8
248-
self._bloom[idx] = int(self._bloom[idx]) | int((1 << (k % 8)))
248+
self._bloom[idx] = self._bloom[idx] | (1 << (k % 8))
249249
self._els_added += 1
250250

251251
def check(self, key: KeyT) -> bool:
@@ -364,7 +364,7 @@ def current_false_positive_rate(self) -> float:
364364
Return:
365365
float: The current false positive rate"""
366366
num = self.number_hashes * -1 * self.elements_added
367-
dbl = num / float(self.number_bits)
367+
dbl = num / self.number_bits
368368
exp = math.exp(dbl)
369369
return math.pow((1 - exp), self.number_hashes)
370370

@@ -483,21 +483,21 @@ def _get_optimized_params(cls, estimated_elements: int, false_positive_rate: flo
483483
if number_hashes == 0:
484484
raise InitializationError("Bloom: Number hashes is zero; unusable parameters provided")
485485

486-
return t_fpr, number_hashes, int(m_bt)
486+
return t_fpr, number_hashes, m_bt
487487

488488
def _set_values(
489489
self, est_els: int, fpr: float, n_hashes: int, n_bits: int, hash_func: Union[HashFuncT, None]
490490
) -> None:
491-
self._est_elements = int(est_els)
492-
self._fpr = float(fpr)
493-
self._bloom_length = int(math.ceil(n_bits / self._bits_per_elm))
491+
self._est_elements = est_els
492+
self._fpr = fpr
493+
self._bloom_length = math.ceil(n_bits / self._bits_per_elm)
494494
if hash_func is not None:
495495
self._hash_func = hash_func
496496
else:
497497
self._hash_func = default_fnv_1a
498498
self._els_added = 0
499-
self._number_hashes = int(n_hashes)
500-
self._num_bits = int(n_bits)
499+
self._number_hashes = n_hashes
500+
self._num_bits = n_bits
501501

502502
def _load_hex(self, hex_string: str, hash_function: Union[HashFuncT, None] = None) -> None:
503503
"""placeholder for loading from hex string"""

probables/blooms/countingbloom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def __init__(
5757
self._on_disk = False
5858
self._type = "counting"
5959
self._typecode = "I"
60+
self._els_added = 0
6061
if is_valid_file(filepath):
6162
self._load(filepath, hash_function)
6263
elif is_hex_string(hex_string):
@@ -205,7 +206,7 @@ def remove_alt(self, hashes: HashResultsT, num_els: int = 1) -> int:
205206
min_val = min(vals)
206207
if min_val == UINT32_T_MAX: # cannot remove if we have hit the max
207208
return UINT32_T_MAX
208-
elif min_val == 0:
209+
if min_val == 0:
209210
return 0
210211

211212
to_remove = num_els if min_val > num_els else min_val

probables/blooms/expandingbloom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" BloomFilter, python implementation
1+
""" Expanding and Rotating BloomFilter, python implementations
22
License: MIT
33
Author: Tyler Barrus ([email protected])
44
URL: https://github.com/barrust/pyprobables
@@ -17,7 +17,7 @@
1717
from .bloom import BloomFilter
1818

1919

20-
class ExpandingBloomFilter(object):
20+
class ExpandingBloomFilter:
2121
"""Simple expanding Bloom Filter implementation for use in python; the
2222
Bloom Fiter will automatically expand, or grow, if the false
2323
positive rate is about to become greater than the desired false
@@ -55,7 +55,7 @@ def __init__(
5555
self.__fpr = false_positive_rate
5656
self.__est_elements = est_elements
5757
self.__hash_func = hash_function
58-
self._added_elements = int(0) # total added...
58+
self._added_elements = 0 # total added...
5959

6060
if is_valid_file(filepath):
6161
self.__load(filepath)

probables/countminsketch/countminsketch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Count-Min Sketch python implementation
1+
""" Count-Min Sketch, Heavy Hitters, and Stream Threshold, python implementations
22
License: MIT
33
Author: Tyler Barrus ([email protected])
44
URL: https://github.com/barrust/count-min-sketch

probables/cuckoo/countingcuckoo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def __bucket_decomposition(buckets, bucket_size: int):
351351
return arr
352352

353353

354-
class CountingCuckooBin(object):
354+
class CountingCuckooBin:
355355
"""A container class for the counting cuckoo filter"""
356356

357357
# keep it lightweight

probables/cuckoo/cuckoo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def expansion_rate(self) -> int:
243243
@expansion_rate.setter
244244
def expansion_rate(self, val: int):
245245
"""set the self expand value"""
246-
self.__expansion_rate = int(val)
246+
self.__expansion_rate = val
247247

248248
@property
249249
def error_rate(self) -> float:
@@ -278,7 +278,7 @@ def fingerprint_size(self) -> int:
278278
@fingerprint_size.setter
279279
def fingerprint_size(self, val: int):
280280
"""set the fingerprint size"""
281-
tmp = int(val)
281+
tmp = val
282282
if not 1 <= tmp <= 4:
283283
msg = ("{}: fingerprint size must be between 1 and 4").format(self.__class__.__name__)
284284
raise ValueError(msg)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyprobables"
3-
version = "0.5.4"
3+
version = "0.5.5"
44
description = "Probabilistic data structures in Python"
55
authors = ["Tyler Barrus <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)