2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
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.
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.
31 #ifndef CDSUNIT_STRIPED_MAP_TEST_MAP_DATA_H
32 #define CDSUNIT_STRIPED_MAP_TEST_MAP_DATA_H
34 #include <cds_test/check_size.h>
35 #include <cds_test/fixture.h>
37 #include <cds/opt/hash.h>
41 class striped_map_fixture: public fixture
47 explicit key_type( int n )
51 explicit key_type( std::string const& str )
52 : nKey( std::stoi( str ))
55 key_type( key_type const& s )
68 explicit value_type( int n )
70 , strVal( std::to_string( n ))
73 explicit value_type( std::string const& str )
74 : nVal( std::stoi( str ))
78 explicit value_type( std::string&& str )
79 : nVal( std::stoi( str ))
80 , strVal( std::move( str ))
83 value_type( int n, std::string const& str )
88 value_type( int n, std::string&& str )
90 , strVal( std::move( str ))
93 value_type( value_type&& v )
95 , strVal( std::move( v.strVal ))
98 value_type( value_type const& v )
103 value_type& operator=( value_type const& v )
112 value_type& operator=( value_type&& v )
116 strVal = std::move( v.strVal );
121 value_type& operator=( int i )
124 strVal = std::to_string( i );
128 value_type& operator=( std::string const& s )
130 nVal = std::stoi( s );
136 typedef std::pair<key_type const, value_type> pair_type;
140 bool operator ()( key_type const& v1, key_type const& v2 ) const
142 return v1.nKey < v2.nKey;
145 bool operator ()( key_type const& v1, int v2 ) const
150 bool operator ()( int v1, key_type const& v2 ) const
155 bool operator ()( key_type const& v1, std::string const& v2 ) const
157 return v1.nKey < std::stoi(v2 );
160 bool operator ()( std::string const& v1, key_type const& v2 ) const
162 return std::stoi( v1 ) < v2.nKey;
167 int operator ()( key_type const& v1, key_type const& v2 ) const
169 if ( v1.nKey < v2.nKey )
171 return v1.nKey > v2.nKey ? 1 : 0;
174 int operator ()( key_type const& v1, int v2 ) const
178 return v1.nKey > v2 ? 1 : 0;
181 int operator ()( int v1, key_type const& v2 ) const
185 return v1 > v2.nKey ? 1 : 0;
188 int operator ()( key_type const& v1, std::string const& v2 ) const
190 int n2 = std::stoi( v2 );
193 return v1.nKey > n2 ? 1 : 0;
196 int operator ()( std::string const& v1, key_type const& v2 ) const
198 int n1 = std::stoi( v1 );
201 return n1 > v2.nKey ? 1 : 0;
207 bool operator ()( key_type const& v1, key_type const& v2 ) const
209 return v1.nKey == v2.nKey;
212 bool operator ()( key_type const& v1, int v2 ) const
214 return v1.nKey == v2;
217 bool operator ()( int v1, key_type const& v2 ) const
219 return v1 == v2.nKey;
222 bool operator ()( key_type const& v1, std::string const& v2 ) const
224 return v1.nKey == std::stoi( v2 );
227 bool operator ()( std::string const& v1, key_type const& v2 ) const
229 return std::stoi( v1 ) == v2.nKey;
234 size_t operator()( int i ) const
236 return cds::opt::v::hash<int>()( i );
239 size_t operator()( std::string const& str ) const
241 return cds::opt::v::hash<int>()( std::stoi( str ));
244 template <typename T>
245 size_t operator()( T const& i ) const
247 return cds::opt::v::hash<int>()(i.nKey);
251 struct hash2: private hash1
253 typedef hash1 base_class;
255 size_t operator()( int i ) const
257 size_t h = ~(base_class::operator()( i ));
258 return ~h + 0x9e3779b9 + (h << 6) + (h >> 2);
260 template <typename Item>
261 size_t operator()( const Item& i ) const
263 size_t h = ~(base_class::operator()( i ));
264 return ~h + 0x9e3779b9 + (h << 6) + (h >> 2);
271 other_item( int key )
278 bool operator ()( key_type const& v1, other_item const& v2 ) const
280 return v1.nKey < v2.nKey;
282 bool operator ()( other_item const& v1, key_type const& v2 ) const
284 return v1.nKey < v2.nKey;
288 struct other_equal_to
290 bool operator ()( key_type const& v1, other_item const& v2 ) const
292 return v1.nKey == v2.nKey;
294 bool operator ()( other_item const& v1, key_type const& v2 ) const
296 return v1.nKey == v2.nKey;
300 } // namespace cds_test
302 #endif // CDSUNIT_STRIPED_MAP_TEST_MAP_DATA_H