Added copyright and license
[libcds.git] / tests / test-hdr / set / hdr_intrusive_skiplist_set_rcu.h
index bc65e86c5157118147ce48448f9e5b9582a36064..a9c5f7578e88cb67a1416c77f11d85cb8cc0217f 100644 (file)
@@ -1,4 +1,35 @@
-//$$CDS-header$$
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
+
+    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:
+
+    * Redistributions of source code must retain the above copyright notice, this
+      list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+
+    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+    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.     
+*/
+
+#ifndef CDSTEST_HDR_INTRUSIVE_SKIPLIST_SET_RCU_H
+#define CDSTEST_HDR_INTRUSIVE_SKIPLIST_SET_RCU_H
 
 #include "set/hdr_intrusive_set.h"
 
@@ -106,7 +137,7 @@ namespace set {
                 rcu_lock l;
                 for ( set_iterator it = s.begin(), itEnd = s.end(); it != itEnd; ++it ) {
                     CPPUNIT_ASSERT( (*it).nKey * 2 == it->nVal );
-                    CPPUNIT_ASSERT( s.find( it->nKey ));
+                    CPPUNIT_ASSERT( s.contains( it->nKey ));
                     it->nVal = (*it).nKey;
                     ++nCount;
                     if ( it != s.begin() ) {
@@ -135,7 +166,7 @@ namespace set {
 
             for ( size_t i = 0; i < sizeof(v)/sizeof(v[0]); ++i ) {
                 CPPUNIT_ASSERT( v[i].nKey == v[i].nVal );
-                CPPUNIT_ASSERT( s.find( v[i].nKey ));
+                CPPUNIT_ASSERT( s.contains( v[i].nKey ));
             }
 
             s.clear();
@@ -254,21 +285,24 @@ namespace set {
             // extract/get test
             {
                 typename Set::exempt_ptr ep;
+                typename Set::raw_ptr rp;
                 // extract
                 {
                     fill_skiplist( s, v );
-                    value_type * pVal;
+
                     for ( int i = c_nArrSize - 1; i >= 0; i -= 1 ) {
                         {
                             rcu_lock l;
-                            pVal = s.get( i );
-                            CPPUNIT_ASSERT( pVal != NULL );
-                            CPPUNIT_CHECK( pVal->nKey == i );
-                            CPPUNIT_CHECK( pVal->nVal == i * 2 );
-                            pVal->nVal *= 2;
+                            rp = s.get( i );
+                            CPPUNIT_ASSERT( rp );
+                            CPPUNIT_CHECK( rp->nKey == i );
+                            CPPUNIT_CHECK( rp->nVal == i * 2 );
+                            rp->nVal *= 2;
                         }
+                        rp.release();
 
-                        CPPUNIT_ASSERT( s.extract( ep, i ));
+                        ep = s.extract( i );
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty() );
                         CPPUNIT_CHECK( ep->nKey == i );
                         CPPUNIT_CHECK( ep->nVal == i * 4 );
@@ -276,9 +310,10 @@ namespace set {
 
                         {
                             rcu_lock l;
-                            CPPUNIT_CHECK( s.get( i ) == NULL );
+                            CPPUNIT_CHECK( !s.get( i ));
                         }
-                        CPPUNIT_CHECK( !s.extract( ep, i ) );
+                        ep = s.extract( i );
+                        CPPUNIT_CHECK( !ep );
                         CPPUNIT_ASSERT( ep.empty() );
                     }
                     CPPUNIT_CHECK( s.empty() );
@@ -291,14 +326,16 @@ namespace set {
                     for ( int i = c_nArrSize - 1; i >= 0; i -= 1 ) {
                         {
                             rcu_lock l;
-                            value_type * pVal = s.get_with( other_key(i), other_key_less<typename Set::value_type>() );
-                            CPPUNIT_ASSERT( pVal != NULL );
-                            CPPUNIT_CHECK( pVal->nKey == i );
-                            CPPUNIT_CHECK( pVal->nVal == i * 2 );
-                            pVal->nVal *= 2;
+                            rp = s.get_with( other_key(i), other_key_less<typename Set::value_type>() );
+                            CPPUNIT_ASSERT( rp );
+                            CPPUNIT_CHECK( rp->nKey == i );
+                            CPPUNIT_CHECK( rp->nVal == i * 2 );
+                            rp->nVal *= 2;
                         }
+                        rp.release();
 
-                        CPPUNIT_ASSERT( s.extract_with( ep, other_key(i), other_key_less<typename Set::value_type>() ));
+                        ep = s.extract_with( other_key( i ), other_key_less<typename Set::value_type>() );
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty() );
                         CPPUNIT_CHECK( ep->nKey == i );
                         CPPUNIT_CHECK( ep->nVal == i * 4 );
@@ -306,9 +343,10 @@ namespace set {
 
                         {
                             rcu_lock l;
-                            CPPUNIT_CHECK( s.get_with( other_key(i), other_key_less<typename Set::value_type>() ) == NULL );
+                            CPPUNIT_CHECK( !s.get_with( other_key( i ), other_key_less<typename Set::value_type>() ));
                         }
-                        CPPUNIT_CHECK( !s.extract_with( ep, other_key(i), other_key_less<typename Set::value_type>() ));
+                        ep = s.extract_with( other_key( i ), other_key_less<typename Set::value_type>() );
+                        CPPUNIT_CHECK( !ep );
                     }
                     CPPUNIT_CHECK( s.empty() );
                 }
@@ -319,21 +357,24 @@ namespace set {
                     fill_skiplist( s, v );
                     int nPrevKey;
 
-                    CPPUNIT_ASSERT( s.extract_min(ep));
+                    ep = s.extract_min();
+                    CPPUNIT_ASSERT( ep );
                     CPPUNIT_ASSERT( !ep.empty());
                     nPrevKey = ep->nKey;
                     ep.release();
 
                     while ( !s.empty() ) {
-                        CPPUNIT_ASSERT( s.extract_min(ep) );
+                        ep = s.extract_min();
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty());
                         CPPUNIT_CHECK( ep->nKey == nPrevKey + 1 );
                         CPPUNIT_CHECK( ep->nVal == (nPrevKey + 1) * 2 );
                         nPrevKey = ep->nKey;
                         ep.release();
                     }
-                    CPPUNIT_CHECK( !s.extract_min(ep) );
-                    CPPUNIT_CHECK( !s.extract_max(ep) );
+                    ep = s.extract_min();
+                    CPPUNIT_CHECK( !ep );
+                    CPPUNIT_CHECK( !s.extract_max() );
                 }
                 Set::gc::force_dispose();
 
@@ -342,26 +383,29 @@ namespace set {
                     fill_skiplist( s, v );
                     int nPrevKey;
 
-                    CPPUNIT_ASSERT( s.extract_max(ep));
+                    ep = s.extract_max();
+                    CPPUNIT_ASSERT( ep );
                     CPPUNIT_ASSERT( !ep.empty());
                     nPrevKey = ep->nKey;
                     ep.release();
 
                     while ( !s.empty() ) {
-                        CPPUNIT_ASSERT( s.extract_max(ep));
+                        ep = s.extract_max();
+                        CPPUNIT_ASSERT( ep );
                         CPPUNIT_ASSERT( !ep.empty());
                         CPPUNIT_CHECK( ep->nKey == nPrevKey - 1 );
                         CPPUNIT_CHECK( ep->nVal == (nPrevKey - 1) * 2 );
                         nPrevKey = ep->nKey;
                         ep.release();
                     }
+                    ep = s.extract_min();
+                    CPPUNIT_CHECK( !ep );
+                    CPPUNIT_CHECK( !s.extract_max() );
                 }
                 Set::gc::force_dispose();
-                CPPUNIT_CHECK( !s.extract_min(ep) );
-                CPPUNIT_CHECK( !s.extract_max(ep) );
             }
 
-            CPPUNIT_MSG( PrintStat()(s, NULL) );
+            CPPUNIT_MSG( PrintStat()(s, nullptr) );
         }
 
         template <typename Set>
@@ -371,7 +415,7 @@ namespace set {
             for ( int i = 0; i < (int) c_nArrSize; ++i ) {
                 nRand[i] = i;
             }
-            std::random_shuffle( nRand, nRand + c_nArrSize );
+            shuffle( nRand, nRand + c_nArrSize );
 
             for ( int i = 0; i < (int) c_nArrSize; ++i ) {
                 pArr[i].nKey = nRand[i];
@@ -776,3 +820,5 @@ namespace set {
         CPPUNIT_TEST_SUITE_END()
     };
 } // namespace set
+
+#endif // #ifndef CDSTEST_HDR_INTRUSIVE_SKIPLIST_SET_RCU_H