[SkipList] Added random-lvel generators for max height 32/24/16
[libcds.git] / test / unit / intrusive-set / intrusive_skiplist_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-2017
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 "test_intrusive_set_hp.h"
32
33 #include <cds/intrusive/skip_list_hp.h>
34
35 namespace {
36     namespace ci = cds::intrusive;
37     typedef cds::gc::HP gc_type;
38
39     class IntrusiveSkipListSet_HP : public cds_test::intrusive_set_hp
40     {
41     protected:
42         typedef cds_test::intrusive_set_hp base_class;
43
44     protected:
45         typedef typename base_class::base_int_item< ci::skip_list::node< gc_type>>   base_item_type;
46         typedef typename base_class::member_int_item< ci::skip_list::node< gc_type>> member_item_type;
47
48         void SetUp()
49         {
50             typedef ci::SkipListSet< gc_type, base_item_type,
51                 typename ci::skip_list::make_traits<
52                     ci::opt::hook<ci::skip_list::base_hook< ci::opt::gc< gc_type >>>
53                     ,ci::opt::disposer<mock_disposer>
54                     ,ci::opt::compare<mock_disposer>
55                 >::type
56             > set_type;
57
58             // +1 - for guarded_ptr
59             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
60             cds::threading::Manager::attachThread();
61         }
62
63         void TearDown()
64         {
65             cds::threading::Manager::detachThread();
66             cds::gc::hp::GarbageCollector::Destruct( true );
67         }
68     };
69
70
71     TEST_F( IntrusiveSkipListSet_HP, base_cmp )
72     {
73         struct traits : public ci::skip_list::traits
74         {
75             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
76             typedef mock_disposer disposer;
77             typedef cmp<base_item_type> compare;
78         };
79
80         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
81
82         set_type s;
83         test( s );
84     }
85
86     TEST_F( IntrusiveSkipListSet_HP, base_less )
87     {
88         struct traits : public ci::skip_list::traits
89         {
90             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
91             typedef mock_disposer disposer;
92             typedef base_class::less<base_item_type> less;
93             typedef cds::atomicity::item_counter item_counter;
94         };
95
96         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
97
98         set_type s;
99         test( s );
100     }
101
102     TEST_F( IntrusiveSkipListSet_HP, base_cmpmix )
103     {
104         struct traits : public ci::skip_list::traits
105         {
106             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
107             typedef mock_disposer disposer;
108             typedef cmp<base_item_type> compare;
109             typedef base_class::less<base_item_type> less;
110             typedef ci::skip_list::stat<> stat;
111         };
112
113         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
114
115         set_type s;
116         test( s );
117     }
118
119     TEST_F( IntrusiveSkipListSet_HP, base_xorshift32 )
120     {
121         struct traits : public ci::skip_list::traits
122         {
123             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
124             typedef mock_disposer disposer;
125             typedef cmp<base_item_type> compare;
126             typedef ci::skip_list::xorshift32 random_level_generator;
127         };
128
129         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
130
131         set_type s;
132         test( s );
133     }
134
135     TEST_F( IntrusiveSkipListSet_HP, base_xorshift24 )
136     {
137         struct traits: public ci::skip_list::traits
138         {
139             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
140             typedef mock_disposer disposer;
141             typedef cmp<base_item_type> compare;
142             typedef ci::skip_list::xorshift24 random_level_generator;
143         };
144
145         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
146
147         set_type s;
148         test( s );
149     }
150
151     TEST_F( IntrusiveSkipListSet_HP, base_xorshift16 )
152     {
153         struct traits: public ci::skip_list::traits
154         {
155             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
156             typedef mock_disposer disposer;
157             typedef cmp<base_item_type> compare;
158             typedef ci::skip_list::xorshift16 random_level_generator;
159         };
160
161         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
162
163         set_type s;
164         test( s );
165     }
166
167     TEST_F( IntrusiveSkipListSet_HP, base_turbo32 )
168     {
169         struct traits: public ci::skip_list::traits
170         {
171             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
172             typedef mock_disposer disposer;
173             typedef cmp<base_item_type> compare;
174             typedef ci::skip_list::turbo32 random_level_generator;
175         };
176
177         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
178
179         set_type s;
180         test( s );
181     }
182
183     TEST_F( IntrusiveSkipListSet_HP, base_turbo24 )
184     {
185         struct traits: public ci::skip_list::traits
186         {
187             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
188             typedef mock_disposer disposer;
189             typedef cmp<base_item_type> compare;
190             typedef ci::skip_list::turbo24 random_level_generator;
191         };
192
193         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
194
195         set_type s;
196         test( s );
197     }
198
199     TEST_F( IntrusiveSkipListSet_HP, base_turbo16 )
200     {
201         struct traits: public ci::skip_list::traits
202         {
203             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
204             typedef mock_disposer disposer;
205             typedef cmp<base_item_type> compare;
206             typedef ci::skip_list::turbo16 random_level_generator;
207         };
208
209         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
210
211         set_type s;
212         test( s );
213     }
214
215     TEST_F( IntrusiveSkipListSet_HP, member_cmp )
216     {
217         struct traits : public ci::skip_list::traits
218         {
219             typedef ci::skip_list::member_hook< offsetof(member_item_type, hMember), ci::opt::gc< gc_type >> hook;
220             typedef mock_disposer disposer;
221             typedef cmp<member_item_type> compare;
222         };
223
224         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
225
226         set_type s;
227         test( s );
228     }
229
230     TEST_F( IntrusiveSkipListSet_HP, member_less )
231     {
232         struct traits : public ci::skip_list::traits
233         {
234             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
235             typedef mock_disposer disposer;
236             typedef base_class::less<member_item_type> less;
237             typedef cds::atomicity::item_counter item_counter;
238             typedef ci::opt::v::sequential_consistent memory_model;
239         };
240
241         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
242
243         set_type s;
244         test( s );
245     }
246
247     TEST_F( IntrusiveSkipListSet_HP, member_cmpmix )
248     {
249         struct traits : public ci::skip_list::traits
250         {
251             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
252             typedef mock_disposer disposer;
253             typedef cmp<member_item_type> compare;
254             typedef base_class::less<member_item_type> less;
255             typedef ci::skip_list::stat<> stat;
256         };
257
258         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
259
260         set_type s;
261         test( s );
262     }
263
264     TEST_F( IntrusiveSkipListSet_HP, member_xorshift32 )
265     {
266         struct traits : public ci::skip_list::traits
267         {
268             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
269             typedef mock_disposer disposer;
270             typedef cmp<member_item_type> compare;
271             typedef ci::skip_list::xorshift32 random_level_generator;
272         };
273
274         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
275
276         set_type s;
277         test( s );
278     }
279
280     TEST_F( IntrusiveSkipListSet_HP, member_xorshift24 )
281     {
282         struct traits: public ci::skip_list::traits
283         {
284             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
285             typedef mock_disposer disposer;
286             typedef cmp<member_item_type> compare;
287             typedef ci::skip_list::xorshift24 random_level_generator;
288         };
289
290         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
291
292         set_type s;
293         test( s );
294     }
295
296     TEST_F( IntrusiveSkipListSet_HP, member_xorshift16 )
297     {
298         struct traits: public ci::skip_list::traits
299         {
300             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
301             typedef mock_disposer disposer;
302             typedef cmp<member_item_type> compare;
303             typedef ci::skip_list::xorshift16 random_level_generator;
304         };
305
306         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
307
308         set_type s;
309         test( s );
310     }
311
312     TEST_F( IntrusiveSkipListSet_HP, member_turbo32 )
313     {
314         struct traits: public ci::skip_list::traits
315         {
316             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
317             typedef mock_disposer disposer;
318             typedef cmp<member_item_type> compare;
319             typedef ci::skip_list::turbo32 random_level_generator;
320         };
321
322         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
323
324         set_type s;
325         test( s );
326     }
327
328     TEST_F( IntrusiveSkipListSet_HP, member_turbo24 )
329     {
330         struct traits: public ci::skip_list::traits
331         {
332             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
333             typedef mock_disposer disposer;
334             typedef cmp<member_item_type> compare;
335             typedef ci::skip_list::turbo24 random_level_generator;
336         };
337
338         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
339
340         set_type s;
341         test( s );
342     }
343
344     TEST_F( IntrusiveSkipListSet_HP, member_turbo16 )
345     {
346         struct traits: public ci::skip_list::traits
347         {
348             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
349             typedef mock_disposer disposer;
350             typedef cmp<member_item_type> compare;
351             typedef ci::skip_list::turbo16 random_level_generator;
352         };
353
354         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
355
356         set_type s;
357         test( s );
358     }
359
360 } // namespace