-//$$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
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
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>
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
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>
/// 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 )
{}
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 )
{}
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
{
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 );
}
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.
*/
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;
{
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 )