forked from xtaci/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_code.h
More file actions
38 lines (35 loc) · 674 Bytes
/
Copy pathhash_code.h
File metadata and controls
38 lines (35 loc) · 674 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
#ifndef ALGO_HASH_CODE_H__
#define ALGO_HASH_CODE_H__
#include <string.h>
#include "hash_string.h"
namespace alg {
/**
* default compare funcs
*/
template<typename T>
struct hash_code {
uint32_t operator()(T) {
printf("must provide a hash function for _Key\n");
return 0;
}
};
template<>
struct hash_code<const char *> {
uint32_t operator()(const char* value) {
return hash_fnv1a(value, strlen(value));
}
};
template<>
struct hash_code<uint32_t> {
uint32_t operator()(uint32_t value) {
return value;
}
};
template<>
struct hash_code<int32_t> {
uint32_t operator()(int32_t value) {
return (uint32_t)value;
}
};
}
#endif //