3 #ifndef CDSUNIT_MAP_TYPE_H
4 #define CDSUNIT_MAP_TYPE_H
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>
12 #include <cds/sync/spinlock.h>
13 #include <cds/opt/hash.h>
14 #include <boost/functional/hash/hash.hpp>
16 #include "cppunit/cppunit_mini.h"
19 namespace cc = cds::container;
20 namespace co = cds::opt;
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;
30 template <typename Key>
32 int operator ()(Key const& k1, Key const& k2) const
34 if ( std::less<Key>( k1, k2 ) )
36 return std::less<Key>( k2, k1 ) ? 1 : 0;
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
52 struct cmp<std::string>
54 int operator()(std::string const& s1, std::string const& s2)
56 return s1.compare( s2 );
58 int operator()(std::string const& s1, char const * s2)
60 return s1.compare( s2 );
62 int operator()(char const * s1, std::string const& s2)
64 return -s2.compare( s1 );
69 template <typename ImplSelector, typename Key, typename Value>
72 template <typename Key, typename Value>
75 typedef co::v::hash<Key> key_hash;
76 typedef std::less<Key> less;
77 typedef cmp<Key> compare;
80 bool operator()( Key const& k1, Key const& k2 ) const
82 return compare()( k1, k2 ) == 0;
86 struct hash: public key_hash
88 size_t operator()( Key const& k ) const
90 return key_hash::operator()( k );
93 size_t operator()( Q const& k ) const
95 return key_hash::operator()( k );
99 struct hash2: public key_hash
101 size_t operator()( Key const& k ) const
103 size_t seed = ~key_hash::operator ()( k );
104 boost::hash_combine( seed, k );
107 template <typename Q>
108 size_t operator()( Q const& k ) const
110 size_t seed = ~key_hash::operator()( k );
111 boost::hash_combine( seed, k );
117 template <typename Map>
118 static inline void print_stat( Map const& /*m*/ )
121 template <typename Map>
122 static inline void check_before_cleanup( Map& /*m*/ )
125 template <typename Map>
126 static inline void additional_cleanup( Map& /*m*/ )
129 template <typename Map>
130 static inline void additional_check( Map& /*m*/ )
135 #endif // ifndef CDSUNIT_MAP_TYPE_H