Skip to content

Commit

Permalink
use __slots__; flake8 fixes (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrust authored Nov 7, 2018
1 parent 8f11f2b commit 9ad336c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# PyProbables Changelog

### Version 0.2.0
* Use __slots__

### Version 0.1.4:
* Drop support for python 3.3
* Ensure passing parameters correctly to parent classes
Expand Down
2 changes: 1 addition & 1 deletion probables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
__maintainer__ = 'Tyler Barrus'
__email__ = '[email protected]'
__license__ = 'MIT'
__version__ = '0.1.4'
__version__ = '0.2.0'
__credits__ = []
__url__ = 'https://github.com/barrust/pyprobables'
__bugtrack_url__ = 'https://github.com/barrust/pyprobables/issues'
Expand Down
7 changes: 7 additions & 0 deletions probables/blooms/basebloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

class BaseBloom(object):
''' basic bloom filter object '''

__slots__ = [
'_bloom', '__num_bits', '__est_elements', '__fpr',
'__number_hashes', '__hash_func', '_els_added', '_on_disk',
'__impt_type', '__blm_type', '__bloom_length'
]

def __init__(self, blm_type, est_elements=None, false_positive_rate=None,
filepath=None, hex_string=None, hash_function=None):
''' setup the basic values needed '''
Expand Down
2 changes: 2 additions & 0 deletions probables/blooms/bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class BloomFilter(BaseBloom):
2) From Hex String
3) From params '''

__slots__ = []

def __init__(self, est_elements=None, false_positive_rate=None,
filepath=None, hex_string=None, hash_function=None):
''' setup the basic values needed '''
Expand Down
3 changes: 3 additions & 0 deletions probables/blooms/countingbloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class CountingBloomFilter(BaseBloom):
1) From file
2) From Hex String
3) From params '''

__slots__ = BaseBloom.__slots__

def __init__(self, est_elements=None, false_positive_rate=None,
filepath=None, hex_string=None, hash_function=None):
''' setup the basic values needed '''
Expand Down
16 changes: 16 additions & 0 deletions probables/countminsketch/countminsketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class CountMinSketch(object):
For width and depth, width may realistically be in the thousands \
while depth is in the single digit to teens '''

__slots__ = [
'__width', '__depth', '__confidence', '__error_rate',
'__elements_added', '__query_method', '_bins', '_hash_function'
]

def __init__(self, width=None, depth=None, confidence=None,
error_rate=None, filepath=None, hash_function=None):
''' default initilization function '''
Expand Down Expand Up @@ -373,6 +378,9 @@ class CountMeanSketch(CountMinSketch):
Note:
For width and depth, width may realistically be in the thousands \
while depth is in the single digit to teens '''

__slots__ = CountMinSketch.__slots__

def __init__(self, width=None, depth=None, confidence=None,
error_rate=None, filepath=None, hash_function=None):
super(CountMeanSketch, self).__init__(width, depth, confidence,
Expand Down Expand Up @@ -406,6 +414,9 @@ class CountMeanMinSketch(CountMinSketch):
Note:
For width and depth, width may realistically be in the thousands \
while depth is in the single digit to teens '''

__slots__ = CountMinSketch.__slots__

def __init__(self, width=None, depth=None, confidence=None,
error_rate=None, filepath=None, hash_function=None):
super(CountMeanMinSketch, self).__init__(width, depth, confidence,
Expand Down Expand Up @@ -440,6 +451,9 @@ class HeavyHitters(CountMinSketch):
For width and depth, width may realistically be in the thousands \
while depth is in the single digit to teens '''

__slots__ = CountMinSketch.__slots__
__slots__.extend(['__top_x', '__top_x_size', '__num_hitters', '__smallest'])

def __init__(self, num_hitters=100, width=None, depth=None,
confidence=None, error_rate=None, filepath=None,
hash_function=None):
Expand Down Expand Up @@ -549,6 +563,8 @@ def clear(self):
class StreamThreshold(CountMinSketch):
''' keep track of those elements over a certain threshold '''

__slots__ = ['__threshold', '__meets_threshold']

def __init__(self, threshold=100, width=None, depth=None,
confidence=None, error_rate=None, filepath=None,
hash_function=None):
Expand Down
2 changes: 2 additions & 0 deletions probables/cuckoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

from . cuckoo import (CuckooFilter)
from . countingcuckoo import (CountingCuckooFilter)

__all__ = ['CuckooFilter', 'CountingCuckooFilter']
4 changes: 4 additions & 0 deletions probables/cuckoo/countingcuckoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class CountingCuckooFilter(CuckooFilter):
filename (str): The path to the file to load or None if no file
Returns:
CountingCuckooFilter: A Cuckoo Filter object '''

__slots__ = CuckooFilter.__slots__
__slots__.extend(['__unique_elements'])

def __init__(self, capacity=10000, bucket_size=4, max_swaps=500,
expansion_rate=2, auto_expand=True, finger_size=4,
filepath=None, hash_function=None):
Expand Down
7 changes: 7 additions & 0 deletions probables/cuckoo/cuckoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class CuckooFilter(object):
`hf(key)`
Returns:
CuckooFilter: A Cuckoo Filter object '''

__slots__ = [
'_bucket_size', '_cuckoo_capacity', '__max_cuckoo_swaps', '__expansion_rate',
'__auto_expand', '__fingerprint_size', '__hash_func', '_inserted_elements',
'_buckets'
]

def __init__(self, capacity=10000, bucket_size=4, max_swaps=500,
expansion_rate=2, auto_expand=True, finger_size=4,
filepath=None, hash_function=None):
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
[bdist_wheel]
universal=1

[pep8]
max-line-length=120

[flake8]
max-line-length=120

0 comments on commit 9ad336c

Please sign in to comment.