1 #ifndef ENTT_CORE_HASHED_STRING_HPP 2 #define ENTT_CORE_HASHED_STRING_HPP 22 struct ConstCharWrapper final {
24 constexpr ConstCharWrapper(
const char *str) noexcept: str{str} {}
28 static constexpr std::uint64_t offset = 14695981039346656037ull;
29 static constexpr std::uint64_t prime = 1099511628211ull;
32 static constexpr std::uint64_t helper(std::uint64_t partial,
const char *str) noexcept {
33 return str[0] == 0 ? partial : helper((partial^str[0])*prime, str+1);
54 template <std::
size_t N>
56 : hash{helper(offset, str)}, str{str}
66 : hash{helper(offset, wrapper.str)}, str{wrapper.str}
73 constexpr
operator const char *()
const noexcept {
return str; }
79 constexpr
operator hash_type() const noexcept {
return hash; }
87 return hash == other.hash;
103 return !(lhs == rhs);
110 #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.