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