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