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