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_SET_TYPE_CUCKOO_H
32 #define CDSUNIT_SET_TYPE_CUCKOO_H
34 #include "set2/set_type.h"
36 #include <cds/container/cuckoo_set.h>
37 #include "print_cuckoo_stat.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 )
52 cfg.c_nCuckooInitialSize,
53 static_cast<unsigned int>( cfg.c_nCuckooProbesetSize ),
54 static_cast<unsigned int>( cfg.c_nCuckooProbesetThreshold )
58 template <typename Q, typename Pred>
59 bool erase_with( Q const& key, Pred /*pred*/ )
61 return cuckoo_base_class::erase_with( key, typename std::conditional< cuckoo_base_class::c_isSorted, Pred, typename Pred::equal_to>::type() );
65 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
66 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
67 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
72 template <typename Key, typename Val>
73 struct set_type< tag_CuckooSet, Key, Val >: public set_type_base< Key, Val >
75 typedef set_type_base< Key, Val > base_class;
76 typedef typename base_class::key_val key_val;
77 typedef typename base_class::compare compare;
78 typedef typename base_class::equal_to equal_to;
79 typedef typename base_class::less less;
80 typedef typename base_class::hash hash;
81 typedef typename base_class::hash2 hash2;
83 // ***************************************************************************
86 template <typename Traits>
87 struct traits_CuckooStripedSet : public Traits
89 typedef cc::cuckoo::striping<> mutex_policy;
91 template <typename Traits>
92 struct traits_CuckooRefinableSet : public Traits
94 typedef cc::cuckoo::refinable<> mutex_policy;
97 struct traits_CuckooSet_list_unord :
98 public cc::cuckoo::make_traits <
99 cc::cuckoo::probeset_type< cc::cuckoo::list >
100 , co::equal_to< equal_to >
101 , co::hash< std::tuple< hash, hash2 > >
104 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_unord>> CuckooStripedSet_list_unord;
105 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_unord>> CuckooRefinableSet_list_unord;
107 struct traits_CuckooSet_list_unord_stat : public traits_CuckooSet_list_unord
109 typedef cc::cuckoo::stat stat;
111 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_unord_stat>> CuckooStripedSet_list_unord_stat;
112 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_unord_stat>> CuckooRefinableSet_list_unord_stat;
114 struct traits_CuckooSet_list_unord_storehash : public traits_CuckooSet_list_unord
116 static CDS_CONSTEXPR const bool store_hash = true;
118 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_unord_storehash>> CuckooStripedSet_list_unord_storehash;
119 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_unord_storehash>> CuckooRefinableSet_list_unord_storehash;
121 struct traits_CuckooSet_list_ord :
122 public cc::cuckoo::make_traits <
123 cc::cuckoo::probeset_type< cc::cuckoo::list >
124 , co::compare< compare >
125 , co::hash< std::tuple< hash, hash2 > >
128 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_ord>> CuckooStripedSet_list_ord;
129 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_ord>> CuckooRefinableSet_list_ord;
131 struct traits_CuckooSet_list_ord_stat : public traits_CuckooSet_list_ord
133 typedef cc::cuckoo::stat stat;
135 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_ord_stat>> CuckooStripedSet_list_ord_stat;
136 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_ord_stat>> CuckooRefinableSet_list_ord_stat;
138 struct traits_CuckooSet_list_ord_storehash : public traits_CuckooSet_list_ord
140 static CDS_CONSTEXPR const bool store_hash = true;
142 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_list_ord_storehash>> CuckooStripedSet_list_ord_storehash;
143 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_list_ord_storehash>> CuckooRefinableSet_list_ord_storehash;
146 struct traits_CuckooSet_vector_unord :
147 public cc::cuckoo::make_traits <
148 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
149 , co::equal_to< equal_to >
150 , co::hash< std::tuple< hash, hash2 > >
153 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_unord>> CuckooStripedSet_vector_unord;
154 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_unord>> CuckooRefinableSet_vector_unord;
156 struct traits_CuckooSet_vector_unord_stat : public traits_CuckooSet_vector_unord
158 typedef cc::cuckoo::stat stat;
160 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_unord_stat>> CuckooStripedSet_vector_unord_stat;
161 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_unord_stat>> CuckooRefinableSet_vector_unord_stat;
163 struct traits_CuckooSet_vector_unord_storehash : public traits_CuckooSet_vector_unord
165 static CDS_CONSTEXPR const bool store_hash = true;
167 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_unord_storehash>> CuckooStripedSet_vector_unord_storehash;
168 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_unord_storehash>> CuckooRefinableSet_vector_unord_storehash;
170 struct traits_CuckooSet_vector_ord :
171 public cc::cuckoo::make_traits <
172 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
173 , co::compare< compare >
174 , co::hash< std::tuple< hash, hash2 > >
177 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_ord>> CuckooStripedSet_vector_ord;
178 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_ord>> CuckooRefinableSet_vector_ord;
180 struct traits_CuckooSet_vector_ord_stat : public traits_CuckooSet_vector_ord
182 typedef cc::cuckoo::stat stat;
184 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_ord_stat>> CuckooStripedSet_vector_ord_stat;
185 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_ord_stat>> CuckooRefinableSet_vector_ord_stat;
187 struct traits_CuckooSet_vector_ord_storehash : public traits_CuckooSet_vector_ord
189 static CDS_CONSTEXPR const bool store_hash = true;
191 typedef CuckooSet< key_val, traits_CuckooStripedSet<traits_CuckooSet_vector_ord_storehash>> CuckooStripedSet_vector_ord_storehash;
192 typedef CuckooSet< key_val, traits_CuckooRefinableSet<traits_CuckooSet_vector_ord_storehash>> CuckooRefinableSet_vector_ord_storehash;
196 template <typename T, typename Traits >
197 static inline void print_stat( cc::CuckooSet< T, Traits > const& s )
199 CPPUNIT_MSG( s.statistics() << s.mutex_policy_statistics() );
202 template <typename V, typename Traits>
203 static inline void print_stat( CuckooSet< V, Traits > const& s )
205 typedef CuckooSet< V, Traits > set_type;
206 print_stat( static_cast<typename set_type::cuckoo_base_class const&>(s) );
211 #endif // #ifndef CDSUNIT_SET_TYPE_CUCKOO_H