mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-05-10 04:26:50 +03:00
Merge branch 'fnv_support' into 'master'
Use Fowler-Noll-Vo hash instead of std::hash See merge request OpenMW/openmw!2273
This commit is contained in:
commit
cdec6495aa
1 changed files with 10 additions and 3 deletions
|
@ -69,10 +69,17 @@ namespace Misc::StringUtils
|
||||||
{
|
{
|
||||||
using is_transparent = void;
|
using is_transparent = void;
|
||||||
|
|
||||||
std::size_t operator()(std::string_view str) const
|
constexpr std::size_t operator()(std::string_view str) const
|
||||||
{
|
{
|
||||||
// TODO avoid string copy
|
// FNV-1a
|
||||||
return std::hash<std::string>{}(lowerCase(str));
|
std::size_t hash{0xcbf29ce484222325ull};
|
||||||
|
constexpr std::size_t prime{0x00000100000001B3ull};
|
||||||
|
for(char c : str)
|
||||||
|
{
|
||||||
|
hash ^= static_cast<std::size_t>(toLower(c));
|
||||||
|
hash *= prime;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue