2023-08-27 03:12:04 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
namespace rage
|
|
|
|
{
|
|
|
|
using joaat_t = std::uint32_t;
|
2024-07-16 09:59:37 +08:00
|
|
|
inline constexpr char JoaatToLower(char c)
|
2023-08-27 03:12:04 +08:00
|
|
|
{
|
|
|
|
return c >= 'A' && c <= 'Z' ? c | 1 << 5 : c;
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:59:37 +08:00
|
|
|
inline constexpr joaat_t Joaat(const std::string_view str)
|
2023-08-27 03:12:04 +08:00
|
|
|
{
|
|
|
|
joaat_t hash = 0;
|
|
|
|
for (auto c : str)
|
|
|
|
{
|
2024-07-16 09:59:37 +08:00
|
|
|
hash += JoaatToLower(c);
|
2023-08-27 03:12:04 +08:00
|
|
|
hash += (hash << 10);
|
|
|
|
hash ^= (hash >> 6);
|
|
|
|
}
|
|
|
|
hash += (hash << 3);
|
|
|
|
hash ^= (hash >> 11);
|
|
|
|
hash += (hash << 15);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
};
|