Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_splitlist_set_dhp.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_dhp.h>
33 #include <cds/intrusive/split_list.h>
34
35 namespace set {
36
37     void IntrusiveHashSetHdrTest::split_dyn_DHP_base_cmp()
38     {
39         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
40         typedef ci::MichaelList< cds::gc::DHP
41             ,item
42             ,ci::michael_list::make_traits<
43                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
44                 ,co::compare< cmp<item> >
45                 ,ci::opt::disposer< faked_disposer >
46             >::type
47         >    ord_list;
48
49         typedef ci::SplitListSet< cds::gc::DHP, 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_DHP_base_less()
62     {
63         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
64         typedef ci::MichaelList< cds::gc::DHP
65             ,item
66             ,ci::michael_list::make_traits<
67                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
68                 ,co::less< less<item> >
69                 ,ci::opt::disposer< faked_disposer >
70             >::type
71         >    ord_list;
72
73         typedef ci::SplitListSet< cds::gc::DHP, 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_DHP_base_cmpmix()
85     {
86         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::DHP> > > item;
87         typedef ci::MichaelList< cds::gc::DHP
88             ,item
89             ,ci::michael_list::make_traits<
90                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
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::DHP, 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_DHP_base_cmpmix_stat()
110     {
111         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::DHP> > > item;
112         typedef ci::MichaelList< cds::gc::DHP
113             ,item
114             ,ci::michael_list::make_traits<
115                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
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::DHP, 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_DHP_member_cmp()
136     {
137         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
138         typedef ci::MichaelList< cds::gc::DHP
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::DHP>
144                 > >
145                 ,co::compare< cmp<item> >
146                 ,ci::opt::disposer< faked_disposer >
147             >::type
148         >    ord_list;
149
150         typedef ci::SplitListSet< cds::gc::DHP, ord_list,
151             ci::split_list::make_traits<
152                 co::hash< hash_int >
153             >::type
154         > set;
155         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
156
157         test_int<set>();
158     }
159
160     void IntrusiveHashSetHdrTest::split_dyn_DHP_member_less()
161     {
162         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
163         typedef ci::MichaelList< cds::gc::DHP
164             ,item
165             ,ci::michael_list::make_traits<
166                 ci::opt::hook< ci::michael_list::member_hook<
167                     offsetof( item, hMember ),
168                     co::gc<cds::gc::DHP>
169                 > >
170                 ,co::less< less<item> >
171                 ,ci::opt::disposer< faked_disposer >
172             >::type
173         >    ord_list;
174
175         typedef ci::SplitListSet< cds::gc::DHP, ord_list,
176             ci::split_list::make_traits<
177                 co::hash< hash_int >
178                 ,co::memory_model<co::v::relaxed_ordering>
179             >::type
180         > set;
181         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
182
183         test_int<set>();
184     }
185
186     void IntrusiveHashSetHdrTest::split_dyn_DHP_member_cmpmix()
187     {
188         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
189         typedef ci::MichaelList< cds::gc::DHP
190             ,item
191             ,ci::michael_list::make_traits<
192                 ci::opt::hook< ci::michael_list::member_hook<
193                     offsetof( item, hMember ),
194                     co::gc<cds::gc::DHP>
195                 > >
196                 ,co::compare< cmp<item> >
197                 ,co::less< less<item> >
198                 ,ci::opt::disposer< faked_disposer >
199             >::type
200         >    ord_list;
201
202         typedef ci::SplitListSet< cds::gc::DHP, ord_list,
203             ci::split_list::make_traits<
204                 co::hash< hash_int >
205                 ,co::item_counter< simple_item_counter >
206                 ,co::memory_model<co::v::sequential_consistent>
207             >::type
208         > set;
209         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
210
211         test_int<set>();
212     }
213
214     void IntrusiveHashSetHdrTest::split_dyn_DHP_member_cmpmix_stat()
215     {
216         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
217         struct list_traits : public ci::michael_list::traits
218         {
219             typedef ci::michael_list::member_hook< offsetof( item, hMember ), co::gc<cds::gc::DHP> > hook;
220             typedef cmp<item> compare;
221             typedef IntrusiveHashSetHdrTest::less<item> less;
222             typedef faked_disposer disposer;
223         };
224         typedef ci::MichaelList< cds::gc::DHP, 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 co::v::sequential_consistent memory_model;
230             typedef ci::split_list::stat<> stat;
231         };
232         typedef ci::SplitListSet< cds::gc::DHP, ord_list, set_traits > set;
233         static_assert( set::traits::dynamic_bucket_table, "Set has static bucket table" );
234
235         test_int<set>();
236     }
237
238
239     // Static bucket table
240     void IntrusiveHashSetHdrTest::split_st_DHP_base_cmp()
241     {
242         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
243         typedef ci::MichaelList< cds::gc::DHP
244             ,item
245             ,ci::michael_list::make_traits<
246                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
247                 ,co::compare< cmp<item> >
248                 ,ci::opt::disposer< faked_disposer >
249             >::type
250         >    ord_list;
251
252         typedef ci::SplitListSet< cds::gc::DHP, ord_list,
253             ci::split_list::make_traits<
254                 co::hash< hash_int >
255                 ,ci::split_list::dynamic_bucket_table<false>
256                 ,co::memory_model<co::v::relaxed_ordering>
257             >::type
258         > set;
259         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
260
261         test_int<set>();
262     }
263
264     void IntrusiveHashSetHdrTest::split_st_DHP_base_less()
265     {
266         typedef base_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
267         typedef ci::MichaelList< cds::gc::DHP
268             ,item
269             ,ci::michael_list::make_traits<
270                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
271                 ,co::less< less<item> >
272                 ,ci::opt::disposer< faked_disposer >
273             >::type
274         >    ord_list;
275
276         typedef ci::SplitListSet< cds::gc::DHP, ord_list,
277             ci::split_list::make_traits<
278                 co::hash< hash_int >
279                 ,ci::split_list::dynamic_bucket_table<false>
280                 ,co::memory_model<co::v::sequential_consistent>
281             >::type
282         > set;
283         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
284
285         test_int<set>();
286     }
287
288     void IntrusiveHashSetHdrTest::split_st_DHP_base_cmpmix()
289     {
290         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::DHP> > > item;
291         typedef ci::MichaelList< cds::gc::DHP
292             ,item
293             ,ci::michael_list::make_traits<
294                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
295                 ,co::less< less<item> >
296                 ,co::compare< cmp<item> >
297                 ,ci::opt::disposer< faked_disposer >
298             >::type
299         >    ord_list;
300
301         typedef ci::SplitListSet< cds::gc::DHP, ord_list,
302             ci::split_list::make_traits<
303                 co::hash< hash_int >
304                 ,co::item_counter< simple_item_counter >
305                 ,ci::split_list::dynamic_bucket_table<false>
306             >::type
307         > set;
308         static_assert( !set::traits::dynamic_bucket_table, "Set has dynamic bucket table" );
309
310         test_int<set>();
311     }
312
313     void IntrusiveHashSetHdrTest::split_st_DHP_base_cmpmix_stat()
314     {
315         typedef base_int_item< ci::split_list::node<ci::michael_list::node<cds::gc::DHP> > > item;
316         struct list_traits :
317             public ci::michael_list::make_traits<
318                 ci::opt::hook< ci::michael_list::base_hook< co::gc<cds::gc::DHP> > >
319                 ,co::less< less<item> >
320                 ,co::compare< cmp<item> >
321                 ,ci::opt::disposer< faked_disposer >
322             >::type
323         {};
324         typedef ci::MichaelList< cds::gc::DHP, item, list_traits > ord_list;
325
326         struct set_traits :
327             public ci::split_list::make_traits<
328                 co::hash< hash_int >
329                 ,co::item_counter< simple_item_counter >
330                 ,ci::split_list::dynamic_bucket_table<false>
331                 ,co::stat< ci::split_list::stat<> >
332             >::type
333         {};
334         typedef ci::SplitListSet< cds::gc::DHP, ord_list, set_traits > set;
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_DHP_member_cmp()
341     {
342         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
343         typedef ci::MichaelList< cds::gc::DHP
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::DHP>
349                 > >
350                 ,co::compare< cmp<item> >
351                 ,ci::opt::disposer< faked_disposer >
352             >::type
353         >    ord_list;
354
355         typedef ci::SplitListSet< cds::gc::DHP, 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_DHP_member_less()
368     {
369         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
370         typedef ci::MichaelList< cds::gc::DHP
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::DHP>
376                 > >
377                 ,co::less< less<item> >
378                 ,ci::opt::disposer< faked_disposer >
379             >::type
380         >    ord_list;
381
382         typedef ci::SplitListSet< cds::gc::DHP, 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_DHP_member_cmpmix()
395     {
396         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
397         typedef ci::MichaelList< cds::gc::DHP
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::DHP>
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::DHP, 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_DHP_member_cmpmix_stat()
423     {
424         typedef member_int_item< ci::split_list::node< ci::michael_list::node<cds::gc::DHP> > > item;
425         typedef ci::MichaelList< cds::gc::DHP
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::DHP>
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::DHP, 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
452 } // namespace set