public class BitSetBloomFilter extends Object implements BloomFilter
| Constructor and Description |
|---|
BitSetBloomFilter(int c,
int n,
int k)
构造一个布隆过滤器,过滤器的容量为c * n 个bit
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(String text)
在boolean的bitMap中增加一个字符串
如果存在就返回
false如果不存在先增加这个字符串.再返回true |
boolean |
contains(String text)
判定是否包含指定字符串
|
static int[] |
createHashes(String text,
int hashNumber)
将字符串的字节表示进行多哈希编码
|
double |
getFalsePositiveProbability() |
static int |
hash(String text,
int k)
计算Hash值
|
void |
init(String path,
String charset)
通过文件初始化过滤器.
|
public BitSetBloomFilter(int c,
int n,
int k)
c - 当前过滤器预先开辟的最大包含记录,通常要比预计存入的记录多一倍n - 当前过滤器预计所要包含的记录k - 哈希函数的个数,等同每条记录要占用的bit数public static int[] createHashes(String text, int hashNumber)
text - 待添加进过滤器的字符串字节表示hashNumber - 要经过的哈希个数public static int hash(String text, int k)
text - 被计算Hash的字符串k - Hash算法序号public void init(String path, String charset) throws IOException
path - 文件路径charset - 字符集IOException - IO异常public boolean add(String text)
BloomFilterfalse如果不存在先增加这个字符串.再返回trueadd in interface BloomFiltertext - 字符串false如果不存在返回truepublic boolean contains(String text)
contains in interface BloomFiltertext - 字符串public double getFalsePositiveProbability()
Copyright © 2021. All rights reserved.