HP and DHP SMR totally refactored
[libcds.git] / test / unit / intrusive-set / intrusive_split_michael_nogc.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_nogc.h"
32
33 #include <cds/intrusive/michael_list_nogc.h>
34 #include <cds/intrusive/split_list_nogc.h>
35 #include <cds/intrusive/free_list.h>
36
37 namespace {
38     namespace ci = cds::intrusive;
39     typedef cds::gc::nogc gc_type;
40
41     class IntrusiveSplitListSet_NoGC : public cds_test::intrusive_set_nogc
42     {
43     protected:
44         typedef cds_test::intrusive_set_nogc base_class;
45
46     protected:
47         typedef typename base_class::base_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>>   base_item_type;
48         typedef typename base_class::member_int_item< ci::split_list::node< ci::michael_list::node<gc_type>>> member_item_type;
49
50         //void SetUp()
51         //{}
52
53         //void TearDown()
54         //{}
55     };
56
57
58     TEST_F( IntrusiveSplitListSet_NoGC, base_cmp )
59     {
60         typedef ci::MichaelList< gc_type
61             , base_item_type
62             ,ci::michael_list::make_traits<
63                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
64                 ,ci::opt::compare< cmp<base_item_type> >
65                 ,ci::opt::disposer< mock_disposer >
66             >::type
67         > bucket_type;
68
69         typedef ci::SplitListSet< gc_type, bucket_type,
70             ci::split_list::make_traits<
71                 ci::opt::hash< hash_int >
72             >::type
73         > set_type;
74
75         set_type s( kSize, 2 );
76         test( s );
77     }
78
79     TEST_F( IntrusiveSplitListSet_NoGC, base_less )
80     {
81         typedef ci::MichaelList< gc_type
82             , base_item_type
83             ,ci::michael_list::make_traits<
84                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
85                 ,ci::opt::less< less<base_item_type> >
86                 ,ci::opt::disposer< mock_disposer >
87             >::type
88         > bucket_type;
89
90         typedef ci::SplitListSet< gc_type, bucket_type,
91             ci::split_list::make_traits<
92                 ci::opt::hash< hash_int >
93                 , ci::opt::item_counter< cds::atomicity::item_counter >
94             >::type
95         > set_type;
96
97         set_type s( kSize, 2 );
98         test( s );
99     }
100
101     TEST_F( IntrusiveSplitListSet_NoGC, base_cmpmix )
102     {
103         struct list_traits : public ci::michael_list::traits
104         {
105             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
106             typedef base_class::less<base_item_type> less;
107             typedef cmp<base_item_type> compare;
108             typedef mock_disposer disposer;
109         };
110         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
111
112         struct set_traits : public ci::split_list::traits
113         {
114             typedef hash_int hash;
115             typedef simple_item_counter item_counter;
116             typedef ci::split_list::stat<> stat;
117         };
118         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
119
120         set_type s( kSize, 2 );
121         test( s );
122     }
123
124     TEST_F( IntrusiveSplitListSet_NoGC, base_static_bucket_table )
125     {
126         struct list_traits: public ci::michael_list::traits
127         {
128             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
129             typedef base_class::less<base_item_type> less;
130             typedef cmp<base_item_type> compare;
131             typedef mock_disposer disposer;
132         };
133         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
134
135         struct set_traits: public ci::split_list::traits
136         {
137             typedef hash_int hash;
138             typedef simple_item_counter item_counter;
139             typedef ci::split_list::stat<> stat;
140             enum {
141                 dynamic_bucket_table = false
142             };
143         };
144         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
145
146         set_type s( kSize, 2 );
147         test( s );
148     }
149
150     TEST_F( IntrusiveSplitListSet_NoGC, base_static_bucket_table_free_list )
151     {
152         struct list_traits: public ci::michael_list::traits
153         {
154             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
155             typedef cmp<base_item_type> compare;
156             typedef mock_disposer disposer;
157         };
158         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
159
160         struct set_traits: public ci::split_list::traits
161         {
162             typedef hash_int hash;
163             typedef simple_item_counter item_counter;
164             typedef ci::split_list::stat<> stat;
165             enum {
166                 dynamic_bucket_table = false
167             };
168             typedef ci::FreeList free_list;
169         };
170         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
171
172         set_type s( kSize, 2 );
173         test( s );
174     }
175
176     TEST_F( IntrusiveSplitListSet_NoGC, base_free_list )
177     {
178         struct list_traits: public ci::michael_list::traits
179         {
180             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
181             typedef base_class::less<base_item_type> less;
182             typedef mock_disposer disposer;
183         };
184         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
185
186         struct set_traits: public ci::split_list::traits
187         {
188             typedef hash_int hash;
189             typedef simple_item_counter item_counter;
190             typedef ci::split_list::stat<> stat;
191             typedef ci::FreeList free_list;
192         };
193         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
194
195         set_type s( kSize, 2 );
196         test( s );
197     }
198
199     TEST_F( IntrusiveSplitListSet_NoGC, member_cmp )
200     {
201         typedef ci::MichaelList< gc_type
202             ,member_item_type
203             ,ci::michael_list::make_traits<
204                 ci::opt::hook< ci::michael_list::member_hook<
205                     offsetof( member_item_type, hMember ),
206                     ci::opt::gc<gc_type>
207                 > >
208                 ,ci::opt::compare< cmp<member_item_type> >
209                 ,ci::opt::disposer< mock_disposer >
210             >::type
211         >    bucket_type;
212
213         typedef ci::SplitListSet< gc_type, bucket_type,
214             ci::split_list::make_traits<
215                 ci::opt::hash< hash_int >
216             >::type
217         > set_type;
218
219         set_type s( kSize, 2 );
220         test( s );
221     }
222
223     TEST_F( IntrusiveSplitListSet_NoGC, member_less )
224     {
225         typedef ci::MichaelList< gc_type
226             , member_item_type
227             ,ci::michael_list::make_traits<
228                 ci::opt::hook< ci::michael_list::member_hook<
229                     offsetof( member_item_type, hMember ),
230                     ci::opt::gc<gc_type>
231                 > >
232                 ,ci::opt::less< less<member_item_type> >
233                 ,ci::opt::disposer< mock_disposer >
234             >::type
235         > bucket_type;
236
237         typedef ci::SplitListSet< gc_type, bucket_type,
238             ci::split_list::make_traits<
239                 ci::opt::hash< hash_int >
240                 , ci::opt::back_off< cds::backoff::pause >
241             >::type
242         > set_type;
243
244         set_type s( kSize, 2 );
245         test( s );
246     }
247
248     TEST_F( IntrusiveSplitListSet_NoGC, member_cmpmix )
249     {
250         struct list_traits : public ci::michael_list::traits
251         {
252             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
253             typedef base_class::less<member_item_type> less;
254             typedef cmp<member_item_type> compare;
255             typedef mock_disposer disposer;
256         };
257         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
258
259         struct set_traits : public ci::split_list::traits
260         {
261             typedef hash_int hash;
262             typedef simple_item_counter item_counter;
263         };
264         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
265
266         set_type s( kSize, 2 );
267         test( s );
268     }
269
270     TEST_F( IntrusiveSplitListSet_NoGC, member_static_bucket_table )
271     {
272         struct list_traits: public ci::michael_list::traits
273         {
274             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
275             typedef base_class::less<member_item_type> less;
276             typedef cmp<member_item_type> compare;
277             typedef mock_disposer disposer;
278         };
279         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
280
281         struct set_traits: public ci::split_list::traits
282         {
283             typedef hash_int hash;
284             typedef simple_item_counter item_counter;
285             enum {
286                 dynamic_bucket_table = false
287             };
288         };
289         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
290
291         set_type s( kSize, 2 );
292         test( s );
293     }
294
295     TEST_F( IntrusiveSplitListSet_NoGC, member_static_bucket_table_free_list )
296     {
297         struct list_traits: public ci::michael_list::traits
298         {
299             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
300             typedef cmp<member_item_type> compare;
301             typedef mock_disposer disposer;
302         };
303         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
304
305         struct set_traits: public ci::split_list::traits
306         {
307             typedef hash_int hash;
308             typedef simple_item_counter item_counter;
309             enum {
310                 dynamic_bucket_table = false
311             };
312             typedef ci::FreeList free_list;
313         };
314         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
315
316         set_type s( kSize, 2 );
317         test( s );
318     }
319
320     TEST_F( IntrusiveSplitListSet_NoGC, member_free_list )
321     {
322         struct list_traits: public ci::michael_list::traits
323         {
324             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
325             typedef base_class::less<member_item_type> less;
326             typedef mock_disposer disposer;
327         };
328         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
329
330         struct set_traits: public ci::split_list::traits
331         {
332             typedef hash_int hash;
333             typedef simple_item_counter item_counter;
334             typedef ci::FreeList free_list;
335         };
336         typedef ci::SplitListSet< gc_type, bucket_type, set_traits > set_type;
337
338         set_type s( kSize, 2 );
339         test( s );
340     }
341
342 } // namespace