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) {}
36 : mStrHash(other.mStrHash),
38 mLastMatch(
nullptr) {}
41 : mStrHash(other.mStrHash),
42 mStr(std::move(other.mStr)),
43 mLastMatch(other.mLastMatch) {
45 other.mLastMatch =
nullptr;
52 mStrHash = other.mStrHash;
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 MCFOLD static ::HashedString
const& getEmptyString();
143 MCAPI static ::HashedString& defaultErrorValue();
149 MCAPI
void* $ctor(nullptr_t);
155 MCFOLD
void* $ctor(::std::string
const& str);
157 MCAPI
void* $ctor(
char const* str);
159 MCAPI
void* $ctor(uint64 hash,
char const* str);