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         template <class BucketEntry, typename... Options>
72         class StripedHashSet_seq_rational:
73             public cc::StripedSet< BucketEntry,
74                 co::mutex_policy< cc::striped_set::striping<> >
75                 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
76                 , Options...
77             >
78         {
79             typedef cc::StripedSet< BucketEntry,
80                 co::mutex_policy< cc::striped_set::striping<> >
81                 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
82                 , Options...
83             > base_class;
84             typedef typename base_class::resizing_policy resizing_policy_t;
85
86             resizing_policy_t   m_placeHolder;
87         public:
88             StripedHashSet_seq_rational( size_t nCapacity, size_t nDenominator ) // LoadFactor = 1 / nDenominator
89                 : base_class( nCapacity * nDenominator / 16, *(new(&m_placeHolder) resizing_policy_t( 1, nDenominator )) )
90             {}
91
92             template <typename Q, typename Less>
93             bool erase_with( Q const& v, Less /*pred*/ )
94             {
95                 return base_class::erase( v );
96             }
97         };
98
99         // for non-sequential ordered containers
100         template <class BucketEntry, typename... Options>
101         class StripedHashSet_ord:
102             public cc::StripedSet< BucketEntry,
103                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
104                 ,co::mutex_policy< cc::striped_set::striping<> >
105                 , Options...
106             >
107         {
108             typedef cc::StripedSet< BucketEntry,
109                co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
110                 ,co::mutex_policy< cc::striped_set::striping<> >
111                 , Options...
112             > base_class;
113             typedef typename base_class::resizing_policy resizing_policy_t;
114
115             resizing_policy_t   m_placeHolder;
116         public:
117             StripedHashSet_ord( size_t /*nCapacity*/, size_t nLoadFactor )
118                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor * 1024 )) )
119             {}
120
121             template <typename Q, typename Less>
122             bool erase_with( Q const& v, Less /*pred*/ )
123             {
124                 return base_class::erase( v );
125             }
126         };
127
128         template <class BucketEntry, typename... Options>
129         class StripedHashSet_ord_rational:
130             public cc::StripedSet< BucketEntry,
131                 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
132                 ,co::mutex_policy< cc::striped_set::striping<> >
133                 , Options...
134             >
135         {
136             typedef cc::StripedSet< BucketEntry,
137                co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
138                 ,co::mutex_policy< cc::striped_set::striping<> >
139                 , Options...
140             > base_class;
141             typedef typename base_class::resizing_policy resizing_policy_t;
142
143             resizing_policy_t   m_placeHolder;
144         public:
145             StripedHashSet_ord_rational( size_t /*nCapacity*/, size_t nDenominator ) // LoadFactor = 1 / nDenominator
146                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( 1024, nDenominator )) )
147             {}
148
149             template <typename Q, typename Less>
150             bool erase_with( Q const& v, Less /*pred*/ )
151             {
152                 return base_class::erase( v );
153             }
154         };
155
156         typedef StripedHashSet_seq<
157             std::list< key_val >
158             , co::hash< hash2 >
159             , co::less< less >
160         > StripedSet_list;
161
162         typedef StripedHashSet_seq_rational<
163             std::list< key_val >
164             , co::hash< hash2 >
165             , co::less< less >
166         > StripedSet_rational_list;
167
168         typedef StripedHashSet_seq<
169             std::vector< key_val >
170             , co::hash< hash2 >
171             , co::less< less >
172         > StripedSet_vector;
173
174         typedef StripedHashSet_seq_rational<
175             std::vector< key_val >
176             , co::hash< hash2 >
177             , co::less< less >
178         > StripedSet_rational_vector;
179
180 #if BOOST_VERSION >= 104800
181         typedef StripedHashSet_seq<
182             boost::container::slist< key_val >
183             , co::hash< hash2 >
184             , co::less< less >
185         > StripedSet_boost_slist;
186
187         typedef StripedHashSet_seq_rational<
188             boost::container::slist< key_val >
189             , co::hash< hash2 >
190             , co::less< less >
191         > StripedSet_rational_boost_slist;
192
193         typedef StripedHashSet_seq<
194             boost::container::list< key_val >
195             , co::hash< hash2 >
196             , co::less< less >
197         > StripedSet_boost_list;
198
199         typedef StripedHashSet_seq_rational<
200             boost::container::list< key_val >
201             , co::hash< hash2 >
202             , co::less< less >
203         > StripedSet_rational_boost_list;
204
205         typedef StripedHashSet_seq<
206             boost::container::vector< key_val >
207             , co::hash< hash2 >
208             , co::less< less >
209         > StripedSet_boost_vector;
210
211         typedef StripedHashSet_seq_rational<
212             boost::container::vector< key_val >
213             , co::hash< hash2 >
214             , co::less< less >
215         > StripedSet_rational_boost_vector;
216
217         typedef StripedHashSet_seq<
218             boost::container::stable_vector< key_val >
219             , co::hash< hash2 >
220             , co::less< less >
221         > StripedSet_boost_stable_vector;
222
223         typedef StripedHashSet_seq_rational<
224             boost::container::stable_vector< key_val >
225             , co::hash< hash2 >
226             , co::less< less >
227         > StripedSet_rational_boost_stable_vector;
228 #endif
229
230         typedef StripedHashSet_ord<
231             std::set< key_val, less >
232             , co::hash< hash2 >
233         > StripedSet_set;
234
235         typedef StripedHashSet_ord_rational<
236             std::set< key_val, less >
237             , co::hash< hash2 >
238         > StripedSet_rational_set;
239
240         typedef StripedHashSet_ord<
241             std::unordered_set< key_val, hash, equal_to >
242             , co::hash< hash2 >
243         > StripedSet_hashset;
244
245         typedef StripedHashSet_ord_rational<
246             std::unordered_set< key_val, hash, equal_to >
247             , co::hash< hash2 >
248         > StripedSet_rational_hashset;
249
250 #if BOOST_VERSION >= 104800
251         typedef StripedHashSet_ord<
252             boost::container::set< key_val, less >
253             , co::hash< hash2 >
254         > StripedSet_boost_set;
255
256         typedef StripedHashSet_ord_rational<
257             boost::container::set< key_val, less >
258             , co::hash< hash2 >
259         > StripedSet_rational_boost_set;
260
261         typedef StripedHashSet_ord<
262             boost::container::flat_set< key_val, less >
263             , co::hash< hash2 >
264         > StripedSet_boost_flat_set;
265
266         typedef StripedHashSet_ord_rational<
267             boost::container::flat_set< key_val, less >
268             , co::hash< hash2 >
269         > StripedSet_rational_boost_flat_set;
270 #endif
271
272         typedef StripedHashSet_ord<
273             boost::unordered_set< key_val, hash, equal_to >
274             , co::hash< hash2 >
275         > StripedSet_boost_unordered_set;
276
277         typedef StripedHashSet_ord_rational<
278             boost::unordered_set< key_val, hash, equal_to >
279             , co::hash< hash2 >
280         > StripedSet_rational_boost_unordered_set;
281
282
283         // ***************************************************************************
284         // RefinableSet
285
286         // for sequential containers
287         template <class BucketEntry, typename... Options>
288         class RefinableHashSet_seq:
289             public cc::StripedSet< BucketEntry,
290             co::mutex_policy< cc::striped_set::refinable<> >
291             ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
292             , Options...
293             >
294         {
295             typedef cc::StripedSet< BucketEntry,
296                 co::mutex_policy< cc::striped_set::refinable<> >
297                 ,co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
298                 , Options...
299             > base_class;
300             typedef typename base_class::resizing_policy resizing_policy_t;
301
302             resizing_policy_t   m_placeHolder;
303         public:
304             RefinableHashSet_seq( size_t nCapacity, size_t nLoadFactor )
305                 : base_class( nCapacity / nLoadFactor / 16, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor )) )
306             {}
307
308             template <typename Q, typename Less>
309             bool erase_with( Q const& v, Less /*pred*/ )
310             {
311                 return base_class::erase( v );
312             }
313         };
314
315         template <class BucketEntry, typename... Options>
316         class RefinableHashSet_seq_rational:
317             public cc::StripedSet< BucketEntry,
318             co::mutex_policy< cc::striped_set::refinable<> >
319             ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
320             , Options...
321             >
322         {
323             typedef cc::StripedSet< BucketEntry,
324                 co::mutex_policy< cc::striped_set::refinable<> >
325                 ,co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
326                 , Options...
327             > base_class;
328             typedef typename base_class::resizing_policy resizing_policy_t;
329
330             resizing_policy_t   m_placeHolder;
331         public:
332             RefinableHashSet_seq_rational( size_t nCapacity, size_t nDenominator ) // LoadFactor = 1 / nDenominator
333                 : base_class( nCapacity * nDenominator / 16, *(new(&m_placeHolder) resizing_policy_t( 1, nDenominator )) )
334             {}
335
336             template <typename Q, typename Less>
337             bool erase_with( Q const& v, Less /*pred*/ )
338             {
339                 return base_class::erase( v );
340             }
341         };
342
343         // for non-sequential ordered containers
344         template <class BucketEntry, typename... Options>
345         class RefinableHashSet_ord:
346             public cc::StripedSet< BucketEntry,
347                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
348                 ,co::mutex_policy< cc::striped_set::refinable<> >
349                 , Options...
350             >
351         {
352             typedef cc::StripedSet< BucketEntry,
353                 co::resizing_policy<cc::striped_set::load_factor_resizing<0> >
354                 ,co::mutex_policy< cc::striped_set::refinable<> >
355                 , Options...
356             > base_class;
357             typedef typename base_class::resizing_policy resizing_policy_t;
358
359             resizing_policy_t   m_placeHolder;
360         public:
361             RefinableHashSet_ord( size_t /*nCapacity*/, size_t nLoadFactor )
362                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( nLoadFactor * 1024 )) )
363             {}
364
365             template <typename Q, typename Less>
366             bool erase_with( Q const& v, Less /*pred*/ )
367             {
368                 return base_class::erase( v );
369             }
370         };
371
372         template <class BucketEntry, typename... Options>
373         class RefinableHashSet_ord_rational:
374             public cc::StripedSet< BucketEntry,
375                 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
376                 ,co::mutex_policy< cc::striped_set::refinable<> >
377                 , Options...
378             >
379         {
380             typedef cc::StripedSet< BucketEntry,
381                 co::resizing_policy<cc::striped_set::rational_load_factor_resizing<0> >
382                 ,co::mutex_policy< cc::striped_set::refinable<> >
383                 , Options...
384             > base_class;
385             typedef typename base_class::resizing_policy resizing_policy_t;
386
387             resizing_policy_t   m_placeHolder;
388         public:
389             RefinableHashSet_ord_rational( size_t /*nCapacity*/, size_t nDenominator ) // LoadFactor = 1 / nDenominator
390                 : base_class( 0, *(new(&m_placeHolder) resizing_policy_t( 1024, nDenominator )) )
391             {}
392
393             template <typename Q, typename Less>
394             bool erase_with( Q const& v, Less /*pred*/ )
395             {
396                 return base_class::erase( v );
397             }
398         };
399
400         typedef RefinableHashSet_seq<
401             std::list< key_val >
402             , co::hash< hash2 >
403             , co::less< less >
404         > RefinableSet_list;
405
406         typedef RefinableHashSet_seq_rational<
407             std::list< key_val >
408             , co::hash< hash2 >
409             , co::less< less >
410         > RefinableSet_rational_list;
411
412         typedef RefinableHashSet_seq<
413             std::vector< key_val >
414             , co::hash< hash2 >
415             , co::less< less >
416         > RefinableSet_vector;
417
418         typedef RefinableHashSet_seq_rational<
419             std::vector< key_val >
420             , co::hash< hash2 >
421             , co::less< less >
422         > RefinableSet_rational_vector;
423
424 #if BOOST_VERSION >= 104800
425         typedef RefinableHashSet_seq<
426             boost::container::slist< key_val >
427             , co::hash< hash2 >
428             , co::less< less >
429         > RefinableSet_boost_slist;
430
431         typedef RefinableHashSet_seq_rational<
432             boost::container::slist< key_val >
433             , co::hash< hash2 >
434             , co::less< less >
435         > RefinableSet_rational_boost_slist;
436
437         typedef RefinableHashSet_seq<
438             boost::container::list< key_val >
439             , co::hash< hash2 >
440             , co::less< less >
441         > RefinableSet_boost_list;
442
443         typedef RefinableHashSet_seq_rational<
444             boost::container::list< key_val >
445             , co::hash< hash2 >
446             , co::less< less >
447         > RefinableSet_rational_boost_list;
448
449         typedef RefinableHashSet_seq<
450             boost::container::vector< key_val >
451             , co::hash< hash2 >
452             , co::less< less >
453         > RefinableSet_boost_vector;
454
455         typedef RefinableHashSet_seq_rational<
456             boost::container::vector< key_val >
457             , co::hash< hash2 >
458             , co::less< less >
459         > RefinableSet_rational_boost_vector;
460
461         typedef RefinableHashSet_seq<
462             boost::container::stable_vector< key_val >
463             , co::hash< hash2 >
464             , co::less< less >
465         > RefinableSet_boost_stable_vector;
466
467         typedef RefinableHashSet_seq_rational<
468             boost::container::stable_vector< key_val >
469             , co::hash< hash2 >
470             , co::less< less >
471         > RefinableSet_rational_boost_stable_vector;
472 #endif
473
474         typedef RefinableHashSet_ord<
475             std::set< key_val, less >
476             , co::hash< hash2 >
477         > RefinableSet_set;
478
479         typedef RefinableHashSet_ord_rational<
480             std::set< key_val, less >
481             , co::hash< hash2 >
482         > RefinableSet_rational_set;
483
484         typedef RefinableHashSet_ord<
485             std::unordered_set< key_val, hash, equal_to >
486             , co::hash< hash2 >
487         > RefinableSet_hashset;
488
489         typedef RefinableHashSet_ord_rational<
490             std::unordered_set< key_val, hash, equal_to >
491             , co::hash< hash2 >
492         > RefinableSet_rational_hashset;
493
494 #if BOOST_VERSION >= 104800
495         typedef RefinableHashSet_ord<
496             boost::container::set< key_val, less >
497             , co::hash< hash2 >
498         > RefinableSet_boost_set;
499
500         typedef RefinableHashSet_ord_rational<
501             boost::container::set< key_val, less >
502             , co::hash< hash2 >
503         > RefinableSet_rational_boost_set;
504
505         typedef RefinableHashSet_ord<
506             boost::container::flat_set< key_val, less >
507             , co::hash< hash2 >
508         > RefinableSet_boost_flat_set;
509
510         typedef RefinableHashSet_ord_rational<
511             boost::container::flat_set< key_val, less >
512             , co::hash< hash2 >
513         > RefinableSet_rational_boost_flat_set;
514 #endif
515
516         typedef RefinableHashSet_ord<
517             boost::unordered_set< key_val, hash, equal_to >
518             , co::hash< hash2 >
519         > RefinableSet_boost_unordered_set;
520
521         typedef RefinableHashSet_ord_rational<
522             boost::unordered_set< key_val, hash, equal_to >
523             , co::hash< hash2 >
524         > RefinableSet_rational_boost_unordered_set;
525     };
526
527 } // namespace set2
528
529 #endif // #ifndef CDSUNIT_SET_TYPE_STRIPED_H