Fixed -Wshadow warnings
[libcds.git] / test / unit / intrusive-set / test_intrusive_feldman_hashset.h
index bbcf320e2adf12705ce37524e0751a42736ffd73..92115d1f4490f207a1a484d99b5cefb676e26efd 100644 (file)
@@ -1,7 +1,7 @@
 /*
     This file is a part of libcds - Concurrent Data Structures library
 
-    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
 
     Source code repo: http://github.com/khizmax/libcds/
     Download: http://sourceforge.net/projects/libcds/files/
@@ -47,9 +47,9 @@ namespace cds_test {
     public:
         struct stat
         {
-            unsigned int nDisposeCount  ;   // count of disposer calling
-            unsigned int nFindCount     ;   // count of find-functor calling
-            unsigned int nInsertCount   ;
+            unsigned int nDisposeCount;   // count of disposer calling
+            unsigned int nFindCount;   // count of find-functor calling
+            unsigned int nInsertCount;
             mutable unsigned int nEraseCount;
 
             stat()
@@ -59,7 +59,7 @@ namespace cds_test {
 
             void clear_stat()
             {
-                memset( this, 0, sizeof( *this ) );
+                memset( this, 0, sizeof( *this ));
             }
         };
 
@@ -76,9 +76,9 @@ namespace cds_test {
                 , nVal( key )
             {}
 
-            int_item(int key, int val)
+            int_item( int key, int val )
                 : nKey( key )
-                , nVal(val)
+                , nVal( val )
             {}
 
             int_item( int_item const& v )
@@ -93,6 +93,53 @@ namespace cds_test {
             }
         };
 
+        struct key_val {
+            int nKey;
+            int nVal;
+
+            key_val()
+            {}
+
+            key_val( int key )
+                : nKey( key )
+                , nVal( key )
+            {}
+
+            key_val( int key, int val )
+                : nKey( key )
+                , nVal( val )
+            {}
+
+            key_val( key_val const& v )
+                : nKey( v.nKey )
+                , nVal( v.nVal )
+            {}
+
+            int key() const
+            {
+                return nKey;
+            }
+        };
+
+        struct int_item2: public key_val, public stat
+        {
+            int_item2()
+            {}
+
+            explicit int_item2( int key )
+                : key_val( key )
+            {}
+
+            int_item2( int key, int val )
+                : key_val( key, val )
+            {}
+
+            int_item2( int_item2 const& v )
+                : key_val( v )
+                , stat()
+            {}
+        };
+
         struct hash_accessor {
             int operator()( int_item const& v ) const
             {
@@ -100,6 +147,13 @@ namespace cds_test {
             }
         };
 
+        struct hash_accessor2 {
+            key_val const& operator()( int_item2 const& v ) const
+            {
+                return v;
+            }
+        };
+
         struct simple_item_counter {
             size_t  m_nCount;
 
@@ -137,6 +191,15 @@ namespace cds_test {
             }
         };
 
+        struct cmp2 {
+            int operator ()( key_val const& lhs, key_val const& rhs ) const
+            {
+                if ( lhs.key() < rhs.key())
+                    return -1;
+                return lhs.key() > rhs.key() ? 1 : 0;
+            }
+        };
+
         struct mock_disposer
         {
             template <typename T>
@@ -153,9 +216,9 @@ namespace cds_test {
             // Precondition: set is empty
             // Postcondition: set is empty
 
-            ASSERT_TRUE( s.empty() );
+            ASSERT_TRUE( s.empty());
             ASSERT_CONTAINER_SIZE( s, 0 );
-            size_t const nSetSize = std::max( s.head_size() * 2, static_cast<size_t>(100) );
+            size_t const nSetSize = std::max( s.head_size() * 2, static_cast<size_t>(100));
 
             typedef typename Set::value_type value_type;
 
@@ -167,7 +230,7 @@ namespace cds_test {
                 data.push_back( value_type( static_cast<int>( key )));
                 indices.push_back( key );
             }
-            shuffle( indices.begin(), indices.end() );
+            shuffle( indices.begin(), indices.end());
 
             // insert/find
             for ( auto idx : indices ) {
@@ -194,7 +257,7 @@ namespace cds_test {
                     EXPECT_EQ( i.nInsertCount, 0u );
                     ASSERT_TRUE( s.insert( i, []( value_type& v ) { ++v.nInsertCount;} ));
                     EXPECT_EQ( i.nInsertCount, 1u );
-                    ASSERT_FALSE( s.insert( i, []( value_type& v ) { ++v.nInsertCount;} ) );
+                    ASSERT_FALSE( s.insert( i, []( value_type& v ) { ++v.nInsertCount;} ));
                     EXPECT_EQ( i.nInsertCount, 1u );
                     i.nInsertCount = 0;
                     break;
@@ -205,12 +268,12 @@ namespace cds_test {
                     break;
                 }
 
-                ASSERT_TRUE( s.contains( i.nKey ) );
-                EXPECT_EQ( i.nFindCount, 0 );
+                ASSERT_TRUE( s.contains( i.nKey ));
+                EXPECT_EQ( i.nFindCount, 0u );
                 ASSERT_TRUE( s.find( i.nKey, []( value_type& v ) { ++v.nFindCount; } ));
                 EXPECT_EQ( i.nFindCount, 1u );
             }
-            ASSERT_FALSE( s.empty() );
+            ASSERT_FALSE( s.empty());
             ASSERT_CONTAINER_SIZE( s, nSetSize );
 
             std::for_each( data.begin(), data.end(), []( value_type& v ) { v.clear_stat(); });
@@ -223,13 +286,13 @@ namespace cds_test {
             }
 
             // erase
-            shuffle( indices.begin(), indices.end() );
+            shuffle( indices.begin(), indices.end());
             for ( auto idx : indices ) {
                 auto& i = data[ idx ];
 
-                ASSERT_TRUE( s.contains( i.nKey ) );
-                EXPECT_EQ( i.nFindCount, 0 );
-                ASSERT_TRUE( s.find( i.nKey, []( value_type& v ) { ++v.nFindCount; } ) );
+                ASSERT_TRUE( s.contains( i.nKey ));
+                EXPECT_EQ( i.nFindCount, 0u );
+                ASSERT_TRUE( s.find( i.nKey, []( value_type& v ) { ++v.nFindCount; } ));
                 EXPECT_EQ( i.nFindCount, 1u );
 
                 value_type v( i );
@@ -237,11 +300,11 @@ namespace cds_test {
                 case 0:
                     ASSERT_FALSE( s.unlink( v ));
                     ASSERT_TRUE( s.unlink( i ));
-                    ASSERT_FALSE( s.unlink( i ) );
+                    ASSERT_FALSE( s.unlink( i ));
                     break;
                 case 1:
                     ASSERT_TRUE( s.erase( i.key()));
-                    ASSERT_FALSE( s.erase( i.key() ) );
+                    ASSERT_FALSE( s.erase( i.key()));
                     break;
                 case 2:
                     EXPECT_EQ( i.nEraseCount, 0u );
@@ -255,7 +318,7 @@ namespace cds_test {
                 ASSERT_FALSE( s.contains( i.nKey ));
                 ASSERT_FALSE( s.find( i.nKey, []( value_type const& ) {} ));
             }
-            ASSERT_TRUE( s.empty() );
+            ASSERT_TRUE( s.empty());
             ASSERT_CONTAINER_SIZE( s, 0 );
 
             // Force retiring cycle
@@ -269,7 +332,7 @@ namespace cds_test {
                 i.clear_stat();
                 ASSERT_TRUE( s.insert( i ));
             }
-            ASSERT_FALSE( s.empty() );
+            ASSERT_FALSE( s.empty());
             ASSERT_CONTAINER_SIZE( s, nSetSize );
 
             // Forward iterator test
@@ -297,8 +360,8 @@ namespace cds_test {
 
             ASSERT_TRUE( s.empty());
             ASSERT_CONTAINER_SIZE( s, 0u );
-            ASSERT_TRUE( s.begin() == s.end() );
-            ASSERT_TRUE( s.cbegin() == s.cend() );
+            ASSERT_TRUE( s.begin() == s.end());
+            ASSERT_TRUE( s.cbegin() == s.cend());
 
             // Force retiring cycle
             Set::gc::force_dispose();