ec1bbc284e190cf5b4f3a44893ed79de5cfb603f
[libcds.git] / tests / unit / map2 / map_type_feldman_hashmap.h
1 //$$CDS-header$$
2
3 #ifndef CDSUNIT_MAP_TYPE_FELDMAN_HASHMAP_H
4 #define CDSUNIT_MAP_TYPE_FELDMAN_HASHMAP_H
5
6 #include "map2/map_type.h"
7
8 #include <cds/container/feldman_hashmap_hp.h>
9 #include <cds/container/feldman_hashmap_dhp.h>
10 #include <cds/container/feldman_hashmap_rcu.h>
11
12 #include "print_feldman_hashset_stat.h"
13 #include "hashing/hash_func.h"
14
15 namespace map2 {
16
17     template <class GC, typename Key, typename T, typename Traits = cc::feldman_hashmap::traits>
18     class FeldmanHashMap : public cc::FeldmanHashMap< GC, Key, T, Traits >
19     {
20         typedef cc::FeldmanHashMap< GC, Key, T, Traits > base_class;
21     public:
22         template <typename Config>
23         FeldmanHashMap( Config const& cfg)
24             : base_class( cfg.c_nFeldmanMap_HeadBits, cfg.c_nFeldmanMap_ArrayBits )
25         {}
26
27         // for testing
28         static CDS_CONSTEXPR bool const c_bExtractSupported = true;
29         static CDS_CONSTEXPR bool const c_bLoadFactorDepended = false;
30         static CDS_CONSTEXPR bool const c_bEraseExactKey = true;
31     };
32
33     struct tag_FeldmanHashMap;
34
35     template <typename Key, typename Value>
36     struct map_type< tag_FeldmanHashMap, Key, Value >: public map_type_base< Key, Value >
37     {
38         typedef map_type_base< Key, Value > base_class;
39         typedef typename base_class::compare    compare;
40         typedef typename base_class::less       less;
41
42         struct traits_FeldmanHashMap_stdhash : public cc::feldman_hashmap::traits
43         {
44             typedef std::hash< Key > hash;
45         };
46
47         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_hp_stdhash;
48         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_dhp_stdhash;
49         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_rcu_gpi_stdhash;
50         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_rcu_gpb_stdhash;
51         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_rcu_gpt_stdhash;
52 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
53         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_rcu_shb_stdhash;
54         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_stdhash >    FeldmanHashMap_rcu_sht_stdhash;
55 #endif
56
57         struct traits_FeldmanHashMap_stdhash_stat: traits_FeldmanHashMap_stdhash
58         {
59             typedef cc::feldman_hashmap::stat<> stat;
60         };
61
62         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_hp_stdhash_stat;
63         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_dhp_stdhash_stat;
64         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_rcu_gpi_stdhash_stat;
65         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_rcu_gpb_stdhash_stat;
66         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_rcu_gpt_stdhash_stat;
67 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
68         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_rcu_shb_stdhash_stat;
69         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_stdhash_stat >    FeldmanHashMap_rcu_sht_stdhash_stat;
70 #endif
71
72         // SHA256
73         struct traits_FeldmanHashMap_sha256 : public cc::feldman_hashmap::traits
74         {
75             typedef ::hashing::sha256 hash;
76         };
77         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_hp_sha256;
78         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_dhp_sha256;
79         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_rcu_gpi_sha256;
80         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_rcu_gpb_sha256;
81         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_rcu_gpt_sha256;
82 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
83         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_rcu_shb_sha256;
84         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_sha256 >    FeldmanHashMap_rcu_sht_sha256;
85 #endif
86
87         struct traits_FeldmanHashMap_sha256_stat : public traits_FeldmanHashMap_sha256
88         {
89             typedef cc::feldman_hashmap::stat<> stat;
90         };
91         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_hp_sha256_stat;
92         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_dhp_sha256_stat;
93         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_rcu_gpi_sha256_stat;
94         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_rcu_gpb_sha256_stat;
95         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_rcu_gpt_sha256_stat;
96 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
97         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_rcu_shb_sha256_stat;
98         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_sha256_stat >    FeldmanHashMap_rcu_sht_sha256_stat;
99 #endif
100
101         //MD5
102         struct traits_FeldmanHashMap_md5 : public cc::feldman_hashmap::traits
103         {
104             typedef ::hashing::md5 hash;
105         };
106         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_hp_md5;
107         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_dhp_md5;
108         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_rcu_gpi_md5;
109         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_rcu_gpb_md5;
110         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_rcu_gpt_md5;
111 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
112         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_rcu_shb_md5;
113         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_md5 >    FeldmanHashMap_rcu_sht_md5;
114 #endif
115
116         struct traits_FeldmanHashMap_md5_stat : public traits_FeldmanHashMap_md5
117         {
118             typedef cc::feldman_hashmap::stat<> stat;
119         };
120         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_hp_md5_stat;
121         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_dhp_md5_stat;
122         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_rcu_gpi_md5_stat;
123         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_rcu_gpb_md5_stat;
124         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_rcu_gpt_md5_stat;
125 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
126         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_rcu_shb_md5_stat;
127         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_md5_stat >    FeldmanHashMap_rcu_sht_md5_stat;
128 #endif
129
130         // CityHash
131 #if CDS_BUILD_BITS == 64
132         struct traits_FeldmanHashMap_city64 : public cc::feldman_hashmap::traits
133         {
134             typedef ::hashing::city64 hash;
135             typedef ::hashing::city64::less less;
136         };
137         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_hp_city64;
138         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_dhp_city64;
139         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_gpi_city64;
140         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_gpb_city64;
141         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_gpt_city64;
142 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
143         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_shb_city64;
144         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_sht_city64;
145 #endif
146
147         struct traits_FeldmanHashMap_city64_stat : public traits_FeldmanHashMap_city64
148         {
149             typedef cc::feldman_hashmap::stat<> stat;
150         };
151         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_hp_city64_stat;
152         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_dhp_city64_stat;
153         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_gpi_city64_stat;
154         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_gpb_city64_stat;
155         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_gpt_city64_stat;
156 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
157         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_shb_city64_stat;
158         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_sht_city64_stat;
159 #endif
160
161         struct traits_FeldmanHashMap_city128 : public cc::feldman_hashmap::traits
162         {
163             typedef ::hashing::city128 hash;
164             typedef ::hashing::city128::less less;
165         };
166         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_hp_city128;
167         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_dhp_city128;
168         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_gpi_city128;
169         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_gpb_city128;
170         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_gpt_city128;
171 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
172         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_shb_city128;
173         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_sht_city128;
174 #endif
175
176         struct traits_FeldmanHashMap_city128_stat : public traits_FeldmanHashMap_city128
177         {
178             typedef cc::feldman_hashmap::stat<> stat;
179         };
180         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_hp_city128_stat;
181         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_dhp_city128_stat;
182         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_gpi_city128_stat;
183         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_gpb_city128_stat;
184         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_gpt_city128_stat;
185 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
186         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_shb_city128_stat;
187         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_sht_city128_stat;
188 #endif
189 #endif // CDS_BUILD_BITS == 64
190
191
192         // for fixed-sized keys - no hash functor required
193         typedef FeldmanHashMap< cds::gc::HP, Key, Value >    FeldmanHashMap_hp_fixed;
194         typedef FeldmanHashMap< cds::gc::DHP, Key, Value >   FeldmanHashMap_dhp_fixed;
195         typedef FeldmanHashMap< rcu_gpi, Key, Value >    FeldmanHashMap_rcu_gpi_fixed;
196         typedef FeldmanHashMap< rcu_gpb, Key, Value >    FeldmanHashMap_rcu_gpb_fixed;
197         typedef FeldmanHashMap< rcu_gpt, Key, Value >    FeldmanHashMap_rcu_gpt_fixed;
198 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
199         typedef FeldmanHashMap< rcu_shb, Key, Value >    FeldmanHashMap_rcu_shb_fixed;
200         typedef FeldmanHashMap< rcu_sht, Key, Value >    FeldmanHashMap_rcu_sht_fixed;
201 #endif
202
203         struct traits_FeldmanHashMap_stat : public cc::feldman_hashmap::traits
204         {
205             typedef cc::feldman_hashmap::stat<> stat;
206         };
207         typedef FeldmanHashMap< cds::gc::HP, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_hp_fixed_stat;
208         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_stat >   FeldmanHashMap_dhp_fixed_stat;
209         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_gpi_fixed_stat;
210         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_gpb_fixed_stat;
211         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_gpt_fixed_stat;
212 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
213         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_shb_fixed_stat;
214         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_sht_fixed_stat;
215 #endif
216
217     };
218
219     template <typename GC, typename K, typename T, typename Traits >
220     static inline void print_stat( FeldmanHashMap< GC, K, T, Traits > const& m )
221     {
222         CPPUNIT_MSG( m.statistics() );
223     }
224
225 }   // namespace map2
226
227 #endif // #ifndef CDSUNIT_MAP_TYPE_FELDMAN_HASHMAP_H