-
Notifications
You must be signed in to change notification settings - Fork 9
/
HashFunctions.h
49 lines (41 loc) · 1.88 KB
/
HashFunctions.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
41
42
43
44
45
46
47
48
49
// --------------------------------------------------------------------
// Various basic hash functions for strings and integers
// --------------------------------------------------------------------
#ifndef UTILS_HASH_FUNCTIONS
#define UTILS_HASH_FUNCTIONS
#include <tr1/cstdint>
#include <string>
namespace utils {
// --------------------------------------------------------------------
// Domagoj's hash functions
// --------------------------------------------------------------------
int inthash(const int key);
int64_t int64hash(const int64_t key);
int32_t int32hash(const int32_t key);
int64_t stringhash(const std::string& str);
// --------------------------------------------------------------------
// String hashing
// --------------------------------------------------------------------
unsigned int RSHash (const std::string& str);
unsigned int JSHash (const std::string& str);
// Method recommended in Aho, Sethi, Ullman book
unsigned int PJWHash (const std::string& str);
unsigned int ELFHash (const std::string& str);
unsigned int BKDRHash(const std::string& str);
unsigned int SDBMHash(const std::string& str);
unsigned int DJBHash (const std::string& str);
unsigned int DEKHash (const std::string& str);
unsigned int APHash (const std::string& str);
// Domagoj's simple hash - weighted sum of characters.
unsigned int DBHash (const std::string& str);
// Merge of PJW & DB hash, more efficient than using the two separately
int64_t PJWDBHash (const std::string& str);
// --------------------------------------------------------------------
// Integer hashing
// --------------------------------------------------------------------
int64_t TWLongHash (const int64_t key);
int64_t MULongHash (const int64_t key);
unsigned int RJHash (const unsigned int key);
unsigned int TWHash (const unsigned int key);
} // End of utils namespace
#endif // UTILS_HASH_FUNCTIONS