diff --git a/src/tarray.h b/src/tarray.h index 92a6552e4..afea5db1e 100644 --- a/src/tarray.h +++ b/src/tarray.h @@ -398,11 +398,26 @@ template struct THashTraits { // Returns the hash value for a key. hash_t Hash(const KT key) { return (hash_t)(intptr_t)key; } + hash_t Hash(double key) { return ((hash_t *)&key)[0] ^ ((hash_t *)&key)[1]; } // Compares two keys, returning zero if they are the same. int Compare(const KT left, const KT right) { return left != right; } }; +template<> struct THashTraits +{ + // Use all bits when hashing singles instead of converting them to ints. + hash_t Hash(float key) { return *((hash_t *)&key); } + int Compare(float left, float right) { return left != right; } +}; + +template<> struct THashTraits +{ + // Use all bits when hashing doubles instead of converting them to ints. + hash_t Hash(double key) { return ((hash_t *)&key)[0] ^ ((hash_t *)&key)[1]; } + int Compare(double left, double right) { return left != right; } +}; + template struct TValueTraits { // Initializes a value for TMap. If a regular constructor isn't diff --git a/src/zstring.h b/src/zstring.h index db42b98e4..fc6287126 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -316,4 +316,12 @@ inline FName &FName::operator = (const FString &text) { Index = NameData.FindNam inline FName &FNameNoInit::operator = (const FString &text) { Index = NameData.FindName (text, text.Len(), false); return *this; } +// Hash FStrings on their contents. (used by TMap) +extern unsigned int SuperFastHash (const char *data, size_t len); +template<> struct THashTraits +{ + hash_t Hash(const FString &key) { return (hash_t)SuperFastHash(key, key.Len()); } + int Compare(const FString &left, const FString &right) { return left.Compare(right); } +}; + #endif