📄 elfhash.cpp
字号:
#include<fstream>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const int M = 86423;
string infile[] = {"en-only.dic", "en_US-only.dic", "en_GB-only.dic", "en_CA-only.dic"};
inline int elfhash(const char *key){
unsigned long h=0;
while (*key){
h=(h<<4) + *key++;
unsigned long g=h & 0Xf0000000L;
if (g) h^= g>>24;
h &= ~g;
}
return h % M;
}
int n, count;
vector<string> hash[M+1];
void update(const string &s, int key){
vector<string> &slot = hash[key];
int size = slot.size();
for (int i=0;i<size;++i){
count++;
if (slot[i] == s) return;
}
slot.push_back(s);
}
int main(){
string s;
for (int i=0;i<1;++i){
ifstream fin(infile[i].c_str());
while (fin>>s) {
n++;
update(s, elfhash(s.c_str()));
}
}
printf("%.4lf\n", double(count)/n);
int cover =0;
for (int i = 0;i< M;++i)
cover += (!hash[i].empty());
cout<<cover<<endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -