HP and DHP SMR totally refactored
[libcds.git] / test / unit / intrusive-set / intrusive_michael_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/michael_set_nogc.h>
35
36 namespace {
37     namespace ci = cds::intrusive;
38     typedef cds::gc::nogc gc_type;
39
40     class IntrusiveMichaelSet_NoGC : public cds_test::intrusive_set_nogc
41     {
42     protected:
43         typedef cds_test::intrusive_set_nogc base_class;
44
45     protected:
46         typedef typename base_class::base_int_item< ci::michael_list::node<gc_type>>   base_item_type;
47         typedef typename base_class::member_int_item< ci::michael_list::node<gc_type>> member_item_type;
48
49         //void SetUp()
50         //{}
51
52         //void TearDown()
53         //{}
54     };
55
56
57     TEST_F( IntrusiveMichaelSet_NoGC, base_cmp )
58     {
59         typedef ci::MichaelList< gc_type
60             , base_item_type
61             ,ci::michael_list::make_traits<
62                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type > > >
63                 ,ci::opt::compare< cmp<base_item_type> >
64                 ,ci::opt::disposer< mock_disposer >
65             >::type
66         > bucket_type;
67
68         typedef ci::MichaelHashSet< gc_type, bucket_type,
69             ci::michael_set::make_traits<
70                 ci::opt::hash< hash_int >
71             >::type
72         > set_type;
73
74         set_type s( kSize, 2 );
75         test( s );
76     }
77
78     TEST_F( IntrusiveMichaelSet_NoGC, base_less )
79     {
80         typedef ci::MichaelList< gc_type
81             , base_item_type
82             ,ci::michael_list::make_traits<
83                 ci::opt::hook< ci::michael_list::base_hook< ci::opt::gc< gc_type >>>
84                 ,ci::opt::less< less<base_item_type> >
85                 ,ci::opt::disposer< mock_disposer >
86             >::type
87         > bucket_type;
88
89         typedef ci::MichaelHashSet< gc_type, bucket_type,
90             ci::michael_set::make_traits<
91                 ci::opt::hash< hash_int >
92             >::type
93         > set_type;
94
95         set_type s( kSize, 2 );
96         test( s );
97     }
98
99     TEST_F( IntrusiveMichaelSet_NoGC, base_cmpmix )
100     {
101         struct list_traits : public ci::michael_list::traits
102         {
103             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
104             typedef base_class::less<base_item_type> less;
105             typedef cmp<base_item_type> compare;
106             typedef mock_disposer disposer;
107         };
108         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
109
110         struct set_traits : public ci::michael_set::traits
111         {
112             typedef hash_int hash;
113             typedef simple_item_counter item_counter;
114         };
115         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
116
117         set_type s( kSize, 2 );
118         test( s );
119     }
120
121     TEST_F( IntrusiveMichaelSet_NoGC, base_stat )
122     {
123         struct list_traits: public ci::michael_list::traits
124         {
125             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
126             typedef base_class::less<base_item_type> less;
127             typedef mock_disposer disposer;
128             typedef ci::michael_list::stat<> stat;
129         };
130         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
131
132         struct set_traits: public ci::michael_set::traits
133         {
134             typedef hash_int hash;
135             typedef simple_item_counter item_counter;
136         };
137         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
138
139         set_type s( kSize, 2 );
140         test( s );
141         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
142     }
143
144     TEST_F( IntrusiveMichaelSet_NoGC, base_wrapped_stat )
145     {
146         struct list_traits: public ci::michael_list::traits
147         {
148             typedef ci::michael_list::base_hook< ci::opt::gc<gc_type>> hook;
149             typedef base_class::less<base_item_type> less;
150             typedef mock_disposer disposer;
151             typedef ci::michael_list::wrapped_stat<> stat;
152         };
153         typedef ci::MichaelList< gc_type, base_item_type, list_traits > bucket_type;
154
155         struct set_traits: public ci::michael_set::traits
156         {
157             typedef hash_int hash;
158             typedef simple_item_counter item_counter;
159         };
160         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
161
162         set_type s( kSize, 2 );
163         test( s );
164         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
165     }
166
167     TEST_F( IntrusiveMichaelSet_NoGC, member_cmp )
168     {
169         typedef ci::MichaelList< gc_type
170             ,member_item_type
171             ,ci::michael_list::make_traits<
172                 ci::opt::hook< ci::michael_list::member_hook<
173                     offsetof( member_item_type, hMember ),
174                     ci::opt::gc<gc_type>
175                 > >
176                 ,ci::opt::compare< cmp<member_item_type> >
177                 ,ci::opt::disposer< mock_disposer >
178             >::type
179         >    bucket_type;
180
181         typedef ci::MichaelHashSet< gc_type, bucket_type,
182             ci::michael_set::make_traits<
183                 ci::opt::hash< hash_int >
184             >::type
185         > set_type;
186
187         set_type s( kSize, 2 );
188         test( s );
189     }
190
191     TEST_F( IntrusiveMichaelSet_NoGC, member_less )
192     {
193         typedef ci::MichaelList< gc_type
194             , member_item_type
195             ,ci::michael_list::make_traits<
196                 ci::opt::hook< ci::michael_list::member_hook<
197                     offsetof( member_item_type, hMember ),
198                     ci::opt::gc<gc_type>
199                 > >
200                 ,ci::opt::less< less<member_item_type> >
201                 ,ci::opt::disposer< mock_disposer >
202             >::type
203         > bucket_type;
204
205         typedef ci::MichaelHashSet< gc_type, bucket_type,
206             ci::michael_set::make_traits<
207                 ci::opt::hash< hash_int >
208             >::type
209         > set_type;
210
211         set_type s( kSize, 2 );
212         test( s );
213     }
214
215     TEST_F( IntrusiveMichaelSet_NoGC, member_cmpmix )
216     {
217         struct list_traits : public ci::michael_list::traits
218         {
219             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
220             typedef base_class::less<member_item_type> less;
221             typedef cmp<member_item_type> compare;
222             typedef mock_disposer disposer;
223         };
224         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
225
226         struct set_traits : public ci::michael_set::traits
227         {
228             typedef hash_int hash;
229             typedef simple_item_counter item_counter;
230         };
231         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
232
233         set_type s( kSize, 2 );
234         test( s );
235     }
236
237     TEST_F( IntrusiveMichaelSet_NoGC, member_stat )
238     {
239         struct list_traits: public ci::michael_list::traits
240         {
241             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
242             typedef cmp<member_item_type> compare;
243             typedef mock_disposer disposer;
244             typedef ci::michael_list::stat<> stat;
245         };
246         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
247
248         struct set_traits: public ci::michael_set::traits
249         {
250             typedef hash_int hash;
251             typedef simple_item_counter item_counter;
252         };
253         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
254
255         set_type s( kSize, 2 );
256         test( s );
257         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
258     }
259
260     TEST_F( IntrusiveMichaelSet_NoGC, member_wrapped_stat )
261     {
262         struct list_traits: public ci::michael_list::traits
263         {
264             typedef ci::michael_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc<gc_type>> hook;
265             typedef cmp<member_item_type> compare;
266             typedef mock_disposer disposer;
267             typedef ci::michael_list::wrapped_stat<> stat;
268         };
269         typedef ci::MichaelList< gc_type, member_item_type, list_traits > bucket_type;
270
271         struct set_traits: public ci::michael_set::traits
272         {
273             typedef hash_int hash;
274             typedef simple_item_counter item_counter;
275         };
276         typedef ci::MichaelHashSet< gc_type, bucket_type, set_traits > set_type;
277
278         set_type s( kSize, 2 );
279         test( s );
280         EXPECT_GE( s.statistics().m_nInsertSuccess, 0u );
281     }
282
283 } // namespace