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::Striped_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 >
115 void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook_bucket_threshold()
117 typedef ci::StripedSet<
118 bi::unordered_set<base_item_type
120 , bi::equal< is_equal<base_item_type> >
121 , bi::power_2_buckets<true>
122 , bi::incremental<true>
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> >
132 void IntrusiveStripedSetHdrTest::Striped_unordered_set_basehook_bucket_threshold_rt()
134 typedef ci::StripedSet<
135 bi::unordered_set<base_item_type
137 , bi::equal< is_equal<base_item_type> >
138 , bi::power_2_buckets<true>
139 , bi::incremental<true>
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> >
146 set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(512) );
150 void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook()
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>
156 , bi::equal< is_equal<member_item_type> >
157 , bi::power_2_buckets<true>
158 , bi::incremental<true>
160 ,co::hash< IntrusiveStripedSetHdrTest::hash_int >
166 void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook_bucket_threshold()
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>
172 , bi::equal< is_equal<member_item_type> >
173 , bi::power_2_buckets<true>
174 , bi::incremental<true>
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<> >
185 void IntrusiveStripedSetHdrTest::Striped_unordered_set_memberhook_bucket_threshold_rt()
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>
191 , bi::equal< is_equal<member_item_type> >
192 , bi::power_2_buckets<true>
193 , bi::incremental<true>
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> >
200 set_type s( 64, ci::striped_set::single_bucket_size_threshold<0>(256) );