Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_boost_vector.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_striped_set.h"
4
5 #include <boost/version.hpp>
6 #include <cds/details/defs.h>
7 #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION == CDS_COMPILER_MSVC12 && BOOST_VERSION <= 105500
8 namespace set {
9     void StripedSetHdrTest::Refinable_boost_vector()
10     {
11         CPPUNIT_MESSAGE("Skipped; for Microsoft Visual C++ 2013 and boost::container::vector you should use boost version 1.56 or above");
12     }
13 }
14
15 #elif BOOST_VERSION >= 104800
16
17 #include <cds/details/defs.h>
18
19 #include <cds/container/striped_set/boost_vector.h>
20 #include <cds/container/striped_set.h>
21 #include <cds/lock/spinlock.h>
22
23 namespace set {
24
25     namespace {
26         struct my_copy_policy {
27             typedef boost::container::vector<StripedSetHdrTest::item> vector_type;
28             typedef vector_type::iterator iterator;
29
30             void operator()( vector_type& vec, iterator itInsert, iterator itWhat )
31             {
32                 vec.insert( itInsert, std::make_pair(itWhat->key(), itWhat->val()) );
33             }
34         };
35
36         typedef boost::container::vector<StripedSetHdrTest::item>  sequence_t;
37     }
38
39     void StripedSetHdrTest::Refinable_boost_vector()
40     {
41         CPPUNIT_MESSAGE( "cmp");
42         typedef cc::StripedSet< sequence_t
43             ,co::mutex_policy< cc::striped_set::refinable<> >
44             , co::hash< hash_int >
45             , co::compare< cmp<item> >
46         >   set_cmp;
47         test_striped2< set_cmp >();
48
49         CPPUNIT_MESSAGE( "less");
50         typedef cc::StripedSet< sequence_t
51             ,co::mutex_policy< cc::striped_set::refinable<> >
52             , co::hash< hash_int >
53             , co::less< less<item> >
54         >   set_less;
55         test_striped2< set_less >();
56
57         CPPUNIT_MESSAGE( "cmpmix");
58         typedef cc::StripedSet< sequence_t
59             ,co::mutex_policy< cc::striped_set::refinable<> >
60             , co::hash< hash_int >
61             , co::compare< cmp<item> >
62             , co::less< less<item> >
63         >   set_cmpmix;
64         test_striped2< set_cmpmix >();
65
66         // Spinlock as lock policy
67         CPPUNIT_MESSAGE( "spinlock");
68         typedef cc::StripedSet< sequence_t
69             ,co::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
70             , co::hash< hash_int >
71             , co::less< less<item> >
72         >   set_spin;
73         test_striped2< set_spin >();
74
75         // Resizing policy
76         CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
77         {
78             typedef cc::StripedSet< sequence_t
79                 ,co::mutex_policy< cc::striped_set::refinable<> >
80                 , co::hash< hash_int >
81                 , co::less< less<item> >
82                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
83             >   set_less_resizing_lf;
84             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(8));
85             test_striped_with(s);
86         }
87
88         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
89         typedef cc::StripedSet< sequence_t
90             ,co::mutex_policy< cc::striped_set::refinable<> >
91             , co::hash< hash_int >
92             , co::less< less<item> >
93             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
94         >   set_less_resizing_lf16;
95         test_striped2< set_less_resizing_lf16 >();
96
97         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
98         {
99             typedef cc::StripedSet< sequence_t
100                 ,co::mutex_policy< cc::striped_set::refinable<> >
101                 , co::hash< hash_int >
102                 , co::less< less<item> >
103                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
104             >   set_less_resizing_sbt;
105             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(8));
106             test_striped_with(s);
107         }
108
109         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
110         typedef cc::StripedSet< sequence_t
111             ,co::mutex_policy< cc::striped_set::refinable<> >
112             , co::hash< hash_int >
113             , co::less< less<item> >
114             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
115         >   set_less_resizing_sbt16;
116         test_striped2< set_less_resizing_sbt16 >();
117
118
119         // Copy policy
120         CPPUNIT_MESSAGE( "copy_item");
121         typedef cc::StripedSet< sequence_t
122             ,co::mutex_policy< cc::striped_set::refinable<> >
123             , co::hash< hash_int >
124             , co::compare< cmp<item> >
125             , co::copy_policy< cc::striped_set::copy_item >
126         >   set_copy_item;
127         test_striped2< set_copy_item >();
128
129         CPPUNIT_MESSAGE( "swap_item");
130         typedef cc::StripedSet< sequence_t
131             ,co::mutex_policy< cc::striped_set::refinable<> >
132             , co::hash< hash_int >
133             , co::compare< cmp<item> >
134             , co::copy_policy< cc::striped_set::swap_item >
135         >   set_swap_item;
136         test_striped2< set_swap_item >();
137
138         CPPUNIT_MESSAGE( "move_item");
139         typedef cc::StripedSet< sequence_t
140             ,co::mutex_policy< cc::striped_set::refinable<> >
141             , co::hash< hash_int >
142             , co::compare< cmp<item> >
143             , co::copy_policy< cc::striped_set::move_item >
144         >   set_move_item;
145         test_striped2< set_move_item >();
146
147         CPPUNIT_MESSAGE( "special copy policy");
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< my_copy_policy >
153         >   set_special_copy_item;
154         test_striped2< set_special_copy_item >();
155     }
156
157 }   // namespace set
158
159 #else // BOOST_VERSION < 104800
160
161 namespace set {
162     void StripedSetHdrTest::Refinable_boost_vector()
163     {
164         CPPUNIT_MESSAGE( "Skipped; for boost::container::vector you should use boost version 1.48 or above" );
165     }
166 }
167 #endif  // BOOST_VERSION