Move MurmurHash to beast

This commit is contained in:
Vinnie Falco
2013-10-25 15:36:07 -07:00
parent 31089931d3
commit dc591f8943
11 changed files with 63 additions and 38 deletions

View File

@@ -404,26 +404,42 @@ beast_wchar String::operator[] (int index) const noexcept
return text [index];
}
//------------------------------------------------------------------------------
namespace detail {
template <typename Type>
struct HashGenerator
{
template <typename CharPointer>
static Type calculate (CharPointer t) noexcept
{
Type result = Type();
while (! t.isEmpty())
result = multiplier * result + t.getAndAdvance();
return result;
}
enum { multiplier = sizeof (Type) > 4 ? 101 : 31 };
};
}
int String::hashCode() const noexcept
{
CharPointerType t (text);
int result = 0;
while (! t.isEmpty())
result = 31 * result + (int) t.getAndAdvance();
return result;
return detail::HashGenerator<int> ::calculate (text);
}
int64 String::hashCode64() const noexcept
{
CharPointerType t (text);
int64 result = 0;
return detail::HashGenerator<int64> ::calculate (text);
}
while (! t.isEmpty())
result = 101 * result + t.getAndAdvance();
return result;
std::size_t String::hash() const noexcept
{
return detail::HashGenerator<std::size_t>::calculate (text);
}
//==============================================================================