31 #define LOG_HASH_CONFLICTS 1 37 void HashCombine(std::size_t &Seed,
const T& Val)
39 Seed ^= std::hash<T>()(Val) + 0x9e3779b9 + (Seed << 6) + (Seed >> 2);
42 template<
typename FirstArgType,
typename... RestArgsType>
43 void HashCombine( std::size_t &Seed,
const FirstArgType& FirstArg,
const RestArgsType&... RestArgs )
45 HashCombine( Seed, FirstArg );
46 HashCombine( Seed, RestArgs... );
49 template<
typename... ArgsType>
50 std::size_t ComputeHash(
const ArgsType&... Args )
53 HashCombine( Seed, Args... );
57 template<
typename CharType>
60 size_t operator()(
const CharType *str )
const 64 while(
size_t Ch = *(str++) )
65 Seed = Seed * 65599 + Ch;
70 template<
typename CharType>
73 bool operator()(
const CharType *str1,
const CharType *str2 )
const 75 UNSUPPORTED(
"Template specialization is not implemented" );
81 struct CStringCompare<Char>
83 bool operator()(
const Char *str1,
const Char *str2 )
const 85 return strcmp( str1, str2 ) == 0;
102 VERIFY( Str,
"String pointer cannot be null" );
118 MakeCopy( Str.c_str() );
122 StringBuff( std::move(Key.StringBuff) ),
123 StrPtr( std::move(Key.StrPtr) ),
126 Key.StrPtr =
nullptr;
139 if( StrPtr == RHS.StrPtr )
143 if( (Hash != 0 && RHS.Hash !=0 && Hash != RHS.Hash) || StrPtr ==
nullptr || RHS.StrPtr ==
nullptr )
146 bool IsEqual = strcmp( StrPtr, RHS.StrPtr ) == 0;
148 #if LOG_HASH_CONFLICTS 149 if( Hash != 0 && RHS.Hash !=0 && Hash == RHS.Hash && !IsEqual )
151 LOG_WARNING_MESSAGE(
"Unequal strings \"", StrPtr,
"\" and \"", RHS.StrPtr,
"\" hashed to the same bucket. " 152 "You may want to use better hash function. You may disable this warning by defining LOG_HASH_CONFLICTS to 0");
158 size_t GetHash()
const 161 Hash = CStringHash<Char>()(StrPtr);
166 const Char* GetStr()
const{
return StrPtr; }
169 void MakeCopy(
const Char* Str )
171 auto LenWithZeroTerm = strlen( Str ) + 1;
172 StringBuff.reset(
new char[ LenWithZeroTerm ] );
173 memcpy( StringBuff.get(), Str, LenWithZeroTerm );
174 StrPtr = StringBuff.get();
181 std::unique_ptr< Char[] > StringBuff;
190 struct hash<
Diligent::HashMapStringKey>
194 return Key.GetHash();
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Definition: AdvancedMath.h:316
This helper structure is intended to facilitate using strings as a hash table key. It provides constructors that can make a copy of the source string or just keep pointer to it, which enables searching in the hash using raw const Char* pointers.
Definition: HashUtils.h:93