Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_striped_hashset_hashset_vc.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_striped_set.h"
4 #include <cds/container/striped_set/std_hash_set.h>
5 #include <cds/container/striped_set.h>
6 #include <cds/lock/spinlock.h>
7
8 #if (CDS_COMPILER == CDS_COMPILER_MSVC || CDS_COMPILER == CDS_COMPILER_INTEL) && _MSC_VER < 1600
9
10 namespace stdext {
11     inline size_t hash_value(set::StripedSetHdrTest::item const& _Keyval)
12     {
13         return set::StripedSetHdrTest::hash_int()( _Keyval );
14     }
15 }
16
17 namespace set {
18
19     namespace {
20         typedef stdext::hash_compare<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> >    hash_set_t;
21
22         struct my_copy_policy {
23             typedef stdext::hash_set< StripedSetHdrTest::item, hash_set_t > set_type;
24             typedef set_type::iterator iterator;
25
26             void operator()( set_type& set, iterator itWhat )
27             {
28                 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
29             }
30         };
31
32         typedef stdext::hash_set<StripedSetHdrTest::item, hash_set_t > set_t;
33     }
34
35     void StripedSetHdrTest::Striped_hashset()
36     {
37         CPPUNIT_MESSAGE( "cmp");
38         typedef cc::StripedSet< set_t
39             , co::hash< hash_int >
40             , co::compare< cmp<item> >
41             ,co::mutex_policy< cc::striped_set::striping<> >
42         >   set_cmp;
43         test_striped< set_cmp >();
44
45         CPPUNIT_MESSAGE( "less");
46         typedef cc::StripedSet< set_t
47             , co::hash< hash_int >
48             , co::less< less<item> >
49             ,co::mutex_policy< cc::striped_set::striping<> >
50         >   set_less;
51         test_striped< set_less >();
52
53         CPPUNIT_MESSAGE( "cmpmix");
54         typedef cc::StripedSet< set_t
55             , co::hash< hash_int >
56             , co::compare< cmp<item> >
57             , co::less< less<item> >
58             ,co::mutex_policy< cc::striped_set::striping<> >
59         >   set_cmpmix;
60         test_striped< set_cmpmix >();
61
62         // Spinlock as lock policy
63         CPPUNIT_MESSAGE( "spinlock");
64         typedef cc::StripedSet< set_t
65             , co::hash< hash_int >
66             , co::less< less<item> >
67             ,co::mutex_policy< cc::striped_set::striping< cds::lock::Spin > >
68         >   set_spin;
69         test_striped< set_spin >();
70
71         // Resizing policy
72         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
73         {
74             typedef cc::StripedSet< set_t
75                 , co::hash< hash_int >
76                 , co::less< less<item> >
77                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
78             >   set_less_resizing_lf;
79             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>( 1024 ));
80             test_striped_with( s );
81         }
82
83         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
84         typedef cc::StripedSet< set_t
85             , co::hash< hash_int >
86             , co::less< less<item> >
87             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
88         >   set_less_resizing_lf16;
89         test_striped< set_less_resizing_lf16 >();
90
91         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024");
92         {
93             typedef cc::StripedSet< set_t
94                 , co::hash< hash_int >
95                 , co::less< less<item> >
96                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
97             >   set_less_resizing_sbt;
98             set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>(1024));
99             test_striped_with(s);
100         }
101
102         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
103         typedef cc::StripedSet< set_t
104             , co::hash< hash_int >
105             , co::less< less<item> >
106             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
107         >   set_less_resizing_sbt16;
108         test_striped< set_less_resizing_sbt16 >();
109
110         // Copy policy
111         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
112         typedef cc::StripedSet< set_t
113             , co::hash< hash_int >
114             , co::compare< cmp<item> >
115             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
116             , co::copy_policy< cc::striped_set::copy_item >
117         >   set_copy_item;
118         test_striped< set_copy_item >();
119
120         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
121         typedef cc::StripedSet< set_t
122             , co::hash< hash_int >
123             , co::compare< cmp<item> >
124             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
125             , co::copy_policy< cc::striped_set::swap_item >
126         >   set_swap_item;
127         test_striped< set_swap_item >();
128
129         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
130         typedef cc::StripedSet< set_t
131             , co::hash< hash_int >
132             , co::compare< cmp<item> >
133             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
134             , co::copy_policy< cc::striped_set::move_item >
135         >   set_move_item;
136         test_striped< set_move_item >();
137
138         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
139         typedef cc::StripedSet< set_t
140             , co::hash< hash_int >
141             , co::compare< cmp<item> >
142             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
143             , co::copy_policy< my_copy_policy >
144         >   set_special_copy_item;
145         test_striped< set_special_copy_item >();
146     }
147
148 }   // namespace set
149 #endif // #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION < 1600