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