Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_splitlist_set_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_set.h"
32 #include <cds/intrusive/michael_list_hp.h>
33 #include <cds/intrusive/split_list.h>
34
35 namespace set {
36
37     void IntrusiveHashSetHdrTest::split_dyn_HP_base_cmp()
38     {
39         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
40         typedef ci::MichaelList< cds::gc::HP
41             ,item
42             ,ci::michael_list::make_traits<
43                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
44                 ,co::compare< cmp<item> >
45                 ,ci::opt::disposer< faked_disposer >
46             >::type
47         >    ord_list;
48
49         typedef ci::SplitListSet< cds::gc::HP, ord_list,
50             ci::split_list::make_traits<
51                 co::hash< hash_int >
52                 ,ci::split_list::dynamic_bucket_table<true>
53                 ,co::memory_model<co::v::relaxed_ordering>
54             >::type
55         > set;
56         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
57
58         test_int<set>();
59     }
60
61     void IntrusiveHashSetHdrTest::split_dyn_HP_base_less()
62     {
63         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
64         typedef ci::MichaelList< cds::gc::HP
65             ,item
66             ,ci::michael_list::make_traits<
67                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
68                 ,co::less< less<item> >
69                 ,ci::opt::disposer< faked_disposer >
70             >::type
71         >    ord_list;
72
73         typedef ci::SplitListSet< cds::gc::HP, ord_list,
74             ci::split_list::make_traits<
75                 co::hash< hash_int >
76                 ,co::memory_model<co::v::sequential_consistent>
77             >::type
78         > set;
79         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
80
81         test_int<set>();
82     }
83
84     void IntrusiveHashSetHdrTest::split_dyn_HP_base_cmpmix()
85     {
86         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::HP> > > item;
87         typedef ci::MichaelList< cds::gc::HP
88             ,item
89             ,ci::michael_list::make_traits<
90                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
91                 ,co::less< less<item> >
92                 ,co::compare< cmp<item> >
93                 ,ci::opt::disposer< faked_disposer >
94             >::type
95         >    ord_list;
96
97         typedef ci::SplitListSet< cds::gc::HP, ord_list,
98             ci::split_list::make_traits<
99                 co::hash< hash_int >
100                 ,co::item_counter< simple_item_counter >
101                 ,ci::split_list::dynamic_bucket_table<true>
102             >::type
103         > set;
104         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
105
106         test_int<set>();
107     }
108
109     void IntrusiveHashSetHdrTest::split_dyn_HP_base_cmpmix_stat()
110     {
111         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::HP> > > item;
112         typedef ci::MichaelList< cds::gc::HP
113             ,item
114             ,ci::michael_list::make_traits<
115                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
116                 ,co::less< less<item> >
117                 ,co::compare< cmp<item> >
118                 ,ci::opt::disposer< faked_disposer >
119             >::type
120         >    ord_list;
121
122         typedef ci::SplitListSet< cds::gc::HP, ord_list,
123             ci::split_list::make_traits<
124                 co::hash< hash_int >
125                 ,co::item_counter< simple_item_counter >
126                 ,ci::split_list::dynamic_bucket_table<true>
127                 ,co::stat< ci::split_list::stat<> >
128             >::type
129         > set;
130         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
131
132         test_int<set>();
133     }
134
135     void IntrusiveHashSetHdrTest::split_dyn_HP_member_cmp()
136     {
137         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
138         typedef ci::MichaelList< cds::gc::HP
139             ,item
140             ,ci::michael_list::make_traits<
141                 ci::opt::hook< ci::michael_list::member_hook<
142                     offsetof( item, hMember ),
143                     co::gc<cds::gc::HP>
144                 > >
145                 ,co::compare< cmp<item> >
146                 ,ci::opt::disposer< faked_disposer >
147             >::type
148         >    ord_list;
149
150         typedef ci::SplitListSet< cds::gc::HP, ord_list,
151             ci::split_list::make_traits<
152                 co::hash< hash_int >
153                 ,co::memory_model<co::v::relaxed_ordering>
154             >::type
155         > set;
156         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
157
158         test_int<set>();
159     }
160
161     void IntrusiveHashSetHdrTest::split_dyn_HP_member_less()
162     {
163         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
164         typedef ci::MichaelList< cds::gc::HP
165             ,item
166             ,ci::michael_list::make_traits<
167                 ci::opt::hook< ci::michael_list::member_hook<
168                     offsetof( item, hMember ),
169                     co::gc<cds::gc::HP>
170                 > >
171                 ,co::less< less<item> >
172                 ,ci::opt::disposer< faked_disposer >
173             >::type
174         >    ord_list;
175
176         typedef ci::SplitListSet< cds::gc::HP, ord_list,
177             ci::split_list::make_traits<
178                 co::hash< hash_int >
179                 ,co::memory_model<co::v::sequential_consistent>
180             >::type
181         > set;
182         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
183
184         test_int<set>();
185     }
186
187     void IntrusiveHashSetHdrTest::split_dyn_HP_member_cmpmix()
188     {
189         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
190         typedef ci::MichaelList< cds::gc::HP
191             ,item
192             ,ci::michael_list::make_traits<
193                 ci::opt::hook< ci::michael_list::member_hook<
194                     offsetof( item, hMember ),
195                     co::gc<cds::gc::HP>
196                 > >
197                 ,co::compare< cmp<item> >
198                 ,co::less< less<item> >
199                 ,ci::opt::disposer< faked_disposer >
200             >::type
201         >    ord_list;
202
203         typedef ci::SplitListSet< cds::gc::HP, ord_list,
204             ci::split_list::make_traits<
205                 co::hash< hash_int >
206                 ,co::item_counter< simple_item_counter >
207                 , ci::split_list::dynamic_bucket_table<true>
208             >::type
209         > set;
210         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
211
212         test_int<set>();
213     }
214
215     void IntrusiveHashSetHdrTest::split_dyn_HP_member_cmpmix_stat()
216     {
217         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
218         struct list_traits : public ci::michael_list::traits {
219             typedef ci::michael_list::member_hook< offsetof( item, hMember ), co::gc<cds::gc::HP>> hook;
220             typedef cmp<item> compare;
221             typedef IntrusiveHashSetHdrTest::less<item> less;
222             typedef faked_disposer disposer;
223         };
224         typedef ci::MichaelList< cds::gc::HP, item, list_traits > ord_list;
225
226         struct set_traits : public ci::split_list::traits {
227             typedef hash_int hash;
228             typedef simple_item_counter item_counter;
229             typedef ci::split_list::stat<> stat;
230         };
231         typedef ci::SplitListSet< cds::gc::HP, ord_list, set_traits > set;
232
233         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
234
235         test_int<set>();
236     }
237
238     // Static bucket table
239     void IntrusiveHashSetHdrTest::split_st_HP_base_cmp()
240     {
241         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
242         typedef ci::MichaelList< cds::gc::HP
243             ,item
244             ,ci::michael_list::make_traits<
245                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
246                 ,co::compare< cmp<item> >
247                 ,ci::opt::disposer< faked_disposer >
248             >::type
249         >    ord_list;
250
251         typedef ci::SplitListSet< cds::gc::HP, ord_list,
252             ci::split_list::make_traits<
253                 co::hash< hash_int >
254                 ,ci::split_list::dynamic_bucket_table<false>
255                 ,co::memory_model<co::v::relaxed_ordering>
256             >::type
257         > set;
258         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
259
260         test_int<set>();
261     }
262
263     void IntrusiveHashSetHdrTest::split_st_HP_base_less()
264     {
265         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
266         typedef ci::MichaelList< cds::gc::HP
267             ,item
268             ,ci::michael_list::make_traits<
269                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
270                 ,co::less< less<item> >
271                 ,ci::opt::disposer< faked_disposer >
272             >::type
273         >    ord_list;
274
275         typedef ci::SplitListSet< cds::gc::HP, ord_list,
276             ci::split_list::make_traits<
277                 co::hash< hash_int >
278                 ,ci::split_list::dynamic_bucket_table<false>
279                 ,co::memory_model<co::v::sequential_consistent>
280             >::type
281         > set;
282         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
283
284         test_int<set>();
285     }
286
287     void IntrusiveHashSetHdrTest::split_st_HP_base_cmpmix()
288     {
289         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::HP> > > item;
290         typedef ci::MichaelList< cds::gc::HP
291             ,item
292             ,ci::michael_list::make_traits<
293                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
294                 ,co::less< less<item> >
295                 ,co::compare< cmp<item> >
296                 ,ci::opt::disposer< faked_disposer >
297             >::type
298         >    ord_list;
299
300         typedef ci::SplitListSet< cds::gc::HP, ord_list,
301             ci::split_list::make_traits<
302                 co::hash< hash_int >
303                 ,co::item_counter< simple_item_counter >
304                 ,ci::split_list::dynamic_bucket_table<false>
305             >::type
306         > set;
307         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
308
309         test_int<set>();
310     }
311
312     void IntrusiveHashSetHdrTest::split_st_HP_base_cmpmix_stat()
313     {
314         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::HP> > > item;
315         struct list_traits :
316             public ci::michael_list::make_traits<
317                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::HP> > >
318                 ,co::less< less<item> >
319                 ,co::compare< cmp<item> >
320                 ,ci::opt::disposer< faked_disposer >
321             >::type
322         {};
323         typedef ci::MichaelList< cds::gc::HP, item, list_traits > ord_list;
324
325         struct set_traits :
326             public ci::split_list::make_traits<
327                 co::hash< hash_int >
328                 ,co::item_counter< simple_item_counter >
329                 ,ci::split_list::dynamic_bucket_table<false>
330                 ,co::stat< ci::split_list::stat<> >
331             >::type
332         {};
333         typedef ci::SplitListSet< cds::gc::HP, ord_list, set_traits > set;
334
335         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
336
337         test_int<set>();
338     }
339
340     void IntrusiveHashSetHdrTest::split_st_HP_member_cmp()
341     {
342         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
343         typedef ci::MichaelList< cds::gc::HP
344             ,item
345             ,ci::michael_list::make_traits<
346                 ci::opt::hook< ci::michael_list::member_hook<
347                     offsetof( item, hMember ),
348                     co::gc<cds::gc::HP>
349                 > >
350                 ,co::compare< cmp<item> >
351                 ,ci::opt::disposer< faked_disposer >
352             >::type
353         >    ord_list;
354
355         typedef ci::SplitListSet< cds::gc::HP, ord_list,
356             ci::split_list::make_traits<
357                 co::hash< hash_int >
358                 ,ci::split_list::dynamic_bucket_table<false>
359                 ,co::memory_model<co::v::relaxed_ordering>
360             >::type
361         > set;
362         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
363
364         test_int<set>();
365     }
366
367     void IntrusiveHashSetHdrTest::split_st_HP_member_less()
368     {
369         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
370         typedef ci::MichaelList< cds::gc::HP
371             ,item
372             ,ci::michael_list::make_traits<
373                 ci::opt::hook< ci::michael_list::member_hook<
374                     offsetof( item, hMember ),
375                     co::gc<cds::gc::HP>
376                 > >
377                 ,co::less< less<item> >
378                 ,ci::opt::disposer< faked_disposer >
379             >::type
380         >    ord_list;
381
382         typedef ci::SplitListSet< cds::gc::HP, ord_list,
383             ci::split_list::make_traits<
384                 ci::split_list::dynamic_bucket_table<false>
385                 ,co::hash< hash_int >
386                 ,co::memory_model<co::v::sequential_consistent>
387             >::type
388         > set;
389         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
390
391         test_int<set>();
392     }
393
394     void IntrusiveHashSetHdrTest::split_st_HP_member_cmpmix()
395     {
396         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
397         typedef ci::MichaelList< cds::gc::HP
398             ,item
399             ,ci::michael_list::make_traits<
400                 ci::opt::hook< ci::michael_list::member_hook<
401                     offsetof( item, hMember ),
402                     co::gc<cds::gc::HP>
403                 > >
404                 ,co::compare< cmp<item> >
405                 ,co::less< less<item> >
406                 ,ci::opt::disposer< faked_disposer >
407             >::type
408         >    ord_list;
409
410         typedef ci::SplitListSet< cds::gc::HP, ord_list,
411             ci::split_list::make_traits<
412                 co::hash< hash_int >
413                 ,co::item_counter< simple_item_counter >
414                 ,ci::split_list::dynamic_bucket_table<false>
415             >::type
416         > set;
417         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
418
419         test_int<set>();
420     }
421
422     void IntrusiveHashSetHdrTest::split_st_HP_member_cmpmix_stat()
423     {
424         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::HP> > > item;
425         typedef ci::MichaelList< cds::gc::HP
426             ,item
427             ,ci::michael_list::make_traits<
428                 ci::opt::hook< ci::michael_list::member_hook<
429                     offsetof( item, hMember ),
430                     co::gc<cds::gc::HP>
431                 > >
432                 ,co::compare< cmp<item> >
433                 ,co::less< less<item> >
434                 ,ci::opt::disposer< faked_disposer >
435             >::type
436         >    ord_list;
437
438         typedef ci::SplitListSet< cds::gc::HP, ord_list,
439             ci::split_list::make_traits<
440                 co::hash< hash_int >
441                 ,co::item_counter< simple_item_counter >
442                 ,ci::split_list::dynamic_bucket_table<false>
443                 ,co::stat< ci::split_list::stat<> >
444             >::type
445         > set;
446         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
447
448         test_int<set>();
449     }
450
451 } // namespace set