77b5d4578d63d7cc260da20fa2232b560859ab6c
[libcds.git] / tests / test-hdr / set / hdr_striped_hashset_boost_flat_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::Striped_boost_flat_set()
38     {
39         CPPUNIT_MESSAGE("Skipped; for Microsoft Visual C++ 2013 and boost::container::flat_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_flat_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::flat_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::Striped_boost_flat_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::striping<> >
71         >   set_cmp;
72         test_striped< set_cmp >();
73
74         CPPUNIT_MESSAGE( "less");
75         typedef cc::StripedSet< set_t
76             , co::hash< hash_int >
77             , co::less< less<item> >
78         >   set_less;
79         test_striped< set_less >();
80
81         CPPUNIT_MESSAGE( "cmpmix");
82         typedef cc::StripedSet< set_t
83             , co::hash< hash_int >
84             , co::compare< cmp<item> >
85             , co::less< less<item> >
86         >   set_cmpmix;
87         test_striped< set_cmpmix >();
88
89         // Spinlock as lock policy
90         CPPUNIT_MESSAGE( "spinlock");
91         typedef cc::StripedSet< set_t
92             , co::hash< hash_int >
93             , co::less< less<item> >
94             ,co::mutex_policy< cc::striped_set::striping< cds::sync::spin> >
95         >   set_spin;
96         test_striped< set_spin >();
97
98         // Resizing policy
99         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
100         {
101             typedef cc::StripedSet< set_t
102                 , co::hash< hash_int >
103                 , co::less< less<item> >
104                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
105             >   set_less_resizing_lf;
106
107             set_less_resizing_lf s( 30, cc::striped_set::load_factor_resizing<0>( 1024 ) );
108             test_striped_with( s );
109         }
110
111         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
112         typedef cc::StripedSet< set_t
113             , co::hash< hash_int >
114             , co::less< less<item> >
115             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
116         >   set_less_resizing_lf16;
117         test_striped< set_less_resizing_lf16 >();
118
119         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
120         {
121             typedef cc::StripedSet< set_t
122                 , co::hash< hash_int >
123                 , co::less< less<item> >
124                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
125             >   set_less_resizing_sbt;
126
127             set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>( 1024 ) );
128             test_striped_with( s );
129         }
130
131         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
132         typedef cc::StripedSet< set_t
133             , co::hash< hash_int >
134             , co::less< less<item> >
135             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
136         >   set_less_resizing_sbt16;
137         test_striped< set_less_resizing_sbt16 >();
138
139         // Copy policy
140         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
141         typedef cc::StripedSet< set_t
142             , co::hash< hash_int >
143             , co::compare< cmp<item> >
144             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
145             , co::copy_policy< cc::striped_set::copy_item >
146         >   set_copy_item;
147         test_striped< set_copy_item >();
148
149         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
150         typedef cc::StripedSet< set_t
151             , co::hash< hash_int >
152             , co::compare< cmp<item> >
153             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
154             , co::copy_policy< cc::striped_set::swap_item >
155         >   set_swap_item;
156         test_striped< set_swap_item >();
157
158         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
159         typedef cc::StripedSet< set_t
160             , co::hash< hash_int >
161             , co::compare< cmp<item> >
162             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
163             , co::copy_policy< cc::striped_set::move_item >
164         >   set_move_item;
165         test_striped< set_move_item >();
166
167         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_policy");
168         typedef cc::StripedSet< set_t
169             , co::hash< hash_int >
170             , co::compare< cmp<item> >
171             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
172             , co::copy_policy< my_copy_policy >
173         >   set_special_copy_item;
174         test_striped< set_special_copy_item >();
175
176     }
177
178 }   // namespace set
179
180 /*
181 #else
182     namespace set {
183         void StripedSetHdrTest::Striped_boost_flat_set()
184         {
185             CPPUNIT_MESSAGE( "Skipped; boost::container::flat_set is not compatible with MS VC++ 11" );
186         }
187     }
188 #endif
189 */
190
191 #else // BOOST_VERSION < 104800
192
193 namespace set {
194     void StripedSetHdrTest::Striped_boost_flat_set()
195     {
196         CPPUNIT_MESSAGE( "Skipped; for boost::container::flat_set you should use boost version 1.48 or above" );
197     }
198 }
199 #endif  // BOOST_VERSION