Reorganized map2 unit test to reduce compiling time and memory
[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     template <typename Key, typename Value>
24     struct map_type< cc::striped_set::implementation_tag, Key, Value >: public map_type_base< Key, Value >
25     {
26         typedef map_type_base< Key, Value > base_class;
27         typedef typename base_class::compare    compare;
28         typedef typename base_class::less       less;
29         typedef typename base_class::equal_to   equal_to;
30         typedef typename base_class::key_hash   key_hash;
31         typedef typename base_class::hash       hash;
32         typedef typename base_class::hash2      hash2;
33
34         // for sequential containers
35         template <class BucketEntry, typename... Options>
36         class StripedHashMap_seq:
37             public cc::StripedMap< BucketEntry,
38                 co::mutex_policy< cc::striped_set::striping<> >
39                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
40                 , Options...
41             >
42         {
43             typedef cc::StripedMap< BucketEntry,
44                 co::mutex_policy< cc::striped_set::striping<> >
45                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
46                 , Options...
47             > base_class;
48             typedef typename base_class::resizing_policy resizing_policy_t;
49
50             resizing_policy_t   m_placeHolder;
51         public:
52             StripedHashMap_seq( size_t nCapacity, size_t nLoadFactor )
53                 : base_class( nCapacity / nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor )) )
54             {}
55         };
56
57         // for non-sequential ordered containers
58         template <class BucketEntry, typename... Options>
59         class StripedHashMap_ord:
60             public cc::StripedMap< BucketEntry,
61                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
62                 ,co::mutex_policy< cc::striped_set::striping<> >
63                 , Options...
64             >
65         {
66             typedef cc::StripedMap< BucketEntry,
67                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
68                 ,co::mutex_policy< cc::striped_set::striping<> >
69                 , Options...
70             > base_class;
71             typedef typename base_class::resizing_policy resizing_policy_t;
72
73             resizing_policy_t   m_placeHolder;
74         public:
75             StripedHashMap_ord( size_t /*nCapacity*/, size_t nLoadFactor )
76                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor * 1024 )) )
77             {}
78         };
79
80
81         typedef StripedHashMap_seq<
82             std::list< std::pair< Key const, Value > >
83             , co::hash< hash2 >
84             , co::less< less >
85         > StripedMap_list;
86
87 #   if (CDS_COMPILER == CDS_COMPILER_MSVC || (CDS_COMPILER == CDS_COMPILER_INTEL && CDS_OS_INTERFACE == CDS_OSI_WINDOWS)) && _MSC_VER < 1600
88         typedef StripedHashMap_ord<
89             stdext::hash_map< Key, Value, stdext::hash_compare<Key, less > >
90             , co::hash< hash2 >
91         > StripedMap_hashmap;
92 #   else
93         typedef StripedHashMap_ord<
94             std::unordered_map< Key, Value, hash, equal_to >
95             , co::hash< hash2 >
96         > StripedMap_hashmap;
97 #   endif
98
99         typedef StripedHashMap_ord<
100             std::map< Key, Value, less >
101             , co::hash< hash2 >
102         > StripedMap_map;
103
104         typedef StripedHashMap_ord<
105             boost::unordered_map< Key, Value, hash, equal_to >
106             , co::hash< hash2 >
107         > StripedMap_boost_unordered_map;
108
109 #   if BOOST_VERSION >= 104800
110         typedef StripedHashMap_seq<
111             boost::container::slist< std::pair< Key const, Value > >
112             , co::hash< hash2 >
113             , co::less< less >
114         > StripedMap_slist;
115
116         typedef StripedHashMap_seq<
117             boost::container::list< std::pair< Key const, Value > >
118             , co::hash< hash2 >
119             , co::less< less >
120         > StripedMap_boost_list;
121
122         typedef StripedHashMap_ord<
123             boost::container::map< Key, Value, less >
124             , co::hash< hash2 >
125         > StripedMap_boost_map;
126
127         typedef StripedHashMap_ord<
128             boost::container::flat_map< Key, Value, less >
129             , co::hash< hash2 >
130         > StripedMap_boost_flat_map;
131 #   endif  // BOOST_VERSION >= 104800
132
133
134         // ***************************************************************************
135         // RefinableHashMap
136
137         // for sequential containers
138         template <class BucketEntry, typename... Options>
139         class RefinableHashMap_seq:
140             public cc::StripedMap< BucketEntry,
141                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
142                 ,co::mutex_policy< cc::striped_set::refinable<> >
143                 , Options...
144             >
145         {
146             typedef cc::StripedMap< BucketEntry,
147                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
148                 ,co::mutex_policy< cc::striped_set::refinable<> >
149                 , Options...
150             > base_class;
151             typedef typename base_class::resizing_policy resizing_policy_t;
152
153             resizing_policy_t   m_placeHolder;
154         public:
155             RefinableHashMap_seq( size_t nCapacity, size_t nLoadFactor )
156                 : base_class( nCapacity / nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor )) )
157             {}
158         };
159
160         // for non-sequential ordered containers
161         template <class BucketEntry, typename... Options>
162         class RefinableHashMap_ord:
163             public cc::StripedMap< BucketEntry,
164                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
165                 ,co::mutex_policy< cc::striped_set::refinable<> >
166                 , Options...
167             >
168         {
169             typedef cc::StripedMap< BucketEntry,
170                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
171                 ,co::mutex_policy< cc::striped_set::refinable<> >
172                 , Options...
173             > base_class;
174             typedef typename base_class::resizing_policy resizing_policy_t;
175
176             resizing_policy_t   m_placeHolder;
177         public:
178             RefinableHashMap_ord( size_t /*nCapacity*/, size_t nLoadFactor )
179                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor * 1024 )) )
180             {}
181         };
182
183
184         typedef RefinableHashMap_seq<
185             std::list< std::pair< Key const, Value > >
186             , co::hash< hash2 >
187             , co::less< less >
188         > RefinableMap_list;
189
190 #   if BOOST_VERSION >= 104800
191         typedef RefinableHashMap_seq<
192             boost::container::slist< std::pair< Key const, Value > >
193             , co::hash< hash2 >
194             , co::less< less >
195         > RefinableMap_slist;
196 #   endif
197
198         typedef RefinableHashMap_ord<
199             std::map< Key, Value, less >
200             , co::hash< hash2 >
201         > RefinableMap_map;
202
203         typedef RefinableHashMap_ord<
204             std::unordered_map< Key, Value, hash, equal_to >
205             , co::hash< hash2 >
206         > RefinableMap_hashmap;
207
208         typedef RefinableHashMap_ord<
209             boost::unordered_map< Key, Value, hash, equal_to >
210             , co::hash< hash2 >
211         > RefinableMap_boost_unordered_map;
212
213 #   if BOOST_VERSION >= 104800
214         typedef RefinableHashMap_seq<
215             boost::container::list< std::pair< Key const, Value > >
216             , co::hash< hash2 >
217             , co::less< less >
218         > RefinableMap_boost_list;
219
220         typedef RefinableHashMap_ord<
221             boost::container::map< Key, Value, less >
222             , co::hash< hash2 >
223         > RefinableMap_boost_map;
224
225         typedef RefinableHashMap_ord<
226             boost::container::flat_map< Key, Value, less >
227             , co::hash< hash2 >
228         > RefinableMap_boost_flat_map;
229 #   endif // #if BOOST_VERSION >= 104800
230
231     };
232 }   // namespace map2
233
234 #endif // ifndef CDSUNIT_MAP_TYPE_MICHAEL_H