forked from jaybaird/python-bloomfilter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re jaybaird#2, add changelog, union, intersection and copy to BloomFi…
…lter, not yet available in SBF. Bumped version number to 1.1
- Loading branch information
Showing
4 changed files
with
59 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Changes in 1.1 | ||
============== | ||
Added copy, intersection and union functions to BloomFilter |
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 |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
except ImportError: | ||
raise ImportError('pybloom requires bitarray >= 0.3.4') | ||
|
||
__version__ = '1.0.3' | ||
__version__ = '1.1' | ||
__author__ = "Jay Baird <[email protected]>, Bob Ippolito <[email protected]>,\ | ||
Marius Eriksen <[email protected]>, Alex Brassetvik <[email protected]>" | ||
|
||
|
@@ -187,6 +187,33 @@ def add(self, key, skip_check=False): | |
self.count += 1 | ||
return False | ||
|
||
def copy(self): | ||
"""Return a copy of this bloom filter. | ||
""" | ||
new_filter = BloomFilter(self.capacity, self.error_rate) | ||
new_filter.bitarray = self.bitarray.copy() | ||
return new_filter | ||
|
||
def union(self, other): | ||
""" Calculates the union of the two underlying bitarrays and returns | ||
a new bloom filter object.""" | ||
new_bloom = self.copy() | ||
new_bloom.bitarray = new_bloom.bitarray | other.bitarray | ||
return new_bloom | ||
|
||
def __or__(self, other): | ||
return self.union(other) | ||
|
||
def intersection(self, other): | ||
""" Calculates the union of the two underlying bitarrays and returns | ||
a new bloom filter object.""" | ||
new_bloom = self.copy() | ||
new_bloom.bitarray = new_bloom.bitarray & other.bitarray | ||
return new_bloom | ||
|
||
def __and__(self, other): | ||
return self.intersection(other) | ||
|
||
def tofile(self, f): | ||
"""Write the bloom filter to file object `f'. Underlying bits | ||
are written as machine values. This is much more space | ||
|
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