902f2d152459031817ebd5e962c2bf04822969e3
[libcds.git] / tests / test-hdr / set / hdr_refinable_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::Refinable_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::refinable<> >
42         >   set_cmp;
43         test_striped< set_cmp >();
44
45         CPPUNIT_MESSAGE( "less");
46         typedef cc::StripedSet< set_t
47             ,co::mutex_policy< cc::striped_set::refinable<> >
48             , co::hash< hash_int >
49             , co::less< less<item> >
50         >   set_less;
51         test_striped< set_less >();
52
53         CPPUNIT_MESSAGE( "cmpmix");
54         typedef cc::StripedSet< set_t
55             ,co::mutex_policy< cc::striped_set::refinable<> >
56             , co::hash< hash_int >
57             , co::compare< cmp<item> >
58             , co::less< less<item> >
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::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
66             , co::hash< hash_int >
67             , co::less< less<item> >
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::mutex_policy< cc::striped_set::refinable<> >
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>(1024));
81             test_striped_with(s);
82         }
83
84         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
85         typedef cc::StripedSet< set_t
86             ,co::mutex_policy< cc::striped_set::refinable<> >
87             , co::hash< hash_int >
88             , co::less< less<item> >
89             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
90         >   set_less_resizing_lf16;
91         test_striped< set_less_resizing_lf16 >();
92
93         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
94         {
95             typedef cc::StripedSet< set_t
96                 ,co::mutex_policy< cc::striped_set::refinable<> >
97                 , co::hash< hash_int >
98                 , co::less< less<item> >
99                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
100             >   set_less_resizing_sbt;
101             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(1024) );
102             test_striped_with(s);
103         }
104
105         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
106         typedef cc::StripedSet< set_t
107             ,co::mutex_policy< cc::striped_set::refinable<> >
108             , co::hash< hash_int >
109             , co::less< less<item> >
110             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
111         >   set_less_resizing_sbt16;
112         test_striped< set_less_resizing_sbt16 >();
113
114         // Copy policy
115         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
116         typedef cc::StripedSet< set_t
117             ,co::mutex_policy< cc::striped_set::refinable<> >
118             , co::hash< hash_int >
119             , co::compare< cmp<item> >
120             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
121             , co::copy_policy< cc::striped_set::copy_item >
122         >   set_copy_item;
123         test_striped< set_copy_item >();
124
125         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
126         typedef cc::StripedSet< set_t
127             ,co::mutex_policy< cc::striped_set::refinable<> >
128             , co::hash< hash_int >
129             , co::compare< cmp<item> >
130             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
131             , co::copy_policy< cc::striped_set::swap_item >
132         >   set_swap_item;
133         test_striped< set_swap_item >();
134
135         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
136         typedef cc::StripedSet< set_t
137             ,co::mutex_policy< cc::striped_set::refinable<> >
138             , co::hash< hash_int >
139             , co::compare< cmp<item> >
140             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
141             , co::copy_policy< cc::striped_set::move_item >
142         >   set_move_item;
143         test_striped< set_move_item >();
144
145         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
146         typedef cc::StripedSet< set_t
147             ,co::mutex_policy< cc::striped_set::refinable<> >
148             , co::hash< hash_int >
149             , co::compare< cmp<item> >
150             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
151             , co::copy_policy< my_copy_policy >
152         >   set_special_copy_item;
153         test_striped< set_special_copy_item >();
154     }
155 }   // namespace set
156 #endif // #if CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION < 1600