1#ifndef ENTT_CORE_HASHED_STRING_HPP
2#define ENTT_CORE_HASHED_STRING_HPP
21struct fnv1a_traits<std::uint32_t> {
22 using type = std::uint32_t;
23 static constexpr std::uint32_t offset = 2166136261;
24 static constexpr std::uint32_t prime = 16777619;
28struct fnv1a_traits<std::uint64_t> {
29 using type = std::uint64_t;
30 static constexpr std::uint64_t offset = 14695981039346656037ull;
31 static constexpr std::uint64_t prime = 1099511628211ull;
34template<
typename Char>
36 using value_type = Char;
37 using size_type = std::size_t;
40 const value_type *repr;
67template<
typename Char>
69 using base_type = internal::basic_hashed_string<Char>;
70 using traits_type = internal::fnv1a_traits<id_type>;
72 struct const_wrapper {
74 constexpr const_wrapper(
const Char *str) noexcept
81 [[nodiscard]]
static constexpr auto helper(
const Char *str)
noexcept {
82 base_type base{str, 0u, traits_type::offset};
84 for(; str[base.length]; ++base.length) {
85 base.hash = (base.hash ^
static_cast<traits_type::type
>(str[base.length])) * traits_type::prime;
92 [[nodiscard]]
static constexpr auto helper(
const Char *str,
const std::size_t len)
noexcept {
93 base_type base{str, len, traits_type::offset};
96 base.hash = (base.hash ^
static_cast<traits_type::type
>(str[pos])) * traits_type::prime;
126 template<std::
size_t N>
150 : base_type{helper(str, len)} {}
157 template<std::
size_t N>
159 : base_type{helper(str)} {}
171 : base_type{helper(wrapper.repr)} {}
178 return base_type::length;
186 return base_type::repr;
194 return base_type::hash;
198 [[nodiscard]]
constexpr operator const value_type *()
const noexcept {
206 [[nodiscard]]
constexpr operator hash_type() const noexcept {
217template<
typename Char>
226template<
typename Char, std::
size_t N>
236template<
typename Char>
238 return lhs.value() == rhs.value();
248template<
typename Char>
250 return !(lhs == rhs);
260template<
typename Char>
262 return lhs.value() < rhs.value();
273template<
typename Char>
286template<
typename Char>
299template<
typename Char>
310inline namespace literals {
317[[nodiscard]]
constexpr hashed_string operator"" _hs(
const char *str, std::size_t)
noexcept {
326[[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.