2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
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 )) )
87 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
88 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
91 // for non-sequential ordered containers
92 template <class BucketEntry, typename... Options>
93 class StripedHashMap_ord:
94 public cc::StripedMap< BucketEntry,
95 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
96 ,co::mutex_policy< cc::striped_set::striping<> >
100 typedef cc::StripedMap< BucketEntry,
101 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
102 ,co::mutex_policy< cc::striped_set::striping<> >
105 typedef typename base_class::resizing_policy resizing_policy_t;
107 resizing_policy_t m_placeHolder;
109 template <class Config>
110 StripedHashMap_ord( Config const& cfg )
111 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nMaxLoadFactor * 1024 )) )
115 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
116 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
120 typedef StripedHashMap_seq<
121 std::list< std::pair< Key const, Value > >
126 typedef StripedHashMap_ord<
127 std::unordered_map< Key, Value, hash, equal_to >
129 > StripedMap_hashmap;
131 typedef StripedHashMap_ord<
132 std::map< Key, Value, less >
136 typedef StripedHashMap_ord<
137 boost::unordered_map< Key, Value, hash, equal_to >
139 > StripedMap_boost_unordered_map;
141 # if BOOST_VERSION >= 104800
142 typedef StripedHashMap_seq<
143 boost::container::slist< std::pair< Key const, Value > >
148 typedef StripedHashMap_seq<
149 boost::container::list< std::pair< Key const, Value > >
152 > StripedMap_boost_list;
154 typedef StripedHashMap_ord<
155 boost::container::map< Key, Value, less >
157 > StripedMap_boost_map;
159 typedef StripedHashMap_ord<
160 boost::container::flat_map< Key, Value, less >
162 > StripedMap_boost_flat_map;
163 # endif // BOOST_VERSION >= 104800
166 // ***************************************************************************
169 // for sequential containers
170 template <class BucketEntry, typename... Options>
171 class RefinableHashMap_seq:
172 public cc::StripedMap< BucketEntry,
173 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
174 ,co::mutex_policy< cc::striped_set::refinable<> >
178 typedef cc::StripedMap< BucketEntry,
179 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
180 ,co::mutex_policy< cc::striped_set::refinable<> >
183 typedef typename base_class::resizing_policy resizing_policy_t;
185 resizing_policy_t m_placeHolder;
187 template <class Config>
188 RefinableHashMap_seq( Config const& cfg )
189 : base_class( cfg.s_nMapSize / cfg.s_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nLoadFactor )))
193 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
194 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
197 // for non-sequential ordered containers
198 template <class BucketEntry, typename... Options>
199 class RefinableHashMap_ord:
200 public cc::StripedMap< BucketEntry,
201 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
202 ,co::mutex_policy< cc::striped_set::refinable<> >
206 typedef cc::StripedMap< BucketEntry,
207 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
208 ,co::mutex_policy< cc::striped_set::refinable<> >
211 typedef typename base_class::resizing_policy resizing_policy_t;
213 resizing_policy_t m_placeHolder;
215 template <class Config>
216 RefinableHashMap_ord( Config const& cfg )
217 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.s_nMaxLoadFactor * 1024 )) )
221 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
222 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
226 typedef RefinableHashMap_seq<
227 std::list< std::pair< Key const, Value > >
232 # if BOOST_VERSION >= 104800
233 typedef RefinableHashMap_seq<
234 boost::container::slist< std::pair< Key const, Value > >
237 > RefinableMap_slist;
240 typedef RefinableHashMap_ord<
241 std::map< Key, Value, less >
245 typedef RefinableHashMap_ord<
246 std::unordered_map< Key, Value, hash, equal_to >
248 > RefinableMap_hashmap;
250 typedef RefinableHashMap_ord<
251 boost::unordered_map< Key, Value, hash, equal_to >
253 > RefinableMap_boost_unordered_map;
255 # if BOOST_VERSION >= 104800
256 typedef RefinableHashMap_seq<
257 boost::container::list< std::pair< Key const, Value > >
260 > RefinableMap_boost_list;
262 typedef RefinableHashMap_ord<
263 boost::container::map< Key, Value, less >
265 > RefinableMap_boost_map;
267 typedef RefinableHashMap_ord<
268 boost::container::flat_map< Key, Value, less >
270 > RefinableMap_boost_flat_map;
271 # endif // #if BOOST_VERSION >= 104800
276 #define CDSSTRESS_StripedMap_case( fixture, test_case, striped_map_type, key_type, value_type ) \
277 TEST_P( fixture, striped_map_type ) \
279 typedef map::map_type< tag_StripedMap, key_type, value_type >::striped_map_type map_type; \
280 test_case<map_type>(); \
283 #define CDSSTRESS_StripedMap( fixture, test_case, key_type, value_type ) \
284 CDSSTRESS_StripedMap_case( fixture, test_case, StripedMap_list, key_type, value_type ) \
285 CDSSTRESS_StripedMap_case( fixture, test_case, StripedMap_hashmap, key_type, value_type ) \
286 CDSSTRESS_StripedMap_case( fixture, test_case, StripedMap_map, key_type, value_type ) \
287 CDSSTRESS_StripedMap_case( fixture, test_case, RefinableMap_list, key_type, value_type ) \
288 CDSSTRESS_StripedMap_case( fixture, test_case, RefinableMap_map, key_type, value_type ) \
289 CDSSTRESS_StripedMap_case( fixture, test_case, RefinableMap_hashmap, key_type, value_type ) \
291 #endif // ifndef CDSUNIT_MAP_TYPE_STRIPED_H