1#ifndef ENTT_CORE_HASHED_STRING_HPP
2#define ENTT_CORE_HASHED_STRING_HPP
13template<
typename =
id_type>
17struct fnv_1a_params<std::uint32_t> {
18 static constexpr auto offset = 2166136261;
19 static constexpr auto prime = 16777619;
23struct fnv_1a_params<std::uint64_t> {
24 static constexpr auto offset = 14695981039346656037ull;
25 static constexpr auto prime = 1099511628211ull;
28template<
typename Char>
30 using value_type = Char;
31 using size_type = std::size_t;
34 const value_type *repr{};
35 hash_type hash{fnv_1a_params<>::offset};
57template<
typename Char>
59 using base_type = internal::basic_hashed_string<Char>;
60 using params = internal::fnv_1a_params<>;
62 struct const_wrapper {
64 constexpr const_wrapper(
const typename base_type::value_type *str) noexcept
67 const typename base_type::value_type *repr;
94 template<std::
size_t N>
122 for(; base_type::length < len; ++base_type::length) {
123 base_type::hash = (base_type::hash ^
static_cast<id_type>(str[base_type::length])) * params::prime;
133 template<std::
size_t N>
138 for(; str[base_type::length]; ++base_type::length) {
139 base_type::hash = (base_type::hash ^
static_cast<id_type>(str[base_type::length])) * params::prime;
153 : base_type{wrapper.repr} {
155 for(; wrapper.repr[base_type::length]; ++base_type::length) {
156 base_type::hash = (base_type::hash ^
static_cast<id_type>(wrapper.repr[base_type::length])) * params::prime;
166 return base_type::length;
174 return base_type::repr;
182 return base_type::hash;
186 [[nodiscard]]
explicit constexpr operator const value_type *()
const noexcept {
194 [[nodiscard]]
constexpr operator hash_type() const noexcept {
205template<
typename Char>
214template<
typename Char, std::
size_t N>
225template<
typename Char>
227 return lhs.value() == rhs.value();
237template<
typename Char>
239 return !(lhs == rhs);
249template<
typename Char>
251 return lhs.value() < rhs.value();
262template<
typename Char>
275template<
typename Char>
288template<
typename Char>
293inline namespace literals {
300[[nodiscard]] ENTT_CONSTEVAL
hashed_string operator""_hs(
const char *str, std::size_t)
noexcept {
309[[nodiscard]] ENTT_CONSTEVAL
hashed_wstring operator""_hws(
const wchar_t *str, std::size_t)
noexcept {
Zero overhead unique identifier.
typename base_type::value_type value_type
constexpr const value_type * data() const noexcept
Returns the human-readable representation of a hashed string.
constexpr hash_type value() const noexcept
Returns the numeric representation of a hashed string.
typename base_type::size_type size_type
static constexpr hash_type value(const value_type(&str)[N]) noexcept
Returns directly the numeric representation of a string.
static constexpr hash_type value(const_wrapper wrapper) noexcept
Returns directly the numeric representation of a string.
typename base_type::hash_type hash_type
constexpr basic_hashed_string(const value_type *str, const size_type len) noexcept
Constructs a hashed string from a string view.
constexpr basic_hashed_string(const value_type(&str)[N]) noexcept
Constructs a hashed string from an array of const characters.
constexpr size_type size() const noexcept
Returns the size of a hashed string.
constexpr basic_hashed_string() noexcept
Constructs an empty hashed string.
static constexpr hash_type value(const value_type *str, const size_type len) noexcept
Returns directly the numeric representation of a string view.
constexpr basic_hashed_string(const_wrapper wrapper) noexcept
Explicit constructor on purpose to avoid constructing a hashed string directly from a const value_typ...
basic_hashed_string(const Char *str, std::size_t len) -> basic_hashed_string< Char >
Deduction guide.
basic_hashed_string< char > hashed_string
Aliases for common character types.
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) noexcept
Compares two hashed strings.
constexpr bool operator<(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
basic_hashed_string< wchar_t > hashed_wstring
Aliases for common character types.
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator>=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator>(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.