资源简介
Bloom Filter的原理与C++实现,并利用Bloom Filter实现简单的词典,进行字词查询
代码片段和文件信息
#include
#include “BitSet.h“
#include “Hash.h“
int main()
{
bitSet st(8388608);
FILE *fp1 = fopen(“Dictionary.txt““r“);
if( fp1 == NULL)
{
printf(“打开文件失败!\n“);
return -1;
}
char word[20];
fscanf(fp1“%20s“word);
while( !feof(fp1))
{
st.putMember(RSHash(word)1);
st.putMember(JSHash(word)1);
st.putMember(PJWHash(word)1);
st.putMember(ELFHash(word)1);
st.putMember(BKDRHash(word)1);
st.putMember(SDBMHash(word)1);
st.putMember(DJBHash(word)1);
st.putMember(APHash(word)1);
fscanf(fp1“%20s“word);
}
fclose(fp1);
int count = 0;
FILE *fp2 = fopen(“MyFile.txt““r“);
if( fp2 == NULL)
{
printf(“打开文件失败!\n“);
return -1;
}
char *temp = new char[20];
fscanf(fp2“%20s“word);
temp = word;
while( !feof(fp2))
{
if(st.getMember(RSHash(temp)) != 1 ||
st.getMember(JSHash(temp)) != 1 ||
st.getMember(PJWHash(temp)) != 1 ||
st.getMember(ELFHash(temp)) != 1 ||
st.getMember(BKDRHash(temp)) != 1 ||
st.getMember(SDBMHash(temp)) != 1 ||
st.getMember(DJBHash(temp)) != 1 ||
st.getMember(APHash(temp)) != 1)
{
count++;
cout< }
fscanf(fp2“%20s“word);
temp = word;
}
fclose(fp2);
cout< return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 549 2010-12-05 23:17 Bloom Filter\Bloom Filter.dsw
文件 50176 2010-12-08 00:52 Bloom Filter\Bloom Filter.ncb
文件 50176 2010-12-08 00:13 Bloom Filter\Debug\vc60.idb
文件 61440 2010-12-08 00:09 Bloom Filter\Debug\vc60.pdb
文件 300524 2010-12-08 00:09 Bloom Filter\Debug\Bloom Filter.pch
文件 19215 2010-12-08 00:09 Bloom Filter\Debug\main.obj
文件 242564 2010-12-08 00:09 Bloom Filter\Debug\Bloom Filter.ilk
文件 204904 2010-12-08 00:09 Bloom Filter\Debug\Bloom Filter.exe
文件 435200 2010-12-08 00:09 Bloom Filter\Debug\Bloom Filter.pdb
文件 13085 2010-12-06 15:01 Bloom Filter\Debug\Bloom Filter.obj
文件 43520 2010-12-07 21:40 Bloom Filter\Debug\Bloom Filter.opt
文件 917 2010-12-08 00:09 Bloom Filter\Bloom Filter.plg
文件 31250 2010-12-08 00:13 Bloom Filter\Dictionary.txt
文件 4462 2010-12-06 15:07 Bloom Filter\Bloom Filter.dsp
文件 7888 2010-12-07 21:20 Bloom Filter\MyFile.txt
文件 3424 2010-12-07 21:35 Bloom Filter\Hash.h
文件 1611 2010-12-07 22:34 Bloom Filter\BitSet.h
文件 1410 2010-12-07 23:38 Bloom Filter\main.cpp
文件 48640 2010-12-08 00:52 Bloom Filter\Bloom Filter.opt
目录 0 2010-12-05 23:17 Bloom Filter\Debug
目录 0 2010-12-05 23:17 Bloom Filter
----------- --------- ---------- ----- ----
1520955 21
评论
共有 条评论