Updated copyright
[libcds.git] / test / stress / map / insdel_func / map_insdel_func.h
index b56f5feda00ae4c48e5f2dc43dc90c59705b7c83..b2605ca5673209ea944dc157c8348175de81aa5b 100644 (file)
@@ -1,11 +1,11 @@
 /*
     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/
-    
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are met:
 
@@ -25,7 +25,7 @@
     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     
+    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 #include "map_type.h"
@@ -79,14 +79,17 @@ namespace map {
                 , nUpdateCall( s.nUpdateCall )
                 , bInitialized( s.bInitialized.load(atomics::memory_order_relaxed))
                 , threadId( cds::OS::get_current_thread_id())
+                , m_access()
             {}
 
             // boost::container::flat_map requires operator =
+            // cppcheck-suppress operatorEqVarError
             value_type& operator=( value_type const& v )
             {
                 nKey = v.nKey;
                 nData = v.nData;
                 nUpdateCall = v.nUpdateCall;
+                threadId = v.threadId;
                 bInitialized.store(v.bInitialized.load(atomics::memory_order_relaxed), atomics::memory_order_relaxed);
 
                 return *this;
@@ -224,7 +227,7 @@ namespace map {
                     operator()( bNew, val.first, val.second );
                 }
 
-                // For FeldmanHashMap
+                // For FeldmanHashMap, IterableList
                 template <typename Val>
                 void operator()( Val& cur, Val * old )
                 {
@@ -324,7 +327,8 @@ namespace map {
                 size_t      nFailedItem;
 
                 value_container()
-                    : nSuccessItem(0)
+                    : nKeyExpected()
+                    , nSuccessItem(0)
                     , nFailedItem(0)
                 {}
             };
@@ -428,7 +432,8 @@ namespace map {
             cds_test::thread_pool& pool = get_pool();
             pool.add( new inserter( pool, testMap ), s_nInsertThreadCount );
             pool.add( new deleter( pool, testMap ), s_nDeleteThreadCount );
-            pool.add( new updater( pool, testMap ), s_nUpdateThreadCount );
+            if ( s_nUpdateThreadCount )
+                pool.add( new updater( pool, testMap ), s_nUpdateThreadCount );
 
             propout() << std::make_pair( "insert_thread_count", s_nInsertThreadCount )
                 << std::make_pair( "delete_thread_count", s_nDeleteThreadCount )
@@ -455,7 +460,7 @@ namespace map {
 
             for ( size_t i = 0; i < pool.size(); ++i ) {
                 cds_test::thread& thr = pool.get( i );
-                switch ( thr.type() ) {
+                switch ( thr.type()) {
                 case insert_thread:
                     {
                         inserter& t = static_cast<inserter&>( thr );
@@ -497,11 +502,11 @@ namespace map {
                 << std::make_pair( "update_failed",  nUpdateFailed )
                 << std::make_pair( "update_functor_create", nEnsFuncCreated )
                 << std::make_pair( "update_functor_modify", nEnsFuncModified )
-                << std::make_pair( "finish_map_size", testMap.size() );
+                << std::make_pair( "finish_map_size", testMap.size());
 
-            EXPECT_EQ( nDelValueFailed, 0 );
+            EXPECT_EQ( nDelValueFailed, 0u );
             EXPECT_EQ( nDelValueSuccess, nDeleteSuccess );
-            EXPECT_EQ( nUpdateFailed, 0 );
+            EXPECT_EQ( nUpdateFailed, 0u );
             EXPECT_EQ( nUpdateCreated + nUpdateModified, nEnsFuncCreated + nEnsFuncModified );
 
             // nInsFuncCalled is call count of insert functor
@@ -513,6 +518,7 @@ namespace map {
                 testMap.erase( nItem );
 
             EXPECT_TRUE( testMap.empty());
+            EXPECT_EQ( testMap.size(), 0u );
 
             additional_check( testMap );
             print_stat( propout(), testMap );
@@ -525,6 +531,19 @@ namespace map {
             Map testMap( *this );
             do_test( testMap );
         }
+
+        template <class Map>
+        void run_test2()
+        {
+            Map testMap( *this );
+            do_test( testMap );
+
+            if ( testMap.size() != 0 ) {
+                for ( auto it = testMap.begin(); it != testMap.end(); ++it ) {
+                    std::cout << "key=" << it->first << std::endl;
+                }
+            }
+        }
     };
 
     class Map_InsDel_func_LF: public Map_InsDel_func
@@ -539,6 +558,14 @@ namespace map {
             Map_InsDel_func::run_test<Set>();
         }
 
+        template <class Set>
+        void run_test2()
+        {
+            s_nLoadFactor = GetParam();
+            propout() << std::make_pair( "load_factor", s_nLoadFactor );
+            Map_InsDel_func::run_test2<Set>();
+        }
+
         static std::vector<size_t> get_load_factors();
     };