Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_feldman_hashmap_rcu_sht.cpp
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8     
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.     
29 */
30
31 #include "map/hdr_feldman_hashmap.h"
32 #include <cds/urcu/signal_threaded.h>
33 #include <cds/container/feldman_hashmap_rcu.h>
34 #include "unit/print_feldman_hashset_stat.h"
35
36 namespace map {
37 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
38     namespace {
39         typedef cds::urcu::gc< cds::urcu::signal_threaded<>> rcu_type;
40     } // namespace
41 #endif
42
43     void FeldmanHashMapHdrTest::rcu_sht_nohash()
44     {
45 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
46         typedef cc::FeldmanHashMap< rcu_type, size_t, Item > map_type;
47
48         test_rcu<map_type>(4, 2);
49 #endif
50     }
51
52     void FeldmanHashMapHdrTest::rcu_sht_stdhash()
53     {
54 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
55         struct traits : public cc::feldman_hashmap::traits {
56             typedef std::hash<size_t> hash;
57         };
58         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
59
60         test_rcu<map_type>(4, 2);
61 #endif
62     }
63
64     void FeldmanHashMapHdrTest::rcu_sht_hash128()
65     {
66 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
67         struct traits : public cc::feldman_hashmap::traits {
68             typedef hash128::make hash;
69             typedef hash128::less less;
70         };
71         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
72         test_rcu<map_type>(4, 2);
73
74         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
75             typename cc::feldman_hashmap::make_traits<
76                 co::hash< hash128::make >
77                 , co::less< hash128::less >
78             >::type
79         > map_type2;
80         test_rcu<map_type2>(4, 2);
81 #endif
82     }
83
84     void FeldmanHashMapHdrTest::rcu_sht_nohash_stat()
85     {
86 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
87         struct traits : public cc::feldman_hashmap::traits {
88             typedef cc::feldman_hashmap::stat<> stat;
89         };
90         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
91         test_rcu<map_type>(4, 2);
92
93         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
94             typename cc::feldman_hashmap::make_traits<
95             co::stat< cc::feldman_hashmap::stat<>>
96             >::type
97         > map_type2;
98         test_rcu<map_type2>(4, 2);
99 #endif
100     }
101
102     void FeldmanHashMapHdrTest::rcu_sht_stdhash_stat()
103     {
104 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
105         struct traits : public cc::feldman_hashmap::traits {
106             typedef std::hash<size_t> hash;
107             typedef cc::feldman_hashmap::stat<> stat;
108         };
109         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
110         test_rcu<map_type>(4, 2);
111
112         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
113             typename cc::feldman_hashmap::make_traits<
114                 co::stat< cc::feldman_hashmap::stat<>>
115                 ,co::hash<std::hash<size_t>>
116             >::type
117         > map_type2;
118         test_rcu<map_type2>(4, 2);
119 #endif
120     }
121
122     void FeldmanHashMapHdrTest::rcu_sht_hash128_stat()
123     {
124 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
125         struct traits : public cc::feldman_hashmap::traits {
126             typedef cc::feldman_hashmap::stat<> stat;
127             typedef hash128::make hash;
128             typedef hash128::cmp compare;
129         };
130         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
131         test_rcu<map_type>(4, 2);
132
133         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
134             typename cc::feldman_hashmap::make_traits<
135                 co::stat< cc::feldman_hashmap::stat<>>
136                 , co::hash< hash128::make >
137                 , co::compare< hash128::cmp >
138             >::type
139         > map_type2;
140         test_rcu<map_type2>(4, 2);
141 #endif
142     }
143
144     void FeldmanHashMapHdrTest::rcu_sht_nohash_5_3()
145     {
146 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
147         typedef cc::FeldmanHashMap< rcu_type, size_t, Item > map_type;
148
149         test_rcu<map_type>(5, 3);
150 #endif
151     }
152
153     void FeldmanHashMapHdrTest::rcu_sht_stdhash_5_3()
154     {
155 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
156         struct traits : public cc::feldman_hashmap::traits {
157             typedef std::hash<size_t> hash;
158         };
159         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
160
161         test_rcu<map_type>(5, 3);
162 #endif
163     }
164
165     void FeldmanHashMapHdrTest::rcu_sht_nohash_5_3_stat()
166     {
167 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
168         struct traits : public cc::feldman_hashmap::traits {
169             typedef cc::feldman_hashmap::stat<> stat;
170             typedef cds::backoff::empty back_off;
171         };
172         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
173         test_rcu<map_type>(5, 3);
174
175         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
176             typename cc::feldman_hashmap::make_traits<
177             co::stat< cc::feldman_hashmap::stat<>>
178             , co::back_off< cds::backoff::empty >
179             >::type
180         > map_type2;
181         test_rcu<map_type2>(5, 3);
182 #endif
183     }
184
185     void FeldmanHashMapHdrTest::rcu_sht_stdhash_5_3_stat()
186     {
187 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
188         struct traits : public cc::feldman_hashmap::traits {
189             typedef cc::feldman_hashmap::stat<> stat;
190             typedef cds::backoff::empty back_off;
191             typedef std::hash<size_t> hash;
192         };
193         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
194         test_rcu<map_type>(5, 3);
195
196         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
197             typename cc::feldman_hashmap::make_traits<
198                 co::stat< cc::feldman_hashmap::stat<>>
199                 ,co::back_off< cds::backoff::empty >
200                 ,co::hash< std::hash<size_t>>
201             >::type
202         > map_type2;
203         test_rcu<map_type2>(5, 3);
204 #endif
205     }
206
207     void FeldmanHashMapHdrTest::rcu_sht_hash128_4_3()
208     {
209 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
210         struct traits : public cc::feldman_hashmap::traits {
211             typedef hash128::make hash;
212             typedef hash128::less less;
213         };
214         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
215         test_rcu<map_type>(4, 3);
216
217         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
218             typename cc::feldman_hashmap::make_traits<
219                 co::hash< hash128::make >
220                 , co::less< hash128::less >
221             >::type
222         > map_type2;
223         test_rcu<map_type2>(4, 3);
224 #endif
225     }
226
227     void FeldmanHashMapHdrTest::rcu_sht_hash128_4_3_stat()
228     {
229 #ifdef CDS_URCU_SIGNAL_HANDLING_ENABLED
230         struct traits : public cc::feldman_hashmap::traits {
231             typedef hash128::make hash;
232             typedef hash128::less less;
233             typedef cc::feldman_hashmap::stat<> stat;
234             typedef co::v::sequential_consistent memory_model;
235         };
236         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
237         test_rcu<map_type>(4, 3);
238
239         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
240             typename cc::feldman_hashmap::make_traits<
241                 co::hash< hash128::make >
242                 , co::less< hash128::less >
243                 , co::stat< cc::feldman_hashmap::stat<>>
244                 , co::memory_model< co::v::sequential_consistent >
245             >::type
246         > map_type2;
247         test_rcu<map_type2>(4, 3);
248 #endif
249     }
250
251 } // namespace map