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