0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 13:48:53 +02:00

ircd::util: Obligatory bernstein hash.

This commit is contained in:
Jason Volk 2016-09-05 15:24:06 -07:00
parent 55d3b7ec0c
commit 94acd49766

View file

@ -254,6 +254,22 @@ operator!(const std::string &str)
return str.empty();
}
constexpr size_t
hash(const char *const &str,
const size_t i = 0)
{
return !str[i]? 7681ULL : (hash(str, i+1) * 33ULL) ^ str[i];
}
inline size_t
hash(const std::string &str,
const size_t i = 0)
{
return i >= str.size()? 7681ULL : (hash(str, i+1) * 33ULL) ^ str.at(i);
}
} // namespace util
} // namespace ircd
#endif // __cplusplus