Added copyright and license
[libcds.git] / tests / test-hdr / map / hdr_feldman_hashmap_rcu_gpi.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/general_instant.h>
33 #include <cds/container/feldman_hashmap_rcu.h>
34 #include "unit/print_feldman_hashset_stat.h"
35
36 namespace map {
37     namespace {
38         typedef cds::urcu::gc< cds::urcu::general_instant<>> rcu_type;
39     } // namespace
40
41     void FeldmanHashMapHdrTest::rcu_gpi_nohash()
42     {
43         typedef cc::FeldmanHashMap< rcu_type, size_t, Item > map_type;
44
45         test_rcu<map_type>(4, 2);
46     }
47
48     void FeldmanHashMapHdrTest::rcu_gpi_stdhash()
49     {
50         struct traits : public cc::feldman_hashmap::traits {
51             typedef std::hash<size_t> hash;
52         };
53         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
54
55         test_rcu<map_type>(4, 2);
56     }
57
58     void FeldmanHashMapHdrTest::rcu_gpi_hash128()
59     {
60         struct traits : public cc::feldman_hashmap::traits {
61             typedef hash128::make hash;
62             typedef hash128::less less;
63         };
64         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
65         test_rcu<map_type>(4, 2);
66
67         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
68             typename cc::feldman_hashmap::make_traits<
69                 co::hash< hash128::make >
70                 , co::less< hash128::less >
71             >::type
72         > map_type2;
73         test_rcu<map_type2>(4, 2);
74     }
75
76     void FeldmanHashMapHdrTest::rcu_gpi_nohash_stat()
77     {
78         struct traits : public cc::feldman_hashmap::traits {
79             typedef cc::feldman_hashmap::stat<> stat;
80         };
81         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
82         test_rcu<map_type>(4, 2);
83
84         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
85             typename cc::feldman_hashmap::make_traits<
86             co::stat< cc::feldman_hashmap::stat<>>
87             >::type
88         > map_type2;
89         test_rcu<map_type2>(4, 2);
90     }
91
92     void FeldmanHashMapHdrTest::rcu_gpi_stdhash_stat()
93     {
94         struct traits : public cc::feldman_hashmap::traits {
95             typedef std::hash<size_t> hash;
96             typedef cc::feldman_hashmap::stat<> stat;
97         };
98         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
99         test_rcu<map_type>(4, 2);
100
101         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
102             typename cc::feldman_hashmap::make_traits<
103                 co::stat< cc::feldman_hashmap::stat<>>
104                 ,co::hash<std::hash<size_t>>
105             >::type
106         > map_type2;
107         test_rcu<map_type2>(4, 2);
108     }
109
110         void FeldmanHashMapHdrTest::rcu_gpi_hash128_stat()
111     {
112         struct traits : public cc::feldman_hashmap::traits {
113             typedef cc::feldman_hashmap::stat<> stat;
114             typedef hash128::make hash;
115             typedef hash128::cmp compare;
116         };
117         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
118         test_rcu<map_type>(4, 2);
119
120         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
121             typename cc::feldman_hashmap::make_traits<
122                 co::stat< cc::feldman_hashmap::stat<>>
123                 , co::hash< hash128::make >
124                 , co::compare< hash128::cmp >
125             >::type
126         > map_type2;
127         test_rcu<map_type2>(4, 2);
128     }
129
130     void FeldmanHashMapHdrTest::rcu_gpi_nohash_5_3()
131     {
132         typedef cc::FeldmanHashMap< rcu_type, size_t, Item > map_type;
133
134         test_rcu<map_type>(5, 3);
135     }
136
137     void FeldmanHashMapHdrTest::rcu_gpi_stdhash_5_3()
138     {
139         struct traits : public cc::feldman_hashmap::traits {
140             typedef std::hash<size_t> hash;
141         };
142         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
143
144         test_rcu<map_type>(5, 3);
145     }
146
147     void FeldmanHashMapHdrTest::rcu_gpi_nohash_5_3_stat()
148     {
149         struct traits : public cc::feldman_hashmap::traits {
150             typedef cc::feldman_hashmap::stat<> stat;
151             typedef cds::backoff::empty back_off;
152         };
153         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
154         test_rcu<map_type>(5, 3);
155
156         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
157             typename cc::feldman_hashmap::make_traits<
158             co::stat< cc::feldman_hashmap::stat<>>
159             , co::back_off< cds::backoff::empty >
160             >::type
161         > map_type2;
162         test_rcu<map_type2>(5, 3);
163     }
164
165     void FeldmanHashMapHdrTest::rcu_gpi_stdhash_5_3_stat()
166     {
167         struct traits : public cc::feldman_hashmap::traits {
168             typedef cc::feldman_hashmap::stat<> stat;
169             typedef cds::backoff::empty back_off;
170             typedef std::hash<size_t> hash;
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                 ,co::hash< std::hash<size_t>>
180             >::type
181         > map_type2;
182         test_rcu<map_type2>(5, 3);
183     }
184
185     void FeldmanHashMapHdrTest::rcu_gpi_hash128_4_3()
186     {
187         struct traits : public cc::feldman_hashmap::traits {
188             typedef hash128::make hash;
189             typedef hash128::less less;
190         };
191         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
192         test_rcu<map_type>(4, 3);
193
194         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
195             typename cc::feldman_hashmap::make_traits<
196                 co::hash< hash128::make >
197                 , co::less< hash128::less >
198             >::type
199         > map_type2;
200         test_rcu<map_type2>(4, 3);
201     }
202
203     void FeldmanHashMapHdrTest::rcu_gpi_hash128_4_3_stat()
204     {
205         struct traits : public cc::feldman_hashmap::traits {
206             typedef hash128::make hash;
207             typedef hash128::less less;
208             typedef cc::feldman_hashmap::stat<> stat;
209             typedef co::v::sequential_consistent memory_model;
210         };
211         typedef cc::FeldmanHashMap< rcu_type, size_t, Item, traits > map_type;
212         test_rcu<map_type>(4, 3);
213
214         typedef cc::FeldmanHashMap< rcu_type, size_t, Item,
215             typename cc::feldman_hashmap::make_traits<
216                 co::hash< hash128::make >
217                 , co::less< hash128::less >
218                 , co::stat< cc::feldman_hashmap::stat<>>
219                 , co::memory_model< co::v::sequential_consistent >
220             >::type
221         > map_type2;
222         test_rcu<map_type2>(4, 3);
223     }
224
225 } // namespace map