21 struct 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;
28 struct 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;
34 template<
typename Char>
35 struct basic_hashed_string {
36 using value_type = Char;
37 using size_type = std::size_t;
38 using hash_type = id_type;
40 const value_type *repr;
67 template<
typename Char>
69 using base_type = details::basic_hashed_string<Char>;
70 using hs_traits = details::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, hs_traits::offset};
84 for(; str[base.length]; ++base.length) {
85 base.hash = (base.hash ^
static_cast<hs_traits::type
>(str[base.length])) * hs_traits::prime;
92 [[nodiscard]]
static constexpr
auto helper(
const Char *str,
const std::size_t len) noexcept {
93 base_type base{str, len, hs_traits::offset};
96 base.hash = (base.hash ^
static_cast<hs_traits::type
>(str[pos])) * hs_traits::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 {
217 template<
typename Char>
226 template<
typename Char, std::
size_t N>
236 template<
typename Char>
238 return lhs.value() == rhs.value();
248 template<
typename Char>
250 return !(lhs == rhs);
260 template<
typename Char>
261 [[nodiscard]] constexpr
bool operator<(const basic_hashed_string<Char> &lhs,
const basic_hashed_string<Char> &rhs) noexcept {
262 return lhs.value() < rhs.value();
273 template<
typename Char>
274 [[nodiscard]] constexpr
bool operator<=(const basic_hashed_string<Char> &lhs,
const basic_hashed_string<Char> &rhs) noexcept {
286 template<
typename Char>
299 template<
typename Char>
310 inline 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 {
constexpr basic_hashed_string(const value_type *str, const size_type len) noexcept
Constructs a hashed string from a string view.
Definition: hashed_string.h:149
constexpr basic_hashed_string(const_wrapper wrapper) noexcept
Explicit constructor on purpose to avoid constructing a hashed string directly from a const value_typ...
Definition: hashed_string.h:170
static constexpr hash_type value(const value_type *str, const size_type len) noexcept
Returns directly the numeric representation of a string view.
Definition: hashed_string.h:116
constexpr basic_hashed_string() noexcept
Constructs an empty hashed string.
Definition: hashed_string.h:141
typename base_type::hash_type hash_type
Unsigned integer type.
Definition: hashed_string.h:108
typename base_type::value_type value_type
Character type.
Definition: hashed_string.h:104
constexpr basic_hashed_string(const value_type(&str)[N]) noexcept
Constructs a hashed string from an array of const characters.
Definition: hashed_string.h:158
constexpr size_type size() const noexcept
Returns the size a hashed string.
Definition: hashed_string.h:177
constexpr const value_type * data() const noexcept
Returns the human-readable representation of a hashed string.
Definition: hashed_string.h:185
Definition: compressed_pair.h:255
typename base_type::size_type size_type
Unsigned integer type.
Definition: hashed_string.h:106
Zero overhead unique identifier.
Definition: hashed_string.h:68
static constexpr hash_type value(const value_type(&str)[N]) noexcept
Returns directly the numeric representation of a string.
Definition: hashed_string.h:127
Definition: compressed_pair.h:10
constexpr hash_type value() const noexcept
Returns the numeric representation of a hashed string.
Definition: hashed_string.h:193
static constexpr hash_type value(const_wrapper wrapper) noexcept
Returns directly the numeric representation of a string.
Definition: hashed_string.h:136