This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/gta/joaat.hpp
tupoy-ya 1087146e56
refactor!: Replace premake5 with CMake. (#551)
Co-authored-by: tupoy-ya <tupoy-ya@users.noreply.github.com>
2022-11-08 21:08:58 +00:00

33 lines
890 B
C++

#pragma once
#include <cstddef>
#include <cstdint>
#include <string_view>
#include <type_traits>
#include "rage/joaat.hpp"
namespace rage
{
template <std::size_t CharCount>
struct constexpr_joaat {
char data[CharCount];
template <std::size_t... Indices>
constexpr constexpr_joaat(const char *str, std::index_sequence<Indices...>) : data{ (str[Indices])... } {}
constexpr joaat_t operator()()
{
joaat_t hash = 0;
for (std::size_t i = 0; i < CharCount; ++i) {
hash += joaat_to_lower(data[i]);
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash;
}
};
}
#define RAGE_JOAAT_IMPL(str) (::rage::constexpr_joaat<sizeof(str) - 1>((str), std::make_index_sequence<sizeof(str) - 1>())())
#define RAGE_JOAAT(str) (std::integral_constant<rage::joaat_t, RAGE_JOAAT_IMPL(str)>::value)