Test working directory set to the binary output directory in order to
[libcds.git] / tests / unit / map2 / map_type.h
1 //$$CDS-header$$
2
3 #ifndef CDSUNIT_MAP_TYPE_H
4 #define CDSUNIT_MAP_TYPE_H
5
6 #include <cds/urcu/general_instant.h>
7 #include <cds/urcu/general_buffered.h>
8 #include <cds/urcu/general_threaded.h>
9 #include <cds/urcu/signal_buffered.h>
10 #include <cds/urcu/signal_threaded.h>
11
12 #include <cds/sync/spinlock.h>
13 #include <cds/opt/hash.h>
14 #include <boost/functional/hash/hash.hpp>
15
16 #include "cppunit/cppunit_mini.h"
17
18 namespace map2 {
19     namespace cc = cds::container;
20     namespace co = cds::opt;
21
22     typedef cds::urcu::gc< cds::urcu::general_instant<> >   rcu_gpi;
23     typedef cds::urcu::gc< cds::urcu::general_buffered<> >  rcu_gpb;
24     typedef cds::urcu::gc< cds::urcu::general_threaded<> >  rcu_gpt;
25 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
26     typedef cds::urcu::gc< cds::urcu::signal_buffered<> >  rcu_shb;
27     typedef cds::urcu::gc< cds::urcu::signal_threaded<> >  rcu_sht;
28 #endif
29
30     template <typename Key>
31     struct cmp {
32         int operator ()(Key const& k1, Key const& k2) const
33         {
34             if ( std::less<Key>( k1, k2 ) )
35                 return -1;
36             return std::less<Key>( k2, k1 ) ? 1 : 0;
37         }
38     };
39
40 #define CDSUNIT_INT_COMPARE(t)  template <> struct cmp<t> { int operator()( t k1, t k2 ){ return (int)(k1 - k2); } }
41     CDSUNIT_INT_COMPARE(char);
42     CDSUNIT_INT_COMPARE(unsigned char);
43     CDSUNIT_INT_COMPARE(int);
44     CDSUNIT_INT_COMPARE(unsigned int);
45     CDSUNIT_INT_COMPARE(long);
46     CDSUNIT_INT_COMPARE(unsigned long);
47     CDSUNIT_INT_COMPARE(long long);
48     CDSUNIT_INT_COMPARE(unsigned long long);
49 #undef CDSUNIT_INT_COMPARE
50
51     template <>
52     struct cmp<std::string>
53     {
54         int operator()(std::string const& s1, std::string const& s2)
55         {
56             return s1.compare( s2 );
57         }
58         int operator()(std::string const& s1, char const * s2)
59         {
60             return s1.compare( s2 );
61         }
62         int operator()(char const * s1, std::string const& s2)
63         {
64             return -s2.compare( s1 );
65         }
66     };
67
68     // forward
69     template <typename ImplSelector, typename Key, typename Value>
70     struct map_type;
71
72     template <typename Key, typename Value>
73     struct map_type_base
74     {
75         typedef co::v::hash<Key>    key_hash;
76         typedef std::less<Key>      less;
77         typedef cmp<Key>            compare;
78
79         struct equal_to {
80             bool operator()( Key const& k1, Key const& k2 ) const
81             {
82                 return compare()( k1, k2 ) == 0;
83             }
84         };
85
86         struct hash: public key_hash
87         {
88             size_t operator()( Key const& k ) const
89             {
90                 return key_hash::operator()( k );
91             }
92             template <typename Q>
93             size_t operator()( Q const& k ) const
94             {
95                 return key_hash::operator()( k );
96             }
97         };
98
99         struct hash2: public key_hash
100         {
101             size_t operator()( Key const& k ) const
102             {
103                 size_t seed = ~key_hash::operator ()( k );
104                 boost::hash_combine( seed, k );
105                 return seed;
106             }
107             template <typename Q>
108             size_t operator()( Q const& k ) const
109             {
110                 size_t seed = ~key_hash::operator()( k );
111                 boost::hash_combine( seed, k );
112                 return seed;
113             }
114         };
115     };
116
117     template <typename Map>
118     static inline void print_stat( Map const& /*m*/ )
119     {}
120
121     template <typename Map>
122     static inline void check_before_cleanup( Map& /*m*/ )
123     {}
124
125     template <typename Map>
126     static inline void additional_cleanup( Map& /*m*/ )
127     {}
128
129     template <typename Map>
130     static inline void additional_check( Map& /*m*/ )
131     {}
132
133 }   // namespace map2
134
135 #endif // ifndef CDSUNIT_MAP_TYPE_H