Move libcds 1.6.0 from SVN
[libcds.git] / tests / test-hdr / set / hdr_intrusive_striped_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::Striped_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         > set_type;
83
84         test<set_type>();
85     }
86
87     void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook_bucket_threshold()
88     {
89         typedef ci::StripedSet<
90             bi::unordered_set<base_item_type
91                 , bi::hash< hasher >
92                 , bi::equal< is_equal<base_item_type> >
93                 , bi::power_2_buckets<true>
94                 , bi::incremental<true>
95             >
96             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
97             ,co::buffer< co::v::static_buffer< cds::any_type, 64 > >
98             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
99         > set_type;
100
101         test<set_type>();
102     }
103
104     void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook_bucket_threshold_rt()
105     {
106         typedef ci::StripedSet<
107             bi::unordered_set<base_item_type
108                 , bi::hash< hasher >
109                 , bi::equal< is_equal<base_item_type> >
110                 , bi::power_2_buckets<true>
111                 , bi::incremental<true>
112             >
113             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
114             ,co::buffer< dyn_buffer< 256, cds::any_type, std::allocator<int> > >
115             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
116         > set_type;
117
118         set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(512) );
119         test_with( s );
120     }
121
122     void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook()
123     {
124         typedef ci::StripedSet<
125             bi::unordered_set<member_item_type
126                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
127                 , bi::hash< hasher >
128                 , bi::equal< is_equal<member_item_type> >
129                 , bi::power_2_buckets<true>
130                 , bi::incremental<true>
131             >
132             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
133         > set_type;
134
135         test<set_type>();
136     }
137
138     void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook_bucket_threshold()
139     {
140         typedef ci::StripedSet<
141             bi::unordered_set<member_item_type
142                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
143                 , bi::hash< hasher >
144                 , bi::equal< is_equal<member_item_type> >
145                 , bi::power_2_buckets<true>
146                 , bi::incremental<true>
147             >
148             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
149             ,co::buffer< dyn_buffer< 64, cds::any_type, std::allocator<int> > >
150             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
151             ,co::mutex_policy< ci::striped_set::striping<> >
152         > set_type;
153
154         test<set_type>();
155     }
156
157     void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook_bucket_threshold_rt()
158     {
159         typedef ci::StripedSet<
160             bi::unordered_set<member_item_type
161                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
162                 , bi::hash< hasher >
163                 , bi::equal< is_equal<member_item_type> >
164                 , bi::power_2_buckets<true>
165                 , bi::incremental<true>
166             >
167             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
168             ,co::buffer< co::v::static_buffer< cds::any_type, 128 > >
169             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
170         > set_type;
171
172         set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(256) );
173         test_with( s );
174     }
175
176 } // namespace set
177
178