2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
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>
36 namespace bi = boost::intrusive;
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;
42 struct hasher: private IntrusiveStripedSetHdrTest::hash_int
44 typedef IntrusiveStripedSetHdrTest::hash_int base_class;
46 size_t operator()( int i ) const
48 return ~( base_class::operator()(i));
50 template <typename Item>
51 size_t operator()( const Item& i ) const
53 return ~( base_class::operator()(i));
55 size_t operator()( IntrusiveStripedSetHdrTest::find_key const& i) const
57 return ~( base_class::operator()(i));
62 struct is_equal: private IntrusiveStripedSetHdrTest::cmp<T>
64 typedef IntrusiveStripedSetHdrTest::cmp<T> base_class;
66 bool operator ()(const T& v1, const T& v2 ) const
68 return base_class::operator()( v1, v2 ) == 0;
72 bool operator ()(const T& v1, const Q& v2 ) const
74 return base_class::operator()( v1, v2 ) == 0;
78 bool operator ()(const Q& v1, const T& v2 ) const
80 return base_class::operator()( v1, v2 ) == 0;
84 template <size_t Capacity, typename T, class Alloc = CDS_DEFAULT_ALLOCATOR>
85 struct dyn_buffer: public co::v::dynamic_buffer< T, Alloc >
87 typedef co::v::dynamic_buffer< T, Alloc > base_class;
91 typedef dyn_buffer<Capacity, Q, Alloc> other ; ///< Rebinding result type
95 : base_class( Capacity )
100 void IntrusiveStripedSetHdrTest::Refinable_unordered_set_basehook()
102 typedef ci::StripedSet<
103 bi::unordered_set<base_item_type
105 , bi::equal< is_equal<base_item_type> >
106 , bi::power_2_buckets<true>
107 , bi::incremental<true>
109 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
110 ,co::mutex_policy< ci::striped_set::refinable<> >
116 void IntrusiveStripedSetHdrTest::Refinable_unordered_set_basehook_bucket_threshold()
118 typedef ci::StripedSet<
119 bi::unordered_set<base_item_type
121 , bi::equal< is_equal<base_item_type> >
122 , bi::power_2_buckets<true>
123 , bi::incremental<true>
125 ,co::mutex_policy< ci::striped_set::refinable<> >
126 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
127 ,co::buffer< co::v::static_buffer< cds::any_type, 64 > >
128 ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
134 void IntrusiveStripedSetHdrTest::Refinable_unordered_set_basehook_bucket_threshold_rt()
136 typedef ci::StripedSet<
137 bi::unordered_set<base_item_type
139 , bi::equal< is_equal<base_item_type> >
140 , bi::power_2_buckets<true>
141 , bi::incremental<true>
143 ,co::mutex_policy< ci::striped_set::refinable<> >
144 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
145 ,co::buffer< dyn_buffer< 256, cds::any_type, std::allocator<int> > >
146 ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
149 set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(512) );
153 void IntrusiveStripedSetHdrTest::Refinable_unordered_set_memberhook()
155 typedef ci::StripedSet<
156 bi::unordered_set<member_item_type
157 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
159 , bi::equal< is_equal<member_item_type> >
160 , bi::power_2_buckets<true>
161 , bi::incremental<true>
163 ,co::mutex_policy< ci::striped_set::refinable<> >
164 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
170 void IntrusiveStripedSetHdrTest::Refinable_unordered_set_memberhook_bucket_threshold()
172 typedef ci::StripedSet<
173 bi::unordered_set<member_item_type
174 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
176 , bi::equal< is_equal<member_item_type> >
177 , bi::power_2_buckets<true>
178 , bi::incremental<true>
180 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
181 ,co::buffer< dyn_buffer< 64, cds::any_type, std::allocator<int> > >
182 ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<256> >
183 ,co::mutex_policy< ci::striped_set::refinable<> >
189 void IntrusiveStripedSetHdrTest::Refinable_unordered_set_memberhook_bucket_threshold_rt()
191 typedef ci::StripedSet<
192 bi::unordered_set<member_item_type
193 , bi::member_hook< member_item_type, bi::unordered_set_member_hook<>, &member_item_type::hMember>
195 , bi::equal< is_equal<member_item_type> >
196 , bi::power_2_buckets<true>
197 , bi::incremental<true>
199 ,co::mutex_policy< ci::striped_set::refinable<> >
200 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
201 ,co::buffer< co::v::static_buffer< cds::any_type, 128 > >
202 ,co::resizing_policy< ci::striped_set::single_bucket_size_threshold<0> >
205 set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(256) );