From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Utilities/HashFunctions.h | 87 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Runtime/Utilities/HashFunctions.h (limited to 'Runtime/Utilities/HashFunctions.h') diff --git a/Runtime/Utilities/HashFunctions.h b/Runtime/Utilities/HashFunctions.h new file mode 100644 index 0000000..0f1f465 --- /dev/null +++ b/Runtime/Utilities/HashFunctions.h @@ -0,0 +1,87 @@ +#ifndef __HASH_FUNCTIONS_H +#define __HASH_FUNCTIONS_H + +#include +#include "Runtime/Utilities/PathNameUtility.h" +#include "Runtime/Utilities/dense_hash_map.h" +#include "Runtime/Utilities/Word.h" +#include "Runtime/Allocator/MemoryMacros.h" + +struct InstanceIDHashFunctor +{ + inline size_t operator()(SInt32 x) const { + + UInt32 a = static_cast (x); + a = (a+0x7ed55d16) + (a<<12); + a = (a^0xc761c23c) ^ (a>>19); + a = (a+0x165667b1) + (a<<5); + a = (a+0xd3a2646c) ^ (a<<9); + a = (a+0xfd7046c5) + (a<<3); + a = (a^0xb55a4f09) ^ (a>>16); + + return a; + } +}; + +typedef pair InstanceIdToObjectPair; +struct InstanceIdToObjectPtrHashMap : + dense_hash_map, STL_ALLOCATOR( kMemSTL, InstanceIdToObjectPair ) > +{ + typedef dense_hash_map, STL_ALLOCATOR( kMemSTL, InstanceIdToObjectPair )> base_t; + InstanceIdToObjectPtrHashMap (int n) + : base_t (n) + { + set_empty_key (-1); + set_deleted_key (-2); + } +}; + +// http://www.cse.yorku.ca/~oz/hash.html +// Other hashes here: http://burtleburtle.net/bob/ +struct djb2_hash +{ + inline size_t operator()(const std::string& str) const + { + unsigned long hash = 5381; + char c; + const char* s = str.c_str (); + + while ((c = *s++)) + hash = ((hash << 5) + hash) ^ c; + + return hash; + } +}; + +#if UNITY_EDITOR +struct djb2_hash_lowercase +{ + inline size_t operator() (const std::string& str) const + { + unsigned long hash = 5381; + char c; +#if UNITY_OSX + const char* s = NULL; + bool ascii = !RequiresNormalization (str); + if (ascii) + s = ToLower (str).c_str(); + else + s = ToLower (NormalizeUnicode (str, true)).c_str(); +#else + std::string help = ToLower(str); + const char* s = help.c_str(); +#endif + + while ((c = *s++)) + hash = ((hash << 5) + hash) ^ c; + + return hash; + } +}; +#endif + + +bool ComputeMD5Hash( const UInt8* data, size_t dataSize, UInt8 outHash[16] ); +bool ComputeSHA1Hash( const UInt8* data, size_t dataSize, UInt8 outHash[20] ); + +#endif -- cgit v1.1-26-g67d0