Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_feldman_hashset_rcu_shb.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8     
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
29 */
30
31 #include "set/hdr_feldman_hashset.h"
32 #include <cds/urcu/signal_buffered.h>
33 #include <cds/container/feldman_hashset_rcu.h>
34 #include "unit/print_feldman_hashset_stat.h"
35
36 namespace set {
37 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
38     namespace {
39         typedef cds::urcu::gc<cds::urcu::signal_buffered<>> rcu_type;
40     } // namespace
41 #endif
42
43     void FeldmanHashSetHdrTest::rcu_shb_nohash()
44     {
45 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
46         typedef size_t key_type;
47
48         struct traits : public cc::feldman_hashset::traits
49         {
50             typedef get_key<key_type> hash_accessor;
51         };
52         typedef cc::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
53         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!");
54         test_rcu<set_type, nohash<key_type>>(4, 2);
55
56         typedef cc::FeldmanHashSet<
57             rcu_type,
58             Item<key_type>,
59             typename cc::feldman_hashset::make_traits<
60             cc::feldman_hashset::hash_accessor< get_key<key_type>>
61             >::type
62         > set_type2;
63         test_rcu<set_type2, nohash<key_type>>(4, 2);
64 #endif
65     }
66
67     void FeldmanHashSetHdrTest::rcu_shb_stdhash()
68     {
69 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
70         typedef size_t hash_type;
71
72         struct traits: public cc::feldman_hashset::traits
73         {
74             typedef get_hash<hash_type> hash_accessor;
75         };
76         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
77         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
78         test_rcu<set_type, std::hash<hash_type>>(4, 2);
79
80         typedef cc::FeldmanHashSet<
81             rcu_type,
82             Item<hash_type>,
83             typename cc::feldman_hashset::make_traits<
84                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
85             >::type
86         > set_type2;
87         test_rcu<set_type2, std::hash<hash_type>>(4, 2);
88 #endif
89     }
90
91     void FeldmanHashSetHdrTest::rcu_shb_hash128()
92     {
93 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
94         typedef hash128 hash_type;
95
96         struct traits: public cc::feldman_hashset::traits
97         {
98             typedef get_hash<hash_type> hash_accessor;
99             typedef hash128::less less;
100         };
101         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
102         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash128!!!" );
103         test_rcu<set_type, hash128::make>(4, 2);
104
105         typedef cc::FeldmanHashSet<
106             rcu_type,
107             Item<hash_type>,
108             typename cc::feldman_hashset::make_traits<
109                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
110                 , co::less< hash_type::less >
111             >::type
112         > set_type2;
113         test_rcu<set_type2, hash128::make>(4, 2);
114 #endif
115     }
116
117     void FeldmanHashSetHdrTest::rcu_shb_nohash_stat()
118     {
119 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
120         typedef size_t key_type;
121
122         struct traits : public cc::feldman_hashset::traits
123         {
124             typedef get_key<key_type> hash_accessor;
125             typedef cc::feldman_hashset::stat<> stat;
126         };
127         typedef cc::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
128         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!");
129         test_rcu<set_type, nohash<key_type>>(4, 2);
130
131         typedef cc::FeldmanHashSet<
132             rcu_type,
133             Item<key_type>,
134             typename cc::feldman_hashset::make_traits<
135             cc::feldman_hashset::hash_accessor< get_key<key_type>>
136             , co::stat< cc::feldman_hashset::stat<>>
137             >::type
138         > set_type2;
139         test_rcu<set_type2, nohash<key_type>>(4, 2);
140 #endif
141     }
142
143     void FeldmanHashSetHdrTest::rcu_shb_stdhash_stat()
144     {
145 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
146         typedef size_t hash_type;
147
148         struct traits: public cc::feldman_hashset::traits
149         {
150             typedef get_hash<hash_type> hash_accessor;
151             typedef cc::feldman_hashset::stat<> stat;
152         };
153         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
154         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
155         test_rcu<set_type, std::hash<hash_type>>(4, 2);
156
157         typedef cc::FeldmanHashSet<
158             rcu_type,
159             Item<hash_type>,
160             typename cc::feldman_hashset::make_traits<
161                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
162                 ,co::stat< cc::feldman_hashset::stat<>>
163             >::type
164         > set_type2;
165         test_rcu<set_type2, std::hash<hash_type>>(4, 2);
166 #endif
167     }
168
169     void FeldmanHashSetHdrTest::rcu_shb_hash128_stat()
170     {
171 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
172         typedef hash128 hash_type;
173
174         struct traits: public cc::feldman_hashset::traits
175         {
176             typedef get_hash<hash_type> hash_accessor;
177             typedef hash128::cmp  compare;
178             typedef cc::feldman_hashset::stat<> stat;
179         };
180         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
181         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash_type!!!" );
182         test_rcu<set_type, hash_type::make>(4, 2);
183
184         typedef cc::FeldmanHashSet<
185             rcu_type,
186             Item<hash_type>,
187             typename cc::feldman_hashset::make_traits<
188                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
189                 ,co::stat< cc::feldman_hashset::stat<>>
190                 ,co::compare< hash128::cmp >
191             >::type
192         > set_type2;
193         test_rcu<set_type2, hash_type::make>(4, 2);
194 #endif
195     }
196
197     void FeldmanHashSetHdrTest::rcu_shb_nohash_5_3()
198     {
199 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
200         typedef size_t key_type;
201
202         struct traits: public cc::feldman_hashset::traits
203         {
204             typedef get_key<key_type> hash_accessor;
205         };
206         typedef cc::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
207         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
208         test_rcu<set_type, nohash<key_type>>(5, 3);
209
210         typedef cc::FeldmanHashSet<
211             rcu_type,
212             Item<key_type>,
213             typename cc::feldman_hashset::make_traits<
214                 cc::feldman_hashset::hash_accessor< get_key<key_type>>
215             >::type
216         > set_type2;
217         test_rcu<set_type2, nohash<key_type>>(5, 3);
218 #endif
219     }
220
221     void FeldmanHashSetHdrTest::rcu_shb_stdhash_5_3()
222     {
223 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
224         typedef size_t hash_type;
225
226         struct traits: public cc::feldman_hashset::traits
227         {
228             typedef get_hash<hash_type> hash_accessor;
229         };
230         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
231         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
232         test_rcu<set_type, std::hash<hash_type>>(5, 3);
233
234         typedef cc::FeldmanHashSet<
235             rcu_type,
236             Item<hash_type>,
237             typename cc::feldman_hashset::make_traits<
238                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
239             >::type
240         > set_type2;
241         test_rcu<set_type2, std::hash<hash_type>>(5, 3);
242 #endif
243     }
244
245     void FeldmanHashSetHdrTest::rcu_shb_hash128_4_3()
246     {
247 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
248         typedef hash128 hash_type;
249
250         struct traits: public cc::feldman_hashset::traits
251         {
252             typedef get_hash<hash_type> hash_accessor;
253             typedef co::v::sequential_consistent memory_model;
254         };
255         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
256         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash_type!!!" );
257         test_rcu<set_type, hash128::make >(4, 3);
258
259         typedef cc::FeldmanHashSet<
260             rcu_type,
261             Item<hash_type>,
262             typename cc::feldman_hashset::make_traits<
263                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
264                 ,co::memory_model< co::v::sequential_consistent >
265             >::type
266         > set_type2;
267         test_rcu<set_type2, hash128::make >(4, 3);
268 #endif
269     }
270
271     void FeldmanHashSetHdrTest::rcu_shb_nohash_5_3_stat()
272     {
273 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
274         typedef size_t key_type;
275
276         struct traits: public cc::feldman_hashset::traits
277         {
278             typedef get_key<key_type> hash_accessor;
279             typedef cc::feldman_hashset::stat<> stat;
280         };
281         typedef cc::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
282         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
283         test_rcu<set_type, nohash<key_type>>(5, 3);
284
285         typedef cc::FeldmanHashSet<
286             rcu_type,
287             Item<key_type>,
288             typename cc::feldman_hashset::make_traits<
289                 cc::feldman_hashset::hash_accessor< get_key<key_type>>
290                 ,co::stat< cc::feldman_hashset::stat<>>
291             >::type
292         > set_type2;
293         test_rcu<set_type2, nohash<key_type>>(5, 3);
294 #endif
295     }
296
297     void FeldmanHashSetHdrTest::rcu_shb_stdhash_5_3_stat()
298     {
299 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
300         typedef size_t hash_type;
301
302         struct traits: public cc::feldman_hashset::traits
303         {
304             typedef get_hash<hash_type> hash_accessor;
305             typedef cc::feldman_hashset::stat<> stat;
306         };
307         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
308         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
309         test_rcu<set_type, std::hash<hash_type>>(5, 3);
310
311         typedef cc::FeldmanHashSet<
312             rcu_type,
313             Item<hash_type>,
314             typename cc::feldman_hashset::make_traits<
315                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
316                 ,co::stat< cc::feldman_hashset::stat<>>
317             >::type
318         > set_type2;
319         test_rcu<set_type2, std::hash<hash_type>>(5, 3);
320 #endif
321     }
322
323     void FeldmanHashSetHdrTest::rcu_shb_hash128_4_3_stat()
324     {
325 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
326         typedef hash128 hash_type;
327
328         struct traits: public cc::feldman_hashset::traits
329         {
330             typedef get_hash<hash_type> hash_accessor;
331             typedef cc::feldman_hashset::stat<> stat;
332             typedef hash128::less less;
333             typedef hash128::cmp compare;
334         };
335         typedef cc::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
336         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash_type!!!" );
337         test_rcu<set_type, hash_type::make>(4, 3);
338
339         typedef cc::FeldmanHashSet<
340             rcu_type,
341             Item<hash_type>,
342             typename cc::feldman_hashset::make_traits<
343                 cc::feldman_hashset::hash_accessor< get_hash<hash_type>>
344                 , co::stat< cc::feldman_hashset::stat<>>
345                 , co::less< hash_type::less >
346                 , co::compare< hash128::cmp >
347             >::type
348         > set_type2;
349         test_rcu<set_type2, hash_type::make>(4, 3);
350 #endif
351     }
352 } // namespace set