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