7 [[nodiscard]]
static constexpr uint64 computeHash(std::string_view str) {
8 if (str.empty())
return 0;
9 uint64 hash = 0xCBF29CE484222325ull;
11 hash = s ^ (0x100000001B3ull * hash);
17 [[nodiscard]]
constexpr HashedString(std::nullptr_t =
nullptr) noexcept : mStrHash(0), mLastMatch(
nullptr) {}
19 [[nodiscard]]
constexpr HashedString(uint64 h,
char const* mStr) noexcept
22 mLastMatch(
nullptr) {}
24 [[nodiscard]]
constexpr HashedString(std::string_view mStr) noexcept
25 : mStrHash(computeHash(mStr)),
27 mLastMatch(
nullptr) {}
29 [[nodiscard]]
constexpr HashedString(std::string&& s) noexcept
30 : mStrHash(computeHash(s)),
32 mLastMatch(
nullptr) {}
34 [[nodiscard]]
constexpr HashedString(std::string
const& s) noexcept
35 : mStrHash(computeHash(s)),
37 mLastMatch(
nullptr) {}
39 [[nodiscard]]
constexpr HashedString(
char const* mStr) noexcept : HashedString(std::string{mStr}) {}
41 [[nodiscard]]
constexpr HashedString(HashedString
const& other) noexcept
42 : mStrHash(other.mStrHash),
44 mLastMatch(
nullptr) {}
46 [[nodiscard]]
constexpr HashedString(HashedString&& other) noexcept
47 : mStrHash(other.mStrHash),
48 mStr(std::move(other.mStr)),
49 mLastMatch(other.mLastMatch) {
51 other.mLastMatch =
nullptr;
54 constexpr HashedString& operator=(HashedString
const& other)
noexcept {
58 mStrHash = other.mStrHash;
64 constexpr HashedString& operator=(HashedString&& other)
noexcept {
68 mStrHash = other.mStrHash;
69 mStr = std::move(other.mStr);
70 mLastMatch = other.mLastMatch;
72 other.mLastMatch =
nullptr;
77 [[nodiscard]]
constexpr char const* c_str()
const noexcept {
return mStr.c_str(); }
79 [[nodiscard]]
constexpr std::string
const& getString()
const noexcept {
return mStr; }
81 [[nodiscard]]
constexpr uint64 getHash()
const noexcept {
return mStrHash; }
83 [[nodiscard]]
constexpr bool empty()
const noexcept {
return mStr.empty(); }
86 constexpr void clear()
noexcept {
93 template <
typename StringType>
94 [[nodiscard]]
constexpr bool operator==(StringType
const& rhs)
const noexcept {
98 [[nodiscard]]
constexpr bool operator==(HashedString
const& other)
const noexcept {
99 if (mStrHash == other.mStrHash) {
100 if (mLastMatch == std::addressof(other) && other.mLastMatch ==
this) {
103 if (mStr == other.mStr) {
104 mLastMatch = std::addressof(other);
105 other.mLastMatch =
this;
109 mLastMatch =
nullptr;
113 template <
typename StringType>
114 [[nodiscard]]
constexpr bool operator!=(StringType
const& rhs)
const noexcept {
118 [[nodiscard]]
constexpr bool operator!=(HashedString
const& other)
const noexcept {
return !(*
this == other); }
120 [[nodiscard]]
constexpr std::strong_ordering operator<=>(HashedString
const& other)
const noexcept {
121 if (mStrHash != other.mStrHash) {
122 return mStrHash <=> other.mStrHash;
124 return mStr <=> other.mStr;
128 [[nodiscard]]
constexpr operator std::string
const&()
const {
return mStr; }
130 [[nodiscard]]
constexpr operator std::string_view()
const {
return std::string_view(mStr); }
137 mutable ::HashedString
const* mLastMatch;
143 MCAPI static ::HashedString& defaultErrorValue();
150 MCAPI
void* $ctor(nullptr_t);
153 MCAPI
void* $ctor(::HashedString&& rhs);
155 MCAPI
void* $ctor(::HashedString
const& rhs);
157 MCAPI
void* $ctor(::std::string
const& str);
159 MCAPI
void* $ctor(
char const* str);
161 MCAPI
void* $ctor(::std::string_view str);
163 MCAPI
void* $ctor(uint64 hash,
char const* str);