include/AK/Tools/Common/AkFNVHash.h
浏览该文件的文档。00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _FNVHASH_H
00029 #define _FNVHASH_H
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 namespace AK
00047 {
00048 struct Hash32
00049 {
00050 typedef unsigned int HashType;
00051 static inline unsigned int Bits() {return 32;}
00052 static inline HashType Prime() {return 16777619;}
00053 static const HashType s_offsetBasis = 2166136261U;
00054 };
00055
00056 struct Hash30 : public Hash32
00057 {
00058 static inline unsigned int Bits() {return 30;}
00059 };
00060
00061 struct Hash64
00062 {
00063 typedef unsigned long long HashType;
00064 static inline unsigned int Bits() {return 64;}
00065 static inline HashType Prime() {return 1099511628211ULL;}
00066 static const HashType s_offsetBasis = 14695981039346656037ULL;
00067 };
00068
00069 template <class HashParams>
00070 class FNVHash
00071 {
00072 public:
00073 inline FNVHash( typename HashParams::HashType in_uBase = HashParams::s_offsetBasis );
00074
00075
00076
00077
00078 inline typename HashParams::HashType Compute( const void* in_pData, unsigned int in_dataSize );
00079 inline typename HashParams::HashType Get() const { return m_uHash; }
00080
00081 template <typename T>
00082 inline typename HashParams::HashType Compute(const T& in_pData) { return Compute(&in_pData, sizeof(T)); }
00083
00084 private:
00085 typename HashParams::HashType m_uHash;
00086 };
00087
00088 #if defined(_MSC_VER)
00089 #pragma warning(push)
00090 #pragma warning(disable:4127)
00091 #endif
00092
00093
00094 template <class HashParams>
00095 FNVHash<HashParams>::FNVHash( typename HashParams::HashType in_uBase )
00096 : m_uHash( in_uBase )
00097 {
00098 }
00099
00100
00101 template <class HashParams>
00102 typename HashParams::HashType FNVHash<HashParams>::Compute( const void* in_pData, unsigned int in_dataSize )
00103 {
00104 const unsigned char* pData = (const unsigned char*) in_pData;
00105 const unsigned char* pEnd = pData + in_dataSize;
00106
00107 typename HashParams::HashType hval = m_uHash;
00108
00109
00110 while( pData < pEnd )
00111 {
00112 hval *= HashParams::Prime();
00113 hval ^= *pData++;
00114 }
00115
00116 m_uHash = hval;
00117
00118
00119 if( HashParams::Bits() >= sizeof(typename HashParams::HashType) * 8 )
00120 return hval;
00121
00122 typename HashParams::HashType mask = static_cast<typename HashParams::HashType>(((typename HashParams::HashType)1 << HashParams::Bits())-1);
00123 return (typename HashParams::HashType)(hval >> HashParams::Bits()) ^ (hval & mask);
00124 }
00125
00126 #if defined(_MSC_VER)
00127 #pragma warning(pop)
00128 #endif
00129
00130 typedef FNVHash<Hash32> FNVHash32;
00131 typedef FNVHash<Hash30> FNVHash30;
00132 typedef FNVHash<Hash64> FNVHash64;
00133
00134 }
00135
00136 #endif
介绍一下自己的项目。我们会竭力为您提供帮助。
来注册自己的项目,我们帮您快速入门,不带任何附加条件!
开始 Wwise 之旅