1#ifndef ENTT_CORE_HASHED_STRING_HPP
2#define ENTT_CORE_HASHED_STRING_HPP
14template<
typename =
id_type>
18struct fnv_1a_params<std::uint32_t> {
19 static constexpr auto offset = 2166136261;
20 static constexpr auto prime = 16777619;
24struct fnv_1a_params<std::uint64_t> {
25 static constexpr auto offset = 14695981039346656037ull;
26 static constexpr auto prime = 1099511628211ull;
29template<
typename Char>
31 using value_type = Char;
32 using size_type = std::size_t;
35 const value_type *repr;
58template<
typename Char>
60 using base_type = internal::basic_hashed_string<Char>;
61 using params = internal::fnv_1a_params<>;
63 struct const_wrapper {
72 [[
nodiscard]]
static constexpr auto helper(
const std::basic_string_view<Char>
view)
noexcept {
73 base_type base{
view.data(),
view.size(), params::offset};
76 base.hash = (base.hash ^
static_cast<id_type>(
curr)) * params::prime;
106 template<std::
size_t N>
131 : base_type{helper({
str,
len})} {}
138 template<std::
size_t N>
141 : base_type{helper({
static_cast<const value_type *
>(
str)})} {}
153 : base_type{helper({
wrapper.repr})} {}
160 return base_type::length;
168 return base_type::repr;
176 return base_type::hash;
199template<
typename Char>
208template<
typename Char, std::
size_t N>
219template<
typename Char>
221 return lhs.value() ==
rhs.value();
231template<
typename Char>
243template<
typename Char>
245 return lhs.value() <
rhs.value();
256template<
typename Char>
269template<
typename Char>
282template<
typename Char>
287inline namespace literals {
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...
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
basic_hashed_string(const Char *str, std::size_t len) -> basic_hashed_string< Char >
Deduction guide.
basic_view< type_list_transform_t< Get, storage_for >, type_list_transform_t< Exclude, storage_for > > view
Alias declaration for the most common use case.
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.
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.