Adjusts sequential map test cases
[libcds.git] / cds / container / striped_set.h
index 8396e0424cd4edd79f1927dd939880865529eb7a..ae2466676d69e78fd83d522079376840464f7a4a 100644 (file)
@@ -1,4 +1,32 @@
-//$$CDS-header$$
+/*
+    This file is a part of libcds - Concurrent Data Structures library
+
+    (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:
+
+    * 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 CDSLIB_CONTAINER_STRIPED_SET_H
 #define CDSLIB_CONTAINER_STRIPED_SET_H
@@ -323,7 +351,7 @@ namespace cds { namespace container {
                         struct swap_item {
                             void operator()( std::list<T>& list, std::list<T>::iterator itInsert, std::list<T>::iterator itWhat )
                             {
-                                std::swap( *list.insert( itInsert, T() ), *itWhat );
+                                std::swap( *list.insert( itInsert, T()), *itWhat );
                             }
                         } \endcode
 
@@ -331,7 +359,7 @@ namespace cds { namespace container {
                         struct move_item {
                             void operator()( std::list<T>& list, std::list<T>::iterator itInsert, std::list<T>::iterator itWhat )
                             {
-                                list.insert( itInsert, std::move( *itWhat ) );
+                                list.insert( itInsert, std::move( *itWhat ));
                             }
                         } \endcode
                     </td>
@@ -375,7 +403,7 @@ namespace cds { namespace container {
                         struct swap_item {
                             void operator()( bc::slist<T>& list, bc::slist<T>::iterator itInsert, bc::slist<T>::iterator itWhat )
                             {
-                                std::swap( *list.insert_after( itInsert, T() ), *itWhat );
+                                std::swap( *list.insert_after( itInsert, T()), *itWhat );
                             }
                         } \endcode
 
@@ -383,7 +411,7 @@ namespace cds { namespace container {
                         struct move_item {
                             void operator()( bc::slist<T>& list, bc::slist<T>::iterator itInsert, bc::slist<T>::iterator itWhat )
                             {
-                                list.insert_after( itInsert, std::move( *itWhat ) );
+                                list.insert_after( itInsert, std::move( *itWhat ));
                             }
                         } \endcode
                     </td>
@@ -492,13 +520,15 @@ namespace cds { namespace container {
     public:
         /// Default ctor. The initial capacity is 16.
         StripedSet()
-        : base_class()
+            : base_class()
         {}
 
         /// Ctor with initial capacity specified
         StripedSet(
             size_t nCapacity    ///< Initial size of bucket table and lock array. Must be power of two, the minimum is 16.
-        ) : base_class( nCapacity )
+        )
+
+            : base_class( nCapacity )
         {}
 
         /// Ctor with resizing policy (copy semantics)
@@ -508,7 +538,9 @@ namespace cds { namespace container {
         StripedSet(
             size_t nCapacity    ///< Initial size of bucket table and lock array. Must be power of two, the minimum is 16.
             ,resizing_policy const& resizingPolicy  ///< Resizing policy
-        ) : base_class( nCapacity, resizingPolicy )
+        )
+
+            : base_class( nCapacity, resizingPolicy )
         {}
 
         /// Ctor with resizing policy (move semantics)
@@ -519,7 +551,9 @@ namespace cds { namespace container {
         StripedSet(
             size_t nCapacity    ///< Initial size of bucket table and lock array. Must be power of two, the minimum is 16.
             ,resizing_policy&& resizingPolicy  ///< Resizing policy
-            ) : base_class( nCapacity, std::forward<resizing_policy>(resizingPolicy) )
+        )
+
+            : base_class( nCapacity, std::forward<resizing_policy>(resizingPolicy))
         {}
 
         /// Destructor destroys internal data
@@ -590,13 +624,14 @@ namespace cds { namespace container {
         {
             bool bOk;
             bool bResize;
-            size_t nHash = base_class::hashing( value_type( std::forward<Args>(args)...));
+            value_type val( std::forward<Args>( args )... );
+            size_t nHash = base_class::hashing( val );
             bucket_type * pBucket;
             {
                 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
                 pBucket = base_class::bucket( nHash );
 
-                bOk = pBucket->emplace( std::forward<Args>(args)...);
+                bOk = pBucket->emplace( std::move( val ));
                 bResize = bOk && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
             }
 
@@ -625,7 +660,7 @@ namespace cds { namespace container {
 
             The functor may change non-key fields of the \p item.
 
-            Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
+            Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successful,
             \p second is true if new item has been added or \p false if the item with \p key
             already is in the map.
         */
@@ -633,7 +668,7 @@ namespace cds { namespace container {
         std::pair<bool, bool> update( Q const& val, Func func, bool bAllowInsert = true )
         {
             std::pair<bool, bool> result;
-            bool bResize;
+            bool bResize = false;
             size_t nHash = base_class::hashing( val );
             bucket_type * pBucket;
             {
@@ -641,7 +676,8 @@ namespace cds { namespace container {
                 pBucket = base_class::bucket( nHash );
 
                 result = pBucket->update( val, func, bAllowInsert );
-                bResize = result.first && result.second && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
+                if ( result.first && result.second )
+                    bResize = base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
             }
 
             if ( bResize )