2022-08-26 04:06:34 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
namespace rage
|
|
|
|
{
|
|
|
|
using joaat_t = std::uint32_t;
|
2022-11-09 05:11:50 +08:00
|
|
|
inline constexpr char joaat_to_lower(char c)
|
2022-08-26 04:06:34 +08:00
|
|
|
{
|
2023-01-13 01:30:11 +08:00
|
|
|
return c >= 'A' && c <= 'Z' ? c | 1 << 5 : c;
|
2022-08-26 04:06:34 +08:00
|
|
|
}
|
|
|
|
|
2023-01-13 01:30:11 +08:00
|
|
|
inline constexpr joaat_t joaat(const std::string_view str)
|
2022-11-09 05:11:50 +08:00
|
|
|
{
|
|
|
|
joaat_t hash = 0;
|
2023-01-13 01:30:11 +08:00
|
|
|
for (auto c : str)
|
|
|
|
{
|
2022-11-09 05:11:50 +08:00
|
|
|
hash += joaat_to_lower(c);
|
|
|
|
hash += (hash << 10);
|
|
|
|
hash ^= (hash >> 6);
|
|
|
|
}
|
|
|
|
hash += (hash << 3);
|
|
|
|
hash ^= (hash >> 11);
|
|
|
|
hash += (hash << 15);
|
|
|
|
return hash;
|
|
|
|
}
|
2022-08-26 04:06:34 +08:00
|
|
|
};
|