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