-
Notifications
You must be signed in to change notification settings - Fork 0
/
BloomFilter.h
57 lines (48 loc) · 1.11 KB
/
BloomFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Created by 郑元庆 on 15/7/10.
// Copyright (c) 2015 郑元庆. All rights reserved.
//
#ifndef __BloomFilter_H_
#define __BloomFilter_H_
#include "BitList.h"
/**
* 布隆过滤器
*/
class BloomFilter
{
public:
/**
* size: 承载多少条记录
* count:使用多少次hash计算 1-8
*/
BloomFilter(unsigned long long size, size_t count);
~BloomFilter();
public:
/**
* 添加一条记录
*
* @param str 记录内容
*/
void add(const char* str);
/**
* 查询记录是否存在
*
* @param str 记录内容
*
* @return true(存在) or false(不存在)
*/
bool find(const char* str);
protected:
unsigned long long SDBMHash(const char *str);
unsigned long long RSHash(const char *str);
unsigned long long JSHash(const char *str);
unsigned long long PJWHash(const char *str);
unsigned long long BKDRHash(const char *str);
unsigned long long DJBHash(const char *str);
unsigned long long APHash(const char *str);
unsigned long long hash(const char *str);
private:
size_t _hash_count;
BitList _data;
};
#endif //__BloomFilter_H_