Updated copyright
[libcds.git] / test / unit / striped-set / intrusive_boost_unordered_set.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 #ifndef CDSUNIT_SET_TEST_INTRUSIVE_BOOST_UNORDERED_SET_H
32 #define CDSUNIT_SET_TEST_INTRUSIVE_BOOST_UNORDERED_SET_H
33
34 #ifdef CDSUNIT_ENABLE_BOOST_CONTAINER
35
36 #include "test_intrusive_set.h"
37
38 #include <cds/intrusive/striped_set/boost_unordered_set.h>
39 #include <cds/intrusive/striped_set.h>
40
41 namespace {
42     namespace ci = cds::intrusive;
43     namespace bi = boost::intrusive;
44
45     class IntrusiveStripedBoostUnorderedSet: public cds_test::intrusive_set
46     {
47     public:
48         typedef base_int_item< bi::unordered_set_base_hook<>> base_item;
49         typedef member_int_item< bi::unordered_set_member_hook<>> member_item;
50     };
51
52     template <size_t Capacity, typename T, class Alloc = CDS_DEFAULT_ALLOCATOR>
53     struct dyn_buffer: public ci::opt::v::initialized_dynamic_buffer< T, Alloc >
54     {
55         typedef ci::opt::v::initialized_dynamic_buffer< T, Alloc >   base_class;
56     public:
57         template <typename Q>
58         struct rebind {
59             typedef dyn_buffer<Capacity, Q, Alloc> other;  ///< Rebinding result type
60         };
61
62         dyn_buffer()
63             : base_class( Capacity )
64         {}
65     };
66
67     TEST_F( IntrusiveStripedBoostUnorderedSet, basehook )
68     {
69         typedef ci::StripedSet<
70             bi::unordered_set< base_item
71                 , bi::hash< hash1 >
72                 , bi::equal< equal_to<base_item> >
73                 , bi::power_2_buckets<true>
74                 , bi::incremental<true>
75             >
76             ,cds::intrusive::opt::hash< hash2 >
77         > set_type;
78
79         std::vector< typename set_type::value_type > data;
80         {
81             set_type s;
82             this->test( s, data );
83         }
84     }
85
86     TEST_F( IntrusiveStripedBoostUnorderedSet, basehook_resize_bucket_threshold )
87     {
88         typedef ci::StripedSet<
89             bi::unordered_set< base_item
90                 , bi::hash< hash1 >
91                 , bi::equal< equal_to<base_item> >
92                 , bi::power_2_buckets<true>
93                 , bi::incremental<true>
94             >
95             ,cds::intrusive::opt::hash< hash2 >
96             ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::initialized_static_buffer< cds::any_type, 64 > >
97             ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
98         > set_type;
99
100         std::vector< typename set_type::value_type > data;
101         {
102             set_type s;
103             this->test( s, data );
104         }
105     }
106
107     TEST_F( IntrusiveStripedBoostUnorderedSet, basehook_resize_bucket_threshold_rt )
108     {
109         typedef ci::StripedSet<
110             bi::unordered_set< base_item
111                 , bi::hash< hash1 >
112                 , bi::equal< equal_to<base_item> >
113                 , bi::power_2_buckets<true>
114                 , bi::incremental<true>
115             >
116             ,ci::opt::hash< hash2 >
117             ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
118             ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
119         > set_type;
120
121         std::vector< typename set_type::value_type > data;
122         {
123             set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ));
124             this->test( s, data );
125         }
126     }
127
128     TEST_F( IntrusiveStripedBoostUnorderedSet, memberhook )
129     {
130         typedef ci::StripedSet<
131             bi::unordered_set< member_item
132                 , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
133                 , bi::hash< hash1 >
134                 , bi::equal< equal_to<member_item> >
135                 , bi::power_2_buckets<true>
136                 , bi::incremental<true>
137             >
138             ,cds::intrusive::opt::hash< hash2 >
139         > set_type;
140
141         std::vector< typename set_type::value_type > data;
142         {
143             set_type s;
144             this->test( s, data );
145         }
146     }
147
148     TEST_F( IntrusiveStripedBoostUnorderedSet, memberhook_resize_bucket_threshold )
149     {
150         typedef ci::StripedSet<
151             bi::unordered_set< member_item
152                 , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
153                 , bi::hash< hash1 >
154                 , bi::equal< equal_to<member_item> >
155                 , bi::power_2_buckets<true>
156                 , bi::incremental<true>
157             >
158             ,cds::intrusive::opt::hash< hash2 >
159             ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::initialized_static_buffer< cds::any_type, 64 > >
160             ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
161         > set_type;
162
163         std::vector< typename set_type::value_type > data;
164         {
165             set_type s;
166             this->test( s, data );
167         }
168     }
169
170     TEST_F( IntrusiveStripedBoostUnorderedSet, memberhook_resize_bucket_threshold_rt )
171     {
172         typedef ci::StripedSet<
173             bi::unordered_set< member_item
174                 , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
175                 , bi::hash< hash1 >
176                 , bi::equal< equal_to<member_item> >
177                 , bi::power_2_buckets<true>
178                 , bi::incremental<true>
179             >
180             ,ci::opt::hash< hash2 >
181             ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
182             ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
183         > set_type;
184
185         std::vector< typename set_type::value_type > data;
186         {
187             set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ));
188             this->test( s, data );
189         }
190     }
191
192     TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_basehook )
193     {
194         typedef ci::StripedSet<
195             bi::unordered_set< base_item
196                 , bi::hash< hash1 >
197                 , bi::equal< equal_to<base_item> >
198                 , bi::power_2_buckets<true>
199                 , bi::incremental<true>
200             >
201             ,cds::intrusive::opt::hash< hash2 >
202             ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
203         > set_type;
204
205         std::vector< typename set_type::value_type > data;
206         {
207             set_type s;
208             this->test( s, data );
209         }
210     }
211
212     TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_basehook_resize_bucket_threshold )
213     {
214         typedef ci::StripedSet<
215             bi::unordered_set< base_item
216                 , bi::hash< hash1 >
217                 , bi::equal< equal_to<base_item> >
218                 , bi::power_2_buckets<true>
219                 , bi::incremental<true>
220             >
221             ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
222             ,cds::intrusive::opt::hash< hash2 >
223             ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::initialized_static_buffer< cds::any_type, 64 > >
224             ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
225         > set_type;
226
227         std::vector< typename set_type::value_type > data;
228         {
229             set_type s;
230             this->test( s, data );
231         }
232     }
233
234     TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_basehook_resize_bucket_threshold_rt )
235     {
236         typedef ci::StripedSet<
237             bi::unordered_set< base_item
238                 , bi::hash< hash1 >
239                 , bi::equal< equal_to<base_item> >
240                 , bi::power_2_buckets<true>
241                 , bi::incremental<true>
242             >
243             ,ci::opt::hash< hash2 >
244             ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
245             ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
246             ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
247         > set_type;
248
249         std::vector< typename set_type::value_type > data;
250         {
251             set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ));
252             this->test( s, data );
253         }
254     }
255
256     TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_memberhook )
257     {
258         typedef ci::StripedSet<
259             bi::unordered_set< member_item
260                 , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
261                 , bi::hash< hash1 >
262                 , bi::equal< equal_to<member_item> >
263                 , bi::power_2_buckets<true>
264                 , bi::incremental<true>
265             >
266             ,cds::intrusive::opt::hash< hash2 >
267             ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
268         > set_type;
269
270         std::vector< typename set_type::value_type > data;
271         {
272             set_type s;
273             this->test( s, data );
274         }
275     }
276
277     TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_memberhook_resize_bucket_threshold )
278     {
279         typedef ci::StripedSet<
280             bi::unordered_set< member_item
281                 , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
282                 , bi::hash< hash1 >
283                 , bi::equal< equal_to<member_item> >
284                 , bi::power_2_buckets<true>
285                 , bi::incremental<true>
286             >
287             ,cds::intrusive::opt::hash< hash2 >
288             ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
289             ,cds::intrusive::opt::buffer< cds::intrusive::opt::v::initialized_static_buffer< cds::any_type, 64 > >
290             ,cds::intrusive::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
291         > set_type;
292
293         std::vector< typename set_type::value_type > data;
294         {
295             set_type s;
296             this->test( s, data );
297         }
298     }
299
300     TEST_F( IntrusiveStripedBoostUnorderedSet, refinable_memberhook_resize_bucket_threshold_rt )
301     {
302         typedef ci::StripedSet<
303             bi::unordered_set< member_item
304                 , bi::member_hook< member_item, bi::unordered_set_member_hook<>, &member_item::hMember>
305                 , bi::hash< hash1 >
306                 , bi::equal< equal_to<member_item> >
307                 , bi::power_2_buckets<true>
308                 , bi::incremental<true>
309             >
310             ,ci::opt::hash< hash2 >
311             ,ci::opt::mutex_policy< ci::striped_set::refinable<> >
312             ,ci::opt::buffer< dyn_buffer<64, cds::any_type>>
313             ,ci::opt::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
314         > set_type;
315
316         std::vector< typename set_type::value_type > data;
317         {
318             set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>( 128 ));
319             this->test( s, data );
320         }
321     }
322
323 } // namespace
324
325 #endif // #ifdef CDSUNIT_ENABLE_BOOST_CONTAINER
326 #endif // CDSUNIT_SET_TEST_INTRUSIVE_BOOST_UNORDERED_SET_H