1 #ifndef ENTT_CORE_HASHED_STRING_HPP
2 #define ENTT_CORE_HASHED_STRING_HPP
7 #include "../config/config.h"
28 struct fnv1a_traits<std::uint32_t> {
29 using type = std::uint32_t;
30 static constexpr std::uint32_t offset = 2166136261;
31 static constexpr std::uint32_t prime = 16777619;
36 struct fnv1a_traits<std::uint64_t> {
37 using type = std::uint64_t;
38 static constexpr std::uint64_t offset = 14695981039346656037ull;
39 static constexpr std::uint64_t prime = 1099511628211ull;
63 template<
typename Char>
65 using traits_type = internal::fnv1a_traits<id_type>;
67 struct const_wrapper {
69 constexpr const_wrapper(
const Char *curr) ENTT_NOEXCEPT: str{curr} {}
74 [[nodiscard]]
static constexpr
id_type helper(
const Char *curr) ENTT_NOEXCEPT {
75 auto value = traits_type::offset;
78 value = (
value ^
static_cast<traits_type::type
>(*(curr++))) * traits_type::prime;
105 template<std::
size_t N>
116 return helper(wrapper.str);
126 id_type partial{traits_type::offset};
127 while(size--) { partial = (partial^(str++)[0])*traits_type::prime; }
133 : str{
nullptr}, hash{}
150 template<std::
size_t N>
152 : str{curr}, hash{helper(curr)}
161 : str{wrapper.str}, hash{helper(wrapper.str)}
181 [[nodiscard]] constexpr
operator const value_type *()
const ENTT_NOEXCEPT {
return data(); }
187 [[nodiscard]] constexpr
operator hash_type() const ENTT_NOEXCEPT {
return value(); }
195 return hash == other.hash;
214 template<
typename Char, std::
size_t N>
226 template<
typename Char>
228 return !(lhs == rhs);
248 [[nodiscard]] constexpr
entt::hashed_string operator"" ENTT_HS_SUFFIX(
const char *str, std::size_t) ENTT_NOEXCEPT {
258 [[nodiscard]] constexpr
entt::hashed_wstring operator"" ENTT_HWS_SUFFIX(
const wchar_t *str, std::size_t) ENTT_NOEXCEPT {