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