Test working directory set to the binary output directory in order to
[libcds.git] / tests / unit / map2 / map_type_cuckoo.h
1 //$$CDS-header$$
2
3 #ifndef CDSUNIT_MAP_TYPE_CUCKOO_H
4 #define CDSUNIT_MAP_TYPE_CUCKOO_H
5
6 #include "map2/map_type.h"
7 #include <cds/container/cuckoo_map.h>
8 #include "print_cuckoo_stat.h"
9
10 namespace map2 {
11
12     template <typename K, typename V, typename Traits>
13     class CuckooMap: public cc::CuckooMap< K, V, Traits >
14     {
15     public:
16         typedef cc::CuckooMap< K, V, Traits > base_class;
17
18     public:
19         template <typename Config>
20         CuckooMap( Config const& cfg )
21             : base_class( 
22                 cfg.c_nCuckooInitialSize,
23                 static_cast<unsigned int>( cfg.c_nCuckooProbesetSize ),
24                 static_cast<unsigned int>( cfg.c_nCuckooProbesetThreshold )
25             )
26         {}
27
28         template <typename Q, typename Pred>
29         bool erase_with( Q const& key, Pred /*pred*/ )
30         {
31             return base_class::erase_with( key, typename std::conditional< base_class::c_isSorted, Pred, typename Pred::equal_to>::type() );
32         }
33
34         // for testing
35         static CDS_CONSTEXPR bool const c_bExtractSupported = false;
36         static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
37         static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
38     };
39
40     struct tag_CuckooMap;
41
42     template <typename Key, typename Value>
43     struct map_type< tag_CuckooMap, Key, Value >: public map_type_base< Key, Value >
44     {
45         typedef map_type_base< Key, Value > base_class;
46         typedef typename base_class::compare    compare;
47         typedef typename base_class::less       less;
48         typedef typename base_class::equal_to   equal_to;
49         typedef typename base_class::key_hash   key_hash;
50         typedef typename base_class::hash       hash;
51         typedef typename base_class::hash2      hash2;
52
53         template <typename Traits>
54         struct traits_CuckooStripedMap: public Traits
55         {
56             typedef cc::cuckoo::striping<> mutex_policy;
57         };
58         template <typename Traits>
59         struct traits_CuckooRefinableMap : public Traits
60         {
61             typedef cc::cuckoo::refinable<> mutex_policy;
62         };
63
64         struct traits_CuckooMap_list_unord :
65             public cc::cuckoo::make_traits <
66                 cc::cuckoo::probeset_type< cc::cuckoo::list >
67                 , co::equal_to< equal_to >
68                 , co::hash< std::tuple< hash, hash2 > >
69             > ::type
70         {};
71         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord>> CuckooStripedMap_list_unord;
72         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord>> CuckooRefinableMap_list_unord;
73
74         struct traits_CuckooMap_list_unord_stat : public traits_CuckooMap_list_unord
75         {
76             typedef cc::cuckoo::stat stat;
77         };
78         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord_stat>> CuckooStripedMap_list_unord_stat;
79         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord_stat>> CuckooRefinableMap_list_unord_stat;
80
81         struct traits_CuckooMap_list_unord_storehash : public traits_CuckooMap_list_unord
82         {
83             static CDS_CONSTEXPR const bool store_hash = true;
84         };
85         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord_storehash>> CuckooStripedMap_list_unord_storehash;
86         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord_storehash>> CuckooRefinableMap_list_unord_storehash;
87
88         struct traits_CuckooMap_list_ord :
89             public cc::cuckoo::make_traits <
90                 cc::cuckoo::probeset_type< cc::cuckoo::list >
91                 , co::compare< compare >
92                 , co::hash< std::tuple< hash, hash2 > >
93             >::type
94         {};
95         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord>> CuckooStripedMap_list_ord;
96         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord>> CuckooRefinableMap_list_ord;
97
98         struct traits_CuckooMap_list_ord_stat : public traits_CuckooMap_list_ord
99         {
100             typedef cc::cuckoo::stat stat;
101         };
102         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord_stat>> CuckooStripedMap_list_ord_stat;
103         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord_stat>> CuckooRefinableMap_list_ord_stat;
104
105         struct traits_CuckooMap_list_ord_storehash : public traits_CuckooMap_list_ord
106         {
107             static CDS_CONSTEXPR const bool store_hash = true;
108         };
109         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord_storehash>> CuckooStripedMap_list_ord_storehash;
110         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord_storehash>> CuckooRefinableMap_list_ord_storehash;
111
112         struct traits_CuckooMap_vector_unord :
113             public cc::cuckoo::make_traits <
114                 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
115                 , co::equal_to< equal_to >
116                 , co::hash< std::tuple< hash, hash2 > >
117             >::type
118         {};
119         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord>> CuckooStripedMap_vector_unord;
120         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord>> CuckooRefinableMap_vector_unord;
121
122         struct traits_CuckooMap_vector_unord_stat : public traits_CuckooMap_vector_unord
123         {
124             typedef cc::cuckoo::stat stat;
125         };
126         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord_stat>> CuckooStripedMap_vector_unord_stat;
127         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord_stat>> CuckooRefinableMap_vector_unord_stat;
128
129         struct traits_CuckooMap_vector_unord_storehash : public traits_CuckooMap_vector_unord
130         {
131             static CDS_CONSTEXPR const bool store_hash = true;
132         };
133         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord_storehash>> CuckooStripedMap_vector_unord_storehash;
134         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord_storehash>> CuckooRefinableMap_vector_unord_storehash;
135
136         struct traits_CuckooMap_vector_ord :
137             public cc::cuckoo::make_traits <
138                 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
139                 , co::compare< compare >
140                 , co::hash< std::tuple< hash, hash2 > >
141             >::type
142         {};
143         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord>> CuckooStripedMap_vector_ord;
144         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord>> CuckooRefinableMap_vector_ord;
145
146         struct traits_CuckooMap_vector_ord_stat : public traits_CuckooMap_vector_ord
147         {
148             typedef cc::cuckoo::stat stat;
149         };
150         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord_stat>> CuckooStripedMap_vector_ord_stat;
151         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord_stat>> CuckooRefinableMap_vector_ord_stat;
152
153         struct traits_CuckooMap_vector_ord_storehash : public traits_CuckooMap_vector_ord
154         {
155             static CDS_CONSTEXPR const bool store_hash = true;
156         };
157         typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord_storehash>> CuckooStripedMap_vector_ord_storehash;
158         typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord_storehash>> CuckooRefinableMap_vector_ord_storehash;
159
160     };
161
162     template <typename K, typename T, typename Traits >
163     static inline void print_stat( cc::CuckooMap< K, T, Traits > const& m )
164     {
165         CPPUNIT_MSG( m.statistics() << m.mutex_policy_statistics() );
166     }
167
168     template <typename K, typename V, typename Traits>
169     static inline void print_stat( CuckooMap< K, V, Traits > const& m )
170     {
171         typedef CuckooMap< K, V, Traits > map_type;
172         print_stat( static_cast<typename map_type::base_class const&>(m) );
173     }
174
175 }   // namespace map2
176
177 #endif // ifndef CDSUNIT_MAP_TYPE_CUCKOO_H