Excluded IterableList-based MichaelMap/Set from "erase by iterator" stress-test
[libcds.git] / test / stress / map / map_type_striped.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef CDSUNIT_MAP_TYPE_STRIPED_H
32 #define CDSUNIT_MAP_TYPE_STRIPED_H
33
34 #include "map_type.h"
35 #include <cds/container/striped_map/std_list.h>
36 #include <cds/container/striped_map/std_map.h>
37 #include <cds/container/striped_map/std_hash_map.h>
38
39 #include <boost/version.hpp>
40 #if BOOST_VERSION >= 104800
41 #   include <cds/container/striped_map/boost_list.h>
42 #   include <cds/container/striped_map/boost_slist.h>
43 #   include <cds/container/striped_map/boost_map.h>
44 #   include <cds/container/striped_map/boost_flat_map.h>
45 #endif
46 #include <cds/container/striped_map/boost_unordered_map.h>
47 #include <cds/container/striped_map.h>
48
49 namespace map {
50
51     struct tag_StripedMap;
52
53     template <typename Key, typename Value>
54     struct map_type< tag_StripedMap, Key, Value >: public map_type_base< Key, Value >
55     {
56         typedef map_type_base< Key, Value >      base_class;
57         typedef typename base_class::key_compare compare;
58         typedef typename base_class::key_less    less;
59         typedef typename base_class::equal_to    equal_to;
60         typedef typename base_class::key_hash    hash;
61         typedef typename base_class::hash2       hash2;
62
63         // for sequential containers
64         template <class BucketEntry, typename... Options>
65         class StripedHashMap_seq:
66             public cc::StripedMap< BucketEntry,
67                 co::mutex_policy< cc::striped_set::striping<> >
68                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
69                 , Options...
70             >
71         {
72             typedef cc::StripedMap< BucketEntry,
73                 co::mutex_policy< cc::striped_set::striping<> >
74                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
75                 , Options...
76             > base_class;
77             typedef typename base_class::resizing_policy resizing_policy_t;
78
79             resizing_policy_t   m_placeHolder;
80         public:
81             template <class Config>
82             StripedHashMap_seq( Config const& cfg )
83                 : base_class( cfg.s_nMapSize / cfg.s_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nLoadFactor )))
84             {}
85
86             empty_stat statistics() const
87             {
88                 return empty_stat();
89             }
90
91             // for testing
92             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
93             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
94         };
95
96         // for non-sequential ordered containers
97         template <class BucketEntry, typename... Options>
98         class StripedHashMap_ord:
99             public cc::StripedMap< BucketEntry,
100                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
101                 ,co::mutex_policy< cc::striped_set::striping<> >
102                 , Options...
103             >
104         {
105             typedef cc::StripedMap< BucketEntry,
106                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
107                 ,co::mutex_policy< cc::striped_set::striping<> >
108                 , Options...
109             > base_class;
110             typedef typename base_class::resizing_policy resizing_policy_t;
111
112             resizing_policy_t   m_placeHolder;
113         public:
114             template <class Config>
115             StripedHashMap_ord( Config const& cfg )
116                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nMaxLoadFactor * 1024 )))
117             {}
118
119             empty_stat statistics() const
120             {
121                 return empty_stat();
122             }
123
124             // for testing
125             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
126             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
127         };
128
129
130         typedef StripedHashMap_seq<
131             std::list< std::pair< Key const, Value > >
132             , co::hash< hash2 >
133             , co::less< less >
134         > StripedMap_list;
135
136         typedef StripedHashMap_ord<
137             std::unordered_map< Key, Value, hash, equal_to >
138             , co::hash< hash2 >
139         > StripedMap_hashmap;
140
141         typedef StripedHashMap_ord<
142             std::map< Key, Value, less >
143             , co::hash< hash2 >
144         > StripedMap_map;
145
146         typedef StripedHashMap_ord<
147             boost::unordered_map< Key, Value, hash, equal_to >
148             , co::hash< hash2 >
149         > StripedMap_boost_unordered_map;
150
151 #   if BOOST_VERSION >= 104800
152         typedef StripedHashMap_seq<
153             boost::container::slist< std::pair< Key const, Value > >
154             , co::hash< hash2 >
155             , co::less< less >
156         > StripedMap_slist;
157
158         typedef StripedHashMap_seq<
159             boost::container::list< std::pair< Key const, Value > >
160             , co::hash< hash2 >
161             , co::less< less >
162         > StripedMap_boost_list;
163
164         typedef StripedHashMap_ord<
165             boost::container::map< Key, Value, less >
166             , co::hash< hash2 >
167         > StripedMap_boost_map;
168
169         typedef StripedHashMap_ord<
170             boost::container::flat_map< Key, Value, less >
171             , co::hash< hash2 >
172         > StripedMap_boost_flat_map;
173 #   endif  // BOOST_VERSION >= 104800
174
175
176         // ***************************************************************************
177         // RefinableHashMap
178
179         // for sequential containers
180         template <class BucketEntry, typename... Options>
181         class RefinableHashMap_seq:
182             public cc::StripedMap< BucketEntry,
183                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
184                 ,co::mutex_policy< cc::striped_set::refinable<> >
185                 , Options...
186             >
187         {
188             typedef cc::StripedMap< BucketEntry,
189                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
190                 ,co::mutex_policy< cc::striped_set::refinable<> >
191                 , Options...
192             > base_class;
193             typedef typename base_class::resizing_policy resizing_policy_t;
194
195             resizing_policy_t   m_placeHolder;
196         public:
197             template <class Config>
198             RefinableHashMap_seq( Config const& cfg )
199                 : base_class( cfg.s_nMapSize / cfg.s_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nLoadFactor )))
200             {}
201
202             empty_stat statistics() const
203             {
204                 return empty_stat();
205             }
206
207             // for testing
208             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
209             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
210         };
211
212         // for non-sequential ordered containers
213         template <class BucketEntry, typename... Options>
214         class RefinableHashMap_ord:
215             public cc::StripedMap< BucketEntry,
216                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
217                 ,co::mutex_policy< cc::striped_set::refinable<> >
218                 , Options...
219             >
220         {
221             typedef cc::StripedMap< BucketEntry,
222                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
223                 ,co::mutex_policy< cc::striped_set::refinable<> >
224                 , Options...
225             > base_class;
226             typedef typename base_class::resizing_policy resizing_policy_t;
227
228             resizing_policy_t   m_placeHolder;
229         public:
230             template <class Config>
231             RefinableHashMap_ord( Config const& cfg )
232                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nMaxLoadFactor * 1024 )))
233             {}
234
235             empty_stat statistics() const
236             {
237                 return empty_stat();
238             }
239
240             // for testing
241             static CDS_CONSTEXPR bool const c_bExtractSupported = false;
242             static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
243         };
244
245
246         typedef RefinableHashMap_seq<
247             std::list< std::pair< Key const, Value > >
248             , co::hash< hash2 >
249             , co::less< less >
250         > RefinableMap_list;
251
252 #   if BOOST_VERSION >= 104800
253         typedef RefinableHashMap_seq<
254             boost::container::slist< std::pair< Key const, Value > >
255             , co::hash< hash2 >
256             , co::less< less >
257         > RefinableMap_slist;
258 #   endif
259
260         typedef RefinableHashMap_ord<
261             std::map< Key, Value, less >
262             , co::hash< hash2 >
263         > RefinableMap_map;
264
265         typedef RefinableHashMap_ord<
266             std::unordered_map< Key, Value, hash, equal_to >
267             , co::hash< hash2 >
268         > RefinableMap_hashmap;
269
270         typedef RefinableHashMap_ord<
271             boost::unordered_map< Key, Value, hash, equal_to >
272             , co::hash< hash2 >
273         > RefinableMap_boost_unordered_map;
274
275 #   if BOOST_VERSION >= 104800
276         typedef RefinableHashMap_seq<
277             boost::container::list< std::pair< Key const, Value > >
278             , co::hash< hash2 >
279             , co::less< less >
280         > RefinableMap_boost_list;
281
282         typedef RefinableHashMap_ord<
283             boost::container::map< Key, Value, less >
284             , co::hash< hash2 >
285         > RefinableMap_boost_map;
286
287         typedef RefinableHashMap_ord<
288             boost::container::flat_map< Key, Value, less >
289             , co::hash< hash2 >
290         > RefinableMap_boost_flat_map;
291 #   endif // #if BOOST_VERSION >= 104800
292
293     };
294 }   // namespace map
295
296 #define CDSSTRESS_StripedMap_case( fixture, test_case, striped_map_type, key_type, value_type ) \
297     TEST_P( fixture, striped_map_type ) \
298     { \
299         typedef map::map_type< tag_StripedMap, key_type, value_type >::striped_map_type map_type; \
300         test_case<map_type>(); \
301     }
302
303 #define CDSSTRESS_StripedMap( fixture, test_case, key_type, value_type ) \
304     CDSSTRESS_StripedMap_case( fixture, test_case, StripedMap_list,         key_type, value_type ) \
305     CDSSTRESS_StripedMap_case( fixture, test_case, StripedMap_hashmap,      key_type, value_type ) \
306     CDSSTRESS_StripedMap_case( fixture, test_case, StripedMap_map,          key_type, value_type ) \
307     CDSSTRESS_StripedMap_case( fixture, test_case, RefinableMap_list,       key_type, value_type ) \
308     CDSSTRESS_StripedMap_case( fixture, test_case, RefinableMap_map,        key_type, value_type ) \
309     CDSSTRESS_StripedMap_case( fixture, test_case, RefinableMap_hashmap,    key_type, value_type ) \
310
311 #endif // ifndef CDSUNIT_MAP_TYPE_STRIPED_H