Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_boost_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-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_striped_set.h"
32
33 #include <boost/version.hpp>
34 #include <cds/details/defs.h>
35 #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION <= 105500
36 namespace set {
37     void StripedSetHdrTest::Refinable_boost_set()
38     {
39         CPPUNIT_MESSAGE("Skipped; for Microsoft Visual C++ 2013 and boost::container::set you should use boost version 1.56 or above");
40     }
41 }
42
43 #elif BOOST_VERSION >= 104800
44
45 #include <cds/container/striped_set/boost_set.h>
46 #include <cds/container/striped_set.h>
47 #include <cds/sync/spinlock.h>
48
49 namespace set {
50
51     namespace {
52         typedef boost::container::set< StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_t;
53
54         struct my_copy_policy {
55             typedef set_t::iterator iterator;
56
57             void operator()( set_t& set, iterator itWhat )
58             {
59                 set.insert( *itWhat );
60             }
61         };
62     }
63
64     void StripedSetHdrTest::Refinable_boost_set()
65     {
66         CPPUNIT_MESSAGE( "cmp");
67         typedef cc::StripedSet< set_t
68             , co::hash< hash_int >
69             , co::compare< cmp<item> >
70             ,co::mutex_policy< cc::striped_set::refinable<> >
71         >   set_cmp;
72         test_striped< set_cmp >();
73
74         CPPUNIT_MESSAGE( "less");
75         typedef cc::StripedSet< set_t
76             ,co::mutex_policy< cc::striped_set::refinable<> >
77             , co::hash< hash_int >
78             , co::less< less<item> >
79         >   set_less;
80         test_striped< set_less >();
81
82         CPPUNIT_MESSAGE( "cmpmix");
83         typedef cc::StripedSet< set_t
84             ,co::mutex_policy< cc::striped_set::refinable<> >
85             , co::hash< hash_int >
86             , co::compare< cmp<item> >
87             , co::less< less<item> >
88         >   set_cmpmix;
89         test_striped< set_cmpmix >();
90
91         // Spinlock as lock policy
92         CPPUNIT_MESSAGE( "spinlock");
93         typedef cc::StripedSet< set_t
94             , co::mutex_policy< cc::striped_set::refinable<cds::sync::reentrant_spin> >
95             , co::hash< hash_int >
96             , co::less< less<item> >
97         >   set_spin;
98         test_striped< set_spin >();
99
100         // Resizing policy
101         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
102         {
103             typedef cc::StripedSet< set_t
104                 ,co::mutex_policy< cc::striped_set::refinable<> >
105                 , co::hash< hash_int >
106                 , co::less< less<item> >
107                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
108             >   set_less_resizing_lf;
109             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(1024));
110             test_striped_with(s);
111         }
112
113         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
114         typedef cc::StripedSet< set_t
115             ,co::mutex_policy< cc::striped_set::refinable<> >
116             , co::hash< hash_int >
117             , co::less< less<item> >
118             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
119         >   set_less_resizing_lf16;
120         test_striped< set_less_resizing_lf16 >();
121
122         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
123         {
124             typedef cc::StripedSet< set_t
125                 ,co::mutex_policy< cc::striped_set::refinable<> >
126                 , co::hash< hash_int >
127                 , co::less< less<item> >
128                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
129             >   set_less_resizing_sbt;
130             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(1024) );
131             test_striped_with(s);
132         }
133
134         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
135         typedef cc::StripedSet< set_t
136             ,co::mutex_policy< cc::striped_set::refinable<> >
137             , co::hash< hash_int >
138             , co::less< less<item> >
139             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
140         >   set_less_resizing_sbt16;
141         test_striped< set_less_resizing_sbt16 >();
142
143         // Copy policy
144         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
145         typedef cc::StripedSet< set_t
146             ,co::mutex_policy< cc::striped_set::refinable<> >
147             , co::hash< hash_int >
148             , co::compare< cmp<item> >
149             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
150             , co::copy_policy< cc::striped_set::copy_item >
151         >   set_copy_item;
152         test_striped< set_copy_item >();
153
154         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
155         typedef cc::StripedSet< set_t
156             ,co::mutex_policy< cc::striped_set::refinable<> >
157             , co::hash< hash_int >
158             , co::compare< cmp<item> >
159             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
160             , co::copy_policy< cc::striped_set::swap_item >
161         >   set_swap_item;
162         test_striped< set_swap_item >();
163
164         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
165         typedef cc::StripedSet< set_t
166             ,co::mutex_policy< cc::striped_set::refinable<> >
167             , co::hash< hash_int >
168             , co::compare< cmp<item> >
169             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
170             , co::copy_policy< cc::striped_set::move_item >
171         >   set_move_item;
172         test_striped< set_move_item >();
173
174         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
175         typedef cc::StripedSet< set_t
176             ,co::mutex_policy< cc::striped_set::refinable<> >
177             , co::hash< hash_int >
178             , co::compare< cmp<item> >
179             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
180             , co::copy_policy< my_copy_policy >
181         >   set_special_copy_item;
182         test_striped< set_special_copy_item >();
183     }
184
185 }   // namespace set
186
187 #else // BOOST_VERSION < 104800
188
189 namespace set {
190     void StripedSetHdrTest::Refinable_boost_set()
191     {
192         CPPUNIT_MESSAGE( "Skipped; for boost::container::set you should use boost version 1.48 or above" );
193     }
194 }
195 #endif  // BOOST_VERSION