Ver código fonte

Add hash for float types

Daniele Bartolini 9 anos atrás
pai
commit
6f1d56021d
1 arquivos alterados com 19 adições e 0 exclusões
  1. 19 0
      src/core/functional.h

+ 19 - 0
src/core/functional.h

@@ -5,6 +5,7 @@
 
 #pragma once
 
+#include "murmur.h"
 #include "types.h"
 
 namespace crown
@@ -148,4 +149,22 @@ struct hash<u64>
 	}
 };
 
+template<>
+struct hash<f32>
+{
+	u32 operator()(const f32 val) const
+	{
+		return val == 0.0f ? 0 : murmur32(&val, sizeof(val), 0);
+	}
+};
+
+template<>
+struct hash<f64>
+{
+	u32 operator()(const f64 val) const
+	{
+		return val == 0.0 ? 0 : murmur32(&val, sizeof(val), 0);
+	}
+};
+
 } // namespace crown