Removed redundant spaces
[libcds.git] / test / stress / set / insdel_func / set_insdel_func.h
index 836c34bf90c20554249d8a4d55887fb20c05afeb..20e88f13706a9945a4bd8b4f9811ab25d0c9a721 100644 (file)
@@ -5,7 +5,7 @@
 
     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 "set_type.h"
@@ -61,8 +61,8 @@ namespace set {
             size_t      nKey;
             size_t      nData;
             atomics::atomic<size_t> nUpdateCall;
-            bool volatile   bInitialized;
-            cds::OS::ThreadId          threadId     ;   // insert thread id
+            bool volatile           bInitialized;
+            cds::OS::ThreadId       threadId;   // insert thread id
 
             typedef cds::sync::spin_lock< cds::backoff::pause > lock_type;
             mutable lock_type   m_access;
@@ -72,7 +72,7 @@ namespace set {
                 , nData(0)
                 , nUpdateCall(0)
                 , bInitialized( false )
-                , threadId( cds::OS::get_current_thread_id() )
+                , threadId( cds::OS::get_current_thread_id())
             {}
 
             value( value const& s )
@@ -80,7 +80,7 @@ namespace set {
                 , nData(s.nData)
                 , nUpdateCall(s.nUpdateCall.load(atomics::memory_order_relaxed))
                 , bInitialized( s.bInitialized )
-                , threadId( cds::OS::get_current_thread_id() )
+                , threadId( cds::OS::get_current_thread_id())
                 , m_access()
             {}
 
@@ -100,7 +100,7 @@ namespace set {
 
         size_t *    m_pKeyFirst;
         size_t *    m_pKeyLast;
-        size_t *    m_pKeyArr;
+        std::unique_ptr< size_t[] > m_pKeyArr;
 
         enum {
             insert_thread,
@@ -418,8 +418,8 @@ namespace set {
             typedef Deleter<Set>        DeleterThread;
             typedef Updater<Set>        UpdaterThread;
 
-            m_pKeyArr = new size_t[ s_nSetSize ];
-            m_pKeyFirst = m_pKeyArr;
+            m_pKeyArr.reset( new size_t[ s_nSetSize ] );
+            m_pKeyFirst = m_pKeyArr.get();
             m_pKeyLast = m_pKeyFirst + s_nSetSize;
             for ( size_t i = 0; i < s_nSetSize; ++i )
                 m_pKeyArr[i] = i;
@@ -440,8 +440,6 @@ namespace set {
 
             propout() << std::make_pair( "duration", duration );
 
-            delete [] m_pKeyArr;
-
             size_t nInsertSuccess = 0;
             size_t nInsertFailed = 0;
             size_t nDeleteSuccess = 0;
@@ -457,7 +455,7 @@ namespace set {
 
             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:
                     {
                         InserterThread& inserter = static_cast<InserterThread&>( thr );
@@ -496,21 +494,25 @@ namespace set {
                 << std::make_pair( "update_created", nUpdateCreated )
                 << std::make_pair( "update_modified", nUpdateModified )
                 << std::make_pair( "update_failed", nUpdateFailed )
-                << std::make_pair( "final_set_size", testSet.size() );
+                << std::make_pair( "final_set_size", testSet.size());
 
 
-            EXPECT_EQ( nDelValueFailed, 0 );
+            EXPECT_EQ( nDelValueFailed, 0u );
             EXPECT_EQ( nDelValueSuccess, nDeleteSuccess );
 
-            EXPECT_EQ( nUpdateFailed, 0 );
+            EXPECT_EQ( nUpdateFailed, 0u );
             EXPECT_EQ( nUpdateCreated, nEnsFuncCreated );
             EXPECT_EQ( nUpdateModified, nEnsFuncModified );
 
             // nTestFunctorRef is call count of insert functor
             EXPECT_EQ( nTestFunctorRef, nInsertSuccess );
 
-            testSet.clear();
-            EXPECT_TRUE( testSet.empty() );
+            //testSet.clear();
+            for ( size_t * p = m_pKeyFirst; p != m_pKeyLast; ++p )
+                testSet.erase( *p );
+
+            EXPECT_TRUE( testSet.empty());
+            EXPECT_EQ( testSet.size(), 0u );
 
             additional_check( testSet );
             print_stat( propout(), testSet  );
@@ -524,6 +526,16 @@ namespace set {
             Set s( *this );
             run_test( s );
         }
+
+        template <class Set>
+        void run_test2()
+        {
+            Set s( *this );
+            run_test( s );
+
+            for ( auto it = s.begin(); it != s.end(); ++it )
+                std::cout << "key=" << it->key << std::endl;
+        }
     };
 
     class Set_InsDel_func_LF: public Set_InsDel_func
@@ -538,6 +550,14 @@ namespace set {
             Set_InsDel_func::run_test<Set>();
         }
 
+        template <class Set>
+        void run_test2()
+        {
+            s_nLoadFactor = GetParam();
+            propout() << std::make_pair( "load_factor", s_nLoadFactor );
+            Set_InsDel_func::run_test2<Set>();
+        }
+
         static std::vector<size_t> get_load_factors();
     };