diff --git a/kernel/hashlib.h b/kernel/hashlib.h index a1dffdaee..4ed1a5605 100644 --- a/kernel/hashlib.h +++ b/kernel/hashlib.h @@ -54,9 +54,9 @@ namespace hashlib { const int hashtable_size_trigger = 2; const int hashtable_size_factor = 3; -#define DJB2_BROKEN_SIZE +#define DJB2_32 + -#ifdef DJB2_BROKEN_SIZE template struct hash_ops; @@ -76,8 +76,13 @@ inline unsigned int mkhash_xorshift(unsigned int a) { } class Hasher { - public: //TODO + public: + #ifdef DJB2_32 using hash_t = uint32_t; + #endif + #ifdef DJB2_64 + using hash_t = uint64_t; + #endif Hasher() { // traditionally 5381 is used as starting value for the djb2 hash @@ -128,7 +133,6 @@ class Hasher { } }; -#endif template struct hash_ops { @@ -201,6 +205,17 @@ template struct hash_ops> { } }; +template struct hash_ops> { + static inline bool cmp(std::array a, std::array b) { + return a == b; + } + static inline Hasher hash_acc(std::array a, Hasher h) { + for (const auto& k : a) + h = hash_ops::hash_acc(k, h); + return h; + } +}; + struct hash_cstr_ops { static inline bool cmp(const char *a, const char *b) { for (int i = 0; a[i] || b[i]; i++)