diff --git a/inc/hgl/util/hash/Hash.h b/inc/hgl/util/hash/Hash.h index cfefdf2..5cec224 100644 --- a/inc/hgl/util/hash/Hash.h +++ b/inc/hgl/util/hash/Hash.h @@ -23,23 +23,24 @@ namespace hgl xxH32, xxH64, - XXH3_64, - XXH3_128, + xxH3_64, + xxH3_128, FNV1a, -// Murmur3, -// City64, -// City128, + Murmur3, + City32, + City64, + City128, - ENUM_CLASS_RANGE(Adler32,FNV1a) + ENUM_CLASS_RANGE(Adler32,City128) };//enum HASH /** * Hash编码结构模板 */ - template struct HashCode + template struct HashCode { - unsigned char code[SIZE]; + uint8 code[SIZE]{}; public: @@ -48,39 +49,15 @@ namespace hgl public: - HashCode() - { - hgl_zero(code); - } + static constexpr int size()noexcept{return SIZE;} - static constexpr int size(){return SIZE;} + const uint8 operator[](int index)const{return code[index];} - const unsigned char operator[](int index)const - { - return code[index]; - } + void CopyFrom (const void *ptr){memcpy(code,ptr,SIZE);} + void FromString (const char *str){ParseHexStr(code,str,SIZE);} - void CopyFrom(const void *ptr) - { - memcpy(code,ptr,SIZE); - } - - void FromString(const char *str) - { - ParseHexStr(code,str,SIZE); - } - - template - void ToUpperString(T *str,const T gap_char=0) const - { - ToUpperHexStr(str,code,SIZE,gap_char); - } - - template - void ToLowerString(T *str,const T gap_char=0) const - { - ToLowerHexStr(str,code,SIZE,gap_char); - } + template void ToUpperString(T *str,const T gap_char=0) const {ToUpperHexStr(str,code,SIZE,gap_char);} + template void ToLowerString(T *str,const T gap_char=0) const {ToLowerHexStr(str,code,SIZE,gap_char);} const int CompFunc(const HashCode &hash)const { @@ -100,36 +77,23 @@ namespace hgl } CompOperator(const HashCode &,CompFunc) - };//template struct HashCode - - using HashCodeCRC32 =HashCode<4> ; - using HashCodeAdler32 =HashCode<4> ; - using HashCodeMD5 =HashCode<16> ; - using HashCodeMD4 =HashCode<16> ; - using HashCodeSHA1 =HashCode<20> ; - using HashCodeSHA1LE =HashCode<20> ; - using HashCodeSHA256 =HashCode<32> ; - using HashCodeSHA512 =HashCode<64> ; - using HashCodexxH32 =HashCode<4> ; - using HashCodexxH64 =HashCode<8> ; - using HashCodeXXH3_64 =HashCode<8> ; - using HashCodeXXH3_128 =HashCode<16> ; - using HashCodeFNV1a =HashCode<4>; - - const int hash_code_bytes[]={4,4,16,16,20,20,32,64,4,8,16,4}; //hash码长度 + };//template struct HashCode /** * 散列值计算功能基类 */ class Hash ///散列值计算功能基类 { + AnsiString hash_name; + size_t hash_size; + public: + Hash(const size_t s,const AnsiString &n):hash_size(s),hash_name(n){} virtual ~Hash()=default; - - virtual void GetName(UTF8String &)const=0; ///<取得HASH算法的名称 - virtual void GetName(UTF16String &)const=0; ///<取得HASH算法的名称 - virtual const int GetHashBytes()const=0; ///<取得HASH码字节长度(MD4/MD5为16,SHA1为20) + + void GetName (AnsiString &name)const {name=hash_name;} ///<取得HASH算法的名称 + const size_t GetHashBytes()const noexcept {return hash_size;} ///<取得HASH码字节长度(MD4/MD5为16,SHA1为20) virtual void Init()=0; ///<初始化散列值计算 virtual void Update(const void *,uint)=0; ///<提交新的数据 @@ -150,50 +114,7 @@ namespace hgl template Hash *CreateHash(); ///<创建一个hash值计算类实例 -#define HGL_CREATE_HASH_FUNC(name) Hash *Create##name##Hash(); \ - template<> inline Hash *CreateHash(){return Create##name##Hash();} - - HGL_CREATE_HASH_FUNC(Adler32) - HGL_CREATE_HASH_FUNC(CRC32) - HGL_CREATE_HASH_FUNC(MD4) - HGL_CREATE_HASH_FUNC(MD5) - HGL_CREATE_HASH_FUNC(SHA1) - HGL_CREATE_HASH_FUNC(SHA1LE) - HGL_CREATE_HASH_FUNC(SHA256) - HGL_CREATE_HASH_FUNC(SHA512) - HGL_CREATE_HASH_FUNC(xxH32) - HGL_CREATE_HASH_FUNC(xxH64) - HGL_CREATE_HASH_FUNC(XXH3_64) - HGL_CREATE_HASH_FUNC(XXH3_128) - HGL_CREATE_HASH_FUNC(FNV1a) - -//#undef HGL_CREATE_HASH_FUNC - - inline Hash *CreateHash(HASH ha) - { - RANGE_CHECK_RETURN_NULLPTR(ha) - - using CreateHashFunc=Hash *(*)(); - - const CreateHashFunc func[(size_t)HASH::RANGE_SIZE]= - { - CreateAdler32Hash, - CreateCRC32Hash, - CreateMD4Hash, - CreateMD5Hash, - CreateSHA1Hash, - CreateSHA1LEHash, - CreateSHA256Hash, - CreateSHA512Hash, - CreatexxH32Hash, - CreatexxH64Hash, - CreateXXH3_64Hash, - CreateXXH3_128Hash, - CreateFNV1aHash - }; - - return func[(size_t)ha](); - } + Hash *CreateHash(const HASH ha); ///<创建一个hash值计算类实例 /** * 计算一段数据的Hash值 @@ -220,141 +141,29 @@ namespace hgl } /** - * 计算一段数据的Hash值 - * @param data 数据指针 - * @param size 数据长度 - * @param ha hash算法 - * @param hash_code 计算后的hash值存放处 + * 取得一个文件的hash值 + * @param filename 文件名 + * @param ha hash对象 + * @param hash_code 计算后的hash存放处 * @return 是否计算成功 */ - inline bool CountHash(const void *data,int size,HASH ha,void *hash_code) + bool GetFileHash(const OSString &filename,Hash *ha,void *hash_code); + + template bool GetFileHash(const OSString &filename,void *hash_code,size_t &hash_size) { - RANGE_CHECK_RETURN_FALSE(ha) - if(!data||size<=0||!hash_code)return(false); - - using CountHashFunc=bool (*)(const void *,int size,void *); - - const CountHashFunc func[(size_t)HASH::RANGE_SIZE]= - { - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash, - CountHash - }; - - return func[(size_t)ha](data,size,hash_code); - } - - /** - * 计算一段数据的Hash值 - * @param data 数据指针 - * @param size 数据长度 - * @param ha hash算法 - * @param hash_str 计算后的hash值存放处 - * @param litter 小写字母 - * @return 是否计算成功 - */ - template bool CountHashStr(const void *data,int size,UTF8String &hash_str,bool litter=true) - { - if(!data||size<=0)return(false); - Hash *h=CreateHash(); - if(!h)return(false); - const int hash_bytes=hash_code_bytes[(size_t)ha]; - - uint8 *hash_code=new uint8[hash_bytes]; - u8char *hash_code_str=new u8char[1+(hash_bytes<<1)]; - - h->Init(); - h->Update(data,size); - h->Final(hash_code); - + if(!GetFileHash(filename,h,hash_code)) + { + delete h; + return(false); + } + hash_size=h->GetHashBytes(); delete h; - - DataToHexStr(hash_code_str,hash_code,hash_bytes,litter?LowerHexChar:UpperHexChar); - - hash_str.SetInstance(hash_code_str,hash_bytes<<1); - - delete[] hash_code; return(true); } - /** - * 计算一段数据的Hash值 - * @param data 数据指针 - * @param size 数据长度 - * @param ha hash算法 - * @param hash_str 计算后的hash值存放处 - * @param litter 小写字母 - * @return 是否计算成功 - */ - inline bool CountHash(const void *data,int size,HASH ha,UTF8String &hash_str,bool litter=true) - { - RANGE_CHECK_RETURN_FALSE(ha) - if(!data||size<=0)return(false); - - using CountHashFunc=bool (*)(const void *,int size,UTF8String &,bool); - - const CountHashFunc func[(size_t)HASH::RANGE_SIZE]= - { - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr, - CountHashStr - }; - - return func[(size_t)ha](data,size,hash_str,litter); - } - -#define HGL_COUNT_HASH_FUNC(name) inline bool Count##name(const void *data, int size, HashCode##name &hc) { return CountHash(data, size, &hc); } \ - inline bool Count##name(const void *data, int size, UTF8String &hash_str, bool litter = true) { return CountHashStr(data, size, hash_str, litter); } \ - inline bool Count##name(const UTF8String &str, UTF8String &hash_str, bool litter = true) { return CountHashStr(str.c_str(), str.Length(), hash_str, litter); } - - HGL_COUNT_HASH_FUNC(Adler32) - HGL_COUNT_HASH_FUNC(CRC32) - HGL_COUNT_HASH_FUNC(MD4) - HGL_COUNT_HASH_FUNC(MD5) - HGL_COUNT_HASH_FUNC(SHA1) - HGL_COUNT_HASH_FUNC(SHA1LE) - HGL_COUNT_HASH_FUNC(SHA256) - HGL_COUNT_HASH_FUNC(SHA512) - HGL_COUNT_HASH_FUNC(xxH32) - HGL_COUNT_HASH_FUNC(xxH64) - HGL_COUNT_HASH_FUNC(XXH3_64) - HGL_COUNT_HASH_FUNC(XXH3_128) - HGL_COUNT_HASH_FUNC(FNV1a) - -#undef HGL_COUNT_HASH_FUNC - - /** - * 取得一个文件的hash值 - * @param filename 文件名 - * @param ha hash算法 - * @param hash_code 计算后的hash存放处 - * @return 是否计算成功 - */ - bool GetFileHash(const OSString &filename,HASH ha,void *hash_code); - /** * 取得一个文件的hash值 * @param filename 文件名 @@ -363,7 +172,7 @@ namespace hgl * @param litter 小写字母 * @return 是否计算成功 */ - bool GetFileHash(const OSString &filename,HASH ha,UTF8String &hash_str,bool litter=true); + //bool GetFileHash(const OSString &filename,HASH ha,UTF8String &hash_str,bool litter=true); }//namespace util }//namespace hgl #endif//HGL_UTIL_HASH_INCLUDE diff --git a/inc/hgl/util/hash/SHA1LE.h b/inc/hgl/util/hash/SHA1LE.h index 2428e2c..f35eb6c 100644 --- a/inc/hgl/util/hash/SHA1LE.h +++ b/inc/hgl/util/hash/SHA1LE.h @@ -36,11 +36,8 @@ namespace hgl void sha1_transform(); public: - - void GetName(UTF8String &str)const override{str=U8_TEXT("SHA1LE");} - void GetName(UTF16String &str)const override{str=U16_TEXT("SHA1LE");} - - const int GetHashBytes()const override {return DIGEST_SIZE;} + + SHA1LE():Hash(20,"SHA1LE"){} void Init(const uint32 *start_digest,const uint32 *mysterious_constants); ///<开始一次新的HASH计算,并指定初始因子和扰乱因子 void Init()override; ///<开始一次新的HASH计算,并使用缺省初始因子和扰乱因子 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7305393..f07ffc7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,6 +131,9 @@ add_cm_library(CMUtil "CM" ${CMD_SOURCE} ${CRYPT_SOURCE_FILES} ) +find_package(cityhash CONFIG REQUIRED) +target_link_libraries(CMUtil PRIVATE cityhash) + if(CM_UTIL_SUPPORT_XML) target_link_libraries(CMUtil PRIVATE expat::expat) endif() diff --git a/src/hash/FNV1a.cpp b/src/hash/FNV1a.cpp index a58ad39..b06d93c 100644 --- a/src/hash/FNV1a.cpp +++ b/src/hash/FNV1a.cpp @@ -29,9 +29,8 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("FNV1a");} - void GetName(UTF16String &str)const override{str=U16_TEXT("FNV1a");} - const int GetHashBytes()const override{return 4;} + FNV1a():Hash(4,"FNV1a"){} + void Init()override { result=2166136261u; @@ -46,7 +45,7 @@ namespace hgl } };//class FNV1a - Hash *CreateFNV1aHash() + template<> Hash *CreateHash() { return(new FNV1a); } diff --git a/src/hash/GoogleCityHash.cpp b/src/hash/GoogleCityHash.cpp index 19db4b7..289edf1 100644 --- a/src/hash/GoogleCityHash.cpp +++ b/src/hash/GoogleCityHash.cpp @@ -2,4 +2,95 @@ // vcpkg: cityhash, cityhash[sse] +#include +#include + +namespace hgl +{ + namespace util + { + class GoogleCityHash32:public Hash + { + uint32 result; + + public: + + GoogleCityHash32():Hash(4,"CityHash32") + {} + void Init()override + { + result=0; + } + void Update(const void *input,uint inputLen)override + { + result=CityHash32((const char *)input,inputLen); + } + void Final(void *digest)override + { + *(uint32 *)digest=result; + } + }; + + template<> Hash *CreateHash() + { + return(new GoogleCityHash32); + } + + class GoogleCityHash64:public Hash + { + uint64 result; + + public: + + GoogleCityHash64():Hash(8,"CityHash64") + {} + void Init()override + { + result=0; + } + void Update(const void *input,uint inputLen)override + { + result=::CityHash64WithSeed((const char *)input,inputLen,result); + } + void Final(void *digest)override + { + *(uint64 *)digest=result; + } + };//class CityHash64:public Hash + + template<> Hash *CreateHash() + { + return(new GoogleCityHash64); + } + + class GoogleCityHash128:public Hash + { + uint128 result; + + public: + + GoogleCityHash128():Hash(16,"CityHash128") + {} + void Init()override + { + result.first=0; + result.second=0; + } + void Update(const void *input,uint inputLen)override + { + ::CityHash128WithSeed((const char *)input,inputLen,result); + } + void Final(void *digest)override + { + ((uint64 *)digest)[0]=result.first; + ((uint64 *)digest)[1]=result.second; + } + };//class CityHash128:public Hash + + template<> Hash *CreateHash() + { + return(new GoogleCityHash128); + } + }//namespace util +}//namespace hgl diff --git a/src/hash/Hash.cpp b/src/hash/Hash.cpp index 4e34997..89e34d1 100644 --- a/src/hash/Hash.cpp +++ b/src/hash/Hash.cpp @@ -5,11 +5,54 @@ namespace hgl { namespace util { - bool GetFileHash(const OSString &filename,HASH ha,void *hash_code) + namespace { - Hash *hash=CreateHash(ha); + struct + { + HASH hash; + Hash *(*func)(); + } + create_hash_func_list[]= + { + #define HASH_FUNC(name) {HASH::name,CreateHash}, + HASH_FUNC(Adler32) + HASH_FUNC(CRC32) + HASH_FUNC(MD4) + HASH_FUNC(MD5) + HASH_FUNC(SHA1) + HASH_FUNC(SHA1LE) + HASH_FUNC(SHA256) + HASH_FUNC(SHA512) + HASH_FUNC(xxH32) + HASH_FUNC(xxH64) + HASH_FUNC(xxH3_64) + HASH_FUNC(xxH3_128) + HASH_FUNC(FNV1a) + HASH_FUNC(Murmur3) + HASH_FUNC(City32) + HASH_FUNC(City64) + HASH_FUNC(City128) + }; + }//namespace + + Hash *CreateHash(const HASH ha) + { + RANGE_CHECK_RETURN_NULLPTR(ha) + + for(auto &hf:create_hash_func_list) + { + if(hf.hash==ha) + return hf.func(); + } + + return nullptr; + } + + bool GetFileHash(const OSString &filename,Hash *hash,void *hash_code) + { if(!hash)return(false); + if(!hash_code)return(false); io::FileInputStream fp; @@ -35,7 +78,6 @@ namespace hgl hash->Final(hash_code); fp.Close(); - delete hash; return(true); } diff --git a/src/hash/MurmurHash3.cpp b/src/hash/MurmurHash3.cpp index 2f717eb..d4e50c2 100644 --- a/src/hash/MurmurHash3.cpp +++ b/src/hash/MurmurHash3.cpp @@ -9,7 +9,7 @@ namespace hgl //本代码来自Github Copilot //MurmurHash 是一种高性能的哈希算法,特别适用于哈希表。它具有良好的分布性和较低的碰撞率。 - uint32_t MurmurHash3(const void *key, int len, uint32_t seed) + uint32_t CountMurmurHash3(const void *key, int len, uint32_t seed) { const uint8_t *data = (const uint8_t *)key; const int nblocks = len / 4; @@ -61,5 +61,32 @@ namespace hgl return h1; } }//namespace + + class MurmurHash3:public Hash + { + uint32_t result; + + public: + + MurmurHash3():Hash(4,"MurmurHash3") + {} + void Init()override + { + result=0; + } + void Update(const void *input,uint inputLen)override + { + result=CountMurmurHash3(input,inputLen,result); + } + void Final(void *digest)override + { + *(uint32_t *)digest=result; + } + };//class MurmurHash3 + + template<> Hash *CreateHash() + { + return(new MurmurHash3); + } }//namespace util }//namespace hgl diff --git a/src/hash/adler32.cpp b/src/hash/adler32.cpp index 2e70026..83cc4bb 100644 --- a/src/hash/adler32.cpp +++ b/src/hash/adler32.cpp @@ -124,10 +124,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("Adler32");} - void GetName(UTF16String &str)const override{str=U16_TEXT("Adler32");} - - const int GetHashBytes()const override{return 4;} + Adler32():Hash(4,"Adler32"){} void Init()override { @@ -145,6 +142,9 @@ namespace hgl } };//class Adler32 - Hash *CreateAdler32Hash(){return(new Adler32);} + template<> Hash *CreateHash() + { + return(new Adler32()); + } }//namespace util }//namespace hgl diff --git a/src/hash/crc32.cpp b/src/hash/crc32.cpp index 1ea5ec1..4690edf 100644 --- a/src/hash/crc32.cpp +++ b/src/hash/crc32.cpp @@ -72,10 +72,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("CRC32");} - void GetName(UTF16String &str)const override{str=U16_TEXT("CRC32");} - - const int GetHashBytes()const override{return 4;} + CRC32():Hash(4,"CRC32"){} void Init()override { @@ -93,6 +90,9 @@ namespace hgl } };//class CRC32 - Hash *CreateCRC32Hash(){return(new CRC32);} + template<> Hash *CreateHash() + { + return(new CRC32); + } }//namespace util }//namepace hgl diff --git a/src/hash/md4.cpp b/src/hash/md4.cpp index a2b4483..68aab37 100644 --- a/src/hash/md4.cpp +++ b/src/hash/md4.cpp @@ -135,25 +135,16 @@ namespace hgl memset(x, 0, sizeof(x)); } }//namespace - + class MD4:public Hash { - enum - { - BLOCK_SIZE = 64, - DIGEST_SIZE = 16 - }; - uint32 state[4]; // state (ABCD) uint32 count[2]; // number of bits, modulo 2^64 (lsb first) uchar buffer[64]; // input buffer public: - void GetName(UTF8String &str)const override{str=U8_TEXT("MD4");} - void GetName(UTF16String &str)const override{str=U16_TEXT("MD4");} - - const int GetHashBytes()const override{return DIGEST_SIZE;} + MD4():Hash(16,"MD4"){} void Init()override { @@ -222,6 +213,9 @@ namespace hgl } };//class MD4 - Hash *CreateMD4Hash(){return(new MD4);} + template<> Hash *CreateHash() + { + return(new MD4); + } }//namespace util }//namespace hgl diff --git a/src/hash/md5.cpp b/src/hash/md5.cpp index f1ea188..da835f1 100644 --- a/src/hash/md5.cpp +++ b/src/hash/md5.cpp @@ -169,22 +169,13 @@ namespace hgl class MD5:public Hash { - enum - { - BLOCK_SIZE = 64, - DIGEST_SIZE = 16 - }; - uint32 state[4]; uint32 count[2]; uchar buffer[64]; public: - void GetName(UTF8String &str)const override{str=U8_TEXT("MD5");} - void GetName(UTF16String &str)const override{str=U16_TEXT("MD5");} - - const int GetHashBytes()const override{return DIGEST_SIZE;} + MD5():Hash(16,"MD5"){} void Init()override { @@ -253,6 +244,9 @@ namespace hgl } };//class MD5 - Hash *CreateMD5Hash(){return(new MD5);} + template<> Hash *CreateHash() + { + return(new MD5); + } }//namespace util }//namespace hgl diff --git a/src/hash/sha1.cpp b/src/hash/sha1.cpp index 9a71d6a..5ebb285 100644 --- a/src/hash/sha1.cpp +++ b/src/hash/sha1.cpp @@ -149,10 +149,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("SHA1");} - void GetName(UTF16String &str)const override{str=U16_TEXT("SHA1");} - - const int GetHashBytes()const override{return DIGEST_SIZE;} + SHA1():Hash(20,"SHA1"){} void Init()override { @@ -245,6 +242,9 @@ namespace hgl } };//class SHA1 - Hash *CreateSHA1Hash(){return(new SHA1);} + template<> Hash *CreateHash() + { + return(new SHA1); + } }//namespace util }//namespace hgl diff --git a/src/hash/sha1le.cpp b/src/hash/sha1le.cpp index b91f98a..040904a 100644 --- a/src/hash/sha1le.cpp +++ b/src/hash/sha1le.cpp @@ -222,6 +222,9 @@ namespace hgl hash[count] = (uint8) ((digest[count>>2]) >> (8*(3-(count & 0x3)))) & 0xff; } - Hash *CreateSHA1LEHash(){return(new SHA1LE);} + template<> Hash *CreateHash() + { + return(new SHA1LE); + } }//namespace util }//namespace hgl diff --git a/src/hash/sha256.cpp b/src/hash/sha256.cpp index b627d39..f18b8b7 100644 --- a/src/hash/sha256.cpp +++ b/src/hash/sha256.cpp @@ -91,10 +91,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("SHA256");} - void GetName(UTF16String &str)const override{str=U16_TEXT("SHA256");} - - const int GetHashBytes()const override{return DIGEST_SIZE;} + SHA256():Hash(DIGEST_SIZE,"SHA256"){} void Init()override { @@ -192,7 +189,10 @@ namespace hgl } };//class SHA256 - Hash *CreateSHA256Hash(){return(new SHA256);} + template<> Hash *CreateHash() + { + return(new SHA256); + } }//namespace util }//namespace hgl diff --git a/src/hash/sha512.cpp b/src/hash/sha512.cpp index a3b92d5..cd8b47e 100644 --- a/src/hash/sha512.cpp +++ b/src/hash/sha512.cpp @@ -163,10 +163,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("SHA512");} - void GetName(UTF16String &str)const override{str=U16_TEXT("SHA512");} - - const int GetHashBytes()const override{return DIGEST_SIZE;} + SHA512():Hash(DIGEST_SIZE,"SHA512"){} void Init()override { @@ -239,6 +236,9 @@ namespace hgl } };//class SHA512 - Hash *CreateSHA512Hash(){return(new SHA512);} + template<> Hash *CreateHash() + { + return(new SHA512); + } }//namespace util }//namespace hgl diff --git a/src/hash/xxHash3.cpp b/src/hash/xxHash3.cpp index 7970bfb..47183dc 100644 --- a/src/hash/xxHash3.cpp +++ b/src/hash/xxHash3.cpp @@ -23,10 +23,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("XXH32");} - void GetName(UTF16String &str)const override{str=U16_TEXT("XXH32");} - - const int GetHashBytes()const override{return 4;} + xxHash32():Hash(4,"xxH32"){} void Init()override { @@ -47,7 +44,7 @@ namespace hgl } };//class xxHash32 - Hash *CreatexxH32Hash() + template<> Hash *CreateHash() { return(new xxHash32); } @@ -59,10 +56,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("XXH64");} - void GetName(UTF16String &str)const override{str=U16_TEXT("XXH64");} - - const int GetHashBytes()const override{return 8;} + xxHash64():Hash(8,"xxH64"){} void Init()override { @@ -83,7 +77,7 @@ namespace hgl } };//class xxHash64 - Hash *CreatexxH64Hash() + template<> Hash *CreateHash() { return(new xxHash64); } @@ -95,10 +89,7 @@ namespace hgl public: - void GetName(UTF8String &str)const override{str=U8_TEXT("XXH3_64bits");} - void GetName(UTF16String &str)const override{str=U16_TEXT("XXH3_64bits");} - - const int GetHashBytes()const override{return 8;} + xxHash3_64():Hash(8,"xxH3_64bits"){} void Init()override { @@ -119,7 +110,7 @@ namespace hgl } };//class xxHash3_64 - Hash *CreateXXH3_64Hash() + template<> Hash *CreateHash() { return(new xxHash3_64); } @@ -130,11 +121,8 @@ namespace hgl XXH64_hash_t seed; public: - - void GetName(UTF8String &str)const override{str=U8_TEXT("XXH3_128bits");} - void GetName(UTF16String &str)const override{str=U16_TEXT("XXH3_128bits");} - - const int GetHashBytes()const override{return 16;} + + xxHash3_128():Hash(16,"xxH3_128bits"){} void Init()override { @@ -155,7 +143,7 @@ namespace hgl } };//class xxHash3_128 - Hash *CreateXXH3_128Hash() + template<> Hash *CreateHash() { return(new xxHash3_128); }