-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
another change to attempt to fix 3.8
- Loading branch information
Showing
13 changed files
with
159 additions
and
137 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
""" CountingBloomFilter, python implementation | ||
License: MIT | ||
Author: Tyler Barrus ([email protected]) | ||
URL: https://github.com/barrust/counting_bloom | ||
"""CountingBloomFilter, python implementation | ||
License: MIT | ||
Author: Tyler Barrus ([email protected]) | ||
URL: https://github.com/barrust/counting_bloom | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from array import array | ||
from collections.abc import ByteString | ||
from pathlib import Path | ||
from struct import Struct | ||
from typing import Union | ||
|
||
from probables.blooms.bloom import BloomFilter | ||
from probables.constants import UINT32_T_MAX, UINT64_T_MAX | ||
|
@@ -18,7 +20,7 @@ | |
MISMATCH_MSG = "The parameter second must be of type CountingBloomFilter" | ||
|
||
|
||
def _verify_not_type_mismatch(second: "CountingBloomFilter") -> bool: | ||
def _verify_not_type_mismatch(second: CountingBloomFilter) -> bool: | ||
"""verify that there is not a type mismatch""" | ||
return isinstance(second, (CountingBloomFilter)) | ||
|
||
|
@@ -47,11 +49,11 @@ class CountingBloomFilter(BloomFilter): | |
|
||
def __init__( | ||
self, | ||
est_elements: Union[int, None] = None, | ||
false_positive_rate: Union[float, None] = None, | ||
filepath: Union[str, Path, None] = None, | ||
hex_string: Union[str, None] = None, | ||
hash_function: Union[HashFuncT, None] = None, | ||
est_elements: int | None = None, | ||
false_positive_rate: float | None = None, | ||
filepath: str | Path | None = None, | ||
hex_string: str | None = None, | ||
hash_function: HashFuncT | None = None, | ||
) -> None: | ||
"""setup the basic values needed""" | ||
self._filepath = None | ||
|
@@ -80,7 +82,7 @@ def _load_init(self, filepath, hash_function, hex_string, est_elements, false_po | |
_IMPT_STRUCT = Struct("I") | ||
|
||
@classmethod | ||
def frombytes(cls, b: ByteString, hash_function: Union[HashFuncT, None] = None) -> "CountingBloomFilter": | ||
def frombytes(cls, b: ByteString, hash_function: HashFuncT | None = None) -> CountingBloomFilter: | ||
""" | ||
Args: | ||
b (ByteString): the bytes to load as a Counting Bloom Filter | ||
|
@@ -207,7 +209,7 @@ def remove_alt(self, hashes: HashResultsT, num_els: int = 1) -> int: | |
self.elements_added -= to_remove | ||
return min_val - to_remove | ||
|
||
def intersection(self, second: "CountingBloomFilter") -> Union["CountingBloomFilter", None]: # type: ignore | ||
def intersection(self, second: CountingBloomFilter) -> CountingBloomFilter | None: # type: ignore | ||
"""Take the intersection of two Counting Bloom Filters | ||
Args: | ||
|
@@ -240,7 +242,7 @@ def intersection(self, second: "CountingBloomFilter") -> Union["CountingBloomFil | |
res.elements_added = res.estimate_elements() | ||
return res | ||
|
||
def jaccard_index(self, second: "CountingBloomFilter") -> Union[float, None]: # type:ignore | ||
def jaccard_index(self, second: CountingBloomFilter) -> float | None: # type:ignore | ||
"""Take the Jaccard Index of two Counting Bloom Filters | ||
Args: | ||
|
@@ -270,7 +272,7 @@ def jaccard_index(self, second: "CountingBloomFilter") -> Union[float, None]: # | |
return 1.0 | ||
return count_inter / count_union | ||
|
||
def union(self, second: "CountingBloomFilter") -> Union["CountingBloomFilter", None]: # type:ignore | ||
def union(self, second: CountingBloomFilter) -> CountingBloomFilter | None: # type:ignore | ||
"""Return a new Countiong Bloom Filter that contains the union of | ||
the two | ||
|
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
Oops, something went wrong.