bugfix in cds::gc::HP::guarded_ptr
[libcds.git] / tests / test-hdr / set / hdr_striped_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::Striped_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::striping<> >
31         >   set_cmp;
32         test_striped< set_cmp >();
33
34         CPPUNIT_MESSAGE( "less");
35         typedef cc::StripedSet< set_t
36             , co::hash< hash_int >
37             , co::less< less<item> >
38             ,co::mutex_policy< cc::striped_set::striping<> >
39         >   set_less;
40         test_striped< set_less >();
41
42         CPPUNIT_MESSAGE( "cmpmix");
43         typedef cc::StripedSet< set_t
44             , co::hash< hash_int >
45             , co::compare< cmp<item> >
46             , co::less< less<item> >
47             ,co::mutex_policy< cc::striped_set::striping<> >
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::hash< hash_int >
55             , co::less< less<item> >
56             ,co::mutex_policy< cc::striped_set::striping< cds::lock::Spin > >
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::hash< hash_int >
65                 , co::less< less<item> >
66                 , co::resizing_policy< cc::striped_set::load_factor_resizing<0> >
67             >   set_less_resizing_lf;
68             set_less_resizing_lf s(30, cc::striped_set::load_factor_resizing<0>( 1024 ));
69             test_striped_with( s );
70         }
71
72         CPPUNIT_MESSAGE( "load_factor_resizing<256>");
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<256> >
77         >   set_less_resizing_lf16;
78         test_striped< set_less_resizing_lf16 >();
79
80         CPPUNIT_MESSAGE( "single_bucket_size_threshold<0>(1024");
81         {
82             typedef cc::StripedSet< set_t
83                 , co::hash< hash_int >
84                 , co::less< less<item> >
85                 , co::resizing_policy< cc::striped_set::single_bucket_size_threshold<0> >
86             >   set_less_resizing_sbt;
87             set_less_resizing_sbt s( 30, cc::striped_set::single_bucket_size_threshold<0>(1024));
88             test_striped_with(s);
89         }
90
91         CPPUNIT_MESSAGE( "single_bucket_size_threshold<256>");
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<256> >
96         >   set_less_resizing_sbt16;
97         test_striped< set_less_resizing_sbt16 >();
98
99         // Copy policy
100         CPPUNIT_MESSAGE( "load_factor_resizing<256>, copy_item");
101         typedef cc::StripedSet< set_t
102             , co::hash< hash_int >
103             , co::compare< cmp<item> >
104             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
105             , co::copy_policy< cc::striped_set::copy_item >
106         >   set_copy_item;
107         test_striped< set_copy_item >();
108
109         CPPUNIT_MESSAGE( "load_factor_resizing<256>, swap_item");
110         typedef cc::StripedSet< set_t
111             , co::hash< hash_int >
112             , co::compare< cmp<item> >
113             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
114             , co::copy_policy< cc::striped_set::swap_item >
115         >   set_swap_item;
116         test_striped< set_swap_item >();
117
118         CPPUNIT_MESSAGE( "load_factor_resizing<256>, move_item");
119         typedef cc::StripedSet< set_t
120             , co::hash< hash_int >
121             , co::compare< cmp<item> >
122             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
123             , co::copy_policy< cc::striped_set::move_item >
124         >   set_move_item;
125         test_striped< set_move_item >();
126
127         CPPUNIT_MESSAGE( "load_factor_resizing<256>, special copy_item");
128         typedef cc::StripedSet< set_t
129             , co::hash< hash_int >
130             , co::compare< cmp<item> >
131             , co::resizing_policy< cc::striped_set::load_factor_resizing<256> >
132             , co::copy_policy< my_copy_policy >
133         >   set_special_copy_item;
134         test_striped< set_special_copy_item >();
135     }
136
137 }   // namespace set