#include #include using namespace std; const int hashsize = 60000; unsigned int hash(string s) { unsigned int h = 278364; int len = s.length(); for (int i = 0; i < len; i += 1) h = h * 69 + s[i]; return h % hashsize; } int main() { ifstream fd("/home/www/class/een318/namesonly.txt", ios::in); if (fd.fail()) { cerr << "didn't work\n"; exit(1); } int * h = new int[hashsize]; for (int i=0; i= hashsize) hashpos = 0; if (hashpos == origpos) { cerr << "Hash table full\n"; exit(1); } } /* cout << filepos << ": " << line << " (" << state << ")\n"; */ } fd.close(); ofstream fi("index.dat", ios::out | ios::binary | ios::trunc); if (fi.fail()) { cerr << "creating file didn't work\n"; exit(1); } fi.write((char *)h, hashsize * sizeof(* h)); if (fi.fail()) { cerr << "writing table didn't work\n"; exit(1); } cout << "file position is " << fi.tellp() << "\n"; fi.close(); }