1、使用说明:
Help on class CountingBloomFilter in module bloompy:
class CountingBloomFilter(BloomFilter)
| CountingBloomFilter(error_rate=0.001, element_num=10000, bit_num=None)
|
| Method resolution order:
| CountingBloomFilter
| BloomFilter
| builtins.object
|
| Methods defined here:
|
| __init__(self, error_rate=0.001, element_num=10000, bit_num=None)
| Initialize self. See help(type(self)) for accurate signature.
|
| add(self, element)
| query the element status in the filter and add it into the filter
|
| copy(self)
|
| delete(self, element)
| query the element status in the filter and delete it from the filter
|
| exists(self, element)
|
| to_pack(self)
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| fromfile(path) from builtins.type
|
| ----------------------------------------------------------------------
| Methods inherited from BloomFilter:
|
| __and__(self, other)
|
| __contains__(self, item)
|
| __len__(self)
|
| __or__(self, other)
|
| tofile(self, path, mode='wb')
|
| ----------------------------------------------------------------------
| Data descriptors inherited from BloomFilter:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
None
2、示例:
import bloompy
cbf = bloompy.CountingBloomFilter(error_rate=0.001,element_num=10**3)
print("", cbf.add(12))
print("", cbf.exists(12))
# 将过滤器存储在一个文件里
cbf.tofile('filename.suffix')
# 从一个文件里恢复过滤器,自动识别过滤器的种类
recovered_bf = bloompy.get_filter_fromfile('filename.suffix')
print("recovered_bf:", recovered_bf)
# 或者使用过滤器类的类方法 'fromfile' 来进行过滤器的复原,对应的类只能恢复对应的过滤器
recovered_bf1 = bloompy.CountingBloomFilter.fromfile('你的文件存储路径/filename.suffix')
print("recovered_bf1:", recovered_bf1)
# 已插入的元素个数
print("cbf.count:", cbf.count)
# 过滤器的容量
print("cbf.capacity:", cbf.capacity)
# 过滤器的位向量
print("cbf.bit_array:", cbf.bit_array)
# 过滤器位数组长度
print("cbf.bit_num:", cbf.bit_num)
# 过滤器的哈希种子,默认是素数
print("cbf.seeds:", cbf.seeds)
print("len(cbf.seeds):", len(cbf.seeds))
# 过滤器哈希函数个数
print("cbf.hash_num:", cbf.hash_num)
标签:__,cbf,示例,self,bloompy,过滤器,num,print,CountingBloomFilter From: https://blog.csdn.net/2201_75392924/article/details/143814921