1 #ifndef ENTT_CORE_HASHED_STRING_HPP
2 #define ENTT_CORE_HASHED_STRING_HPP
6 #include "../config/config.h"
22 struct fnv1a_traits<std::uint32_t> {
23 using type = std::uint32_t;
24 static constexpr std::uint32_t offset = 2166136261;
25 static constexpr std::uint32_t prime = 16777619;
29 struct fnv1a_traits<std::uint64_t> {
30 using type = std::uint64_t;
31 static constexpr std::uint64_t offset = 14695981039346656037ull;
32 static constexpr std::uint64_t prime = 1099511628211ull;
57 template<
typename Char>
59 using hs_traits = internal::fnv1a_traits<id_type>;
61 struct const_wrapper {
63 constexpr const_wrapper(
const Char *curr) ENTT_NOEXCEPT: str{curr} {}
68 [[nodiscard]]
static constexpr
id_type helper(
const Char *curr) ENTT_NOEXCEPT {
69 auto value = hs_traits::offset;
72 value = (
value ^
static_cast<hs_traits::type
>(*(curr++))) * hs_traits::prime;
91 id_type partial{hs_traits::offset};
92 while(size--) { partial = (partial ^ (str++)[0]) * hs_traits::prime; }
111 template<std::
size_t N>
122 return helper(wrapper.str);
144 template<std::
size_t N>
147 hash{helper(curr)} {}
160 hash{helper(wrapper.str)} {}
179 [[nodiscard]] constexpr
operator const value_type *()
const ENTT_NOEXCEPT {
187 [[nodiscard]] constexpr
operator hash_type() const ENTT_NOEXCEPT {
206 template<
typename Char, std::
size_t N>
216 template<
typename Char>
218 return lhs.value() == rhs.value();
228 template<
typename Char>
230 return !(lhs == rhs);
240 template<
typename Char>
242 return lhs.value() < rhs.value();
253 template<
typename Char>
266 template<
typename Char>
279 template<
typename Char>
290 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.
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.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
std::uint32_t id_type
Alias declaration for type identifiers.
constexpr bool operator<=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
constexpr bool operator>=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
constexpr bool operator<(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
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.
constexpr bool operator>(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.