Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SAMPLE HASH FUNCTIONS for SPELLER
- ----------------------
- // Hashes word to a number
- unsigned int hash(const char *word)
- {
- // djb2 hash function source:http://www.cse.yorku.ca/~oz/hash.html
- unsigned long x = 5381;
- while (*word)
- {
- x += (x << 5) + tolower(*word);
- word++;
- }
- return x % N;
- }
- -------------------------------
- // Hashes word to a number
- unsigned int hash(const char *word)
- {
- unsigned int hashing = 3581;
- for (int i = 0, n = strlen(word); i < n; i++)
- {
- hashing = (hashing << 2) ^ tolower(word[i]);
- }
- return hashing % N;
- }
- ----------------------------------------------------
- unsigned int hash(const char *word)
- {
- // 32-bit MurmurHash
- unsigned int h = 3323198485;
- while (*word)
- {
- h ^= tolower(*word);
- h *= 0x5bd1e995;
- h ^= h >> 15;
- word++;
- }
- return h % N;
- }
- -------------------------------
- // Hashes word to a number
- unsigned int hash(const char *word)
- {
- // String Folding source: https://opendsa-server.cs.vt.edu/
- unsigned int sum = 0;
- long factor = 1;
- int length = strlen(word);
- for (int i = 0; i < length; i++)
- {
- factor = i % 4 == 0 ? 1 : factor << 8;
- sum += tolower(word[i]) * factor;
- }
- return sum % N;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement