Merge branch 'integration' into dev
[libcds.git] / tests / unit / set2 / set_type_striped.h
1 //$$CDS-header$$
2
3 #ifndef CDSUNIT_SET_TYPE_STRIPED_H
4 #define CDSUNIT_SET_TYPE_STRIPED_H
5
6 #include "set2/set_type.h"
7
8 #include <cds/container/striped_set/std_list.h>
9 #include <cds/container/striped_set/std_vector.h>
10 #include <cds/container/striped_set/std_set.h>
11 #include <cds/container/striped_set/std_hash_set.h>
12 #include <cds/container/striped_set/boost_unordered_set.h>
13
14 #include <boost/version.hpp>
15 #if BOOST_VERSION >= 104800
16 #   include <cds/container/striped_set/boost_slist.h>
17 #   include <cds/container/striped_set/boost_list.h>
18 #   include <cds/container/striped_set/boost_vector.h>
19 #   include <cds/container/striped_set/boost_stable_vector.h>
20 #   include <cds/container/striped_set/boost_set.h>
21 #   include <cds/container/striped_set/boost_flat_set.h>
22 #endif
23 #include <cds/container/striped_set.h>
24
25 namespace set2 {
26
27     template <typename Key, typename Val>
28     struct set_type< cc::striped_set::implementation_tag, Key, Val >: public set_type_base< Key, Val >
29     {
30         typedef set_type_base< Key, Val > base_class;
31         typedef typename base_class::key_val key_val;
32         typedef typename base_class::compare compare;
33         typedef typename base_class::less less;
34         typedef typename base_class::equal_to equal_to;
35         typedef typename base_class::hash hash;
36         typedef typename base_class::hash2 hash2;
37
38
39         // ***************************************************************************
40         // StripedSet
41
42         // for sequential containers
43         template <class BucketEntry, typename... Options>
44         class StripedHashSet_seq:
45             public cc::StripedSet< BucketEntry,
46                 co::mutex_policy< cc::striped_set::striping<> >
47                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
48                 , Options...
49             >
50         {
51             typedef cc::StripedSet< BucketEntry,
52                 co::mutex_policy< cc::striped_set::striping<> >
53                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
54                 , Options...
55             > base_class;
56             typedef typename base_class::resizing_policy resizing_policy_t;
57
58             resizing_policy_t   m_placeHolder;
59         public:
60             StripedHashSet_seq( size_t nCapacity, size_t nLoadFactor )
61                 : base_class( nCapacity / nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor )) )
62             {}
63
64             template <typename Q, typename Less>
65             bool erase_with( Q const& v, Less /*pred*/ )
66             {
67                 return base_class::erase( v );
68             }
69         };
70
71         // for non-sequential ordered containers
72         template <class BucketEntry, typename... Options>
73         class StripedHashSet_ord:
74             public cc::StripedSet< BucketEntry,
75                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
76                 ,co::mutex_policy< cc::striped_set::striping<> >
77                 , Options...
78             >
79         {
80             typedef cc::StripedSet< BucketEntry,
81                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
82                 ,co::mutex_policy< cc::striped_set::striping<> >
83                 , Options...
84             > base_class;
85             typedef typename base_class::resizing_policy resizing_policy_t;
86
87             resizing_policy_t   m_placeHolder;
88         public:
89             StripedHashSet_ord( size_t /*nCapacity*/, size_t nLoadFactor )
90                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor * 1024 )) )
91             {}
92
93             template <typename Q, typename Less>
94             bool erase_with( Q const& v, Less /*pred*/ )
95             {
96                 return base_class::erase( v );
97             }
98         };
99
100         typedef StripedHashSet_seq<
101             std::list< key_val >
102             , co::hash< hash2 >
103             , co::less< less >
104         > StripedSet_list;
105
106         typedef StripedHashSet_seq<
107             std::vector< key_val >
108             , co::hash< hash2 >
109             , co::less< less >
110         > StripedSet_vector;
111
112 #if BOOST_VERSION >= 104800
113         typedef StripedHashSet_seq<
114             boost::container::slist< key_val >
115             , co::hash< hash2 >
116             , co::less< less >
117         > StripedSet_boost_slist;
118
119         typedef StripedHashSet_seq<
120             boost::container::list< key_val >
121             , co::hash< hash2 >
122             , co::less< less >
123         > StripedSet_boost_list;
124
125         typedef StripedHashSet_seq<
126             boost::container::vector< key_val >
127             , co::hash< hash2 >
128             , co::less< less >
129         > StripedSet_boost_vector;
130
131         typedef StripedHashSet_seq<
132             boost::container::stable_vector< key_val >
133             , co::hash< hash2 >
134             , co::less< less >
135         > StripedSet_boost_stable_vector;
136 #endif
137
138         typedef StripedHashSet_ord<
139             std::set< key_val, less >
140             , co::hash< hash2 >
141         > StripedSet_set;
142
143         typedef StripedHashSet_ord<
144             std::unordered_set< key_val, hash, equal_to >
145             , co::hash< hash2 >
146         > StripedSet_hashset;
147
148 #if BOOST_VERSION >= 104800
149         typedef StripedHashSet_ord<
150             boost::container::set< key_val, less >
151             , co::hash< hash2 >
152         > StripedSet_boost_set;
153
154         typedef StripedHashSet_ord<
155             boost::container::flat_set< key_val, less >
156             , co::hash< hash2 >
157         > StripedSet_boost_flat_set;
158 #endif
159
160         typedef StripedHashSet_ord<
161             boost::unordered_set< key_val, hash, equal_to >
162             , co::hash< hash2 >
163         > StripedSet_boost_unordered_set;
164
165
166         // ***************************************************************************
167         // RefinableSet
168
169         // for sequential containers
170         template <class BucketEntry, typename... Options>
171         class RefinableHashSet_seq:
172             public cc::StripedSet< BucketEntry,
173             co::mutex_policy< cc::striped_set::refinable<> >
174             ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
175             , Options...
176             >
177         {
178             typedef cc::StripedSet< BucketEntry,
179                 co::mutex_policy< cc::striped_set::refinable<> >
180                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
181                 , Options...
182             > base_class;
183             typedef typename base_class::resizing_policy resizing_policy_t;
184
185             resizing_policy_t   m_placeHolder;
186         public:
187             RefinableHashSet_seq( size_t nCapacity, size_t nLoadFactor )
188                 : base_class( nCapacity / nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor )) )
189             {}
190
191             template <typename Q, typename Less>
192             bool erase_with( Q const& v, Less /*pred*/ )
193             {
194                 return base_class::erase( v );
195             }
196         };
197
198         // for non-sequential ordered containers
199         template <class BucketEntry, typename... Options>
200         class RefinableHashSet_ord:
201             public cc::StripedSet< BucketEntry,
202                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
203                 ,co::mutex_policy< cc::striped_set::refinable<> >
204                 , Options...
205             >
206         {
207             typedef cc::StripedSet< BucketEntry,
208                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
209                 ,co::mutex_policy< cc::striped_set::refinable<> >
210                 , Options...
211             > base_class;
212             typedef typename base_class::resizing_policy resizing_policy_t;
213
214             resizing_policy_t   m_placeHolder;
215         public:
216             RefinableHashSet_ord( size_t /*nCapacity*/, size_t nLoadFactor )
217                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor * 1024 )) )
218             {}
219
220             template <typename Q, typename Less>
221             bool erase_with( Q const& v, Less /*pred*/ )
222             {
223                 return base_class::erase( v );
224             }
225         };
226
227         typedef RefinableHashSet_seq<
228             std::list< key_val >
229             , co::hash< hash2 >
230             , co::less< less >
231         > RefinableSet_list;
232
233         typedef RefinableHashSet_seq<
234             std::vector< key_val >
235             , co::hash< hash2 >
236             , co::less< less >
237         > RefinableSet_vector;
238
239 #if BOOST_VERSION >= 104800
240         typedef RefinableHashSet_seq<
241             boost::container::slist< key_val >
242             , co::hash< hash2 >
243             , co::less< less >
244         > RefinableSet_boost_slist;
245
246         typedef RefinableHashSet_seq<
247             boost::container::list< key_val >
248             , co::hash< hash2 >
249             , co::less< less >
250         > RefinableSet_boost_list;
251
252         typedef RefinableHashSet_seq<
253             boost::container::vector< key_val >
254             , co::hash< hash2 >
255             , co::less< less >
256         > RefinableSet_boost_vector;
257
258         typedef RefinableHashSet_seq<
259             boost::container::stable_vector< key_val >
260             , co::hash< hash2 >
261             , co::less< less >
262         > RefinableSet_boost_stable_vector;
263 #endif
264
265         typedef RefinableHashSet_ord<
266             std::set< key_val, less >
267             , co::hash< hash2 >
268         > RefinableSet_set;
269
270         typedef RefinableHashSet_ord<
271             std::unordered_set< key_val, hash, equal_to >
272             , co::hash< hash2 >
273         > RefinableSet_hashset;
274
275 #if BOOST_VERSION >= 104800
276         typedef RefinableHashSet_ord<
277             boost::container::set< key_val, less >
278             , co::hash< hash2 >
279         > RefinableSet_boost_set;
280
281         typedef RefinableHashSet_ord<
282             boost::container::flat_set< key_val, less >
283             , co::hash< hash2 >
284         > RefinableSet_boost_flat_set;
285 #endif
286
287         typedef RefinableHashSet_ord<
288             boost::unordered_set< key_val, hash, equal_to >
289             , co::hash< hash2 >
290         > RefinableSet_boost_unordered_set;
291     };
292
293 } // namespace set2
294
295 #endif // #ifndef CDSUNIT_SET_TYPE_STRIPED_H