1 #ifndef ENTT_CORE_HASHED_STRING_HPP 2 #define ENTT_CORE_HASHED_STRING_HPP 21 struct ConstCharWrapper final {
23 constexpr ConstCharWrapper(
const char *str) noexcept: str{str} {}
27 static constexpr std::uint64_t offset = 14695981039346656037ull;
28 static constexpr std::uint64_t prime = 1099511628211ull;
31 static constexpr std::uint64_t helper(std::uint64_t partial,
const char *str) noexcept {
32 return str[0] == 0 ? partial : helper((partial^str[0])*prime, str+1);
53 template <std::
size_t N>
55 : hash{helper(offset, str)}, str{str}
65 : hash{helper(offset, wrapper.str)}, str{wrapper.str}
72 constexpr
operator const char *()
const noexcept {
return str; }
78 constexpr
operator hash_type() const noexcept {
return hash; }
86 return hash == other.hash;
102 return !(lhs == rhs);
109 #endif // ENTT_CORE_HASHED_STRING_HPP constexpr HashedString(ConstCharWrapper wrapper) noexcept
Explicit constructor on purpose to avoid constructing a hashed string directly from a const char *...
Zero overhead resource identifier.
constexpr HashedString(const char(&str)[N]) noexcept
Constructs a hashed string from an array of const chars.
std::uint64_t hash_type
Unsigned integer type.
constexpr bool operator!=(const HashedString &lhs, const HashedString &rhs) noexcept
Compares two hashed strings.
constexpr bool operator==(const HashedString &other) const noexcept
Compares two hashed strings.