3 #ifndef CDSUNIT_MAP_TYPE_CUCKOO_H
4 #define CDSUNIT_MAP_TYPE_CUCKOO_H
6 #include "map2/map_type.h"
7 #include <cds/container/cuckoo_map.h>
8 #include "print_cuckoo_stat.h"
12 template <typename K, typename V, typename Traits>
13 class CuckooMap: public cc::CuckooMap< K, V, Traits >
16 typedef cc::CuckooMap< K, V, Traits > base_class;
19 template <typename Config>
20 CuckooMap( Config const& cfg )
22 cfg.c_nCuckooInitialSize,
23 static_cast<unsigned int>( cfg.c_nCuckooProbesetSize ),
24 static_cast<unsigned int>( cfg.c_nCuckooProbesetThreshold )
28 template <typename Q, typename Pred>
29 bool erase_with( Q const& key, Pred /*pred*/ )
31 return base_class::erase_with( key, typename std::conditional< base_class::c_isSorted, Pred, typename Pred::equal_to>::type() );
35 static CDS_CONSTEXPR bool const c_bExtractSupported = false;
36 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
37 static CDS_CONSTEXPR bool const c_bEraseExactKey = false;
42 template <typename Key, typename Value>
43 struct map_type< tag_CuckooMap, Key, Value >: public map_type_base< Key, Value >
45 typedef map_type_base< Key, Value > base_class;
46 typedef typename base_class::compare compare;
47 typedef typename base_class::less less;
48 typedef typename base_class::equal_to equal_to;
49 typedef typename base_class::key_hash key_hash;
50 typedef typename base_class::hash hash;
51 typedef typename base_class::hash2 hash2;
53 template <typename Traits>
54 struct traits_CuckooStripedMap: public Traits
56 typedef cc::cuckoo::striping<> mutex_policy;
58 template <typename Traits>
59 struct traits_CuckooRefinableMap : public Traits
61 typedef cc::cuckoo::refinable<> mutex_policy;
64 struct traits_CuckooMap_list_unord :
65 public cc::cuckoo::make_traits <
66 cc::cuckoo::probeset_type< cc::cuckoo::list >
67 , co::equal_to< equal_to >
68 , co::hash< std::tuple< hash, hash2 > >
71 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord>> CuckooStripedMap_list_unord;
72 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord>> CuckooRefinableMap_list_unord;
74 struct traits_CuckooMap_list_unord_stat : public traits_CuckooMap_list_unord
76 typedef cc::cuckoo::stat stat;
78 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord_stat>> CuckooStripedMap_list_unord_stat;
79 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord_stat>> CuckooRefinableMap_list_unord_stat;
81 struct traits_CuckooMap_list_unord_storehash : public traits_CuckooMap_list_unord
83 static CDS_CONSTEXPR const bool store_hash = true;
85 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_unord_storehash>> CuckooStripedMap_list_unord_storehash;
86 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_unord_storehash>> CuckooRefinableMap_list_unord_storehash;
88 struct traits_CuckooMap_list_ord :
89 public cc::cuckoo::make_traits <
90 cc::cuckoo::probeset_type< cc::cuckoo::list >
91 , co::compare< compare >
92 , co::hash< std::tuple< hash, hash2 > >
95 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord>> CuckooStripedMap_list_ord;
96 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord>> CuckooRefinableMap_list_ord;
98 struct traits_CuckooMap_list_ord_stat : public traits_CuckooMap_list_ord
100 typedef cc::cuckoo::stat stat;
102 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord_stat>> CuckooStripedMap_list_ord_stat;
103 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord_stat>> CuckooRefinableMap_list_ord_stat;
105 struct traits_CuckooMap_list_ord_storehash : public traits_CuckooMap_list_ord
107 static CDS_CONSTEXPR const bool store_hash = true;
109 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_list_ord_storehash>> CuckooStripedMap_list_ord_storehash;
110 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_list_ord_storehash>> CuckooRefinableMap_list_ord_storehash;
112 struct traits_CuckooMap_vector_unord :
113 public cc::cuckoo::make_traits <
114 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
115 , co::equal_to< equal_to >
116 , co::hash< std::tuple< hash, hash2 > >
119 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord>> CuckooStripedMap_vector_unord;
120 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord>> CuckooRefinableMap_vector_unord;
122 struct traits_CuckooMap_vector_unord_stat : public traits_CuckooMap_vector_unord
124 typedef cc::cuckoo::stat stat;
126 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord_stat>> CuckooStripedMap_vector_unord_stat;
127 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord_stat>> CuckooRefinableMap_vector_unord_stat;
129 struct traits_CuckooMap_vector_unord_storehash : public traits_CuckooMap_vector_unord
131 static CDS_CONSTEXPR const bool store_hash = true;
133 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_unord_storehash>> CuckooStripedMap_vector_unord_storehash;
134 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_unord_storehash>> CuckooRefinableMap_vector_unord_storehash;
136 struct traits_CuckooMap_vector_ord :
137 public cc::cuckoo::make_traits <
138 cc::cuckoo::probeset_type< cc::cuckoo::vector<4> >
139 , co::compare< compare >
140 , co::hash< std::tuple< hash, hash2 > >
143 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord>> CuckooStripedMap_vector_ord;
144 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord>> CuckooRefinableMap_vector_ord;
146 struct traits_CuckooMap_vector_ord_stat : public traits_CuckooMap_vector_ord
148 typedef cc::cuckoo::stat stat;
150 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord_stat>> CuckooStripedMap_vector_ord_stat;
151 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord_stat>> CuckooRefinableMap_vector_ord_stat;
153 struct traits_CuckooMap_vector_ord_storehash : public traits_CuckooMap_vector_ord
155 static CDS_CONSTEXPR const bool store_hash = true;
157 typedef CuckooMap< Key, Value, traits_CuckooStripedMap<traits_CuckooMap_vector_ord_storehash>> CuckooStripedMap_vector_ord_storehash;
158 typedef CuckooMap< Key, Value, traits_CuckooRefinableMap<traits_CuckooMap_vector_ord_storehash>> CuckooRefinableMap_vector_ord_storehash;
162 template <typename K, typename T, typename Traits >
163 static inline void print_stat( cc::CuckooMap< K, T, Traits > const& m )
165 CPPUNIT_MSG( m.statistics() << m.mutex_policy_statistics() );
168 template <typename K, typename V, typename Traits>
169 static inline void print_stat( CuckooMap< K, V, Traits > const& m )
171 typedef CuckooMap< K, V, Traits > map_type;
172 print_stat( static_cast<typename map_type::base_class const&>(m) );
177 #endif // ifndef CDSUNIT_MAP_TYPE_CUCKOO_H