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_MICHAEL_H
32 #define CDSUNIT_MAP_TYPE_MICHAEL_H
34 #include "map2/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>
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::compare compare;
58 typedef typename base_class::less less;
59 typedef typename base_class::equal_to equal_to;
60 typedef typename base_class::key_hash key_hash;
61 typedef typename base_class::hash hash;
62 typedef typename base_class::hash2 hash2;
64 // for sequential containers
65 template <class BucketEntry, typename... Options>
66 class StripedHashMap_seq:
67 public cc::StripedMap< BucketEntry,
68 co::mutex_policy< cc::striped_set::striping<> >
69 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
73 typedef cc::StripedMap< BucketEntry,
74 co::mutex_policy< cc::striped_set::striping<> >
75 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
78 typedef typename base_class::resizing_policy resizing_policy_t;
80 resizing_policy_t m_placeHolder;
82 template <class Config>
83 StripedHashMap_seq( Config const& cfg )
84 : base_class( cfg.c_nMapSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )) )
88 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
89 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
92 // for non-sequential ordered containers
93 template <class BucketEntry, typename... Options>
94 class StripedHashMap_ord:
95 public cc::StripedMap< BucketEntry,
96 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
97 ,co::mutex_policy< cc::striped_set::striping<> >
101 typedef cc::StripedMap< BucketEntry,
102 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
103 ,co::mutex_policy< cc::striped_set::striping<> >
106 typedef typename base_class::resizing_policy resizing_policy_t;
108 resizing_policy_t m_placeHolder;
110 template <class Config>
111 StripedHashMap_ord( Config const& cfg )
112 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
116 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
117 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
121 typedef StripedHashMap_seq<
122 std::list< std::pair< Key const, Value > >
127 # if (CDS_COMPILER == CDS_COMPILER_MSVC || (CDS_COMPILER == CDS_COMPILER_INTEL && CDS_OS_INTERFACE == CDS_OSI_WINDOWS)) && _MSC_VER < 1600
128 typedef StripedHashMap_ord<
129 stdext::hash_map< Key, Value, stdext::hash_compare<Key, less > >
131 > StripedMap_hashmap;
133 typedef StripedHashMap_ord<
134 std::unordered_map< Key, Value, hash, equal_to >
136 > StripedMap_hashmap;
139 typedef StripedHashMap_ord<
140 std::map< Key, Value, less >
144 typedef StripedHashMap_ord<
145 boost::unordered_map< Key, Value, hash, equal_to >
147 > StripedMap_boost_unordered_map;
149 # if BOOST_VERSION >= 104800
150 typedef StripedHashMap_seq<
151 boost::container::slist< std::pair< Key const, Value > >
156 typedef StripedHashMap_seq<
157 boost::container::list< std::pair< Key const, Value > >
160 > StripedMap_boost_list;
162 typedef StripedHashMap_ord<
163 boost::container::map< Key, Value, less >
165 > StripedMap_boost_map;
167 typedef StripedHashMap_ord<
168 boost::container::flat_map< Key, Value, less >
170 > StripedMap_boost_flat_map;
171 # endif // BOOST_VERSION >= 104800
174 // ***************************************************************************
177 // for sequential containers
178 template <class BucketEntry, typename... Options>
179 class RefinableHashMap_seq:
180 public cc::StripedMap< BucketEntry,
181 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
182 ,co::mutex_policy< cc::striped_set::refinable<> >
186 typedef cc::StripedMap< BucketEntry,
187 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
188 ,co::mutex_policy< cc::striped_set::refinable<> >
191 typedef typename base_class::resizing_policy resizing_policy_t;
193 resizing_policy_t m_placeHolder;
195 template <class Config>
196 RefinableHashMap_seq( Config const& cfg )
197 : base_class( cfg.c_nMapSize / cfg.c_nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nLoadFactor )))
201 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
202 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = true;
205 // for non-sequential ordered containers
206 template <class BucketEntry, typename... Options>
207 class RefinableHashMap_ord:
208 public cc::StripedMap< BucketEntry,
209 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
210 ,co::mutex_policy< cc::striped_set::refinable<> >
214 typedef cc::StripedMap< BucketEntry,
215 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
216 ,co::mutex_policy< cc::striped_set::refinable<> >
219 typedef typename base_class::resizing_policy resizing_policy_t;
221 resizing_policy_t m_placeHolder;
223 template <class Config>
224 RefinableHashMap_ord( Config const& cfg )
225 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( cfg.c_nMaxLoadFactor * 1024 )) )
229 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
230 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
234 typedef RefinableHashMap_seq<
235 std::list< std::pair< Key const, Value > >
240 # if BOOST_VERSION >= 104800
241 typedef RefinableHashMap_seq<
242 boost::container::slist< std::pair< Key const, Value > >
245 > RefinableMap_slist;
248 typedef RefinableHashMap_ord<
249 std::map< Key, Value, less >
253 typedef RefinableHashMap_ord<
254 std::unordered_map< Key, Value, hash, equal_to >
256 > RefinableMap_hashmap;
258 typedef RefinableHashMap_ord<
259 boost::unordered_map< Key, Value, hash, equal_to >
261 > RefinableMap_boost_unordered_map;
263 # if BOOST_VERSION >= 104800
264 typedef RefinableHashMap_seq<
265 boost::container::list< std::pair< Key const, Value > >
268 > RefinableMap_boost_list;
270 typedef RefinableHashMap_ord<
271 boost::container::map< Key, Value, less >
273 > RefinableMap_boost_map;
275 typedef RefinableHashMap_ord<
276 boost::container::flat_map< Key, Value, less >
278 > RefinableMap_boost_flat_map;
279 # endif // #if BOOST_VERSION >= 104800
284 #endif // ifndef CDSUNIT_MAP_TYPE_MICHAEL_H