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