forked from genetronhealth/uvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hash.hpp
41 lines (35 loc) · 894 Bytes
/
Hash.hpp
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
#ifndef Hashing_hpp_INLCUDED
#define Hashing_hpp_INLCUDED
#include "common.hpp"
template <class T>
inline
uvc1_hash_t
strnhash(const T *str, size_t n, const uvc1_hash_t base = 31UL) {
uvc1_hash_t ret = 0;
for (size_t i = 0; i < n && str[i]; i++) {
ret = ret * base + ((uvc1_hash_t)str[i]);
}
return ret;
}
template <class T>
inline
uvc1_hash_t
strnhash_rc(const T *str, size_t n, const uvc1_hash_t base = 31UL) {
uvc1_hash_t ret = 0;
for (size_t i = 0; i < n && str[i]; i++) {
ret = ret * base + STATIC_REV_COMPLEMENT.data[((uvc1_hash_t)str[n-i-(size_t)1])];
}
return ret;
}
template<class T>
inline
uvc1_hash_t
strhash(const T *str, const uvc1_hash_t base = 31UL) {
return strnhash(str, SIZE_MAX, base);
}
inline
uvc1_hash_t
hash2hash(uvc1_hash_t hash1, uvc1_hash_t hash2) {
return hash1 * ((1UL<<(31UL)) - 1UL) + hash2;
}
#endif