-//$$CDS-header$$
+/*
+ This file is a part of libcds - Concurrent Data Structures library
-#ifndef __CDS_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H
-#define __CDS_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H
+ (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 CDSLIB_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H
+#define CDSLIB_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H
-#include <functional> // ref
#include <cds/intrusive/details/base.h>
#include <cds/opt/compare.h>
#include <cds/opt/hash.h>
#include <cds/algo/bitop.h>
-#include <cds/cxx11_atomic.h>
+#include <cds/algo/atomic.h>
namespace cds { namespace intrusive {
/** @ingroup cds_intrusive_helper
*/
namespace michael_set {
-
- /// Type traits for MichaelHashSet class
- struct type_traits {
+ /// MichaelHashSet traits
+ struct traits {
/// Hash function
/**
Hash function converts the key fields of struct \p T stored in the hash-set
This is mandatory type and has no predefined one.
*/
- typedef opt::none hash;
+ typedef opt::none hash;
/// Item counter
/**
- The item counting is an important part of MichaelHashSet algorithm:
- the <tt>empty()</tt> member function depends on correct item counting.
- Therefore, atomicity::empty_item_counter is not allowed as a type of the option.
+ The item counting is an important part of \p MichaelHashSet algorithm:
+ the \p empty() member function depends on correct item counting.
+ Therefore, \p atomicity::empty_item_counter is not allowed as a type of the option.
- Default is atomicity::item_counter.
+ Default is \p atomicity::item_counter.
*/
- typedef atomicity::item_counter item_counter;
+ typedef cds::atomicity::item_counter item_counter;
/// Bucket table allocator
/**
Allocator for bucket table. Default is \ref CDS_DEFAULT_ALLOCATOR
- The allocator uses only in ctor (for allocating bucket table)
- and in dtor (for destroying bucket table)
+ The allocator uses only in constructor for allocating bucket table
+ and in destructor for destroying bucket table
*/
typedef CDS_DEFAULT_ALLOCATOR allocator;
};
/// Metafunction converting option list to traits struct
/**
- This is a wrapper for <tt> cds::opt::make_options< type_traits, Options...> </tt>
-
Available \p Options:
- - opt::hash - mandatory option, specifies hash functor.
- - opt::item_counter - optional, specifies item counting policy. See type_traits::item_counter
+ - \p opt::hash - mandatory option, specifies hash functor.
+ - \p opt::item_counter - optional, specifies item counting policy. See \p traits::item_counter
for default type.
- - opt::allocator - optional, bucket table allocator. Default is \ref CDS_DEFAULT_ALLOCATOR.
-
- See \ref MichaelHashSet, \ref type_traits.
+ - \p opt::allocator - optional, bucket table allocator. Default is \ref CDS_DEFAULT_ALLOCATOR.
*/
template <typename... Options>
struct make_traits {
- typedef typename cds::opt::make_options< type_traits, Options...>::type type ; ///< Result of metafunction
+ typedef typename cds::opt::make_options< traits, Options...>::type type; ///< Metafunction result
};
//@cond
nLoadFactor = 1;
if ( nMaxItemCount == 0 )
nMaxItemCount = 4;
- const size_t nBucketCount = (size_t)( nMaxItemCount / nLoadFactor );
- const size_t nLog2 = cds::bitop::MSB( nBucketCount );
+ const size_t nBucketCount = nMaxItemCount / nLoadFactor;
+ const size_t exp2 = size_t( 1 ) << cds::bitop::MSB( nBucketCount );
- return (( size_t( 1 << nLog2 ) < nBucketCount ? size_t( 1 << (nLog2 + 1) ) : size_t( 1 << nLog2 ))) - 1;
+ return ( exp2 < nBucketCount ? exp2 * 2 : exp2 ) - 1;
}
template <typename OrderedList, bool IsConst>
template <typename OrderedList, bool IsConst>
class iterator
{
+ friend class iterator< OrderedList, !IsConst >;
+
protected:
typedef OrderedList bucket_type;
typedef typename list_iterator_selector< bucket_type, IsConst>::bucket_ptr bucket_ptr;
void next()
{
if ( m_pCurBucket < m_pEndBucket ) {
- if ( ++m_itList != m_pCurBucket->end() )
+ if ( ++m_itList != m_pCurBucket->end())
return;
while ( ++m_pCurBucket < m_pEndBucket ) {
m_itList = m_pCurBucket->begin();
- if ( m_itList != m_pCurBucket->end() )
+ if ( m_itList != m_pCurBucket->end())
return;
}
}
, m_itList( it )
, m_pEndBucket( pLast )
{
- if ( it == pFirst->end() )
+ if ( it == pFirst->end())
next();
}
}
template <bool C>
- bool operator ==(iterator<OrderedList, C> const& i ) const
+ bool operator ==(iterator<bucket_type, C> const& i) const
{
return m_pCurBucket == i.m_pCurBucket && m_itList == i.m_itList;
}
};
}
//@endcond
- }
+ } // namespace michael_set
//@cond
// Forward declarations
- template <class GC, class OrderedList, class Traits = michael_set::type_traits>
+ template <class GC, class OrderedList, class Traits = michael_set::traits>
class MichaelHashSet;
//@endcond
}} // namespace cds::intrusive
-#endif // #ifndef __CDS_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H
+#endif // #ifndef CDSLIB_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H