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));
67 bool operator()( hash_type lhs, hash_type rhs ) const
76 typedef uint64_t hash_type;
78 hash_type operator()( void const * pBuf, size_t len )
80 return CityHash64( reinterpret_cast<char const *>( pBuf ), len );
83 hash_type operator()( std::string const& s )
85 return CityHash64( s.c_str(), s.length() );
89 hash_type operator()( T const& s )
91 return CityHash64( reinterpret_cast<char const *>( &s ), sizeof(s));
96 bool operator()( hash_type lhs, hash_type rhs ) const
105 typedef uint128 hash_type;
107 hash_type operator()( void const * pBuf, size_t len )
109 return CityHash128( reinterpret_cast<char const *>( pBuf ), len );
112 hash_type operator()( std::string const& s )
114 return CityHash128( s.c_str(), s.length() );
117 template <typename T>
118 hash_type operator()( T const& s )
120 return CityHash128( reinterpret_cast<char const *>( &s ), sizeof(s));
125 bool operator()( hash_type const& lhs, hash_type const& rhs ) const
127 if ( lhs.first != rhs.first )
128 return lhs.second < rhs.second;
129 return lhs.first < rhs.first;
134 } // namespace hashing
136 #endif // #ifndef CDSUNIT_HASH_FUNC_H