2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
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_TREE_TEST_TREE_MAP_DATA_H
32 #define CDSUNIT_TREE_TEST_TREE_MAP_DATA_H
34 #include <cds_test/check_size.h>
35 #include <cds_test/fixture.h>
37 #include <cds/opt/hash.h>
41 class tree_map_fixture: public fixture
50 explicit key_type( int n )
54 explicit key_type( std::string const& str )
55 : nKey( std::stoi( str ))
58 key_type( key_type const& s )
71 explicit value_type( int n )
73 , strVal( std::to_string( n ))
76 explicit value_type( std::string const& str )
77 : nVal( std::stoi( str ))
81 explicit value_type( std::string&& str )
82 : nVal( std::stoi( str ))
83 , strVal( std::move( str ))
86 value_type( int n, std::string const& str )
91 value_type( int n, std::string&& str )
93 , strVal( std::move( str ))
96 value_type( value_type&& v )
98 , strVal( std::move( v.strVal ))
101 value_type( value_type const& v )
106 value_type& operator=( value_type const& v )
115 value_type& operator=( value_type&& v )
119 strVal = std::move( v.strVal );
124 value_type& operator=( int i )
127 strVal = std::to_string( i );
131 value_type& operator=( std::string const& s )
133 nVal = std::stoi( s );
139 typedef std::pair<key_type const, value_type> pair_type;
142 void operator()( key_type& dest, key_type const& src ) const
144 dest.nKey = src.nKey;
149 bool operator ()( key_type const& v1, key_type const& v2 ) const
151 return v1.nKey < v2.nKey;
154 bool operator ()( key_type const& v1, int v2 ) const
159 bool operator ()( int v1, key_type const& v2 ) const
164 bool operator ()( key_type const& v1, std::string const& v2 ) const
166 return v1.nKey < std::stoi(v2 );
169 bool operator ()( std::string const& v1, key_type const& v2 ) const
171 return std::stoi( v1 ) < v2.nKey;
176 int operator ()( key_type const& v1, key_type const& v2 ) const
178 if ( v1.nKey < v2.nKey )
180 return v1.nKey > v2.nKey ? 1 : 0;
183 int operator ()( key_type const& v1, int v2 ) const
187 return v1.nKey > v2 ? 1 : 0;
190 int operator ()( int v1, key_type const& v2 ) const
194 return v1 > v2.nKey ? 1 : 0;
197 int operator ()( key_type const& v1, std::string const& v2 ) const
199 int n2 = std::stoi( v2 );
202 return v1.nKey > n2 ? 1 : 0;
205 int operator ()( std::string const& v1, key_type const& v2 ) const
207 int n1 = std::stoi( v1 );
210 return n1 > v2.nKey ? 1 : 0;
215 size_t operator()( int i ) const
217 return cds::opt::v::hash<int>()( i );
220 size_t operator()( std::string const& str ) const
222 return cds::opt::v::hash<int>()( std::stoi( str ));
225 template <typename T>
226 size_t operator()( T const& i ) const
228 return cds::opt::v::hash<int>()(i.nKey);
235 other_item( int key )
242 bool operator ()( key_type const& v1, other_item const& v2 ) const
244 return v1.nKey < v2.nKey;
246 bool operator ()( other_item const& v1, key_type const& v2 ) const
248 return v1.nKey < v2.nKey;
252 } // namespace cds_test
254 #endif // CDSUNIT_TREE_TEST_TREE_MAP_DATA_H