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;
97 id_type partial{traits_type::offset};
98 while(size--) { partial = (partial^(str++)[0])*traits_type::prime; }
117 template<std::
size_t N>
128 return helper(wrapper.str);
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);
240 inline namespace literals {
Zero overhead unique identifier.
constexpr basic_hashed_string(const value_type(&curr)[N])
Constructs a hashed string from an array of const characters.
id_type hash_type
Unsigned integer type.
constexpr const value_type * data() const
Returns the human-readable representation of a hashed string.
static hash_type value(const_wrapper wrapper)
Returns directly the numeric representation of a string.
constexpr hash_type value() const
Returns the numeric representation of a hashed string.
constexpr basic_hashed_string(const_wrapper wrapper)
Explicit constructor on purpose to avoid constructing a hashed string directly from a const value_typ...
static constexpr hash_type value(const value_type(&str)[N])
Returns directly the numeric representation of a string.
constexpr basic_hashed_string()
Constructs an empty hashed string.
constexpr bool operator==(const basic_hashed_string &other) const
Compares two hashed strings.
static constexpr hash_type value(const value_type *str, std::size_t size)
Returns directly the numeric representation of a string view.
Char value_type
Character type.
std::uint32_t id_type
Alias declaration for type identifiers.
basic_hashed_string(const Char(&str)[N]) -> basic_hashed_string< Char >
Deduction guide.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.