3 #ifndef CDSUNIT_HASH_FUNC_H
4 #define CDSUNIT_HASH_FUNC_H
6 #include <cds/details/defs.h>
8 #include "hashing/sha256.h"
9 #include "hashing/md5.h"
10 #if CDS_BUILD_BITS == 64
11 # include "hashing/city.h"
16 template <class Hasher>
18 typedef Hasher hasher_type;
22 uint8_t h[hasher_type::HashBytes];
25 hash_type operator()( void const * pBuf, size_t len )
28 m_hasher.add(pBuf, len);
30 m_hasher.getHash( result.h );
34 hash_type operator()( std::string const& s )
36 return operator()( reinterpret_cast<void const *>(s.c_str()), s.length());
40 hash_type operator()( T const& s )
42 return operator()( reinterpret_cast<void const *>(&s), sizeof(s));
46 typedef hasher<SHA256> sha256;
47 typedef hasher<MD5> md5;
49 #if CDS_BUILD_BITS == 64
52 typedef uint32_t hash_type;
54 hash_type operator()( void const * pBuf, size_t len )
56 return CityHash32( reinterpret_cast<char const *>( pBuf ), len );
59 hash_type operator()( std::string const& s )
61 return CityHash32( s.c_str(), s.length() );
65 hash_type operator()( T const& s )
67 return CityHash32( reinterpret_cast<char const *>( &s ), sizeof(s));
72 bool operator()( hash_type lhs, hash_type rhs ) const
81 typedef uint64_t hash_type;
83 hash_type operator()( void const * pBuf, size_t len )
85 return CityHash64( reinterpret_cast<char const *>( pBuf ), len );
88 hash_type operator()( std::string const& s )
90 return CityHash64( s.c_str(), s.length() );
94 hash_type operator()( T const& s )
96 return CityHash64( reinterpret_cast<char const *>( &s ), sizeof(s));
101 bool operator()( hash_type lhs, hash_type rhs ) const
110 typedef uint128 hash_type;
112 hash_type operator()( void const * pBuf, size_t len )
114 return CityHash128( reinterpret_cast<char const *>( pBuf ), len );
117 hash_type operator()( std::string const& s )
119 return CityHash128( s.c_str(), s.length() );
122 template <typename T>
123 hash_type operator()( T const& s )
125 return CityHash128( reinterpret_cast<char const *>( &s ), sizeof(s));
130 bool operator()( hash_type const& lhs, hash_type const& rhs ) const
132 if ( lhs.first != rhs.first )
133 return lhs.second < rhs.second;
134 return lhs.first < rhs.first;
138 #endif // #if CDS_BUILD_BITS == 64
141 } // namespace hashing
143 #endif // #ifndef CDSUNIT_HASH_FUNC_H