Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_refinable_hashset_list.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_striped_set.h"
4 #include <cds/container/striped_set/std_list.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::list<StripedSetHdrTest::item> list_type;
13             typedef list_type::iterator iterator;
14
15             void operator()( list_type& list, iterator itInsert, iterator itWhat )
16             {
17                 list.insert( itInsert, std::make_pair(itWhat->key(), itWhat->val()) );
18             }
19         };
20
21         typedef std::list<StripedSetHdrTest::item> sequence_t;
22     }
23
24     void StripedSetHdrTest::Refinable_list()
25     {
26         CPPUNIT_MESSAGE( "cmp");
27         typedef cc::StripedSet< sequence_t
28             ,co::mutex_policy< cc::striped_set::refinable<> >
29             , co::hash< hash_int >
30             , co::compare< cmp<item> >
31         >   set_cmp;
32         test_striped2< set_cmp >();
33
34         CPPUNIT_MESSAGE( "less");
35         typedef cc::StripedSet< sequence_t
36             ,co::mutex_policy< cc::striped_set::refinable<> >
37             , co::hash< hash_int >
38             , co::less< less<item> >
39         >   set_less;
40         test_striped2< set_less >();
41
42         CPPUNIT_MESSAGE( "cmpmix");
43         typedef cc::StripedSet< sequence_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_striped2< set_cmpmix >();
50
51         // Spinlock as lock policy
52         CPPUNIT_MESSAGE( "spinlock");
53         typedef cc::StripedSet< sequence_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_striped2< set_spin >();
59
60         // Resizing policy
61         CPPUNIT_MESSAGE( "load_factor_resizing<0>(8)");
62         {
63             typedef cc::StripedSet< sequence_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>(8));
70             test_striped_with(s);
71         }
72
73         CPPUNIT_MESSAGE( "load_factor_resizing<4>");
74         typedef cc::StripedSet< sequence_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<4> >
79         >   set_less_resizing_lf16;
80         test_striped2< set_less_resizing_lf16 >();
81
82         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(8)");
83         {
84             typedef cc::StripedSet< sequence_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>(8));
91             test_striped_with(s);
92         }
93
94         CPPUNIT_MESSAGE( "single_bucket_size_threshold<6>");
95         typedef cc::StripedSet< sequence_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<6> >
100         >   set_less_resizing_sbt16;
101         test_striped2< set_less_resizing_sbt16 >();
102
103
104         // Copy policy
105         CPPUNIT_MESSAGE( "copy_item");
106         typedef cc::StripedSet< sequence_t
107             ,co::mutex_policy< cc::striped_set::refinable<> >
108             , co::hash< hash_int >
109             , co::compare< cmp<item> >
110             , co::copy_policy< cc::striped_set::copy_item >
111         >   set_copy_item;
112         test_striped2< set_copy_item >();
113
114         CPPUNIT_MESSAGE( "swap_item");
115         typedef cc::StripedSet< sequence_t
116             ,co::mutex_policy< cc::striped_set::refinable<> >
117             , co::hash< hash_int >
118             , co::compare< cmp<item> >
119             , co::copy_policy< cc::striped_set::swap_item >
120         >   set_swap_item;
121         test_striped2< set_swap_item >();
122
123         CPPUNIT_MESSAGE( "move_item");
124         typedef cc::StripedSet< sequence_t
125             ,co::mutex_policy< cc::striped_set::refinable<> >
126             , co::hash< hash_int >
127             , co::compare< cmp<item> >
128             , co::copy_policy< cc::striped_set::move_item >
129         >   set_move_item;
130         test_striped2< set_move_item >();
131
132         CPPUNIT_MESSAGE( "special copy policy");
133         typedef cc::StripedSet< sequence_t
134             ,co::mutex_policy< cc::striped_set::refinable<> >
135             , co::hash< hash_int >
136             , co::compare< cmp<item> >
137             , co::copy_policy< my_copy_policy >
138         >   set_special_copy_item;
139         test_striped2< set_special_copy_item >();
140     }
141
142 }   // namespace set