3 #ifndef CDSUNIT_SET_TYPE_MICHAEL_H
4 #define CDSUNIT_SET_TYPE_MICHAEL_H
6 #include <cds/container/multilevel_hashset_hp.h>
7 #include <cds/container/multilevel_hashset_dhp.h>
9 #include "print_multilevel_hashset_stat.h"
10 #include "hashing/hash_func.h"
14 template <class GC, typename T, typename Traits = cc::multilevel_hashset::traits>
15 class MultiLevelHashSet : public cc::MultiLevelHashSet< GC, T, Traits >
17 typedef cc::MultiLevelHashSet< GC, T, Traits > base_class;
19 typedef typename T::hasher hasher ;
20 typedef typename base_class::guarded_ptr guarded_ptr;
22 template <class Config>
23 MultiLevelHashSet( Config const& cfg )
24 : base_class( cfg.c_nMultiLevelSet_HeadBits, cfg.c_nMultiLevelSet_ArrayBits )
28 bool erase( Q const& key )
30 return base_class::erase( hasher()( key ));
33 template <typename Q, typename Func>
34 bool erase( Q const& key, Func f )
36 return base_class::erase( hasher()( key ), f );
40 guarded_ptr extract(Q const& key)
42 return base_class::extract( hasher()(key) );
46 bool contains( Q const& key )
48 return base_class::contains( hasher()(key) );
52 static CDS_CONSTEXPR bool const c_bExtractSupported = true;
53 static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
56 struct tag_MultiLevelHashSet;
58 template <typename Key, typename Val>
59 struct set_type< tag_MultiLevelHashSet, Key, Val >: public set_type_base< Key, Val >
61 typedef set_type_base< Key, Val > base_class;
62 typedef typename base_class::compare compare;
63 typedef typename base_class::less less;
64 typedef typename base_class::hash hash;
65 typedef typename base_class::key_type key_type;
66 typedef typename base_class::value_type value_type;
68 template <typename Hasher>
71 typedef Hasher hasher;
72 typedef typename hasher::hash_type type;
75 template <typename TH>
76 struct hash_type<std::hash<TH>>
78 typedef std::hash<TH> hasher;
82 template <typename Hasher>
83 struct key_val: base_class::key_val
85 typedef typename base_class::key_val base;
86 typedef Hasher hasher;
87 typedef typename hash_type<hasher>::type hash_type;
91 /*explicit*/ key_val( key_type const& k ): base(k), hash( hasher()( k )) {}
92 key_val( key_type const& k, value_type const& v ): base(k, v), hash( hasher()( k )) {}
95 /*explicit*/ key_val( K const& k ): base(k), hash( hasher()( k )) {}
97 template <typename K, typename T>
98 key_val( K const& k, T const& v ): base(k, v), hash( hasher()( k )) {}
101 struct default_traits : public cc::multilevel_hashset::traits
103 struct hash_accessor {
104 template <typename Hasher>
105 typename key_val<Hasher>::hash_type const& operator()( key_val<Hasher> const& kv )
112 typedef MultiLevelHashSet< cds::gc::HP, key_val<std::hash<key_type>>, default_traits > MultiLevelHashSet_hp_stdhash;
113 typedef MultiLevelHashSet< cds::gc::DHP, key_val<std::hash<key_type>>, default_traits > MultiLevelHashSet_dhp_stdhash;
115 struct traits_MultiLevelHashSet_stat: public cc::multilevel_hashset::make_traits<
116 co::type_traits< default_traits >,
117 co::stat< cc::multilevel_hashset::stat<>>
121 typedef MultiLevelHashSet< cds::gc::HP, key_val<std::hash<key_type>>, traits_MultiLevelHashSet_stat > MultiLevelHashSet_hp_stdhash_stat;
122 typedef MultiLevelHashSet< cds::gc::DHP, key_val<std::hash<key_type>>, traits_MultiLevelHashSet_stat > MultiLevelHashSet_dhp_stdhash_stat;
125 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::sha256>, default_traits > MultiLevelHashSet_hp_sha256;
126 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::sha256>, default_traits > MultiLevelHashSet_dhp_sha256;
128 struct traits_MultiLevelHashSet_sha256_stat : public default_traits
130 typedef cc::multilevel_hashset::stat<> stat;
132 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::sha256>, traits_MultiLevelHashSet_sha256_stat > MultiLevelHashSet_hp_sha256_stat;
133 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::sha256>, traits_MultiLevelHashSet_sha256_stat > MultiLevelHashSet_dhp_sha256_stat;
136 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::md5>, default_traits > MultiLevelHashSet_hp_md5;
137 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::md5>, default_traits > MultiLevelHashSet_dhp_md5;
139 struct traits_MultiLevelHashSet_md5_stat : public default_traits
141 typedef cc::multilevel_hashset::stat<> stat;
143 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::md5>, traits_MultiLevelHashSet_md5_stat > MultiLevelHashSet_hp_md5_stat;
144 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::md5>, traits_MultiLevelHashSet_md5_stat > MultiLevelHashSet_dhp_md5_stat;
147 struct traits_MultiLevelHashSet_city64 : public default_traits
149 typedef ::hashing::city64::less less;
151 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::city64>, traits_MultiLevelHashSet_city64 > MultiLevelHashSet_hp_city64;
152 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::city64>, traits_MultiLevelHashSet_city64 > MultiLevelHashSet_dhp_city64;
154 struct traits_MultiLevelHashSet_city64_stat : public traits_MultiLevelHashSet_city64
156 typedef cc::multilevel_hashset::stat<> stat;
158 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::city64>, traits_MultiLevelHashSet_city64_stat > MultiLevelHashSet_hp_city64_stat;
159 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::city64>, traits_MultiLevelHashSet_city64_stat > MultiLevelHashSet_dhp_city64_stat;
161 struct traits_MultiLevelHashSet_city128 : public default_traits
163 typedef ::hashing::city128::less less;
165 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::city128>, traits_MultiLevelHashSet_city128 > MultiLevelHashSet_hp_city128;
166 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::city128>, traits_MultiLevelHashSet_city128 > MultiLevelHashSet_dhp_city128;
168 struct traits_MultiLevelHashSet_city128_stat : public traits_MultiLevelHashSet_city128
170 typedef cc::multilevel_hashset::stat<> stat;
172 typedef MultiLevelHashSet< cds::gc::HP, key_val<::hashing::city128>, traits_MultiLevelHashSet_city128_stat > MultiLevelHashSet_hp_city128_stat;
173 typedef MultiLevelHashSet< cds::gc::DHP, key_val<::hashing::city128>, traits_MultiLevelHashSet_city128_stat > MultiLevelHashSet_dhp_city128_stat;
176 template <typename GC, typename T, typename Traits >
177 static inline void print_stat( cc::MultiLevelHashSet< GC, T, Traits > const& s )
179 CPPUNIT_MSG( s.statistics() );
184 #endif // #ifndef CDSUNIT_SET_TYPE_MICHAEL_H