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