Adjusts pass counts for some sequential map test cases
[libcds.git] / test / stress / sequential / sequential-map / find_string / map_find_string.h
index 5479e3b854b541b4923a21251aefbf7cb3fc3cce..b6068a3b566034c2b1a5bf755a2c6fcaca042464 100644 (file)
@@ -39,6 +39,12 @@ namespace map {
         static size_t s_nMapSize;           // map size (count of searching item)
         static size_t s_nPercentExists;     // percent of existing keys in searching sequence
         static size_t s_nPassCount;
+        static size_t s_nBronsonAVLTreeMapPassCount;
+        static size_t s_nEllenBinTreeMapPassCount;
+        static size_t s_nFeldmanPassCount;
+        static size_t s_nMichaelMapPassCount;
+        static size_t s_nSkipListMapPassCount;
+
         static size_t s_nMaxLoadFactor;     // maximum load factor
 
         static size_t s_nCuckooInitialSize;         // initial size for CuckooMap
@@ -117,43 +123,22 @@ namespace map {
                 size_t const nPassCount = s_nPassCount;
 
                 Map& rMap = m_Map;
-                for ( size_t nPass = 0; nPass < nPassCount; ++nPass ) {
-                    if ( id() & 1 ) {
-                        auto itEnd = s_Data.cend();
-                        for ( auto it = s_Data.cbegin(); it != itEnd; ++it ) {
-                            auto bFound = rMap.contains( *(it->pKey));
-                            if ( it->bExists ) {
-                                if ( check_result(bFound, rMap))
-                                    ++m_KeyExists.nSuccess;
-                                else
-                                    ++m_KeyExists.nFailed;
-                            }
-                            else {
-                                if ( check_result(bFound, rMap))
-                                    ++m_KeyNotExists.nFailed;
-                                else
-                                    ++m_KeyNotExists.nSuccess;
-                            }
-                        }
-                    }
-                    else {
-                        auto itEnd = s_Data.crend();
-                        for ( auto it = s_Data.crbegin(); it != itEnd; ++it ) {
-                            auto bFound = rMap.contains( *(it->pKey));
-                            if ( it->bExists ) {
-                                if ( check_result(bFound, rMap))
-                                    ++m_KeyExists.nSuccess;
-                                else
-                                    ++m_KeyExists.nFailed;
-                            }
-                            else {
-                                if ( check_result( bFound, rMap ))
-                                    ++m_KeyNotExists.nFailed;
-                                else
-                                    ++m_KeyNotExists.nSuccess;
-                            }
-                        }
+                for (size_t nPass = 0; nPass < nPassCount; ++nPass) {
+                  auto itEnd = s_Data.cend();
+                  for (auto it = s_Data.cbegin(); it != itEnd; ++it) {
+                    auto bFound = rMap.contains(*(it->pKey));
+                    if (it->bExists) {
+                      if (check_result(bFound, rMap))
+                        ++m_KeyExists.nSuccess;
+                      else
+                        ++m_KeyExists.nFailed;
+                    } else {
+                      if (check_result(bFound, rMap))
+                        ++m_KeyNotExists.nFailed;
+                      else
+                        ++m_KeyNotExists.nSuccess;
                     }
+                  }
                 }
             }
         };
@@ -175,49 +160,12 @@ namespace map {
                 }
             }
 
-            propout() << std::make_pair( "thread_count", s_nThreadCount )
-                << std::make_pair( "map_size", s_nMapSize )
-                << std::make_pair( "percent_exist", s_nPercentExists )
-                << std::make_pair( "pass_count", s_nPassCount );
-
-            cds_test::thread_pool& pool = get_pool();
-            pool.add( new worker( pool, testMap ), s_nThreadCount );
-
-            std::chrono::milliseconds duration = pool.run();
-
-            propout() << std::make_pair( "duration", duration );
-
-            size_t nExistSuccess = 0;
-            size_t nExistFailed = 0;
-            size_t nMissingSuccess = 0;
-            size_t nMissingFailed = 0;
-
-            // Postcondition: the number of success searching == the number of map item
-            for ( size_t i = 0; i < pool.size(); ++i ) {
-                worker& w = static_cast<worker&>(pool.get( i ));
-                nExistSuccess += w.m_KeyExists.nSuccess;
-                nExistFailed += w.m_KeyExists.nFailed;
-                nMissingSuccess += w.m_KeyNotExists.nSuccess;
-                nMissingFailed += w.m_KeyNotExists.nFailed;
-
-                EXPECT_EQ( w.m_KeyExists.nSuccess, s_nMapSize * s_nPassCount ) << "thread " << i;
-                EXPECT_EQ( w.m_KeyExists.nFailed, 0u ) << "thread " << i;
-                EXPECT_EQ( w.m_KeyNotExists.nSuccess, (s_Data.size() - s_nMapSize) * s_nPassCount ) << "thread " << i;
-                EXPECT_EQ( w.m_KeyNotExists.nFailed, 0u ) << "thread " << i;
-            }
-
-            propout()
-                << std::make_pair( "exist_found", nExistSuccess )
-                << std::make_pair( "exist_not_found", nExistFailed )  // must = 0
-                << std::make_pair( "missing_not_found", nMissingSuccess )
-                << std::make_pair( "missing_found", nMissingFailed );  // must = 0
-
-            check_before_cleanup( testMap );
+            cds_test::thread_pool &pool = get_pool();
+            std::unique_ptr<worker> worker_thread(new worker(pool, testMap));
+            worker_thread->test();
 
             testMap.clear();
-            additional_check( testMap );
-            print_stat( propout(), testMap );
-            additional_cleanup( testMap );
+            additional_cleanup(testMap);
         }
 
         template <class Map>
@@ -228,6 +176,42 @@ namespace map {
             Map testMap( *this );
             test( testMap );
         }
+
+        template <class Map>
+        void run_bronson_avl_tree() {
+          Map_find_string::s_nPassCount =
+              Map_find_string::s_nBronsonAVLTreeMapPassCount;
+          run_test<Map>();
+        }
+
+        template <class Map>
+        void run_ellen_bin_tree() {
+          Map_find_string::s_nPassCount =
+              Map_find_string::s_nEllenBinTreeMapPassCount;
+          run_test<Map>();
+        }
+
+        template <class Map>
+        void run_feldman() {
+          Map_find_string::s_nPassCount =
+              Map_find_string::s_nFeldmanPassCount;
+          run_test<Map>();
+        }
+
+        template <class Map>
+        void run_michael() {
+          Map_find_string::s_nPassCount =
+              Map_find_string::s_nMichaelMapPassCount;
+          run_test<Map>();
+        }
+
+        template <class Map>
+        void run_skip_list() {
+          Map_find_string::s_nPassCount =
+              Map_find_string::s_nSkipListMapPassCount;
+          run_test<Map>();
+        }
+
     };
 
     class Map_find_string_stdhash: public Map_find_string