我正在尝试编写一个布隆过滤器来存储大约 80,000 个字符串......现在我猜测每个字符串可以是 2 个单词的长度。要存储 80,000 个字符串..我需要 80,000*2 = 16kBytes?
如果我必须存储 16kB = 16*1000*8 = 128,000 位,我至少需要 2^17=131,072 的位图。这就是我现在所拥有的
int main() {
char *str = "hello world";
int c = sizeof(unsigned char);
/*
* declare the bit array
*/
unsigned char bit_arr[128000/c];
/*
* couple of hash functions
*/
unsigned int bkd = bkdrhash(str, strlen(str));
unsigned int rsh = rshash(str, strlen(str));
unsigned int jsh = jshash(str, strlen(str));
/*
* logic to set bit
* Access the bitmap arr element
* And then set the required bits in that element
*/
bit_arr[bkd/c] & (1 << (bkd%c));
bit_arr[rsh/c] & (1 << (rsh%c));
bit_arr[jsh/c] & (1 << (jsh %c));
}
有没有更好/最佳的方法来做到这一点?
谢谢