Removed trailing spaces
[libcds.git] / test / unit / map / split_lazy_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_map_hp.h"
32
33 #include <cds/container/lazy_list_hp.h>
34 #include <cds/container/split_list_map.h>
35 #include <cds/intrusive/free_list.h>
36
37 namespace {
38     namespace cc = cds::container;
39     typedef cds::gc::HP gc_type;
40
41     class SplitListLazyMap_HP : public cds_test::container_map_hp
42     {
43     protected:
44         typedef cds_test::container_map_hp base_class;
45
46         void SetUp()
47         {
48             struct map_traits: public cc::split_list::traits {
49                 typedef cc::lazy_list_tag ordered_list;
50                 typedef hash1 hash;
51                 struct ordered_list_traits: public cc::lazy_list::traits
52                 {
53                     typedef cmp compare;
54                 };
55             };
56             typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits >   map_type;
57
58             // +1 - for guarded_ptr
59             cds::gc::hp::GarbageCollector::Construct( map_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     TEST_F( SplitListLazyMap_HP, compare )
71     {
72         typedef cc::SplitListMap< gc_type, key_type, value_type,
73             typename cc::split_list::make_traits<
74                 cc::split_list::ordered_list< cc::lazy_list_tag >
75                 , cds::opt::hash< hash1 >
76                 , cc::split_list::ordered_list_traits<
77                     typename cc::lazy_list::make_traits<
78                         cds::opt::compare< cmp >
79                     >::type
80                 >
81             >::type
82         > map_type;
83
84         map_type m( kSize, 2 );
85         test( m );
86     }
87
88     TEST_F( SplitListLazyMap_HP, less )
89     {
90         typedef cc::SplitListMap< gc_type, key_type, value_type,
91             typename cc::split_list::make_traits<
92                 cc::split_list::ordered_list< cc::lazy_list_tag >
93                 , cds::opt::hash< hash1 >
94                 , cc::split_list::ordered_list_traits<
95                     typename cc::lazy_list::make_traits<
96                         cds::opt::less< less >
97                     >::type
98                 >
99             >::type
100         > map_type;
101
102         map_type m( kSize, 2 );
103         test( m );
104     }
105
106     TEST_F( SplitListLazyMap_HP, cmpmix )
107     {
108         typedef cc::SplitListMap< gc_type, key_type, value_type,
109             typename cc::split_list::make_traits<
110                 cc::split_list::ordered_list< cc::lazy_list_tag >
111                 , cds::opt::hash< hash1 >
112                 , cc::split_list::ordered_list_traits<
113                     typename cc::lazy_list::make_traits<
114                         cds::opt::less< less >
115                         , cds::opt::compare< cmp >
116                     >::type
117                 >
118             >::type
119         > map_type;
120
121         map_type m( kSize, 3 );
122         test( m );
123     }
124
125     TEST_F( SplitListLazyMap_HP, item_counting )
126     {
127         struct map_traits: public cc::split_list::traits
128         {
129             typedef cc::lazy_list_tag ordered_list;
130             typedef hash1 hash;
131             typedef cds::atomicity::item_counter item_counter;
132
133             struct ordered_list_traits: public cc::lazy_list::traits
134             {
135                 typedef cmp compare;
136                 typedef base_class::less less;
137                 typedef cds::backoff::empty back_off;
138             };
139         };
140         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
141
142         map_type m( kSize, 4 );
143         test( m );
144     }
145
146     TEST_F( SplitListLazyMap_HP, stat )
147     {
148         struct map_traits: public cc::split_list::traits
149         {
150             typedef cc::lazy_list_tag ordered_list;
151             typedef hash1 hash;
152             typedef cds::atomicity::item_counter item_counter;
153             typedef cc::split_list::stat<> stat;
154
155             struct ordered_list_traits: public cc::lazy_list::traits
156             {
157                 typedef base_class::less less;
158                 typedef cds::opt::v::sequential_consistent memory_model;
159             };
160         };
161         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
162
163         map_type m( kSize, 2 );
164         test( m );
165     }
166
167     TEST_F( SplitListLazyMap_HP, back_off )
168     {
169         struct map_traits: public cc::split_list::traits
170         {
171             typedef cc::lazy_list_tag ordered_list;
172             typedef hash1 hash;
173             typedef cds::atomicity::item_counter item_counter;
174             typedef cds::backoff::yield back_off;
175             typedef cds::opt::v::sequential_consistent memory_model;
176
177             struct ordered_list_traits: public cc::lazy_list::traits
178             {
179                 typedef cmp compare;
180                 typedef cds::backoff::empty back_off;
181             };
182         };
183         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
184
185         map_type m( kSize, 4 );
186         test( m );
187     }
188
189     TEST_F( SplitListLazyMap_HP, free_list )
190     {
191         struct map_traits: public cc::split_list::traits
192         {
193             typedef cc::lazy_list_tag ordered_list;
194             typedef hash1 hash;
195             typedef cds::intrusive::FreeList free_list;
196
197             struct ordered_list_traits: public cc::lazy_list::traits
198             {
199                 typedef cmp compare;
200                 typedef cds::backoff::empty back_off;
201             };
202         };
203         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
204
205         map_type m( kSize, 4 );
206         test( m );
207     }
208
209     TEST_F( SplitListLazyMap_HP, mutex )
210     {
211         struct map_traits: public cc::split_list::traits
212         {
213             typedef cc::lazy_list_tag ordered_list;
214             typedef hash1 hash;
215             typedef cds::atomicity::item_counter item_counter;
216             typedef cds::backoff::yield back_off;
217             typedef cds::opt::v::sequential_consistent memory_model;
218
219             struct ordered_list_traits: public cc::lazy_list::traits
220             {
221                 typedef cmp compare;
222                 typedef cds::backoff::pause back_off;
223                 typedef std::mutex lock_type;
224             };
225         };
226         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
227
228         map_type m( kSize, 2 );
229         test( m );
230     }
231
232     struct set_static_traits: public cc::split_list::traits
233     {
234         static bool const dynamic_bucket_table = false;
235     };
236
237     TEST_F( SplitListLazyMap_HP, static_bucket_table )
238     {
239         struct map_traits: public set_static_traits
240         {
241             typedef cc::lazy_list_tag ordered_list;
242             typedef hash1 hash;
243             typedef cds::atomicity::item_counter item_counter;
244
245             struct ordered_list_traits: public cc::lazy_list::traits
246             {
247                 typedef cmp compare;
248                 typedef cds::backoff::pause back_off;
249             };
250         };
251         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
252
253         map_type m( kSize, 4 );
254         test( m );
255     }
256
257     TEST_F( SplitListLazyMap_HP, static_bucket_table_free_list )
258     {
259         struct map_traits: public set_static_traits
260         {
261             typedef cc::lazy_list_tag ordered_list;
262             typedef hash1 hash;
263             typedef cds::atomicity::item_counter item_counter;
264             typedef cds::intrusive::FreeList free_list;
265
266             struct ordered_list_traits: public cc::lazy_list::traits
267             {
268                 typedef cmp compare;
269                 typedef cds::backoff::pause back_off;
270             };
271         };
272         typedef cc::SplitListMap< gc_type, key_type, value_type, map_traits > map_type;
273
274         map_type m( kSize, 4 );
275         test( m );
276     }
277
278 } // namespace