fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / libcds-2.3.2 / test / unit / striped-map / test_map_data.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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 #ifndef CDSUNIT_STRIPED_MAP_TEST_MAP_DATA_H
32 #define CDSUNIT_STRIPED_MAP_TEST_MAP_DATA_H
33
34 #include <cds_test/check_size.h>
35 #include <cds_test/fixture.h>
36
37 #include <cds/opt/hash.h>
38
39 namespace cds_test {
40
41     class striped_map_fixture: public fixture
42     {
43     public:
44         struct key_type {
45             int nKey;
46
47             explicit key_type( int n )
48                 : nKey( n )
49             {}
50
51             explicit key_type( std::string const& str )
52                 : nKey( std::stoi( str ))
53             {}
54
55             key_type( key_type const& s )
56                 : nKey( s.nKey )
57             {}
58         };
59
60         struct value_type {
61             int nVal;
62             std::string strVal;
63
64             value_type()
65                 : nVal( 0 )
66             {}
67
68             explicit value_type( int n )
69                 : nVal( n )
70                 , strVal( std::to_string( n ))
71             {}
72
73             explicit value_type( std::string const& str )
74                 : nVal( std::stoi( str ))
75                 , strVal( str )
76             {}
77
78             explicit value_type( std::string&& str )
79                 : nVal( std::stoi( str ))
80                 , strVal( std::move( str ))
81             {}
82
83             value_type( int n, std::string const& str )
84                 : nVal( n )
85                 , strVal( str )
86             {}
87
88             value_type( int n, std::string&& str )
89                 : nVal( n )
90                 , strVal( std::move( str ))
91             {}
92
93             value_type( value_type&& v )
94                 : nVal( v.nVal )
95                 , strVal( std::move( v.strVal ))
96             {}
97
98             value_type( value_type const& v )
99                 : nVal( v.nVal )
100                 , strVal( v.strVal )
101             {}
102
103             value_type& operator=( value_type const& v )
104             {
105                 if ( this != &v ) {
106                     nVal = v.nVal;
107                     strVal = v.strVal;
108                 }
109                 return *this;
110             }
111
112             value_type& operator=( value_type&& v )
113             {
114                 if ( this != &v ) {
115                     nVal = v.nVal;
116                     strVal = std::move( v.strVal );
117                 }
118                 return *this;
119             }
120
121             value_type& operator=( int i )
122             {
123                 nVal = i;
124                 strVal = std::to_string( i );
125                 return *this;
126             }
127
128             value_type& operator=( std::string const& s )
129             {
130                 nVal = std::stoi( s );
131                 strVal = s;
132                 return *this;
133             }
134         };
135
136         typedef std::pair<key_type const, value_type> pair_type;
137
138         struct less
139         {
140             bool operator ()( key_type const& v1, key_type const& v2 ) const
141             {
142                 return v1.nKey < v2.nKey;
143             }
144
145             bool operator ()( key_type const& v1, int v2 ) const
146             {
147                 return v1.nKey < v2;
148             }
149
150             bool operator ()( int v1, key_type const& v2 ) const
151             {
152                 return v1 < v2.nKey;
153             }
154
155             bool operator ()( key_type const& v1, std::string const& v2 ) const
156             {
157                 return v1.nKey < std::stoi(v2 );
158             }
159
160             bool operator ()( std::string const& v1, key_type const& v2 ) const
161             {
162                 return std::stoi( v1 ) < v2.nKey;
163             }
164         };
165
166         struct cmp {
167             int operator ()( key_type const& v1, key_type const& v2 ) const
168             {
169                 if ( v1.nKey < v2.nKey )
170                     return -1;
171                 return v1.nKey > v2.nKey ? 1 : 0;
172             }
173
174             int operator ()( key_type const& v1, int v2 ) const
175             {
176                 if ( v1.nKey < v2 )
177                     return -1;
178                 return v1.nKey > v2 ? 1 : 0;
179             }
180
181             int operator ()( int v1, key_type const& v2 ) const
182             {
183                 if ( v1 < v2.nKey )
184                     return -1;
185                 return v1 > v2.nKey ? 1 : 0;
186             }
187
188             int operator ()( key_type const& v1, std::string const& v2 ) const
189             {
190                 int n2 = std::stoi( v2 );
191                 if ( v1.nKey < n2 )
192                     return -1;
193                 return v1.nKey > n2 ? 1 : 0;
194             }
195
196             int operator ()( std::string const& v1, key_type const& v2 ) const
197             {
198                 int n1 = std::stoi( v1 );
199                 if ( n1 < v2.nKey )
200                     return -1;
201                 return n1 > v2.nKey ? 1 : 0;
202             }
203         };
204
205         struct equal_to
206         {
207             bool operator ()( key_type const& v1, key_type const& v2 ) const
208             {
209                 return v1.nKey == v2.nKey;
210             }
211
212             bool operator ()( key_type const& v1, int v2 ) const
213             {
214                 return v1.nKey == v2;
215             }
216
217             bool operator ()( int v1, key_type const& v2 ) const
218             {
219                 return v1 == v2.nKey;
220             }
221
222             bool operator ()( key_type const& v1, std::string const& v2 ) const
223             {
224                 return v1.nKey == std::stoi( v2 );
225             }
226
227             bool operator ()( std::string const& v1, key_type const& v2 ) const
228             {
229                 return std::stoi( v1 ) == v2.nKey;
230             }
231         };
232
233         struct hash1 {
234             size_t operator()( int i ) const
235             {
236                 return cds::opt::v::hash<int>()( i );
237             }
238
239             size_t operator()( std::string const& str ) const
240             {
241                 return cds::opt::v::hash<int>()( std::stoi( str ));
242             }
243
244             template <typename T>
245             size_t operator()( T const& i ) const
246             {
247                 return cds::opt::v::hash<int>()(i.nKey);
248             }
249         };
250
251         struct hash2: private hash1
252         {
253             typedef hash1 base_class;
254
255             size_t operator()( int i ) const
256             {
257                 size_t h = ~(base_class::operator()( i ));
258                 return ~h + 0x9e3779b9 + (h << 6) + (h >> 2);
259             }
260             template <typename Item>
261             size_t operator()( const Item& i ) const
262             {
263                 size_t h = ~(base_class::operator()( i ));
264                 return ~h + 0x9e3779b9 + (h << 6) + (h >> 2);
265             }
266         };
267
268         struct other_item {
269             int nKey;
270
271             other_item( int key )
272                 : nKey( key )
273             {}
274         };
275
276         struct other_less
277         {
278             bool operator ()( key_type const& v1, other_item const& v2 ) const
279             {
280                 return v1.nKey < v2.nKey;
281             }
282             bool operator ()( other_item const& v1, key_type const& v2 ) const
283             {
284                 return v1.nKey < v2.nKey;
285             }
286         };
287
288         struct other_equal_to
289         {
290             bool operator ()( key_type const& v1, other_item const& v2 ) const
291             {
292                 return v1.nKey == v2.nKey;
293             }
294             bool operator ()( other_item const& v1, key_type const& v2 ) const
295             {
296                 return v1.nKey == v2.nKey;
297             }
298         };
299     };
300 } // namespace cds_test
301
302 #endif // CDSUNIT_STRIPED_MAP_TEST_MAP_DATA_H