From 79032acf269e526caa9ec91304fb52dbc0615c4e Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 21 Jul 2020 03:34:35 -0400
Subject: [PATCH] Add support to LLUUID and LLMaterialID for robinhood

---
 indra/llcommon/lluuid.h          | 22 ++++++++++++---------
 indra/llprimitive/llmaterialid.h | 34 +++++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/indra/llcommon/lluuid.h b/indra/llcommon/lluuid.h
index 69894a4b53e..8acfca95046 100644
--- a/indra/llcommon/lluuid.h
+++ b/indra/llcommon/lluuid.h
@@ -35,6 +35,8 @@
 #include "llpreprocessor.h"
 #include <immintrin.h>
 
+#include <robin_hood.h>
+
 class LLMutex;
 
 const S32 UUID_BYTES = 16;
@@ -177,15 +179,7 @@ class LL_COMMON_API LLUUID
 
 	inline size_t hash() const
 	{
-		size_t seed = 0;
-		for (U8 i = 0; i < 4; ++i)
-		{
-			seed ^= static_cast<size_t>(mData[i * 4]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
-			seed ^= static_cast<size_t>(mData[i * 4 + 1]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
-			seed ^= static_cast<size_t>(mData[i * 4 + 2]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
-			seed ^= static_cast<size_t>(mData[i * 4 + 3]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
-		}
-		return seed;
+		return robin_hood::hash_bytes(mData, UUID_BYTES);
 	}
 	// END BOOST
 
@@ -271,6 +265,16 @@ namespace boost {
 	};
 }
 
+namespace robin_hood {
+	template<> struct hash<LLUUID>
+	{
+		size_t operator()(const LLUUID& id) const
+		{
+			return id.hash();
+		}
+	};
+}
+
 /*
  * Sub-classes for keeping transaction IDs and asset IDs
  * straight.
diff --git a/indra/llprimitive/llmaterialid.h b/indra/llprimitive/llmaterialid.h
index 549f723352c..2b3640e79ad 100644
--- a/indra/llprimitive/llmaterialid.h
+++ b/indra/llprimitive/llmaterialid.h
@@ -33,6 +33,8 @@
 #include <immintrin.h>
 #include "llsd.h"
 
+#include <robin_hood.h>
+
 class LLMaterialID
 {
 public:
@@ -147,7 +149,7 @@ class LLMaterialID
 			seed ^= static_cast<size_t>(mID[i * 4 + 2]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
 			seed ^= static_cast<size_t>(mID[i * 4 + 3]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
 		}
-		return seed;
+		return robin_hood::hash_bytes(mID, MATERIAL_ID_SIZE);
 	}
 // END BOOST
 
@@ -168,5 +170,35 @@ class LLMaterialID
 	U8 mID[MATERIAL_ID_SIZE] = {};
 } ;
 
+namespace std {
+	template <> struct hash<LLMaterialID>
+	{
+		size_t operator()(const LLMaterialID& id) const
+		{
+			return id.hash();
+		}
+	};
+}
+
+namespace boost {
+	template<> struct hash<LLMaterialID>
+	{
+		size_t operator()(const LLMaterialID& id) const
+		{
+			return id.hash();
+		}
+	};
+}
+
+namespace robin_hood {
+	template<> struct hash<LLMaterialID>
+	{
+		size_t operator()(const LLMaterialID& id) const
+		{
+			return id.hash();
+		}
+	};
+}
+
 #endif // LL_LLMATERIALID_H
 
-- 
GitLab