diff --git a/CHANGELOG.md b/CHANGELOG.md index dd82478..ec0c52c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/probables/__init__.py b/probables/__init__.py index e186a5e..4ce2e52 100644 --- a/probables/__init__.py +++ b/probables/__init__.py @@ -11,7 +11,7 @@ __maintainer__ = 'Tyler Barrus' __email__ = 'barrust@gmail.com' __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' diff --git a/probables/blooms/basebloom.py b/probables/blooms/basebloom.py index 83053d3..1302dc6 100644 --- a/probables/blooms/basebloom.py +++ b/probables/blooms/basebloom.py @@ -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 ''' diff --git a/probables/blooms/bloom.py b/probables/blooms/bloom.py index 08d357e..4727076 100644 --- a/probables/blooms/bloom.py +++ b/probables/blooms/bloom.py @@ -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 ''' diff --git a/probables/blooms/countingbloom.py b/probables/blooms/countingbloom.py index 76cc009..df0b76a 100644 --- a/probables/blooms/countingbloom.py +++ b/probables/blooms/countingbloom.py @@ -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 ''' diff --git a/probables/countminsketch/countminsketch.py b/probables/countminsketch/countminsketch.py index 14918c5..9a5b0fb 100644 --- a/probables/countminsketch/countminsketch.py +++ b/probables/countminsketch/countminsketch.py @@ -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 ''' @@ -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, @@ -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, @@ -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): @@ -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): diff --git a/probables/cuckoo/__init__.py b/probables/cuckoo/__init__.py index c77757a..9ef6bfd 100644 --- a/probables/cuckoo/__init__.py +++ b/probables/cuckoo/__init__.py @@ -3,3 +3,5 @@ from . cuckoo import (CuckooFilter) from . countingcuckoo import (CountingCuckooFilter) + +__all__ = ['CuckooFilter', 'CountingCuckooFilter'] diff --git a/probables/cuckoo/countingcuckoo.py b/probables/cuckoo/countingcuckoo.py index e7fbc6f..a77056a 100644 --- a/probables/cuckoo/countingcuckoo.py +++ b/probables/cuckoo/countingcuckoo.py @@ -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): diff --git a/probables/cuckoo/cuckoo.py b/probables/cuckoo/cuckoo.py index d05a3bd..7fd2376 100644 --- a/probables/cuckoo/cuckoo.py +++ b/probables/cuckoo/cuckoo.py @@ -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): diff --git a/setup.cfg b/setup.cfg index 3c6e79c..a793a6f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,8 @@ [bdist_wheel] universal=1 + +[pep8] +max-line-length=120 + +[flake8] +max-line-length=120