-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chg: [library] bloomfilter absclass, checking entries againt PSS files
- Loading branch information
1 parent
4cd2545
commit 874f8de
Showing
4 changed files
with
168 additions
and
14 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,28 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
class BloomFilterBase(ABC): | ||
@abstractmethod | ||
def __init__(self, parameters): | ||
"""Initialize the Bloom filter with given parameters.""" | ||
loaded = False | ||
pass | ||
|
||
@abstractmethod | ||
def add(self, data): | ||
"""Add data to the Bloom filter.""" | ||
pass | ||
|
||
@abstractmethod | ||
def check(self, data): | ||
"""Load a Bloom filter from file.""" | ||
pass | ||
|
||
@abstractmethod | ||
def load(self, data): | ||
"""Load a Bloom filter from file.""" | ||
pass | ||
|
||
@abstractmethod | ||
def write(self): | ||
"""Write the serialized bloom filter to a file descriptor.""" | ||
pass |
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,26 @@ | ||
from flor import BloomFilter | ||
from private_search_set.bloom_filter_base import BloomFilterBase | ||
|
||
class BloomFilterDCSO(BloomFilterBase): | ||
def __init__(self, parameters): | ||
super().__init__(parameters) | ||
self.bf = BloomFilter(n=parameters['capacity'], p=parameters['fp-probability']) | ||
|
||
def add(self, data): | ||
self.bf.add(data) | ||
pass | ||
|
||
def check(self, data): | ||
return data in self.bf | ||
|
||
def load(self, fd): | ||
self.bf.read(fd) | ||
if self.bf.N == 0: | ||
self.loaded = False | ||
else: | ||
self.loaded = True | ||
pass | ||
|
||
def write(self, fd): | ||
self.bf.write(fd) | ||
pass |
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