Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_boost_unordered_set.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_striped_set.h"
4 #include <cds/container/striped_set/boost_unordered_set.h>
5 #include <cds/container/striped_set.h>
6 #include <cds/lock/spinlock.h>
7
8 namespace set {
9
10     namespace {
11         struct equal_item
12         {
13             template <typename T>
14             bool operator ()( T const& i1, T const& i2) const
15             {
16                 return i1.key() == i2.key();
17             }
18         };
19
20         typedef boost::unordered_set< StripedSetHdrTest::item, StripedSetHdrTest::hash_int, equal_item > set_t;
21
22         struct my_copy_policy {
23             typedef set_t::iterator iterator;
24
25             void operator()( set_t& set, iterator itWhat )
26             {
27                 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
28             }
29         };
30     }
31
32     void StripedSetHdrTest::Refinable_boost_unordered_set()
33     {
34         CPPUNIT_MESSAGE( "cmp");
35         typedef cc::StripedSet< set_t
36             , co::hash< hash_int >
37             , co::compare< cmp<item> >
38             ,co::mutex_policy< cc::striped_set::refinable<> >
39         >   set_cmp;
40         test_striped< set_cmp >();
41
42         CPPUNIT_MESSAGE( "less");
43         typedef cc::StripedSet< set_t
44             ,co::mutex_policy< cc::striped_set::refinable<> >
45             , co::hash< hash_int >
46             , co::less< less<item> >
47         >   set_less;
48         test_striped< set_less >();
49
50         CPPUNIT_MESSAGE( "cmpmix");
51         typedef cc::StripedSet< set_t
52             ,co::mutex_policy< cc::striped_set::refinable<> >
53             , co::hash< hash_int >
54             , co::compare< cmp<item> >
55             , co::less< less<item> >
56         >   set_cmpmix;
57         test_striped< set_cmpmix >();
58
59         // Spinlock as lock policy
60         CPPUNIT_MESSAGE( "spinlock");
61         typedef cc::StripedSet< set_t
62             ,co::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
63             , co::hash< hash_int >
64             , co::less< less<item> >
65         >   set_spin;
66         test_striped< set_spin >();
67
68         // Resizing policy
69         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
70         {
71             typedef cc::StripedSet< set_t
72                 ,co::mutex_policy< cc::striped_set::refinable<> >
73                 , co::hash< hash_int >
74                 , co::less< less<item> >
75                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
76             >   set_less_resizing_lf;
77             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(1024));
78             test_striped_with(s);
79         }
80
81         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
82         typedef cc::StripedSet< set_t
83             ,co::mutex_policy< cc::striped_set::refinable<> >
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::mutex_policy< cc::striped_set::refinable<> >
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::mutex_policy< cc::striped_set::refinable<> >
105             , co::hash< hash_int >
106             , co::less< less<item> >
107             , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<256> >
108         >   set_less_resizing_sbt16;
109         test_striped< set_less_resizing_sbt16 >();
110
111         // Copy policy
112         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
113         typedef cc::StripedSet< set_t
114             ,co::mutex_policy< cc::striped_set::refinable<> >
115             , co::hash< hash_int >
116             , co::compare< cmp<item> >
117             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
118             , co::copy_policy< cc::striped_set::copy_item >
119         >   set_copy_item;
120         test_striped< set_copy_item >();
121
122         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
123         typedef cc::StripedSet< set_t
124             ,co::mutex_policy< cc::striped_set::refinable<> >
125             , co::hash< hash_int >
126             , co::compare< cmp<item> >
127             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
128             , co::copy_policy< cc::striped_set::swap_item >
129         >   set_swap_item;
130         test_striped< set_swap_item >();
131
132         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
133         typedef cc::StripedSet< set_t
134             ,co::mutex_policy< cc::striped_set::refinable<> >
135             , co::hash< hash_int >
136             , co::compare< cmp<item> >
137             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
138             , co::copy_policy< cc::striped_set::move_item >
139         >   set_move_item;
140         test_striped< set_move_item >();
141
142         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
143         typedef cc::StripedSet< set_t
144             ,co::mutex_policy< cc::striped_set::refinable<> >
145             , co::hash< hash_int >
146             , co::compare< cmp<item> >
147             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
148             , co::copy_policy< my_copy_policy >
149         >   set_special_copy_item;
150         test_striped< set_special_copy_item >();
151
152     }
153
154 }   // namespace set