1 #ifndef ENTT_CORE_HASHED_STRING_HPP 2 #define ENTT_CORE_HASHED_STRING_HPP 6 #include "../config/config.h" 26 struct fnv1a_traits<std::uint32_t> {
27 static constexpr std::uint32_t offset = 2166136261;
28 static constexpr std::uint32_t prime = 16777619;
33 struct fnv1a_traits<std::uint64_t> {
34 static constexpr std::uint64_t offset = 14695981039346656037ull;
35 static constexpr std::uint64_t prime = 1099511628211ull;
59 template<
typename Char>
61 using traits_type = internal::fnv1a_traits<ENTT_ID_TYPE>;
63 struct const_wrapper {
65 constexpr const_wrapper(
const Char *curr) ENTT_NOEXCEPT: str{curr} {}
70 static constexpr ENTT_ID_TYPE helper(ENTT_ID_TYPE partial,
const Char *curr) ENTT_NOEXCEPT {
71 return curr[0] == 0 ? partial : helper((partial^curr[0])*traits_type::prime, curr+1);
95 template<std::
size_t N>
97 return helper(traits_type::offset, str);
106 return helper(traits_type::offset, wrapper.str);
116 ENTT_ID_TYPE partial{traits_type::offset};
117 while(size--) { partial = (partial^(str++)[0])*traits_type::prime; }
123 : str{
nullptr}, hash{}
140 template<std::
size_t N>
142 : str{curr}, hash{helper(traits_type::offset, curr)}
151 : str{wrapper.str}, hash{helper(traits_type::offset, wrapper.str)}
174 constexpr
operator const value_type *()
const ENTT_NOEXCEPT {
return str; }
177 constexpr
operator hash_type() const ENTT_NOEXCEPT {
return hash; }
185 return hash == other.hash;
204 template<
typename Char, std::
size_t N>
216 template<
typename Char>
218 return !(lhs == rhs);
238 constexpr
entt::hashed_string operator"" ENTT_HS_SUFFIX(
const char *str, std::size_t) ENTT_NOEXCEPT {
248 constexpr
entt::hashed_wstring operator"" ENTT_HWS_SUFFIX(
const wchar_t *str, std::size_t) ENTT_NOEXCEPT {
253 #endif // ENTT_CORE_HASHED_STRING_HPP constexpr basic_hashed_string(const_wrapper wrapper) ENTT_NOEXCEPT
Explicit constructor on purpose to avoid constructing a hashed string directly from a const value_typ...
constexpr bool operator==(const basic_hashed_string &other) const ENTT_NOEXCEPT
Compares two hashed strings.
constexpr basic_hashed_string(const value_type(&curr)[N]) ENTT_NOEXCEPT
Constructs a hashed string from an array of const characters.
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) ENTT_NOEXCEPT
Compares two hashed strings.
Char value_type
Character type.
Zero overhead unique identifier.
basic_hashed_string(const Char(&str)[N]) ENTT_NOEXCEPT -> basic_hashed_string< Char >
Deduction guide.
static hash_type to_value(const value_type *str, std::size_t size) ENTT_NOEXCEPT
Returns directly the numeric representation of a string view.
constexpr hash_type value() const ENTT_NOEXCEPT
Returns the numeric representation of a hashed string.
constexpr basic_hashed_string() ENTT_NOEXCEPT
Constructs an empty hashed string.
constexpr const value_type * data() const ENTT_NOEXCEPT
Returns the human-readable representation of a hashed string.
static constexpr hash_type to_value(const value_type(&str)[N]) ENTT_NOEXCEPT
Returns directly the numeric representation of a string.
ENTT_ID_TYPE hash_type
Unsigned integer type.
static hash_type to_value(const_wrapper wrapper) ENTT_NOEXCEPT
Returns directly the numeric representation of a string.