Migrated Set_DelOdd stress test to gtest framework
[libcds.git] / test / include / cds_test / hash_func.h
1 //$$CDS-header$$
2
3 #ifndef CDSUNIT_HASH_FUNC_H
4 #define CDSUNIT_HASH_FUNC_H
5
6 #include <cds/details/defs.h>
7
8 #if CDS_BUILD_BITS == 64
9 #   include <cds_test/city.h>
10 #endif
11
12 namespace cds_test {
13
14 #if CDS_BUILD_BITS == 64
15     class city32 {
16     public:
17         typedef uint32_t hash_type;
18
19         hash_type operator()( void const * pBuf, size_t len )
20         {
21             return CityHash32( reinterpret_cast<char const *>( pBuf ), len );
22         }
23
24         hash_type operator()( std::string const& s )
25         {
26             return CityHash32( s.c_str(), s.length() );
27         }
28
29         template <typename T>
30         hash_type operator()( T const& s )
31         {
32             return CityHash32( reinterpret_cast<char const *>( &s ), sizeof(s));
33         }
34
35         struct less
36         {
37             bool operator()( hash_type lhs, hash_type rhs ) const
38             {
39                 return lhs < rhs;
40             }
41         };
42     };
43
44     class city64 {
45     public:
46         typedef uint64_t hash_type;
47
48         hash_type operator()( void const * pBuf, size_t len )
49         {
50             return CityHash64( reinterpret_cast<char const *>( pBuf ), len );
51         }
52
53         hash_type operator()( std::string const& s )
54         {
55             return CityHash64( s.c_str(), s.length() );
56         }
57
58         template <typename T>
59         hash_type operator()( T const& s )
60         {
61             return CityHash64( reinterpret_cast<char const *>( &s ), sizeof(s));
62         }
63
64         struct less
65         {
66             bool operator()( hash_type lhs, hash_type rhs ) const
67             {
68                 return lhs < rhs;
69             }
70         };
71     };
72
73     class city128 {
74     public:
75         typedef uint128 hash_type;
76
77         hash_type operator()( void const * pBuf, size_t len )
78         {
79             return CityHash128( reinterpret_cast<char const *>( pBuf ), len );
80         }
81
82         hash_type operator()( std::string const& s )
83         {
84             return CityHash128( s.c_str(), s.length() );
85         }
86
87         template <typename T>
88         hash_type operator()( T const& s )
89         {
90             return CityHash128( reinterpret_cast<char const *>( &s ), sizeof(s));
91         }
92
93         struct less
94         {
95             bool operator()( hash_type const& lhs, hash_type const& rhs ) const
96             {
97                 if ( lhs.first != rhs.first )
98                     return lhs.second < rhs.second;
99                 return lhs.first < rhs.first;
100             }
101         };
102     };
103 #endif // #if CDS_BUILD_BITS == 64
104
105
106 } // namespace cds_test
107
108 #endif // #ifndef CDSUNIT_HASH_FUNC_H