2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #ifndef CDSUNIT_MAP_TYPE_STRIPED_H
32 #define CDSUNIT_MAP_TYPE_STRIPED_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>
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>
46 #include <cds/container/striped_map/boost_unordered_map.h>
47 #include <cds/container/striped_map.h>
51 struct tag_StripedMap;
53 template <typename Key, typename Value>
54 struct map_type< tag_StripedMap, Key, Value >: public map_type_base< Key, Value >
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;
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> >
72 typedef cc::StripedMap< BucketEntry,
73 co::mutex_policy< cc::striped_set::striping<> >
74 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
77 typedef typename base_class::resizing_policy resizing_policy_t;
79 resizing_policy_t m_placeHolder;
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 )))
86 empty_stat statistics() const
92 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
93 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
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<> >
105 typedef cc::StripedMap< BucketEntry,
106 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
107 ,co::mutex_policy< cc::striped_set::striping<> >
110 typedef typename base_class::resizing_policy resizing_policy_t;
112 resizing_policy_t m_placeHolder;
114 template <class Config>
115 StripedHashMap_ord( Config const& cfg )
116 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nMaxLoadFactor * 1024 )))
119 empty_stat statistics() const
125 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
126 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
130 typedef StripedHashMap_seq<
131 std::list< std::pair< Key const, Value > >
136 typedef StripedHashMap_ord<
137 std::unordered_map< Key, Value, hash, equal_to >
139 > StripedMap_hashmap;
141 typedef StripedHashMap_ord<
142 std::map< Key, Value, less >
146 typedef StripedHashMap_ord<
147 boost::unordered_map< Key, Value, hash, equal_to >
149 > StripedMap_boost_unordered_map;
151 # if BOOST_VERSION >= 104800
152 typedef StripedHashMap_seq<
153 boost::container::slist< std::pair< Key const, Value > >
158 typedef StripedHashMap_seq<
159 boost::container::list< std::pair< Key const, Value > >
162 > StripedMap_boost_list;
164 typedef StripedHashMap_ord<
165 boost::container::map< Key, Value, less >
167 > StripedMap_boost_map;
169 typedef StripedHashMap_ord<
170 boost::container::flat_map< Key, Value, less >
172 > StripedMap_boost_flat_map;
173 # endif // BOOST_VERSION >= 104800
176 // ***************************************************************************
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<> >
188 typedef cc::StripedMap< BucketEntry,
189 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
190 ,co::mutex_policy< cc::striped_set::refinable<> >
193 typedef typename base_class::resizing_policy resizing_policy_t;
195 resizing_policy_t m_placeHolder;
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 )))
202 empty_stat statistics() const
208 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
209 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
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<> >
221 typedef cc::StripedMap< BucketEntry,
222 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
223 ,co::mutex_policy< cc::striped_set::refinable<> >
226 typedef typename base_class::resizing_policy resizing_policy_t;
228 resizing_policy_t m_placeHolder;
230 template <class Config>
231 RefinableHashMap_ord( Config const& cfg )
232 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nMaxLoadFactor * 1024 )))
235 empty_stat statistics() const
241 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
242 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
246 typedef RefinableHashMap_seq<
247 std::list< std::pair< Key const, Value > >
252 # if BOOST_VERSION >= 104800
253 typedef RefinableHashMap_seq<
254 boost::container::slist< std::pair< Key const, Value > >
257 > RefinableMap_slist;
260 typedef RefinableHashMap_ord<
261 std::map< Key, Value, less >
265 typedef RefinableHashMap_ord<
266 std::unordered_map< Key, Value, hash, equal_to >
268 > RefinableMap_hashmap;
270 typedef RefinableHashMap_ord<
271 boost::unordered_map< Key, Value, hash, equal_to >
273 > RefinableMap_boost_unordered_map;
275 # if BOOST_VERSION >= 104800
276 typedef RefinableHashMap_seq<
277 boost::container::list< std::pair< Key const, Value > >
280 > RefinableMap_boost_list;
282 typedef RefinableHashMap_ord<
283 boost::container::map< Key, Value, less >
285 > RefinableMap_boost_map;
287 typedef RefinableHashMap_ord<
288 boost::container::flat_map< Key, Value, less >
290 > RefinableMap_boost_flat_map;
291 # endif // #if BOOST_VERSION >= 104800
296 #define CDSSTRESS_StripedMap_case( fixture, test_case, striped_map_type, key_type, value_type ) \
297 TEST_P( fixture, striped_map_type ) \
299 typedef map::map_type< tag_StripedMap, key_type, value_type >::striped_map_type map_type; \
300 test_case<map_type>(); \
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 ) \
311 #endif // ifndef CDSUNIT_MAP_TYPE_STRIPED_H