Refactored Map_insdel_int MT-test
[libcds.git] / tests / unit / map2 / map_type_striped.h
1 //$$CDS-header$$
2
3 #ifndef CDSUNIT_MAP_TYPE_MICHAEL_H
4 #define CDSUNIT_MAP_TYPE_MICHAEL_H
5
6 #include "map2/map_type.h"
7 #include <cds/container/striped_map/std_list.h>
8 #include <cds/container/striped_map/std_map.h>
9 #include <cds/container/striped_map/std_hash_map.h>
10
11 #include <boost/version.hpp>
12 #if BOOST_VERSION >= 104800
13 #   include <cds/container/striped_map/boost_list.h>
14 #   include <cds/container/striped_map/boost_slist.h>
15 #   include <cds/container/striped_map/boost_map.h>
16 #   include <cds/container/striped_map/boost_flat_map.h>
17 #endif
18 #include <cds/container/striped_map/boost_unordered_map.h>
19 #include <cds/container/striped_map.h>
20
21 namespace map2 {
22
23     struct tag_StripedMap;
24
25     template <typename Key, typename Value>
26     struct map_type< tag_StripedMap, Key, Value >: public map_type_base< Key, Value >
27     {
28         typedef map_type_base< Key, Value > base_class;
29         typedef typename base_class::compare    compare;
30         typedef typename base_class::less       less;
31         typedef typename base_class::equal_to   equal_to;
32         typedef typename base_class::key_hash   key_hash;
33         typedef typename base_class::hash       hash;
34         typedef typename base_class::hash2      hash2;
35
36         // for sequential containers
37         template <class BucketEntry, typename... Options>
38         class StripedHashMap_seq:
39             public cc::StripedMap< BucketEntry,
40                 co::mutex_policy< cc::striped_set::striping<> >
41                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
42                 , Options...
43             >
44         {
45             typedef cc::StripedMap< BucketEntry,
46                 co::mutex_policy< cc::striped_set::striping<> >
47                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
48                 , Options...
49             > base_class;
50             typedef typename base_class::resizing_policy resizing_policy_t;
51
52             resizing_policy_t   m_placeHolder;
53         public:
54             template <class Config>
55             StripedHashMap_seq( Config const& cfg )
56                 : base_class( cfg.c_nMapSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )) )
57             {}
58
59             // for testing
60             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
61             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
62         };
63
64         // for non-sequential ordered containers
65         template <class BucketEntry, typename... Options>
66         class StripedHashMap_ord:
67             public cc::StripedMap< BucketEntry,
68                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
69                 ,co::mutex_policy< cc::striped_set::striping<> >
70                 , Options...
71             >
72         {
73             typedef cc::StripedMap< BucketEntry,
74                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
75                 ,co::mutex_policy< cc::striped_set::striping<> >
76                 , Options...
77             > base_class;
78             typedef typename base_class::resizing_policy resizing_policy_t;
79
80             resizing_policy_t   m_placeHolder;
81         public:
82             template <class Config>
83             StripedHashMap_ord( Config const& cfg )
84                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
85             {}
86
87             // for testing
88             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
89             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
90         };
91
92
93         typedef StripedHashMap_seq<
94             std::list< std::pair< Key const, Value > >
95             , co::hash< hash2 >
96             , co::less< less >
97         > StripedMap_list;
98
99 #   if (CDS_COMPILER == CDS_COMPILER_MSVC || (CDS_COMPILER == CDS_COMPILER_INTEL && CDS_OS_INTERFACE == CDS_OSI_WINDOWS)) && _MSC_VER < 1600
100         typedef StripedHashMap_ord<
101             stdext::hash_map< Key, Value, stdext::hash_compare<Key, less > >
102             , co::hash< hash2 >
103         > StripedMap_hashmap;
104 #   else
105         typedef StripedHashMap_ord<
106             std::unordered_map< Key, Value, hash, equal_to >
107             , co::hash< hash2 >
108         > StripedMap_hashmap;
109 #   endif
110
111         typedef StripedHashMap_ord<
112             std::map< Key, Value, less >
113             , co::hash< hash2 >
114         > StripedMap_map;
115
116         typedef StripedHashMap_ord<
117             boost::unordered_map< Key, Value, hash, equal_to >
118             , co::hash< hash2 >
119         > StripedMap_boost_unordered_map;
120
121 #   if BOOST_VERSION >= 104800
122         typedef StripedHashMap_seq<
123             boost::container::slist< std::pair< Key const, Value > >
124             , co::hash< hash2 >
125             , co::less< less >
126         > StripedMap_slist;
127
128         typedef StripedHashMap_seq<
129             boost::container::list< std::pair< Key const, Value > >
130             , co::hash< hash2 >
131             , co::less< less >
132         > StripedMap_boost_list;
133
134         typedef StripedHashMap_ord<
135             boost::container::map< Key, Value, less >
136             , co::hash< hash2 >
137         > StripedMap_boost_map;
138
139         typedef StripedHashMap_ord<
140             boost::container::flat_map< Key, Value, less >
141             , co::hash< hash2 >
142         > StripedMap_boost_flat_map;
143 #   endif  // BOOST_VERSION >= 104800
144
145
146         // ***************************************************************************
147         // RefinableHashMap
148
149         // for sequential containers
150         template <class BucketEntry, typename... Options>
151         class RefinableHashMap_seq:
152             public cc::StripedMap< BucketEntry,
153                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
154                 ,co::mutex_policy< cc::striped_set::refinable<> >
155                 , Options...
156             >
157         {
158             typedef cc::StripedMap< BucketEntry,
159                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
160                 ,co::mutex_policy< cc::striped_set::refinable<> >
161                 , Options...
162             > base_class;
163             typedef typename base_class::resizing_policy resizing_policy_t;
164
165             resizing_policy_t   m_placeHolder;
166         public:
167             template <class Config>
168             RefinableHashMap_seq( Config const& cfg )
169                 : base_class( cfg.c_nMapSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )))
170             {}
171
172             // for testing
173             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
174             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
175         };
176
177         // for non-sequential ordered containers
178         template <class BucketEntry, typename... Options>
179         class RefinableHashMap_ord:
180             public cc::StripedMap< BucketEntry,
181                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
182                 ,co::mutex_policy< cc::striped_set::refinable<> >
183                 , Options...
184             >
185         {
186             typedef cc::StripedMap< BucketEntry,
187                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
188                 ,co::mutex_policy< cc::striped_set::refinable<> >
189                 , Options...
190             > base_class;
191             typedef typename base_class::resizing_policy resizing_policy_t;
192
193             resizing_policy_t   m_placeHolder;
194         public:
195             template <class Config>
196             RefinableHashMap_ord( Config const& cfg )
197                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
198             {}
199
200             // for testing
201             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
202             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
203         };
204
205
206         typedef RefinableHashMap_seq<
207             std::list< std::pair< Key const, Value > >
208             , co::hash< hash2 >
209             , co::less< less >
210         > RefinableMap_list;
211
212 #   if BOOST_VERSION >= 104800
213         typedef RefinableHashMap_seq<
214             boost::container::slist< std::pair< Key const, Value > >
215             , co::hash< hash2 >
216             , co::less< less >
217         > RefinableMap_slist;
218 #   endif
219
220         typedef RefinableHashMap_ord<
221             std::map< Key, Value, less >
222             , co::hash< hash2 >
223         > RefinableMap_map;
224
225         typedef RefinableHashMap_ord<
226             std::unordered_map< Key, Value, hash, equal_to >
227             , co::hash< hash2 >
228         > RefinableMap_hashmap;
229
230         typedef RefinableHashMap_ord<
231             boost::unordered_map< Key, Value, hash, equal_to >
232             , co::hash< hash2 >
233         > RefinableMap_boost_unordered_map;
234
235 #   if BOOST_VERSION >= 104800
236         typedef RefinableHashMap_seq<
237             boost::container::list< std::pair< Key const, Value > >
238             , co::hash< hash2 >
239             , co::less< less >
240         > RefinableMap_boost_list;
241
242         typedef RefinableHashMap_ord<
243             boost::container::map< Key, Value, less >
244             , co::hash< hash2 >
245         > RefinableMap_boost_map;
246
247         typedef RefinableHashMap_ord<
248             boost::container::flat_map< Key, Value, less >
249             , co::hash< hash2 >
250         > RefinableMap_boost_flat_map;
251 #   endif // #if BOOST_VERSION >= 104800
252
253     };
254 }   // namespace map2
255
256 #endif // ifndef CDSUNIT_MAP_TYPE_MICHAEL_H