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