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:
parent
55d3b7ec0c
commit
94acd49766
1 changed files with 16 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue