The intrusive ordered list implementation specifies the type \p T stored in the hash-set,
the comparing functor for the type \p T and other features specific for the ordered list.
- \p Traits - set traits, default isd \p split_list::traits.
- Instead of defining \p Traits struct you may use option-based syntax with \p split_list::make_traits metafunction.
+ Instead of defining \p Traits struct you can use option-based syntax provided by \p split_list::make_traits metafunction.
@note About required features of hash functor see \ref cds_SplitList_hash_functor "SplitList general description".
protected:
//@cond
- typedef split_list::details::rebind_list_traits<OrderedList, traits> wrapped_ordered_list;
+ typedef split_list::details::rebind_list_traits<OrderedList, traits> ordered_list_adapter;
//@endcond
public:
# ifdef CDS_DOXYGEN_INVOKED
typedef OrderedList ordered_list; ///< type of ordered list used as base for split-list
# else
- typedef typename wrapped_ordered_list::result ordered_list;
+ typedef typename ordered_list_adapter::result ordered_list;
# endif
typedef typename ordered_list::value_type value_type; ///< type of value stored in the split-list
typedef typename ordered_list::key_comparator key_comparator; ///< key compare functor
This traits is intended for converting between underlying ordered list node type \ref list_node_type
and split-list node type \ref node_type
*/
- typedef split_list::node_traits<typename ordered_list::node_traits> node_traits;
+ typedef typename ordered_list_adapter::node_traits node_traits;
/// Bucket table implementation
typedef typename split_list::details::bucket_table_selector<
traits::dynamic_bucket_table
, gc
- , node_type
+ , typename ordered_list_adapter::aux_node
, opt::allocator< typename traits::allocator >
, opt::memory_model< memory_model >
+ , opt::free_list< typename traits::free_list >
>::type bucket_table;
typedef typename bucket_table::aux_node_type aux_node_type; ///< auxiliary node type
*/
SplitListSet()
: m_nBucketCountLog2(1)
- , m_nMaxItemCount( max_item_count(2, m_Buckets.load_factor()) )
+ , m_nMaxItemCount( max_item_count(2, m_Buckets.load_factor()))
{
init();
}
)
: m_Buckets( nItemCount, nLoadFactor )
, m_nBucketCountLog2(1)
- , m_nMaxItemCount( max_item_count(2, m_Buckets.load_factor()) )
+ , m_nMaxItemCount( max_item_count(2, m_Buckets.load_factor()))
{
init();
}
aux_node_type * pHead = get_bucket( nHash );
assert( pHead != nullptr );
- if ( m_List.unlink_at( pHead, val ) ) {
+ if ( m_List.unlink_at( pHead, val )) {
--m_ItemCounter;
m_Stat.onEraseSuccess();
return true;
template <typename Q>
bool erase( Q const& key )
{
- return erase_( key, key_comparator() );
+ return erase_( key, key_comparator());
}
/// Deletes the item from the set using \p pred for searching
bool erase_with( Q const& key, Less pred )
{
CDS_UNUSED( pred );
- return erase_( key, typename wrapped_ordered_list::template make_compare_from_less<Less>() );
+ return erase_( key, typename ordered_list_adapter::template make_compare_from_less<Less>());
}
/// Deletes the item from the set
bool erase_with( Q const& key, Less pred, Func f )
{
CDS_UNUSED( pred );
- return erase_( key, typename wrapped_ordered_list::template make_compare_from_less<Less>(), f );
+ return erase_( key, typename ordered_list_adapter::template make_compare_from_less<Less>(), f );
}
/// Extracts an item from the set
template <typename Q>
exempt_ptr extract( Q const& key )
{
- return exempt_ptr(extract_( key, key_comparator() ));
+ return exempt_ptr(extract_( key, key_comparator()));
}
/// Extracts an item from the set using \p pred for searching
bool find_with( Q& key, Less pred, Func f )
{
CDS_UNUSED( pred );
- return find_( key, typename wrapped_ordered_list::template make_compare_from_less<Less>(), f );
+ return find_( key, typename ordered_list_adapter::template make_compare_from_less<Less>(), f );
}
//@cond
template <typename Q, typename Less, typename Func>
bool find_with( Q const& key, Less pred, Func f )
{
CDS_UNUSED( pred );
- return find_( key, typename wrapped_ordered_list::template make_compare_from_less<Less>(), f );
+ return find_( key, typename ordered_list_adapter::template make_compare_from_less<Less>(), f );
}
//@endcond
template <typename Q>
bool contains( Q const& key )
{
- return find_value( key, key_comparator() );
+ return find_value( key, key_comparator());
}
//@cond
template <typename Q>
bool contains( Q const& key, Less pred )
{
CDS_UNUSED( pred );
- return find_value( key, typename wrapped_ordered_list::template make_compare_from_less<Less>() );
+ return find_value( key, typename ordered_list_adapter::template make_compare_from_less<Less>());
}
//@cond
template <typename Q, typename Less>
template <typename Q>
raw_ptr get( Q const& key )
{
- return get_( key, key_comparator() );
+ return get_( key, key_comparator());
}
/// Finds the key \p key and return the item found
raw_ptr get_with( Q const& key, Less pred )
{
CDS_UNUSED( pred );
- return get_( key, typename wrapped_ordered_list::template make_compare_from_less<Less>());
+ return get_( key, typename ordered_list_adapter::template make_compare_from_less<Less>());
}
void clear()
{
iterator it = begin();
- while ( it != end() ) {
+ while ( it != end()) {
iterator i(it);
++i;
unlink( *it );
*/
iterator begin()
{
- return iterator( m_List.begin(), m_List.end() );
+ return iterator( m_List.begin(), m_List.end());
}
/// Returns an iterator that addresses the location succeeding the last element in a split-list
*/
iterator end()
{
- return iterator( m_List.end(), m_List.end() );
+ return iterator( m_List.end(), m_List.end());
}
/// Returns a forward const iterator addressing the first element in a split-list
/// Returns a forward const iterator addressing the first element in a split-list
const_iterator cbegin() const
{
- return const_iterator( m_List.cbegin(), m_List.cend() );
+ return const_iterator( m_List.cbegin(), m_List.cend());
}
/// Returns an const iterator that addresses the location succeeding the last element in a split-list
/// Returns an const iterator that addresses the location succeeding the last element in a split-list
const_iterator cend() const
{
- return const_iterator( m_List.cend(), m_List.cend() );
+ return const_iterator( m_List.cend(), m_List.cend());
}
//@}
static size_t parent_bucket( size_t nBucket )
{
assert( nBucket > 0 );
- return nBucket & ~( 1 << bitop::MSBnz( nBucket ) );
+ return nBucket & ~( 1 << bitop::MSBnz( nBucket ));
}
- aux_node_type * init_bucket( size_t nBucket )
+ aux_node_type * init_bucket( size_t const nBucket )
{
assert( nBucket > 0 );
size_t nParent = parent_bucket( nBucket );
assert( pParentBucket != nullptr );
- // Allocate a dummy node for new bucket
- {
- aux_node_type * pBucket = alloc_aux_node( split_list::dummy_hash( nBucket ) );
- if ( m_List.insert_aux_node( pParentBucket, pBucket ) ) {
- m_Buckets.bucket( nBucket, pBucket );
- m_Stat.onNewBucket();
+ // Allocate an aux node for new bucket
+ aux_node_type * pBucket = m_Buckets.bucket( nBucket );
+
+ back_off bkoff;
+ for ( ;; pBucket = m_Buckets.bucket( nBucket )) {
+ if ( pBucket )
return pBucket;
+
+ pBucket = alloc_aux_node( split_list::dummy_hash( nBucket ));
+ if ( pBucket ) {
+ if ( m_List.insert_aux_node( pParentBucket, pBucket )) {
+ m_Buckets.bucket( nBucket, pBucket );
+ m_Stat.onNewBucket();
+ return pBucket;
+ }
+
+ // Another thread set the bucket. Wait while it done
+ free_aux_node( pBucket );
+ m_Stat.onBucketInitContenton();
+ break;
}
- free_aux_node( pBucket );
+
+ // There are no free buckets. It means that the bucket table is full
+ // Wait while another thread set the bucket or a free bucket will be available
+ m_Stat.onBucketsExhausted();
+ bkoff();
}
// Another thread set the bucket. Wait while it done
-
- // In this point, we must wait while nBucket is empty.
- // The compiler can decide that waiting loop can be "optimized" (stripped)
- // To prevent this situation, we use waiting on volatile bucket_head_ptr pointer.
- //
- m_Stat.onBucketInitContenton();
- back_off bkoff;
- while ( true ) {
- aux_node_type volatile * p = m_Buckets.bucket( nBucket );
- if ( p != nullptr )
- return const_cast<aux_node_type *>( p );
+ for ( pBucket = m_Buckets.bucket( nBucket ); pBucket == nullptr; pBucket = m_Buckets.bucket( nBucket )) {
bkoff();
m_Stat.onBusyWaitBucketInit();
}
+
+ return pBucket;
}
aux_node_type * get_bucket( size_t nHash )
if ( pHead == nullptr )
pHead = init_bucket( nBucket );
- assert( pHead->is_dummy() );
+ assert( pHead->is_dummy());
return pHead;
}
size_t sz = m_nBucketCountLog2.load(memory_model::memory_order_relaxed);
const size_t nBucketCount = static_cast<size_t>(1) << sz;
- if ( nBucketCount < m_Buckets.capacity() ) {
+ if ( nBucketCount < m_Buckets.capacity()) {
// we may grow the bucket table
const size_t nLoadFactor = m_Buckets.load_factor();
if ( nMaxCount < max_item_count( nBucketCount, nLoadFactor ))
value_type * extract_with_( Q const& val, Less pred )
{
CDS_UNUSED( pred );
- return extract_( val, typename wrapped_ordered_list::template make_compare_from_less<Less>());
+ return extract_( val, typename ordered_list_adapter::template make_compare_from_less<Less>());
}
template <typename Q, typename Compare>
aux_node_type * pHead = get_bucket( nHash );
assert( pHead != nullptr );
- if ( m_List.erase_at( pHead, sv, cmp ) ) {
+ if ( m_List.erase_at( pHead, sv, cmp )) {
--m_ItemCounter;
m_Stat.onEraseSuccess();
return true;