Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_intrusive_refinable_hashset_uset.cpp
1 //$$CDS-header$$
2
3 #include "set/hdr_intrusive_striped_set.h"
4 #include <cds/intrusive/striped_set/boost_unordered_set.h>
5 #include <cds/intrusive/striped_set.h>
6
7 namespace set {
8     namespace bi = boost::intrusive;
9
10     namespace {
11         typedef IntrusiveStripedSetHdrTest::base_item< bi::unordered_set_base_hook<> > base_item_type;
12         typedef IntrusiveStripedSetHdrTest::member_item< bi::unordered_set_member_hook<> > member_item_type;
13
14         struct hasher: private IntrusiveStripedSetHdrTest::hash_int
15         {
16             typedef IntrusiveStripedSetHdrTest::hash_int base_class;
17
18             size_t operator()( int i ) const
19             {
20                 return ~( base_class::operator()(i));
21             }
22             template <typename Item>
23             size_t operator()( const Item& i ) const
24             {
25                 return ~( base_class::operator()(i));
26             }
27             size_t operator()( IntrusiveStripedSetHdrTest::find_key const& i) const
28             {
29                 return ~( base_class::operator()(i));
30             }
31         };
32
33         template <typename T>
34         struct is_equal: private IntrusiveStripedSetHdrTest::cmp<T>
35         {
36             typedef IntrusiveStripedSetHdrTest::cmp<T> base_class;
37
38             bool operator ()(const T& v1, const T& v2 ) const
39             {
40                 return base_class::operator()( v1, v2 ) == 0;
41             }
42
43             template <typename Q>
44             bool operator ()(const T& v1, const Q& v2 ) const
45             {
46                 return base_class::operator()( v1, v2 ) == 0;
47             }
48
49             template <typename Q>
50             bool operator ()(const Q& v1, const T& v2 ) const
51             {
52                 return base_class::operator()( v1, v2 ) == 0;
53             }
54         };
55
56         template <size_t Capacity, typename T, class Alloc = CDS_DEFAULT_ALLOCATOR>
57         struct dyn_buffer: public co::v::dynamic_buffer< T, Alloc >
58         {
59             typedef co::v::dynamic_buffer< T, Alloc >   base_class;
60         public:
61             template <typename Q>
62             struct rebind {
63                 typedef dyn_buffer<Capacity, Q, Alloc> other   ;  ///< Rebinding result type
64             };
65
66             dyn_buffer()
67                 : base_class( Capacity )
68             {}
69         };
70     }
71
72     void IntrusiveStripedSetHdrTest::Refinable_unordered_set_basehook()
73     {
74         typedef ci::StripedSet<
75             bi::unordered_set<base_item_type
76                 , bi::hash< hasher >
77                 , bi::equal< is_equal<base_item_type> >
78                 , bi::power_2_buckets<true>
79                 , bi::incremental<true>
80             >
81             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
82             ,co::mutex_policy< ci::striped_set::refinable<> >
83         > set_type;
84
85         test<set_type>();
86     }
87
88     void IntrusiveStripedSetHdrTest::Refinable_unordered_set_basehook_bucket_threshold()
89     {
90         typedef ci::StripedSet<
91             bi::unordered_set<base_item_type
92                 , bi::hash< hasher >
93                 , bi::equal< is_equal<base_item_type> >
94                 , bi::power_2_buckets<true>
95                 , bi::incremental<true>
96             >
97             ,co::mutex_policy< ci::striped_set::refinable<> >
98             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
99             ,co::buffer< co::v::static_buffer< cds::any_type, 64 > >
100             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
101         > set_type;
102
103         test<set_type>();
104     }
105
106     void IntrusiveStripedSetHdrTest::Refinable_unordered_set_basehook_bucket_threshold_rt()
107     {
108         typedef ci::StripedSet<
109             bi::unordered_set<base_item_type
110                 , bi::hash< hasher >
111                 , bi::equal< is_equal<base_item_type> >
112                 , bi::power_2_buckets<true>
113                 , bi::incremental<true>
114             >
115             ,co::mutex_policy< ci::striped_set::refinable<> >
116             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
117             ,co::buffer< dyn_buffer< 256, cds::any_type, std::allocator<int> > >
118             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
119         > set_type;
120
121         set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(512) );
122         test_with( s );
123     }
124
125     void IntrusiveStripedSetHdrTest::Refinable_unordered_set_memberhook()
126     {
127         typedef ci::StripedSet<
128             bi::unordered_set<member_item_type
129                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
130                 , bi::hash< hasher >
131                 , bi::equal< is_equal<member_item_type> >
132                 , bi::power_2_buckets<true>
133                 , bi::incremental<true>
134             >
135             ,co::mutex_policy< ci::striped_set::refinable<> >
136             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
137         > set_type;
138
139         test<set_type>();
140     }
141
142     void IntrusiveStripedSetHdrTest::Refinable_unordered_set_memberhook_bucket_threshold()
143     {
144         typedef ci::StripedSet<
145             bi::unordered_set<member_item_type
146                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
147                 , bi::hash< hasher >
148                 , bi::equal< is_equal<member_item_type> >
149                 , bi::power_2_buckets<true>
150                 , bi::incremental<true>
151             >
152             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
153             ,co::buffer< dyn_buffer< 64, cds::any_type, std::allocator<int> > >
154             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
155             ,co::mutex_policy< ci::striped_set::refinable<> >
156         > set_type;
157
158         test<set_type>();
159     }
160
161     void IntrusiveStripedSetHdrTest::Refinable_unordered_set_memberhook_bucket_threshold_rt()
162     {
163         typedef ci::StripedSet<
164             bi::unordered_set<member_item_type
165                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
166                 , bi::hash< hasher >
167                 , bi::equal< is_equal<member_item_type> >
168                 , bi::power_2_buckets<true>
169                 , bi::incremental<true>
170             >
171             ,co::mutex_policy< ci::striped_set::refinable<> >
172             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
173             ,co::buffer< co::v::static_buffer< cds::any_type, 128 > >
174             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
175         > set_type;
176
177         set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(256) );
178         test_with( s );
179     }
180
181 } // namespace set
182
183