1 // This code belongs to the public domain.
7 * Hashing algorithm for strings from:
8 * Sedgewick's "Algorithms in C++, third edition"
9 * parts 1-4, Chapter 14 (hashing) p.593
11 * Modified to work on C++ string class objects by John Tsiombikas
13 unsigned int string_hash(const std::string &key, unsigned long size) {
14 int hash = 0, a = 31415, b = 27183;
15 char *str = new char[key.length() + 1];
16 strcpy(str, key.c_str());
21 hash = (a * hash + *sptr++) % size;
22 a = a * b % (size - 1);
27 return (unsigned int)(hash < 0 ? (hash + size) : hash);