-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_function.cpp
More file actions
42 lines (29 loc) · 822 Bytes
/
hash_function.cpp
File metadata and controls
42 lines (29 loc) · 822 Bytes
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
41
/* This assignment originated at UC Riverside.*/
/**
* @file hash_function.cpp hashing function for our table.
*
* @brief
* Is the FNV-1a hashing function. Differs from the FNV-1 becuase of the order of the XOR and multiply step.
* It's a well known hash and is reliable (http://isthe.com/chongo/tech/comp/fnv/#history).
*
* REFERENCE:
* (http://isthe.com/chongo/tech/comp/fnv/)
*
* @author Clint Bettiga
* @date 11/08/13
*/
#include <string>
#include "hash.h"
using namespace std;
typedef unsigned int uint32;
#define FNV1_32A_INIT 0x811c9dc5
#define FNV_32_PRIME 0x01000193
int
Hash::hf ( string ins ) {
uint32 hval = FNV1_32A_INIT;
for(unsigned int i = 0; i < ins.length(); i++){
hval ^= (uint32)ins.at(i);
hval *= FNV_32_PRIME;
}
return hval % HASH_TABLE_SIZE;
}