2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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 #ifndef CDSUNIT_SET_TYPE_CUCKOO_H
32 #define CDSUNIT_SET_TYPE_CUCKOO_H
34 #include "set/set_type.h"
36 #include <cds/container/cuckoo_set.h>
37 #include <cds_test/stat_cuckoo_out.h>
41 template <typename V, typename Traits>
42 class CuckooSet : public cc::CuckooSet< V, Traits >
45 typedef cc::CuckooSet< V, Traits > cuckoo_base_class;
48 template <typename Config>
49 CuckooSet( Config const& cfg )
51 cfg.s_nCuckooInitialSize,
52 static_cast<unsigned int>( cfg.s_nCuckooProbesetSize ),
53 static_cast<unsigned int>( cfg.s_nCuckooProbesetThreshold )
57 template <typename Q, typename Pred>
58 bool erase_with( Q const& key, Pred /*pred*/ )
60 return cuckoo_base_class::erase_with( key, typename std::conditional< cuckoo_base_class::c_isSorted, Pred, typename Pred::equal_to>::type());
64 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
65 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
66 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
71 template <typename Key, typename Val>
72 struct set_type< tag_CuckooSet, Key, Val >: public set_type_base< Key, Val >
74 typedef set_type_base< Key, Val > base_class;
75 typedef typename base_class::key_val key_val;
76 typedef typename base_class::compare compare;
77 typedef typename base_class::equal_to equal_to;
78 typedef typename base_class::less less;
79 typedef typename base_class::hash hash;
80 typedef typename base_class::hash2 hash2;
82 // ***************************************************************************
85 template <typename Traits>
86 struct traits_CuckooStripedSet : public Traits
88 typedef cc::cuckoo::striping<> mutex_policy;
90 template <typename Traits>
91 struct traits_CuckooRefinableSet : public Traits
93 typedef cc::cuckoo::refinable<> mutex_policy;
96 struct traits_CuckooSet_list_unord :
97 public cc::cuckoo::make_traits <
98 cc::cuckoo::probeset_type< cc::cuckoo::list >
99 , co::equal_to< equal_to >
100 , co::hash< std::tuple< hash, hash2 > >
103 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_unord>> CuckooStripedSet_list_unord;
104 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_unord>> CuckooRefinableSet_list_unord;
106 struct traits_CuckooSet_list_unord_stat : public traits_CuckooSet_list_unord
108 typedef cc::cuckoo::stat stat;
110 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_unord_stat>> CuckooStripedSet_list_unord_stat;
111 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_unord_stat>> CuckooRefinableSet_list_unord_stat;
113 struct traits_CuckooSet_list_unord_storehash : public traits_CuckooSet_list_unord
115 static CDS_CONSTEXPR const bool store_hash = true;
117 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_unord_storehash>> CuckooStripedSet_list_unord_storehash;
118 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_unord_storehash>> CuckooRefinableSet_list_unord_storehash;
120 struct traits_CuckooSet_list_ord :
121 public cc::cuckoo::make_traits <
122 cc::cuckoo::probeset_type< cc::cuckoo::list >
123 , co::compare< compare >
124 , co::hash< std::tuple< hash, hash2 > >
127 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_ord>> CuckooStripedSet_list_ord;
128 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_ord>> CuckooRefinableSet_list_ord;
130 struct traits_CuckooSet_list_ord_stat : public traits_CuckooSet_list_ord
132 typedef cc::cuckoo::stat stat;
134 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_ord_stat>> CuckooStripedSet_list_ord_stat;
135 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_ord_stat>> CuckooRefinableSet_list_ord_stat;
137 struct traits_CuckooSet_list_ord_storehash : public traits_CuckooSet_list_ord
139 static CDS_CONSTEXPR const bool store_hash = true;
141 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_ord_storehash>> CuckooStripedSet_list_ord_storehash;
142 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_ord_storehash>> CuckooRefinableSet_list_ord_storehash;
145 struct traits_CuckooSet_vector_unord :
146 public cc::cuckoo::make_traits <
147 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
148 , co::equal_to< equal_to >
149 , co::hash< std::tuple< hash, hash2 > >
152 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_unord>> CuckooStripedSet_vector_unord;
153 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_unord>> CuckooRefinableSet_vector_unord;
155 struct traits_CuckooSet_vector_unord_stat : public traits_CuckooSet_vector_unord
157 typedef cc::cuckoo::stat stat;
159 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_unord_stat>> CuckooStripedSet_vector_unord_stat;
160 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_unord_stat>> CuckooRefinableSet_vector_unord_stat;
162 struct traits_CuckooSet_vector_unord_storehash : public traits_CuckooSet_vector_unord
164 static CDS_CONSTEXPR const bool store_hash = true;
166 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_unord_storehash>> CuckooStripedSet_vector_unord_storehash;
167 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_unord_storehash>> CuckooRefinableSet_vector_unord_storehash;
169 struct traits_CuckooSet_vector_ord :
170 public cc::cuckoo::make_traits <
171 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
172 , co::compare< compare >
173 , co::hash< std::tuple< hash, hash2 > >
176 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_ord>> CuckooStripedSet_vector_ord;
177 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_ord>> CuckooRefinableSet_vector_ord;
179 struct traits_CuckooSet_vector_ord_stat : public traits_CuckooSet_vector_ord
181 typedef cc::cuckoo::stat stat;
183 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_ord_stat>> CuckooStripedSet_vector_ord_stat;
184 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_ord_stat>> CuckooRefinableSet_vector_ord_stat;
186 struct traits_CuckooSet_vector_ord_storehash : public traits_CuckooSet_vector_ord
188 static CDS_CONSTEXPR const bool store_hash = true;
190 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_ord_storehash>> CuckooStripedSet_vector_ord_storehash;
191 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_ord_storehash>> CuckooRefinableSet_vector_ord_storehash;
195 template <typename T, typename Traits >
196 static inline void print_stat( cds_test::property_stream& o, cc::CuckooSet< T, Traits > const& s )
198 o << s.statistics() << s.mutex_policy_statistics();
201 template <typename V, typename Traits>
202 static inline void print_stat( cds_test::property_stream& o, CuckooSet< V, Traits > const& s )
204 typedef CuckooSet< V, Traits > set_type;
205 print_stat( o, static_cast<typename set_type::cuckoo_base_class const&>(s));
210 #define CDSSTRESS_CuckooSet_case( fixture, test_case, cuckoo_set_type, key_type, value_type ) \
211 TEST_F( fixture, cuckoo_set_type ) \
213 typedef set::set_type< tag_CuckooSet, key_type, value_type >::cuckoo_set_type set_type; \
214 test_case<set_type>(); \
217 #define CDSSTRESS_CuckooSet( fixture, test_case, key_type, value_type ) \
218 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_list_unord, key_type, value_type ) \
219 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_list_unord, key_type, value_type ) \
220 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_list_unord_stat, key_type, value_type ) \
221 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_list_unord_stat, key_type, value_type ) \
222 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_list_unord_storehash, key_type, value_type ) \
223 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_list_unord_storehash, key_type, value_type ) \
224 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_list_ord, key_type, value_type ) \
225 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_list_ord, key_type, value_type ) \
226 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_list_ord_stat, key_type, value_type ) \
227 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_list_ord_stat, key_type, value_type ) \
228 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_list_ord_storehash, key_type, value_type ) \
229 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_list_ord_storehash, key_type, value_type ) \
230 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_vector_unord, key_type, value_type ) \
231 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_vector_unord, key_type, value_type ) \
232 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_vector_unord_stat, key_type, value_type ) \
233 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_vector_unord_stat, key_type, value_type ) \
234 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_vector_unord_storehash, key_type, value_type ) \
235 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_vector_unord_storehash, key_type, value_type ) \
236 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_vector_ord, key_type, value_type ) \
237 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_vector_ord, key_type, value_type ) \
238 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_vector_ord_stat, key_type, value_type ) \
239 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_vector_ord_stat, key_type, value_type ) \
240 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooStripedSet_vector_ord_storehash, key_type, value_type ) \
241 CDSSTRESS_CuckooSet_case( fixture, test_case, CuckooRefinableSet_vector_ord_storehash, key_type, value_type ) \
244 #endif // #ifndef CDSUNIT_SET_TYPE_CUCKOO_H