Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_set.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_striped_set.h"
4 #include <cds/container/striped_set/std_set.h>
5 #include <cds/container/striped_set.h>
6 #include <cds/lock/spinlock.h>
7
8 namespace set {
9
10     namespace {
11         struct my_copy_policy {
12             typedef std::set<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_type;
13             typedef set_type::iterator iterator;
14
15             void operator()( set_type& set, iterator itWhat )
16             {
17                 set.insert( std::make_pair(itWhat->key(), itWhat->val()) );
18             }
19         };
20
21         typedef std::set<StripedSetHdrTest::item, StripedSetHdrTest::less<StripedSetHdrTest::item> > set_t;
22     }
23
24     void StripedSetHdrTest::Refinable_set()
25     {
26         CPPUNIT_MESSAGE( "cmp");
27         typedef cc::StripedSet< set_t
28             , co::hash< hash_int >
29             , co::compare< cmp<item> >
30             ,co::mutex_policy< cc::striped_set::refinable<> >
31         >   set_cmp;
32         test_striped< set_cmp >();
33
34         CPPUNIT_MESSAGE( "less");
35         typedef cc::StripedSet< set_t
36             ,co::mutex_policy< cc::striped_set::refinable<> >
37             , co::hash< hash_int >
38             , co::less< less<item> >
39         >   set_less;
40         test_striped< set_less >();
41
42         CPPUNIT_MESSAGE( "cmpmix");
43         typedef cc::StripedSet< set_t
44             ,co::mutex_policy< cc::striped_set::refinable<> >
45             , co::hash< hash_int >
46             , co::compare< cmp<item> >
47             , co::less< less<item> >
48         >   set_cmpmix;
49         test_striped< set_cmpmix >();
50
51         // Spinlock as lock policy
52         CPPUNIT_MESSAGE( "spinlock");
53         typedef cc::StripedSet< set_t
54             ,co::mutex_policy< cc::striped_set::refinable<cds::lock::ReentrantSpin> >
55             , co::hash< hash_int >
56             , co::less< less<item> >
57         >   set_spin;
58         test_striped< set_spin >();
59
60         // Resizing policy
61         CPPUNIT_MESSAGE( "load_factor_resizing<0>(1024)");
62         {
63             typedef cc::StripedSet< set_t
64                 ,co::mutex_policy< cc::striped_set::refinable<> >
65                 , co::hash< hash_int >
66                 , co::less< less<item> >
67                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
68             >   set_less_resizing_lf;
69             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>(1024));
70             test_striped_with(s);
71         }
72
73         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
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<256> >
79         >   set_less_resizing_lf16;
80         test_striped< set_less_resizing_lf16 >();
81
82         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024)");
83         {
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::single_bucket_size_threshold<0> >
89             >   set_less_resizing_sbt;
90             set_less_resizing_sbt s(30, cc::striped_set::single_bucket_size_threshold<0>(1024) );
91             test_striped_with(s);
92         }
93
94         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
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<256> >
100         >   set_less_resizing_sbt16;
101         test_striped< set_less_resizing_sbt16 >();
102
103         // Copy policy
104         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
105         typedef cc::StripedSet< set_t
106             ,co::mutex_policy< cc::striped_set::refinable<> >
107             , co::hash< hash_int >
108             , co::compare< cmp<item> >
109             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
110             , co::copy_policy< cc::striped_set::copy_item >
111         >   set_copy_item;
112         test_striped< set_copy_item >();
113
114         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_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::swap_item >
121         >   set_swap_item;
122         test_striped< set_swap_item >();
123
124         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_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::move_item >
131         >   set_move_item;
132         test_striped< set_move_item >();
133
134         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_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< my_copy_policy >
141         >   set_special_copy_item;
142         test_striped< set_special_copy_item >();
143     }
144 }   // namespace set