Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinniefalco/1db48a0c6ea4a3e18e4a2f0ff5180d02 to your computer and use it in GitHub Desktop.
Save vinniefalco/1db48a0c6ea4a3e18e4a2f0ff5180d02 to your computer and use it in GitHub Desktop.
// 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