fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / set / split_michael_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-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_set_hp.h"
32
33 #include <cds/container/michael_list_dhp.h>
34 #include <cds/container/split_list_set.h>
35 #include <cds/intrusive/free_list.h>
36
37 namespace {
38     namespace cc = cds::container;
39     typedef cds::gc::DHP gc_type;
40
41     class SplitListMichaelSet_DHP : public cds_test::container_set_hp
42     {
43     protected:
44         typedef cds_test::container_set_hp base_class;
45
46         void SetUp()
47         {
48             struct set_traits: public cc::split_list::traits {
49                 typedef cc::michael_list_tag ordered_list;
50                 typedef hash_int hash;
51                 struct ordered_list_traits: public cc::michael_list::traits
52                 {
53                     typedef cmp compare;
54                 };
55             };
56             typedef cc::SplitListSet< gc_type, int_item, set_traits >   set_type;
57
58             cds::gc::dhp::smr::construct( set_type::c_nHazardPtrCount );
59             cds::threading::Manager::attachThread();
60         }
61
62         void TearDown()
63         {
64             cds::threading::Manager::detachThread();
65             cds::gc::dhp::smr::destruct();
66         }
67     };
68
69     TEST_F( SplitListMichaelSet_DHP, compare )
70     {
71         typedef cc::SplitListSet< gc_type, int_item,
72             typename cc::split_list::make_traits<
73                 cc::split_list::ordered_list< cc::michael_list_tag >
74                 , cds::opt::hash< hash_int >
75                 , cc::split_list::ordered_list_traits<
76                     typename cc::michael_list::make_traits<
77                         cds::opt::compare< cmp >
78                     >::type
79                 >
80             >::type
81         > set_type;
82
83         set_type s( kSize, 2 );
84         test( s );
85     }
86
87     TEST_F( SplitListMichaelSet_DHP, less )
88     {
89         typedef cc::SplitListSet< gc_type, int_item,
90             typename cc::split_list::make_traits<
91                 cc::split_list::ordered_list< cc::michael_list_tag >
92                 , cds::opt::hash< hash_int >
93                 , cc::split_list::ordered_list_traits<
94                     typename cc::michael_list::make_traits<
95                         cds::opt::less< less >
96                     >::type
97                 >
98             >::type
99         > set_type;
100
101         set_type s;
102         test( s );
103     }
104
105     TEST_F( SplitListMichaelSet_DHP, cmpmix )
106     {
107         typedef cc::SplitListSet< gc_type, int_item,
108             typename cc::split_list::make_traits<
109                 cc::split_list::ordered_list< cc::michael_list_tag >
110                 , cds::opt::hash< hash_int >
111                 , cc::split_list::ordered_list_traits<
112                     typename cc::michael_list::make_traits<
113                         cds::opt::less< less >
114                         , cds::opt::compare< cmp >
115                     >::type
116                 >
117             >::type
118         > set_type;
119
120         set_type s( kSize, 3 );
121         test( s );
122     }
123
124     TEST_F( SplitListMichaelSet_DHP, item_counting )
125     {
126         struct set_traits: public cc::split_list::traits
127         {
128             typedef cc::michael_list_tag ordered_list;
129             typedef hash_int hash;
130             typedef cds::atomicity::item_counter item_counter;
131
132             struct ordered_list_traits: public cc::michael_list::traits
133             {
134                 typedef cmp compare;
135                 typedef base_class::less less;
136                 typedef cds::backoff::empty back_off;
137             };
138         };
139         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
140
141         set_type s( kSize, 4 );
142         test( s );
143     }
144
145     TEST_F( SplitListMichaelSet_DHP, stat )
146     {
147         struct set_traits: public cc::split_list::traits
148         {
149             typedef cc::michael_list_tag ordered_list;
150             typedef hash_int hash;
151             typedef cds::atomicity::item_counter item_counter;
152             typedef cc::split_list::stat<> stat;
153
154             struct ordered_list_traits: public cc::michael_list::traits
155             {
156                 typedef base_class::less less;
157                 typedef cds::opt::v::sequential_consistent memory_model;
158             };
159         };
160         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
161
162         set_type s( kSize, 2 );
163         test( s );
164     }
165
166     TEST_F( SplitListMichaelSet_DHP, back_off )
167     {
168         struct set_traits: public cc::split_list::traits
169         {
170             typedef cc::michael_list_tag ordered_list;
171             typedef hash_int hash;
172             typedef cds::atomicity::item_counter item_counter;
173             typedef cds::backoff::yield back_off;
174             typedef cds::opt::v::sequential_consistent memory_model;
175
176             struct ordered_list_traits: public cc::michael_list::traits
177             {
178                 typedef cmp compare;
179                 typedef cds::backoff::pause back_off;
180             };
181         };
182         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
183
184         set_type s( kSize, 2 );
185         test( s );
186     }
187
188     TEST_F( SplitListMichaelSet_DHP, free_list )
189     {
190         struct set_traits: public cc::split_list::traits
191         {
192             typedef cc::michael_list_tag ordered_list;
193             typedef hash_int hash;
194             typedef cds::intrusive::FreeList free_list;
195
196             struct ordered_list_traits: public cc::michael_list::traits
197             {
198                 typedef cmp compare;
199                 typedef cds::backoff::pause back_off;
200             };
201         };
202         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
203
204         set_type s( kSize, 2 );
205         test( s );
206     }
207
208     struct set_static_traits: public cc::split_list::traits
209     {
210         static bool const dynamic_bucket_table = false;
211     };
212
213     TEST_F( SplitListMichaelSet_DHP, static_bucket_table )
214     {
215         struct set_traits: public set_static_traits
216         {
217             typedef cc::michael_list_tag ordered_list;
218             typedef hash_int hash;
219             typedef cds::atomicity::item_counter item_counter;
220
221             struct ordered_list_traits: public cc::michael_list::traits
222             {
223                 typedef cmp compare;
224                 typedef cds::backoff::pause back_off;
225             };
226         };
227         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
228
229         set_type s( kSize, 4 );
230         test( s );
231     }
232
233     TEST_F( SplitListMichaelSet_DHP, static_bucket_table_free_list )
234     {
235         struct set_traits: public set_static_traits
236         {
237             typedef cc::michael_list_tag ordered_list;
238             typedef hash_int hash;
239             typedef cds::atomicity::item_counter item_counter;
240             typedef cds::intrusive::FreeList free_list;
241
242             struct ordered_list_traits: public cc::michael_list::traits
243             {
244                 typedef cmp compare;
245                 typedef cds::backoff::pause back_off;
246             };
247         };
248         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
249
250         set_type s( kSize, 4 );
251         test( s );
252     }
253
254     TEST_F( SplitListMichaelSet_DHP, bit_reversal_swar )
255     {
256         struct set_traits: public cc::split_list::traits
257         {
258             typedef cc::michael_list_tag ordered_list;
259             typedef hash_int hash;
260             typedef cds::atomicity::item_counter item_counter;
261             typedef cds::algo::bit_reversal::swar bit_reversal;
262
263             struct ordered_list_traits: public cc::michael_list::traits
264             {
265                 typedef cmp compare;
266                 typedef base_class::less less;
267                 typedef cds::backoff::empty back_off;
268             };
269         };
270         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
271
272         set_type s( kSize, 2 );
273         test( s );
274     }
275
276     TEST_F( SplitListMichaelSet_DHP, bit_reversal_lookup )
277     {
278         struct set_traits: public cc::split_list::traits
279         {
280             typedef cc::michael_list_tag ordered_list;
281             typedef hash_int hash;
282             typedef cds::atomicity::item_counter item_counter;
283             typedef cds::algo::bit_reversal::lookup bit_reversal;
284
285             struct ordered_list_traits: public cc::michael_list::traits
286             {
287                 typedef cmp compare;
288                 typedef base_class::less less;
289                 typedef cds::backoff::empty back_off;
290             };
291         };
292         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
293
294         set_type s( kSize, 2 );
295         test( s );
296     }
297
298     TEST_F( SplitListMichaelSet_DHP, bit_reversal_muldiv )
299     {
300         struct set_traits: public cc::split_list::traits
301         {
302             typedef cc::michael_list_tag ordered_list;
303             typedef hash_int hash;
304             typedef cds::atomicity::item_counter item_counter;
305             typedef cds::algo::bit_reversal::muldiv bit_reversal;
306
307             struct ordered_list_traits: public cc::michael_list::traits
308             {
309                 typedef cmp compare;
310                 typedef base_class::less less;
311                 typedef cds::backoff::empty back_off;
312             };
313         };
314         typedef cc::SplitListSet< gc_type, int_item, set_traits > set_type;
315
316         set_type s( kSize, 2 );
317         test( s );
318     }
319
320 } // namespace