1#ifndef ENTT_CORE_HASHED_STRING_HPP
2#define ENTT_CORE_HASHED_STRING_HPP
17struct fnv1a_traits<std::uint32_t> {
18 using type = std::uint32_t;
19 static constexpr std::uint32_t offset = 2166136261;
20 static constexpr std::uint32_t prime = 16777619;
24struct fnv1a_traits<std::uint64_t> {
25 using type = std::uint64_t;
26 static constexpr std::uint64_t offset = 14695981039346656037ull;
27 static constexpr std::uint64_t prime = 1099511628211ull;
30template<
typename Char>
32 using value_type = Char;
33 using size_type = std::size_t;
36 const value_type *repr;
59template<
typename Char>
61 using base_type = internal::basic_hashed_string<Char>;
62 using traits_type = internal::fnv1a_traits<id_type>;
64 struct const_wrapper {
66 constexpr const_wrapper(
const Char *str) noexcept
73 [[nodiscard]]
static constexpr auto helper(
const Char *str)
noexcept {
74 base_type base{str, 0u, traits_type::offset};
76 for(; str[base.length]; ++base.length) {
77 base.hash = (base.hash ^
static_cast<traits_type::type
>(str[base.length])) * traits_type::prime;
84 [[nodiscard]]
static constexpr auto helper(
const Char *str,
const std::size_t len)
noexcept {
85 base_type base{str, len, traits_type::offset};
88 base.hash = (base.hash ^
static_cast<traits_type::type
>(str[pos])) * traits_type::prime;
118 template<std::
size_t N>
142 : base_type{helper(str, len)} {}
149 template<std::
size_t N>
151 : base_type{helper(str)} {}
163 : base_type{helper(wrapper.repr)} {}
170 return base_type::length;
178 return base_type::repr;
186 return base_type::hash;
190 [[nodiscard]]
constexpr operator const value_type *()
const noexcept {
198 [[nodiscard]]
constexpr operator hash_type() const noexcept {
209template<
typename Char>
218template<
typename Char, std::
size_t N>
228template<
typename Char>
230 return lhs.value() == rhs.value();
240template<
typename Char>
242 return !(lhs == rhs);
252template<
typename Char>
254 return lhs.value() < rhs.value();
265template<
typename Char>
278template<
typename Char>
291template<
typename Char>
302inline namespace literals {
309[[nodiscard]]
constexpr hashed_string operator"" _hs(
const char *str, std::size_t)
noexcept {
318[[nodiscard]]
constexpr hashed_wstring operator"" _hws(
const wchar_t *str, std::size_t)
noexcept {
Zero overhead unique identifier.
typename base_type::value_type value_type
Character 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
Unsigned integer 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
Unsigned integer 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 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...
std::uint32_t id_type
Alias declaration for type identifiers.
basic_hashed_string(const Char *str, const std::size_t len) -> basic_hashed_string< Char >
Deduction guide.
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.
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.