1 #ifndef ENTT_CORE_HASHED_STRING_HPP 2 #define ENTT_CORE_HASHED_STRING_HPP 7 #include "../config/config.h" 23 struct ConstCharWrapper final {
25 constexpr ConstCharWrapper(
const char *str) ENTT_NOEXCEPT: str{str} {}
29 static constexpr std::uint64_t offset = 14695981039346656037ull;
30 static constexpr std::uint64_t prime = 1099511628211ull;
33 static constexpr std::uint64_t helper(std::uint64_t partial,
const char *str) ENTT_NOEXCEPT {
34 return str[0] == 0 ? partial : helper((partial^str[0])*prime, str+1);
55 template<std::
size_t N>
57 : hash{helper(offset, str)}, str{str}
66 explicit constexpr
HashedString(ConstCharWrapper wrapper) ENTT_NOEXCEPT
67 : hash{helper(offset, wrapper.str)}, str{wrapper.str}
74 constexpr
operator const char *()
const ENTT_NOEXCEPT {
return str; }
80 constexpr
operator hash_type() const ENTT_NOEXCEPT {
return hash; }
88 return hash == other.hash;
104 return !(lhs == rhs);
116 constexpr
entt::HashedString operator"" ENTT_HS_SUFFIX(
const char *str, std::size_t) ENTT_NOEXCEPT {
121 #endif // ENTT_CORE_HASHED_STRING_HPP constexpr bool operator!=(const HashedString &lhs, const HashedString &rhs) ENTT_NOEXCEPT
Compares two hashed strings.
constexpr HashedString(ConstCharWrapper wrapper) ENTT_NOEXCEPT
Explicit constructor on purpose to avoid constructing a hashed string directly from a const char *...
constexpr bool operator==(const HashedString &other) const ENTT_NOEXCEPT
Compares two hashed strings.
Zero overhead resource identifier.
constexpr HashedString(const char(&str)[N]) ENTT_NOEXCEPT
Constructs a hashed string from an array of const chars.
std::uint64_t hash_type
Unsigned integer type.