3 #ifndef CDSUNIT_HASH_FUNC_H
4 #define CDSUNIT_HASH_FUNC_H
6 #include "hashing/sha256.h"
7 #include "hashing/md5.h"
8 #include "hashing/city.h"
12 template <class Hasher>
14 typedef Hasher hasher_type;
18 uint8_t h[hasher_type::HashBytes];
21 hash_type operator()( void const * pBuf, size_t len )
24 m_hasher.add(pBuf, len);
26 m_hasher.getHash( result.h );
30 hash_type operator()( std::string const& s )
32 return operator()( reinterpret_cast<void const *>(s.c_str()), s.length());
36 hash_type operator()( T const& s )
38 return operator()( reinterpret_cast<void const *>(&s), sizeof(s));
42 typedef hasher<SHA256> sha256;
43 typedef hasher<MD5> md5;
47 typedef uint32_t hash_type;
49 hash_type operator()( void const * pBuf, size_t len )
51 return CityHash32( reinterpret_cast<char const *>( pBuf ), len );
54 hash_type operator()( std::string const& s )
56 return CityHash32( s.c_str(), s.length() );
60 hash_type operator()( T const& s )
62 return CityHash32( reinterpret_cast<char const *>( &s ), sizeof(s));
68 typedef uint64_t hash_type;
70 hash_type operator()( void const * pBuf, size_t len )
72 return CityHash64( reinterpret_cast<char const *>( pBuf ), len );
75 hash_type operator()( std::string const& s )
77 return CityHash64( s.c_str(), s.length() );
81 hash_type operator()( T const& s )
83 return CityHash64( reinterpret_cast<char const *>( &s ), sizeof(s));
89 typedef uint128 hash_type;
91 hash_type operator()( void const * pBuf, size_t len )
93 return CityHash128( reinterpret_cast<char const *>( pBuf ), len );
96 hash_type operator()( std::string const& s )
98 return CityHash128( s.c_str(), s.length() );
101 template <typename T>
102 hash_type operator()( T const& s )
104 return CityHash128( reinterpret_cast<char const *>( &s ), sizeof(s));
108 } // namespace hashing
110 #endif // #ifndef CDSUNIT_HASH_FUNC_H