From: khizmax Date: Sat, 27 Sep 2014 15:10:06 +0000 (+0400) Subject: Move cds/intrusive/michael_set_base.h to cds/intrusive/details directory X-Git-Tag: v2.0.0~278 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=37c90b6523be2c38f2edd610271ed0d5e2d29c1b;p=libcds.git Move cds/intrusive/michael_set_base.h to cds/intrusive/details directory --- diff --git a/cds/container/michael_set_base.h b/cds/container/michael_set_base.h index b7c2c3c0..29544473 100644 --- a/cds/container/michael_set_base.h +++ b/cds/container/michael_set_base.h @@ -3,7 +3,7 @@ #ifndef __CDS_CONTAINER_MICHAEL_SET_BASE_H #define __CDS_CONTAINER_MICHAEL_SET_BASE_H -#include +#include namespace cds { namespace container { diff --git a/cds/intrusive/details/michael_set_base.h b/cds/intrusive/details/michael_set_base.h new file mode 100644 index 00000000..5792f7f1 --- /dev/null +++ b/cds/intrusive/details/michael_set_base.h @@ -0,0 +1,207 @@ +//$$CDS-header$$ + +#ifndef __CDS_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H +#define __CDS_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H + +#include +#include +#include +#include +#include +#include + +namespace cds { namespace intrusive { + + /// MichaelHashSet related definitions + /** @ingroup cds_intrusive_helper + */ + namespace michael_set { + + /// Type traits for MichaelHashSet class + struct type_traits { + /// Hash function + /** + Hash function converts the key fields of struct \p T stored in the hash-set + into value of type \p size_t called hash value that is an index of hash table. + + This is mandatory type and has no predefined one. + */ + typedef opt::none hash; + + /// Item counter + /** + The item counting is an important part of MichaelHashSet algorithm: + the empty() member function depends on correct item counting. + Therefore, atomicity::empty_item_counter is not allowed as a type of the option. + + Default is atomicity::item_counter. + */ + typedef 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) + */ + typedef CDS_DEFAULT_ALLOCATOR allocator; + }; + + /// Metafunction converting option list to traits struct + /** + This is a wrapper for cds::opt::make_options< type_traits, Options...> + + Available \p Options: + - opt::hash - mandatory option, specifies hash functor. + - opt::item_counter - optional, specifies item counting policy. See type_traits::item_counter + for default type. + - opt::allocator - optional, bucket table allocator. Default is \ref CDS_DEFAULT_ALLOCATOR. + + See \ref MichaelHashSet, \ref type_traits. + */ + template + struct make_traits { + typedef typename cds::opt::make_options< type_traits, Options...>::type type ; ///< Result of metafunction + }; + + //@cond + namespace details { + static inline size_t init_hash_bitmask( size_t nMaxItemCount, size_t nLoadFactor ) + { + if ( nLoadFactor == 0 ) + nLoadFactor = 1; + if ( nMaxItemCount == 0 ) + nMaxItemCount = 4; + const size_t nBucketCount = (size_t)( nMaxItemCount / nLoadFactor ); + const size_t nLog2 = cds::bitop::MSB( nBucketCount ); + + return (( size_t( 1 << nLog2 ) < nBucketCount ? size_t( 1 << (nLog2 + 1) ) : size_t( 1 << nLog2 ))) - 1; + } + + template + struct list_iterator_selector; + + template + struct list_iterator_selector< OrderedList, false> + { + typedef OrderedList * bucket_ptr; + typedef typename OrderedList::iterator type; + }; + + template + struct list_iterator_selector< OrderedList, true> + { + typedef OrderedList const * bucket_ptr; + typedef typename OrderedList::const_iterator type; + }; + + template + class iterator + { + protected: + typedef OrderedList bucket_type; + typedef typename list_iterator_selector< bucket_type, IsConst>::bucket_ptr bucket_ptr; + typedef typename list_iterator_selector< bucket_type, IsConst>::type list_iterator; + + bucket_ptr m_pCurBucket; + list_iterator m_itList; + bucket_ptr m_pEndBucket; + + void next() + { + if ( m_pCurBucket < m_pEndBucket ) { + if ( ++m_itList != m_pCurBucket->end() ) + return; + while ( ++m_pCurBucket < m_pEndBucket ) { + m_itList = m_pCurBucket->begin(); + if ( m_itList != m_pCurBucket->end() ) + return; + } + } + m_pCurBucket = m_pEndBucket - 1; + m_itList = m_pCurBucket->end(); + } + + public: + typedef typename list_iterator::value_ptr value_ptr; + typedef typename list_iterator::value_ref value_ref; + + public: + iterator() + : m_pCurBucket( nullptr ) + , m_itList() + , m_pEndBucket( nullptr ) + {} + + iterator( list_iterator const& it, bucket_ptr pFirst, bucket_ptr pLast ) + : m_pCurBucket( pFirst ) + , m_itList( it ) + , m_pEndBucket( pLast ) + { + if ( it == pFirst->end() ) + next(); + } + + iterator( iterator const& src ) + : m_pCurBucket( src.m_pCurBucket ) + , m_itList( src.m_itList ) + , m_pEndBucket( src.m_pEndBucket ) + {} + + value_ptr operator ->() const + { + assert( m_pCurBucket != nullptr ); + return m_itList.operator ->(); + } + + value_ref operator *() const + { + assert( m_pCurBucket != nullptr ); + return m_itList.operator *(); + } + + /// Pre-increment + iterator& operator ++() + { + next(); + return *this; + } + + iterator& operator = (const iterator& src) + { + m_pCurBucket = src.m_pCurBucket; + m_pEndBucket = src.m_pEndBucket; + m_itList = src.m_itList; + return *this; + } + + bucket_ptr bucket() const + { + return m_pCurBucket != m_pEndBucket ? m_pCurBucket : nullptr; + } + + template + bool operator ==(iterator const& i ) const + { + return m_pCurBucket == i.m_pCurBucket && m_itList == i.m_itList; + } + template + bool operator !=(iterator const& i ) const + { + return !( *this == i ); + } + + }; + } + //@endcond + } + + //@cond + // Forward declarations + template + class MichaelHashSet; + //@endcond + +}} // namespace cds::intrusive + +#endif // #ifndef __CDS_INTRUSIVE_DETAILS_MICHAEL_SET_BASE_H diff --git a/cds/intrusive/michael_set.h b/cds/intrusive/michael_set.h index 27f5435c..d6242b76 100644 --- a/cds/intrusive/michael_set.h +++ b/cds/intrusive/michael_set.h @@ -3,7 +3,7 @@ #ifndef __CDS_INTRUSIVE_MICHAEL_SET_H #define __CDS_INTRUSIVE_MICHAEL_SET_H -#include +#include #include namespace cds { namespace intrusive { diff --git a/cds/intrusive/michael_set_base.h b/cds/intrusive/michael_set_base.h deleted file mode 100644 index f0fe5946..00000000 --- a/cds/intrusive/michael_set_base.h +++ /dev/null @@ -1,207 +0,0 @@ -//$$CDS-header$$ - -#ifndef __CDS_INTRUSIVE_MICHAEL_SET_BASE_H -#define __CDS_INTRUSIVE_MICHAEL_SET_BASE_H - -#include -#include -#include -#include -#include -#include - -namespace cds { namespace intrusive { - - /// MichaelHashSet related definitions - /** @ingroup cds_intrusive_helper - */ - namespace michael_set { - - /// Type traits for MichaelHashSet class - struct type_traits { - /// Hash function - /** - Hash function converts the key fields of struct \p T stored in the hash-set - into value of type \p size_t called hash value that is an index of hash table. - - This is mandatory type and has no predefined one. - */ - typedef opt::none hash; - - /// Item counter - /** - The item counting is an important part of MichaelHashSet algorithm: - the empty() member function depends on correct item counting. - Therefore, atomicity::empty_item_counter is not allowed as a type of the option. - - Default is atomicity::item_counter. - */ - typedef 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) - */ - typedef CDS_DEFAULT_ALLOCATOR allocator; - }; - - /// Metafunction converting option list to traits struct - /** - This is a wrapper for cds::opt::make_options< type_traits, Options...> - - Available \p Options: - - opt::hash - mandatory option, specifies hash functor. - - opt::item_counter - optional, specifies item counting policy. See type_traits::item_counter - for default type. - - opt::allocator - optional, bucket table allocator. Default is \ref CDS_DEFAULT_ALLOCATOR. - - See \ref MichaelHashSet, \ref type_traits. - */ - template - struct make_traits { - typedef typename cds::opt::make_options< type_traits, Options...>::type type ; ///< Result of metafunction - }; - - //@cond - namespace details { - static inline size_t init_hash_bitmask( size_t nMaxItemCount, size_t nLoadFactor ) - { - if ( nLoadFactor == 0 ) - nLoadFactor = 1; - if ( nMaxItemCount == 0 ) - nMaxItemCount = 4; - const size_t nBucketCount = (size_t)( nMaxItemCount / nLoadFactor ); - const size_t nLog2 = cds::bitop::MSB( nBucketCount ); - - return (( size_t( 1 << nLog2 ) < nBucketCount ? size_t( 1 << (nLog2 + 1) ) : size_t( 1 << nLog2 ))) - 1; - } - - template - struct list_iterator_selector; - - template - struct list_iterator_selector< OrderedList, false> - { - typedef OrderedList * bucket_ptr; - typedef typename OrderedList::iterator type; - }; - - template - struct list_iterator_selector< OrderedList, true> - { - typedef OrderedList const * bucket_ptr; - typedef typename OrderedList::const_iterator type; - }; - - template - class iterator - { - protected: - typedef OrderedList bucket_type; - typedef typename list_iterator_selector< bucket_type, IsConst>::bucket_ptr bucket_ptr; - typedef typename list_iterator_selector< bucket_type, IsConst>::type list_iterator; - - bucket_ptr m_pCurBucket; - list_iterator m_itList; - bucket_ptr m_pEndBucket; - - void next() - { - if ( m_pCurBucket < m_pEndBucket ) { - if ( ++m_itList != m_pCurBucket->end() ) - return; - while ( ++m_pCurBucket < m_pEndBucket ) { - m_itList = m_pCurBucket->begin(); - if ( m_itList != m_pCurBucket->end() ) - return; - } - } - m_pCurBucket = m_pEndBucket - 1; - m_itList = m_pCurBucket->end(); - } - - public: - typedef typename list_iterator::value_ptr value_ptr; - typedef typename list_iterator::value_ref value_ref; - - public: - iterator() - : m_pCurBucket( nullptr ) - , m_itList() - , m_pEndBucket( nullptr ) - {} - - iterator( list_iterator const& it, bucket_ptr pFirst, bucket_ptr pLast ) - : m_pCurBucket( pFirst ) - , m_itList( it ) - , m_pEndBucket( pLast ) - { - if ( it == pFirst->end() ) - next(); - } - - iterator( iterator const& src ) - : m_pCurBucket( src.m_pCurBucket ) - , m_itList( src.m_itList ) - , m_pEndBucket( src.m_pEndBucket ) - {} - - value_ptr operator ->() const - { - assert( m_pCurBucket != nullptr ); - return m_itList.operator ->(); - } - - value_ref operator *() const - { - assert( m_pCurBucket != nullptr ); - return m_itList.operator *(); - } - - /// Pre-increment - iterator& operator ++() - { - next(); - return *this; - } - - iterator& operator = (const iterator& src) - { - m_pCurBucket = src.m_pCurBucket; - m_pEndBucket = src.m_pEndBucket; - m_itList = src.m_itList; - return *this; - } - - bucket_ptr bucket() const - { - return m_pCurBucket != m_pEndBucket ? m_pCurBucket : nullptr; - } - - template - bool operator ==(iterator const& i ) const - { - return m_pCurBucket == i.m_pCurBucket && m_itList == i.m_itList; - } - template - bool operator !=(iterator const& i ) const - { - return !( *this == i ); - } - - }; - } - //@endcond - } - - //@cond - // Forward declarations - template - class MichaelHashSet; - //@endcond - -}} // namespace cds::intrusive - -#endif // #ifndef __CDS_INTRUSIVE_MICHAEL_SET_BASE_H diff --git a/cds/intrusive/michael_set_nogc.h b/cds/intrusive/michael_set_nogc.h index 1196c128..59b542db 100644 --- a/cds/intrusive/michael_set_nogc.h +++ b/cds/intrusive/michael_set_nogc.h @@ -3,7 +3,7 @@ #ifndef __CDS_INTRUSIVE_MICHAEL_SET_NOGC_H #define __CDS_INTRUSIVE_MICHAEL_SET_NOGC_H -#include +#include #include #include diff --git a/cds/intrusive/michael_set_rcu.h b/cds/intrusive/michael_set_rcu.h index d155e93d..7c2c80cc 100644 --- a/cds/intrusive/michael_set_rcu.h +++ b/cds/intrusive/michael_set_rcu.h @@ -3,7 +3,7 @@ #ifndef __CDS_INTRUSIVE_MICHAEL_SET_RCU_H #define __CDS_INTRUSIVE_MICHAEL_SET_RCU_H -#include +#include #include namespace cds { namespace intrusive { diff --git a/projects/Win/vc12/cds.vcxproj b/projects/Win/vc12/cds.vcxproj index 048f20c2..c564cb4c 100644 --- a/projects/Win/vc12/cds.vcxproj +++ b/projects/Win/vc12/cds.vcxproj @@ -741,6 +741,7 @@ + @@ -932,7 +933,6 @@ - diff --git a/projects/Win/vc12/cds.vcxproj.filters b/projects/Win/vc12/cds.vcxproj.filters index 6697c546..4cb12974 100644 --- a/projects/Win/vc12/cds.vcxproj.filters +++ b/projects/Win/vc12/cds.vcxproj.filters @@ -578,9 +578,6 @@ Header Files\cds\intrusive - - Header Files\cds\intrusive - Header Files\cds\intrusive @@ -1280,5 +1277,8 @@ Header Files\cds\intrusive\impl + + Header Files\cds\intrusive\details + \ No newline at end of file