Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_striped_hashset_uset.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8     
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
29 */
30
31 #include "set/hdr_intrusive_striped_set.h"
32 #include <cds/intrusive/striped_set/boost_unordered_set.h>
33 #include <cds/intrusive/striped_set.h>
34
35 namespace set {
36     namespace bi = boost::intrusive;
37
38     namespace {
39         typedef IntrusiveStripedSetHdrTest::base_item< bi::unordered_set_base_hook<> > base_item_type;
40         typedef IntrusiveStripedSetHdrTest::member_item< bi::unordered_set_member_hook<> > member_item_type;
41
42         struct hasher: private IntrusiveStripedSetHdrTest::hash_int
43         {
44             typedef IntrusiveStripedSetHdrTest::hash_int base_class;
45
46             size_t operator()( int i ) const
47             {
48                 return ~( base_class::operator()(i));
49             }
50             template <typename Item>
51             size_t operator()( const Item& i ) const
52             {
53                 return ~( base_class::operator()(i));
54             }
55             size_t operator()( IntrusiveStripedSetHdrTest::find_key const& i) const
56             {
57                 return ~( base_class::operator()(i));
58             }
59         };
60
61         template <typename T>
62         struct is_equal: private IntrusiveStripedSetHdrTest::cmp<T>
63         {
64             typedef IntrusiveStripedSetHdrTest::cmp<T> base_class;
65
66             bool operator ()(const T& v1, const T& v2 ) const
67             {
68                 return base_class::operator()( v1, v2 ) == 0;
69             }
70
71             template <typename Q>
72             bool operator ()(const T& v1, const Q& v2 ) const
73             {
74                 return base_class::operator()( v1, v2 ) == 0;
75             }
76
77             template <typename Q>
78             bool operator ()(const Q& v1, const T& v2 ) const
79             {
80                 return base_class::operator()( v1, v2 ) == 0;
81             }
82         };
83
84         template <size_t Capacity, typename T, class Alloc = CDS_DEFAULT_ALLOCATOR>
85         struct dyn_buffer: public co::v::dynamic_buffer< T, Alloc >
86         {
87             typedef co::v::dynamic_buffer< T, Alloc >   base_class;
88         public:
89             template <typename Q>
90             struct rebind {
91                 typedef dyn_buffer<Capacity, Q, Alloc> other   ;  ///< Rebinding result type
92             };
93
94             dyn_buffer()
95                 : base_class( Capacity )
96             {}
97         };
98     }
99
100     void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook()
101     {
102         typedef ci::StripedSet<
103             bi::unordered_set<base_item_type
104                 , bi::hash< hasher >
105                 , bi::equal< is_equal<base_item_type> >
106                 , bi::power_2_buckets<true>
107                 , bi::incremental<true>
108             >
109             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
110         > set_type;
111
112         test<set_type>();
113     }
114
115     void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook_bucket_threshold()
116     {
117         typedef ci::StripedSet<
118             bi::unordered_set<base_item_type
119                 , bi::hash< hasher >
120                 , bi::equal< is_equal<base_item_type> >
121                 , bi::power_2_buckets<true>
122                 , bi::incremental<true>
123             >
124             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
125             ,co::buffer< co::v::static_buffer< cds::any_type, 64 > >
126             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
127         > set_type;
128
129         test<set_type>();
130     }
131
132     void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook_bucket_threshold_rt()
133     {
134         typedef ci::StripedSet<
135             bi::unordered_set<base_item_type
136                 , bi::hash< hasher >
137                 , bi::equal< is_equal<base_item_type> >
138                 , bi::power_2_buckets<true>
139                 , bi::incremental<true>
140             >
141             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
142             ,co::buffer< dyn_buffer< 256, cds::any_type, std::allocator<int> > >
143             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
144         > set_type;
145
146         set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(512) );
147         test_with( s );
148     }
149
150     void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook()
151     {
152         typedef ci::StripedSet<
153             bi::unordered_set<member_item_type
154                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
155                 , bi::hash< hasher >
156                 , bi::equal< is_equal<member_item_type> >
157                 , bi::power_2_buckets<true>
158                 , bi::incremental<true>
159             >
160             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
161         > set_type;
162
163         test<set_type>();
164     }
165
166     void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook_bucket_threshold()
167     {
168         typedef ci::StripedSet<
169             bi::unordered_set<member_item_type
170                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
171                 , bi::hash< hasher >
172                 , bi::equal< is_equal<member_item_type> >
173                 , bi::power_2_buckets<true>
174                 , bi::incremental<true>
175             >
176             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
177             ,co::buffer< dyn_buffer< 64, cds::any_type, std::allocator<int> > >
178             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
179             ,co::mutex_policy< ci::striped_set::striping<> >
180         > set_type;
181
182         test<set_type>();
183     }
184
185     void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook_bucket_threshold_rt()
186     {
187         typedef ci::StripedSet<
188             bi::unordered_set<member_item_type
189                 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
190                 , bi::hash< hasher >
191                 , bi::equal< is_equal<member_item_type> >
192                 , bi::power_2_buckets<true>
193                 , bi::incremental<true>
194             >
195             ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
196             ,co::buffer< co::v::static_buffer< cds::any_type, 128 > >
197             ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
198         > set_type;
199
200         set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(256) );
201         test_with( s );
202     }
203
204 } // namespace set
205
206