File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,32 @@ SOFTWARE.
28
28
29
29
#include < stdint.h>
30
30
31
+ #ifdef __cplusplus
32
+ #include < concepts>
33
+
34
+ namespace djb {
35
+
36
+ template <std::integral T = uint32_t >
37
+ static inline constexpr T process (T hash, const char str[], unsigned n) {
38
+ return n ? process (((hash << 5 ) + hash) ^ static_cast <uint8_t >(str[0 ]), str + 1 , n - 1 ) : hash;
39
+ }
40
+
41
+ template <std::integral T = uint32_t >
42
+ static inline T constexpr hash (const char * str, unsigned n) {
43
+ return process (T (5381 ), str, n);
44
+ }
45
+
46
+ template <std::integral T = uint32_t , unsigned S>
47
+ static inline T constexpr hash (const char (&str)[S]) {
48
+ return process (T (5381 ), str, S - 1 );
49
+ }
50
+
51
+ } // namespace djb
52
+
53
+ #endif
54
+
31
55
static inline uint32_t djbProcess (uint32_t hash, const char str[], unsigned n) {
32
- return n ? djbProcess (((hash << 5 ) + hash ) ^ str [0 ], str + 1 , n - 1 ) : hash ;
56
+ return n ? djbProcess (((hash << 5 ) + hash) ^ (( uint8_t ) str[0 ]) , str + 1 , n - 1 ) : hash;
33
57
}
34
58
35
59
static inline uint32_t djbHash (const char * str, unsigned n) { return djbProcess (5381 , str, n); }
You can’t perform that action at this time.
0 commit comments