Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_striped_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::Striped_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::Striped_slist()
37     {
38         CPPUNIT_MESSAGE( "cmp");
39         typedef cc::StripedSet< sequence_t
40             , co::hash< hash_int >
41             , co::compare< cmp<item> >
42             ,co::mutex_policy< cc::striped_set::striping<> >
43         >   set_cmp;
44         test_striped2< set_cmp >();
45
46         CPPUNIT_MESSAGE( "less");
47         typedef cc::StripedSet< sequence_t
48             , co::hash< hash_int >
49             ,co::mutex_policy< cc::striped_set::striping<> >
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::hash< hash_int >
57             , co::compare< cmp<item> >
58             ,co::mutex_policy< cc::striped_set::striping<> >
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::hash< hash_int >
67             , co::less< less<item> >
68             ,co::mutex_policy< cc::striped_set::striping< cds::lock::Spin > >
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::hash< hash_int >
77                 , co::less< less<item> >
78                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
79             >   set_less_resizing_lf;
80             set_less_resizing_lf s( 30, cc::striped_set::load_factor_resizing<0>(8));
81             test_striped_with(s);
82         }
83
84         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
85         typedef cc::StripedSet< sequence_t
86             , co::hash< hash_int >
87             , co::less< less<item> >
88             , co::resizing_policy< cc::striped_set::load_factor_resizing<4> >
89         >   set_less_resizing_lf16;
90         test_striped2< set_less_resizing_lf16 >();
91
92         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
93         {
94             typedef cc::StripedSet< sequence_t
95                 , co::hash< hash_int >
96                 , co::less< less<item> >
97                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
98             >   set_less_resizing_sbt;
99             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(8) );
100             test_striped_with(s);
101         }
102
103         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
104         typedef cc::StripedSet< sequence_t
105             , co::hash< hash_int >
106             , co::less< less<item> >
107             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<6> >
108         >   set_less_resizing_sbt6;
109         test_striped2< set_less_resizing_sbt6 >();
110
111         // Copy policy
112         CPPUNIT_MESSAGE( "copy_item");
113         typedef cc::StripedSet< sequence_t
114             , co::hash< hash_int >
115             , co::compare< cmp<item> >
116             , co::copy_policy< cc::striped_set::copy_item >
117         >   set_copy_item;
118         test_striped2< set_copy_item >();
119
120         CPPUNIT_MESSAGE( "swap_item");
121         typedef cc::StripedSet< sequence_t
122             , co::hash< hash_int >
123             , co::compare< cmp<item> >
124             , co::copy_policy< cc::striped_set::swap_item >
125         >   set_swap_item;
126         test_striped2< set_swap_item >();
127
128         CPPUNIT_MESSAGE( "move_item");
129         typedef cc::StripedSet< sequence_t
130             , co::hash< hash_int >
131             , co::compare< cmp<item> >
132             , co::copy_policy< cc::striped_set::move_item >
133         >   set_move_item;
134         test_striped2< set_move_item >();
135
136         CPPUNIT_MESSAGE( "special copy_item");
137         typedef cc::StripedSet< sequence_t
138             , co::hash< hash_int >
139             , co::compare< cmp<item> >
140             , co::copy_policy< my_copy_policy >
141         >   set_special_copy_item;
142         test_striped2< set_special_copy_item >();
143     }
144
145 }   // namespace set
146
147
148 #else
149
150 namespace set {
151     void StripedSetHdrTest::Striped_slist()
152     {
153         CPPUNIT_MESSAGE("Skipped; for boost::container::slist you should use boost version 1.48 or above");
154     }
155 } // namespace set
156
157 #endif // BOOST_VERSION
158