Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_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_intrusive_feldman_hashset.h"
32 #include <cds/urcu/signal_buffered.h>
33 #include <cds/intrusive/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 IntrusiveFeldmanHashSetHdrTest::rcu_shb_nohash()
44     {
45 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
46         typedef size_t key_type;
47
48         struct traits : public ci::feldman_hashset::traits
49         {
50             typedef get_key<key_type> hash_accessor;
51             typedef item_disposer disposer;
52         };
53         typedef ci::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
54         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!");
55         test_rcu<set_type, nohash<key_type>>(4, 2);
56
57         typedef ci::FeldmanHashSet<
58             rcu_type,
59             Item<key_type>,
60             typename ci::feldman_hashset::make_traits<
61                 ci::feldman_hashset::hash_accessor< get_key<key_type>>
62                 , ci::opt::disposer< item_disposer >
63             >::type
64         > set_type2;
65         test_rcu<set_type2, nohash<key_type>>(4, 2);
66 #endif
67     }
68
69     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_stdhash()
70     {
71 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
72         typedef size_t hash_type;
73
74         struct traits: public ci::feldman_hashset::traits
75         {
76             typedef get_hash<hash_type> hash_accessor;
77             typedef item_disposer disposer;
78         };
79         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
80         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
81         test_rcu<set_type, std::hash<hash_type>>(4, 2);
82
83         typedef ci::FeldmanHashSet<
84             rcu_type,
85             Item<hash_type>,
86             typename ci::feldman_hashset::make_traits<
87                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
88                 , ci::opt::disposer< item_disposer >
89             >::type
90         > set_type2;
91         test_rcu<set_type2, std::hash<hash_type>>(4, 2);
92 #endif
93     }
94
95     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_hash128()
96     {
97 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
98         typedef hash128 hash_type;
99
100         struct traits: public ci::feldman_hashset::traits
101         {
102             typedef get_hash<hash_type> hash_accessor;
103             typedef item_disposer disposer;
104             typedef hash128::less less;
105         };
106         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
107         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash128!!!" );
108         test_rcu<set_type, hash128::make>(4, 2);
109
110         typedef ci::FeldmanHashSet<
111             rcu_type,
112             Item<hash_type>,
113             typename ci::feldman_hashset::make_traits<
114                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
115                 , ci::opt::disposer< item_disposer >
116                 , ci::opt::less< hash_type::less >
117             >::type
118         > set_type2;
119         test_rcu<set_type2, hash128::make>(4, 2);
120 #endif
121     }
122
123     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_nohash_stat()
124     {
125 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
126         typedef size_t key_type;
127
128         struct traits : public ci::feldman_hashset::traits
129         {
130             typedef get_key<key_type> hash_accessor;
131             typedef item_disposer disposer;
132             typedef ci::feldman_hashset::stat<> stat;
133         };
134         typedef ci::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
135         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!");
136         test_rcu<set_type, nohash<key_type>>(4, 2);
137
138         typedef ci::FeldmanHashSet<
139             rcu_type,
140             Item<key_type>,
141             typename ci::feldman_hashset::make_traits<
142             ci::feldman_hashset::hash_accessor< get_key<key_type>>
143             , ci::opt::disposer< item_disposer >
144             , co::stat< ci::feldman_hashset::stat<>>
145             >::type
146         > set_type2;
147         test_rcu<set_type2, nohash<key_type>>(4, 2);
148 #endif
149     }
150
151     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_stdhash_stat()
152     {
153 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
154         typedef size_t hash_type;
155
156         struct traits: public ci::feldman_hashset::traits
157         {
158             typedef get_hash<hash_type> hash_accessor;
159             typedef item_disposer disposer;
160             typedef ci::feldman_hashset::stat<> stat;
161         };
162         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
163         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
164         test_rcu<set_type, std::hash<hash_type>>(4, 2);
165
166         typedef ci::FeldmanHashSet<
167             rcu_type,
168             Item<hash_type>,
169             typename ci::feldman_hashset::make_traits<
170                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
171                 , ci::opt::disposer< item_disposer >
172                 ,co::stat< ci::feldman_hashset::stat<>>
173             >::type
174         > set_type2;
175         test_rcu<set_type2, std::hash<hash_type>>(4, 2);
176 #endif
177     }
178
179     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_hash128_stat()
180     {
181 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
182         typedef hash128 hash_type;
183
184         struct traits: public ci::feldman_hashset::traits
185         {
186             typedef get_hash<hash_type> hash_accessor;
187             typedef item_disposer disposer;
188             typedef hash128::cmp  compare;
189             typedef ci::feldman_hashset::stat<> stat;
190         };
191         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
192         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash_type!!!" );
193         test_rcu<set_type, hash_type::make>(4, 2);
194
195         typedef ci::FeldmanHashSet<
196             rcu_type,
197             Item<hash_type>,
198             typename ci::feldman_hashset::make_traits<
199                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
200                 , ci::opt::disposer< item_disposer >
201                 ,co::stat< ci::feldman_hashset::stat<>>
202                 ,co::compare< hash128::cmp >
203             >::type
204         > set_type2;
205         test_rcu<set_type2, hash_type::make>(4, 2);
206 #endif
207     }
208
209     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_nohash_5_3()
210     {
211 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
212         typedef size_t key_type;
213
214         struct traits : public ci::feldman_hashset::traits
215         {
216             typedef get_key<key_type> hash_accessor;
217             typedef item_disposer disposer;
218         };
219         typedef ci::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
220         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!");
221         test_rcu<set_type, nohash<key_type>>(5, 3);
222
223         typedef ci::FeldmanHashSet<
224             rcu_type,
225             Item<key_type>,
226             typename ci::feldman_hashset::make_traits<
227             ci::feldman_hashset::hash_accessor< get_key<key_type>>
228             , ci::opt::disposer< item_disposer >
229             >::type
230         > set_type2;
231         test_rcu<set_type2, nohash<key_type>>(5, 3);
232 #endif
233     }
234
235     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_stdhash_5_3()
236     {
237 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
238         typedef size_t hash_type;
239
240         struct traits: public ci::feldman_hashset::traits
241         {
242             typedef get_hash<hash_type> hash_accessor;
243             typedef item_disposer disposer;
244         };
245         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
246         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
247         test_rcu<set_type, std::hash<hash_type>>(5, 3);
248
249         typedef ci::FeldmanHashSet<
250             rcu_type,
251             Item<hash_type>,
252             typename ci::feldman_hashset::make_traits<
253                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
254                 , ci::opt::disposer< item_disposer >
255             >::type
256         > set_type2;
257         test_rcu<set_type2, std::hash<hash_type>>(5, 3);
258 #endif
259     }
260
261     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_hash128_4_3()
262     {
263 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
264         typedef hash128 hash_type;
265
266         struct traits: public ci::feldman_hashset::traits
267         {
268             typedef get_hash<hash_type> hash_accessor;
269             typedef item_disposer disposer;
270             typedef co::v::sequential_consistent memory_model;
271         };
272         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
273         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash_type!!!" );
274         test_rcu<set_type, hash128::make >(4, 3);
275
276         typedef ci::FeldmanHashSet<
277             rcu_type,
278             Item<hash_type>,
279             typename ci::feldman_hashset::make_traits<
280                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
281                 , ci::opt::disposer< item_disposer >
282                 ,co::memory_model< co::v::sequential_consistent >
283             >::type
284         > set_type2;
285         test_rcu<set_type2, hash128::make >(4, 3);
286 #endif
287     }
288
289     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_nohash_5_3_stat()
290     {
291 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
292         typedef size_t key_type;
293
294         struct traits: public ci::feldman_hashset::traits
295         {
296             typedef get_key<key_type> hash_accessor;
297             typedef item_disposer disposer;
298             typedef ci::feldman_hashset::stat<> stat;
299         };
300         typedef ci::FeldmanHashSet< rcu_type, Item<key_type>, traits > set_type;
301         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
302         test_rcu<set_type, nohash<key_type>>(5, 3);
303
304         typedef ci::FeldmanHashSet<
305             rcu_type,
306             Item<key_type>,
307             typename ci::feldman_hashset::make_traits<
308                 ci::feldman_hashset::hash_accessor< get_key<key_type>>
309                 , ci::opt::disposer< item_disposer >
310                 ,co::stat< ci::feldman_hashset::stat<>>
311             >::type
312         > set_type2;
313         test_rcu<set_type2, nohash<key_type>>(5, 3);
314 #endif
315     }
316
317     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_stdhash_5_3_stat()
318     {
319 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
320         typedef size_t hash_type;
321
322         struct traits: public ci::feldman_hashset::traits
323         {
324             typedef get_hash<hash_type> hash_accessor;
325             typedef item_disposer disposer;
326             typedef ci::feldman_hashset::stat<> stat;
327         };
328         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
329         static_assert(std::is_same< typename set_type::hash_type, size_t>::value, "set::hash_type != size_t!!!" );
330         test_rcu<set_type, std::hash<hash_type>>(5, 3);
331
332         typedef ci::FeldmanHashSet<
333             rcu_type,
334             Item<hash_type>,
335             typename ci::feldman_hashset::make_traits<
336                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
337                 , ci::opt::disposer< item_disposer >
338                 ,co::stat< ci::feldman_hashset::stat<>>
339             >::type
340         > set_type2;
341         test_rcu<set_type2, std::hash<hash_type>>(5, 3);
342 #endif
343     }
344
345     void IntrusiveFeldmanHashSetHdrTest::rcu_shb_hash128_4_3_stat()
346     {
347 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
348         typedef hash128 hash_type;
349
350         struct traits: public ci::feldman_hashset::traits
351         {
352             typedef get_hash<hash_type> hash_accessor;
353             typedef item_disposer disposer;
354             typedef ci::feldman_hashset::stat<> stat;
355             typedef hash128::less less;
356             typedef hash128::cmp compare;
357         };
358         typedef ci::FeldmanHashSet< rcu_type, Item<hash_type>, traits > set_type;
359         static_assert(std::is_same< typename set_type::hash_type, hash_type>::value, "set::hash_type != hash_type!!!" );
360         test_rcu<set_type, hash_type::make>(4, 3);
361
362         typedef ci::FeldmanHashSet<
363             rcu_type,
364             Item<hash_type>,
365             typename ci::feldman_hashset::make_traits<
366                 ci::feldman_hashset::hash_accessor< get_hash<hash_type>>
367                 , ci::opt::disposer< item_disposer >
368                 , co::stat< ci::feldman_hashset::stat<>>
369                 , co::less< hash_type::less >
370                 , co::compare< hash128::cmp >
371             >::type
372         > set_type2;
373         test_rcu<set_type2, hash_type::make>(4, 3);
374 #endif
375     }
376
377 } // namespace set