-
Notifications
You must be signed in to change notification settings - Fork 12
/
WordsTest.h
40 lines (40 loc) · 1.16 KB
/
WordsTest.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
#include "Stats.h"
#include <iostream>
#include <fstream>
template < typename hashtype >
bool WordsTest( hashfunc<hashtype> hash, double confidence) {
std::vector<hashtype> hashes;
std::set<std::string> words;
std::set<std::string>::iterator it;
std::string line;
std::string filename= "/usr/share/dict/words";
int count= 0;
int lines= 0;
Rand r(82762);
hash.seed_state_rand(r);
std::ifstream wordfile (filename.c_str());
if (!wordfile.is_open())
{
std::cout << "Unable to open word file " << filename << "\n";
exit(1);
}
while ( getline (wordfile,line) )
{
lines++;
words.insert(line);
line.append("!");
words.insert(line);
line.append("!");
words.insert(line);
}
wordfile.close();
hashes.resize(words.size());
for ( it = words.begin(); it != words.end(); it++ )
{
line = *it;
hash(line.c_str(),line.length(),&hashes[count++]);
}
printf("# Hashed %d keys from %d words from file '%s'\n",
count, lines, filename.c_str());
return TestHashList<hashtype>(hashes,true,confidence,false,"Keyset 'Words'");
}