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