Created
May 30, 2020 01:09
-
-
Save vinniefalco/1db48a0c6ea4a3e18e4a2f0ff5180d02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// VFALCO temporarily needed until | |
// boost::string_view supports std::hash | |
struct hash | |
{ | |
std::size_t | |
operator()( | |
string_view s) const | |
{ | |
return (*this)(s, | |
std::integral_constant<bool, | |
(sizeof(std::size_t)>4)>{}); | |
} | |
std::uint64_t | |
operator()( | |
string_view s, | |
std::true_type) const | |
{ | |
unsigned char const* p = | |
reinterpret_cast< | |
unsigned char const*>( | |
s.data()); | |
unsigned char const* const e = | |
p + s.size(); | |
std::uint64_t h = | |
14695981039346656037u; | |
for (; p < e; ++p) | |
h = (h ^ *p) * | |
1099511628211u; | |
return h; | |
} | |
std::uint32_t | |
operator()( | |
string_view s, | |
std::false_type) const | |
{ | |
unsigned char const* p = | |
reinterpret_cast< | |
unsigned char const*>( | |
s.data()); | |
unsigned char const* const e = | |
p + s.size(); | |
std::uint32_t h = | |
2166136261; | |
for (; p < e; ++p) | |
h = (h ^ *p) * | |
16777619; | |
return h; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment