opt::compare< key_compare >
,opt::disposer< wrapped_disposer >
,opt::boundary_node_type< splitlist_node_type >
- >::type result;
+ >::type result;
};
template <typename OrderedList, bool IsConst>
++m_itCur;
}
-
value_ptr operator ->() const
{
return m_itCur.operator->();
return pPred->m_pNext.load(memory_model::memory_order_acquire) == pCur;
}
+ // for split-list
+ template <typename Predicate>
+ void erase_for( Predicate pred )
+ {
+ node_type * pPred = nullptr;
+ node_type * pHead = m_Head.m_pNext.load( memory_model::memory_order_relaxed );
+
+ while ( pHead != &m_Tail ) {
+ node_type * p = pHead->m_pNext.load( memory_model::memory_order_relaxed );
+ if ( pred( *node_traits::to_value_ptr( pHead ))) {
+ assert( pPred != nullptr );
+ pPred->m_pNext.store( p, memory_model::memory_order_relaxed );
+ dispose_node( pHead, disposer() );
+ }
+ else
+ pPred = pHead;
+ pHead = p;
+ }
+ }
//@endcond
};
pCur = pNext;
}
}
+
+ // for split-list
+ template <typename Predicate>
+ void erase_for( Predicate pred )
+ {
+ node_type * pPred = nullptr;
+ node_type * pHead = m_pHead.load( memory_model::memory_order_relaxed );
+ while ( pHead ) {
+ node_type * p = pHead->m_pNext.load( memory_model::memory_order_relaxed );
+ if ( pred( *node_traits::to_value_ptr( pHead ))) {
+ assert( pPred != nullptr );
+ pPred->m_pNext.store( p, memory_model::memory_order_relaxed );
+ dispose_node( pHead, disposer());
+ }
+ else
+ pPred = pHead;
+ pHead = p;
+ }
+ }
//@endcond
};
/// Count of hazard pointer required for the algorithm
static CDS_CONSTEXPR const size_t c_nHazardPtrCount = ordered_list::c_nHazardPtrCount;
-
protected:
item_counter m_ItemCounter; ///< Item counter
hash m_HashFunctor; ///< Hash functor
/**
The function unlink all items from the set.
The function is not atomic. It cleans up each bucket and then resets the item counter to zero.
- If there are a thread that performs insertion while \p clear is working the result is undefined in general case:
+ If there are a thread that performs insertion while \p %clear() is working the result is undefined in general case:
<tt> empty() </tt> may return \p true but the set may contain item(s).
- Therefore, \p clear may be used only for debugging purposes.
+ Therefore, \p %clear() may be used only for debugging purposes.
For each item the \p disposer is called after unlinking.
*/
typedef typename traits::stat stat; ///< Internal statistics, see \p spit_list::stat
typedef typename ordered_list::guarded_ptr guarded_ptr; ///< Guarded pointer
+ /// Count of hazard pointer required
+ static CDS_CONSTEXPR const size_t c_nHazardPtrCount = ordered_list::c_nHazardPtrCount + 4; // +4 - for iterators
+
protected:
typedef typename ordered_list::node_type list_node_type; ///< Node type as declared in ordered list
typedef split_list::node<list_node_type> node_type; ///< split-list node type
class ordered_list_wrapper: public ordered_list
{
typedef ordered_list base_class;
- typedef typename base_class::auxiliary_head bucket_head_type;
+ typedef typename base_class::auxiliary_head bucket_head_type;
public:
list_iterator insert_at_( dummy_node_type * pHead, value_type& val )
bucket_head_type h(static_cast<list_node_type *>(pHead));
return base_class::insert_aux_node( h, pNode );
}
+
+ template <typename Predicate>
+ void erase_for( Predicate pred )
+ {
+ return base_class::erase_for( pred );
+ }
};
//@endcond
}
//@endcond
+
+ /// Clears the set (non-atomic, not thread-safe)
+ /**
+ The function unlink all items from the set.
+ The function is not atomic. It cleans up each bucket and then resets the item counter to zero.
+ If there are a thread that performs insertion while \p %clear() is working the result is undefined in general case:
+ <tt> empty() </tt> may return \p true but the set may contain item(s).
+ Therefore, \p %clear() may be used only for debugging purposes.
+
+ For each item the \p disposer is called after unlinking.
+ */
+ void clear()
+ {
+ m_List.erase_for( []( value_type const& val ) -> bool { return !node_traits::to_node_ptr( val )->is_dummy(); } );
+ m_ItemCounter.reset();
+ }
+
/// Checks if the set is empty
/**
Emptiness is checked by item counting: if item count is zero then the set is empty.