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) {}
33 [[nodiscard]]
constexpr HashedString(
char const* mStr) noexcept : HashedString(std::string{mStr}) {}
35 [[nodiscard]]
constexpr HashedString(HashedString
const& other) noexcept
36 : mStrHash(other.mStrHash),
38 mLastMatch(
nullptr) {}
40 [[nodiscard]]
constexpr HashedString(HashedString&& other) noexcept
41 : mStrHash(other.mStrHash),
42 mStr(std::move(other.mStr)),
43 mLastMatch(other.mLastMatch) {
45 other.mLastMatch =
nullptr;
48 constexpr HashedString& operator=(HashedString
const& other)
noexcept {
52 mStrHash = other.mStrHash;
58 constexpr HashedString& operator=(HashedString&& other)
noexcept {
62 mStrHash = other.mStrHash;
63 mStr = std::move(other.mStr);
64 mLastMatch = other.mLastMatch;
66 other.mLastMatch =
nullptr;
71 [[nodiscard]]
constexpr char const* c_str()
const noexcept {
return mStr.c_str(); }
73 [[nodiscard]]
constexpr std::string
const& getString()
const noexcept {
return mStr; }
75 [[nodiscard]]
constexpr uint64 getHash()
const noexcept {
return mStrHash; }
77 [[nodiscard]]
constexpr bool empty()
const noexcept {
return mStr.empty(); }
80 constexpr void clear()
noexcept {
87 template <
typename StringType>
88 [[nodiscard]]
constexpr bool operator==(StringType
const& rhs)
const noexcept {
92 [[nodiscard]]
constexpr bool operator==(HashedString
const& other)
const noexcept {
93 if (mStrHash == other.mStrHash) {
94 if (mLastMatch == std::addressof(other) && other.mLastMatch ==
this) {
97 if (mStr == other.mStr) {
98 mLastMatch = std::addressof(other);
99 other.mLastMatch =
this;
103 mLastMatch =
nullptr;
107 template <
typename StringType>
108 [[nodiscard]]
constexpr bool operator!=(StringType
const& rhs)
const noexcept {
112 [[nodiscard]]
constexpr bool operator!=(HashedString
const& other)
const noexcept {
return !(*
this == other); }
114 [[nodiscard]]
constexpr std::strong_ordering operator<=>(HashedString
const& other)
const noexcept {
115 if (mStrHash != other.mStrHash) {
116 return mStrHash <=> other.mStrHash;
118 return mStr <=> other.mStr;
122 [[nodiscard]]
constexpr operator std::string
const&()
const {
return mStr; }
124 [[nodiscard]]
constexpr operator std::string_view()
const {
return std::string_view(mStr); }
131 mutable ::HashedString
const* mLastMatch;
137 MCAPI static ::HashedString& defaultErrorValue();
145 MCAPI
void* $ctor(::HashedString&& rhs);
147 MCAPI
void* $ctor(::HashedString
const& rhs);
149 MCFOLD
void* $ctor(::std::string
const& str);
151 MCAPI
void* $ctor(
char const* str);
153 MCAPI_C
void* $ctor(::std::string_view str);
155 MCAPI
void* $ctor(uint64 hash,
char const* str);