Renoved MD5 MT-test
[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         // CityHash
73 #if CDS_BUILD_BITS == 64
74         struct traits_FeldmanHashMap_city64 : public cc::feldman_hashmap::traits
75         {
76             typedef ::hashing::city64 hash;
77             typedef ::hashing::city64::less less;
78         };
79         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_hp_city64;
80         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_dhp_city64;
81         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_gpi_city64;
82         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_gpb_city64;
83         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_gpt_city64;
84 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
85         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_shb_city64;
86         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city64 >    FeldmanHashMap_rcu_sht_city64;
87 #endif
88
89         struct traits_FeldmanHashMap_city64_stat : public traits_FeldmanHashMap_city64
90         {
91             typedef cc::feldman_hashmap::stat<> stat;
92         };
93         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_hp_city64_stat;
94         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_dhp_city64_stat;
95         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_gpi_city64_stat;
96         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_gpb_city64_stat;
97         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_gpt_city64_stat;
98 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
99         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_shb_city64_stat;
100         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city64_stat >    FeldmanHashMap_rcu_sht_city64_stat;
101 #endif
102
103         struct traits_FeldmanHashMap_city128 : public cc::feldman_hashmap::traits
104         {
105             typedef ::hashing::city128 hash;
106             typedef ::hashing::city128::less less;
107         };
108         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_hp_city128;
109         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_dhp_city128;
110         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_gpi_city128;
111         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_gpb_city128;
112         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_gpt_city128;
113 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
114         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_shb_city128;
115         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city128 >    FeldmanHashMap_rcu_sht_city128;
116 #endif
117
118         struct traits_FeldmanHashMap_city128_stat : public traits_FeldmanHashMap_city128
119         {
120             typedef cc::feldman_hashmap::stat<> stat;
121         };
122         typedef FeldmanHashMap< cds::gc::HP,  Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_hp_city128_stat;
123         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_dhp_city128_stat;
124         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_gpi_city128_stat;
125         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_gpb_city128_stat;
126         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_gpt_city128_stat;
127 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
128         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_shb_city128_stat;
129         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_city128_stat >    FeldmanHashMap_rcu_sht_city128_stat;
130 #endif
131 #endif // CDS_BUILD_BITS == 64
132
133
134         // for fixed-sized keys - no hash functor required
135         typedef FeldmanHashMap< cds::gc::HP, Key, Value >    FeldmanHashMap_hp_fixed;
136         typedef FeldmanHashMap< cds::gc::DHP, Key, Value >   FeldmanHashMap_dhp_fixed;
137         typedef FeldmanHashMap< rcu_gpi, Key, Value >    FeldmanHashMap_rcu_gpi_fixed;
138         typedef FeldmanHashMap< rcu_gpb, Key, Value >    FeldmanHashMap_rcu_gpb_fixed;
139         typedef FeldmanHashMap< rcu_gpt, Key, Value >    FeldmanHashMap_rcu_gpt_fixed;
140 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
141         typedef FeldmanHashMap< rcu_shb, Key, Value >    FeldmanHashMap_rcu_shb_fixed;
142         typedef FeldmanHashMap< rcu_sht, Key, Value >    FeldmanHashMap_rcu_sht_fixed;
143 #endif
144
145         struct traits_FeldmanHashMap_stat : public cc::feldman_hashmap::traits
146         {
147             typedef cc::feldman_hashmap::stat<> stat;
148         };
149         typedef FeldmanHashMap< cds::gc::HP, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_hp_fixed_stat;
150         typedef FeldmanHashMap< cds::gc::DHP, Key, Value, traits_FeldmanHashMap_stat >   FeldmanHashMap_dhp_fixed_stat;
151         typedef FeldmanHashMap< rcu_gpi, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_gpi_fixed_stat;
152         typedef FeldmanHashMap< rcu_gpb, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_gpb_fixed_stat;
153         typedef FeldmanHashMap< rcu_gpt, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_gpt_fixed_stat;
154 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
155         typedef FeldmanHashMap< rcu_shb, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_shb_fixed_stat;
156         typedef FeldmanHashMap< rcu_sht, Key, Value, traits_FeldmanHashMap_stat >    FeldmanHashMap_rcu_sht_fixed_stat;
157 #endif
158
159     };
160
161     template <typename GC, typename K, typename T, typename Traits >
162     static inline void print_stat( FeldmanHashMap< GC, K, T, Traits > const& m )
163     {
164         CPPUNIT_MSG( m.statistics() );
165
166         std::vector< cds::intrusive::feldman_hashset::level_statistics > level_stat;
167         m.get_level_statistics( level_stat );
168         CPPUNIT_MSG( "Level statistics, height=" << level_stat.size());
169         size_t i = 0;
170         CPPUNIT_MSG( "  i   node_count capacity    data_cell   array_cell   empty_cell" );
171         for (auto it = level_stat.begin(); it != level_stat.end(); ++it, ++i) {
172             CPPUNIT_MSG( std::setw(3)  << i                    << std::setw(0) << " "
173                       << std::setw(12) << it->array_node_count << std::setw(0) << " "
174                       << std::setw(8)  << it->node_capacity    << std::setw(0) << " "
175                       << std::setw(12) << it->data_cell_count  << std::setw(0) << " "
176                       << std::setw(12) << it->array_cell_count << std::setw(0) << " "
177                       << std::setw(12) << it->empty_cell_count << std::setw(0)
178                       );
179         }
180     }
181
182 }   // namespace map2
183
184 #endif // #ifndef CDSUNIT_MAP_TYPE_FELDMAN_HASHMAP_H