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 #ifndef CDSUNIT_MAP_TYPE_CUCKOO_H
32 #define CDSUNIT_MAP_TYPE_CUCKOO_H
35 #include <cds/container/cuckoo_map.h>
36 #include <cds_test/stat_cuckoo_out.h>
40 template <typename K, typename V, typename Traits>
41 class CuckooMap: public cc::CuckooMap< K, V, Traits >
44 typedef cc::CuckooMap< K, V, Traits > base_class;
47 template <typename Config>
48 CuckooMap( Config const& cfg )
50 cfg.s_nCuckooInitialSize,
51 static_cast<unsigned int>( cfg.s_nCuckooProbesetSize ),
52 static_cast<unsigned int>( cfg.s_nCuckooProbesetThreshold )
56 template <typename Q, typename Pred>
57 bool erase_with( Q const& key, Pred /*pred*/ )
59 return base_class::erase_with( key, typename std::conditional< base_class::c_isSorted, Pred, typename Pred::equal_to>::type() );
63 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
64 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
65 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
70 template <typename Key, typename Value>
71 struct map_type< tag_CuckooMap, Key, Value >: public map_type_base< Key, Value >
73 typedef map_type_base< Key, Value > base_class;
74 typedef typename base_class::key_compare compare;
75 typedef typename base_class::key_less less;
76 typedef typename base_class::equal_to equal_to;
77 typedef typename base_class::key_hash hash;
78 typedef typename base_class::hash2 hash2;
80 template <typename Traits>
81 struct traits_CuckooStripedMap: public Traits
83 typedef cc::cuckoo::striping<> mutex_policy;
85 template <typename Traits>
86 struct traits_CuckooRefinableMap : public Traits
88 typedef cc::cuckoo::refinable<> mutex_policy;
91 struct traits_CuckooMap_list_unord :
92 public cc::cuckoo::make_traits <
93 cc::cuckoo::probeset_type< cc::cuckoo::list >
94 , co::equal_to< equal_to >
95 , co::hash< std::tuple< hash, hash2 > >
98 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord>> CuckooStripedMap_list_unord;
99 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord>> CuckooRefinableMap_list_unord;
101 struct traits_CuckooMap_list_unord_stat : public traits_CuckooMap_list_unord
103 typedef cc::cuckoo::stat stat;
105 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord_stat>> CuckooStripedMap_list_unord_stat;
106 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord_stat>> CuckooRefinableMap_list_unord_stat;
108 struct traits_CuckooMap_list_unord_storehash : public traits_CuckooMap_list_unord
110 static CDS_CONSTEXPR const bool store_hash = true;
112 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord_storehash>> CuckooStripedMap_list_unord_storehash;
113 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord_storehash>> CuckooRefinableMap_list_unord_storehash;
115 struct traits_CuckooMap_list_ord :
116 public cc::cuckoo::make_traits <
117 cc::cuckoo::probeset_type< cc::cuckoo::list >
118 , co::compare< compare >
119 , co::hash< std::tuple< hash, hash2 > >
122 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord>> CuckooStripedMap_list_ord;
123 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord>> CuckooRefinableMap_list_ord;
125 struct traits_CuckooMap_list_ord_stat : public traits_CuckooMap_list_ord
127 typedef cc::cuckoo::stat stat;
129 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord_stat>> CuckooStripedMap_list_ord_stat;
130 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord_stat>> CuckooRefinableMap_list_ord_stat;
132 struct traits_CuckooMap_list_ord_storehash : public traits_CuckooMap_list_ord
134 static CDS_CONSTEXPR const bool store_hash = true;
136 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord_storehash>> CuckooStripedMap_list_ord_storehash;
137 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord_storehash>> CuckooRefinableMap_list_ord_storehash;
139 struct traits_CuckooMap_vector_unord :
140 public cc::cuckoo::make_traits <
141 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
142 , co::equal_to< equal_to >
143 , co::hash< std::tuple< hash, hash2 > >
146 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord>> CuckooStripedMap_vector_unord;
147 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord>> CuckooRefinableMap_vector_unord;
149 struct traits_CuckooMap_vector_unord_stat : public traits_CuckooMap_vector_unord
151 typedef cc::cuckoo::stat stat;
153 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord_stat>> CuckooStripedMap_vector_unord_stat;
154 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord_stat>> CuckooRefinableMap_vector_unord_stat;
156 struct traits_CuckooMap_vector_unord_storehash : public traits_CuckooMap_vector_unord
158 static CDS_CONSTEXPR const bool store_hash = true;
160 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord_storehash>> CuckooStripedMap_vector_unord_storehash;
161 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord_storehash>> CuckooRefinableMap_vector_unord_storehash;
163 struct traits_CuckooMap_vector_ord :
164 public cc::cuckoo::make_traits <
165 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
166 , co::compare< compare >
167 , co::hash< std::tuple< hash, hash2 > >
170 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord>> CuckooStripedMap_vector_ord;
171 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord>> CuckooRefinableMap_vector_ord;
173 struct traits_CuckooMap_vector_ord_stat : public traits_CuckooMap_vector_ord
175 typedef cc::cuckoo::stat stat;
177 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord_stat>> CuckooStripedMap_vector_ord_stat;
178 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord_stat>> CuckooRefinableMap_vector_ord_stat;
180 struct traits_CuckooMap_vector_ord_storehash : public traits_CuckooMap_vector_ord
182 static CDS_CONSTEXPR const bool store_hash = true;
184 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord_storehash>> CuckooStripedMap_vector_ord_storehash;
185 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord_storehash>> CuckooRefinableMap_vector_ord_storehash;
189 template <typename Key, typename T, typename Traits >
190 static inline void print_stat( cds_test::property_stream& o, cc::CuckooMap< Key, T, Traits > const& s )
192 o << s.statistics() << s.mutex_policy_statistics();
195 template <typename Key, typename V, typename Traits>
196 static inline void print_stat( cds_test::property_stream& o, CuckooMap< Key, V, Traits > const& s )
198 typedef CuckooMap< Key, V, Traits > map_type;
199 print_stat( o, static_cast<typename map_type::base_class const&>(s) );
205 #define CDSSTRESS_CuckooMap_case( fixture, test_case, cuckoo_map_type, key_type, value_type ) \
206 TEST_F( fixture, cuckoo_map_type ) \
208 typedef map::map_type< tag_CuckooMap, key_type, value_type >::cuckoo_map_type map_type; \
209 test_case<map_type>(); \
212 #define CDSSTRESS_CuckooMap( fixture, test_case, key_type, value_type ) \
213 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_list_unord, key_type, value_type ) \
214 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_list_unord, key_type, value_type ) \
215 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_list_unord_stat, key_type, value_type ) \
216 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_list_unord_stat, key_type, value_type ) \
217 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_list_unord_storehash, key_type, value_type ) \
218 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_list_unord_storehash, key_type, value_type ) \
219 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_list_ord, key_type, value_type ) \
220 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_list_ord, key_type, value_type ) \
221 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_list_ord_stat, key_type, value_type ) \
222 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_list_ord_stat, key_type, value_type ) \
223 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_list_ord_storehash, key_type, value_type ) \
224 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_list_ord_storehash, key_type, value_type ) \
225 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_vector_unord, key_type, value_type ) \
226 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_vector_unord, key_type, value_type ) \
227 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_vector_unord_stat, key_type, value_type ) \
228 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_vector_unord_stat, key_type, value_type ) \
229 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_vector_unord_storehash, key_type, value_type ) \
230 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_vector_unord_storehash, key_type, value_type ) \
231 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_vector_ord, key_type, value_type ) \
232 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_vector_ord, key_type, value_type ) \
233 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_vector_ord_stat, key_type, value_type ) \
234 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_vector_ord_stat, key_type, value_type ) \
235 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooStripedMap_vector_ord_storehash, key_type, value_type ) \
236 CDSSTRESS_CuckooMap_case( fixture, test_case, CuckooRefinableMap_vector_ord_storehash, key_type, value_type )
238 #endif // ifndef CDSUNIT_MAP_TYPE_CUCKOO_H