Add support for Intel C++ compiler for Linux (icc 15)
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_hashset_std.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 && CDS_OS_INTERFACE == CDS_OSI_WINDOWS)) && _MSC_VER < 1600)
9
10 namespace set {
11
12     namespace {
13         struct equal_item
14         {
15             template <typename T>
16             bool operator ()( T const& i1, T const& i2) const
17             {
18                 return i1.key() == i2.key();
19             }
20         };
21
22         typedef std::unordered_set< StripedSetHdrTest::item, StripedSetHdrTest::hash_int, equal_item > set_t;
23
24         struct my_copy_policy {
25             typedef set_t::iterator iterator;
26
27             void operator()( set_t& set, iterator itWhat )
28             {
29                 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
30             }
31         };
32     }
33
34     void StripedSetHdrTest::Refinable_hashset()
35     {
36         CPPUNIT_MESSAGE( "cmp");
37         typedef cc::StripedSet< set_t
38             , co::hash< hash_int >
39             , co::compare< cmp<item> >
40             ,co::mutex_policy< cc::striped_set::refinable<> >
41         >   set_cmp;
42         test_striped< set_cmp >();
43
44         CPPUNIT_MESSAGE( "less");
45         typedef cc::StripedSet< set_t
46             ,co::mutex_policy< cc::striped_set::refinable<> >
47             , co::hash< hash_int >
48             , co::less< less<item> >
49         >   set_less;
50         test_striped< set_less >();
51
52         CPPUNIT_MESSAGE( "cmpmix");
53         typedef cc::StripedSet< set_t
54             ,co::mutex_policy< cc::striped_set::refinable<> >
55             , co::hash< hash_int >
56             , co::compare< cmp<item> >
57             , co::less< less<item> >
58         >   set_cmpmix;
59         test_striped< set_cmpmix >();
60
61         // Spinlock as lock policy
62         CPPUNIT_MESSAGE( "spinlock");
63         typedef cc::StripedSet< set_t
64             ,co::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
65             , co::hash< hash_int >
66             , co::less< less<item> >
67         >   set_spin;
68         test_striped< set_spin >();
69
70         // Resizing policy
71         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
72         {
73             typedef cc::StripedSet< set_t
74                 ,co::mutex_policy< cc::striped_set::refinable<> >
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::mutex_policy< cc::striped_set::refinable<> >
86             , co::hash< hash_int >
87             , co::less< less<item> >
88             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
89         >   set_less_resizing_lf16;
90         test_striped< set_less_resizing_lf16 >();
91
92         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
93         {
94             typedef cc::StripedSet< set_t
95                 ,co::mutex_policy< cc::striped_set::refinable<> >
96                 , co::hash< hash_int >
97                 , co::less< less<item> >
98                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
99             >   set_less_resizing_sbt;
100             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(1024) );
101             test_striped_with(s);
102         }
103
104         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
105         typedef cc::StripedSet< set_t
106             ,co::mutex_policy< cc::striped_set::refinable<> >
107             , co::hash< hash_int >
108             , co::less< less<item> >
109             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
110         >   set_less_resizing_sbt16;
111         test_striped< set_less_resizing_sbt16 >();
112
113         // Copy policy
114         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
115         typedef cc::StripedSet< set_t
116             ,co::mutex_policy< cc::striped_set::refinable<> >
117             , co::hash< hash_int >
118             , co::compare< cmp<item> >
119             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
120             , co::copy_policy< cc::striped_set::copy_item >
121         >   set_copy_item;
122         test_striped< set_copy_item >();
123
124         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
125         typedef cc::StripedSet< set_t
126             ,co::mutex_policy< cc::striped_set::refinable<> >
127             , co::hash< hash_int >
128             , co::compare< cmp<item> >
129             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
130             , co::copy_policy< cc::striped_set::swap_item >
131         >   set_swap_item;
132         test_striped< set_swap_item >();
133
134         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
135         typedef cc::StripedSet< set_t
136             ,co::mutex_policy< cc::striped_set::refinable<> >
137             , co::hash< hash_int >
138             , co::compare< cmp<item> >
139             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
140             , co::copy_policy< cc::striped_set::move_item >
141         >   set_move_item;
142         test_striped< set_move_item >();
143
144         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
145         typedef cc::StripedSet< set_t
146             ,co::mutex_policy< cc::striped_set::refinable<> >
147             , co::hash< hash_int >
148             , co::compare< cmp<item> >
149             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
150             , co::copy_policy< my_copy_policy >
151         >   set_special_copy_item;
152         test_striped< set_special_copy_item >();
153     }
154
155 }   // namespace set
156 #endif // #if !(CDS_COMPILER == CDS_COMPILER_MSVC && CDS_COMPILER_VERSION < 1600)