return insert_at( head(), key, func );
}
- /// Ensures that the \p key exists in the list
+ /// Updates data by \p key
/**
- The operation performs inserting or changing data with lock-free manner.
+ The operation performs inserting or replacing the element with lock-free manner.
If the \p key not found in the list, then the new item created from \p key
- is inserted into the list. Otherwise, the functor \p func is called with the item found.
- The functor \p Func should be a function with signature:
- \code
- void func( bool bNew, value_type& item, const Q& val );
- \endcode
- or a functor:
+ will be inserted iff \p bAllowInsert is \p true.
+ Otherwise, if \p key is found, the functor \p func is called with item found.
+
+ The functor \p Func signature is:
\code
struct my_functor {
- void operator()( bool bNew, value_type& item, const Q& val );
+ void operator()( bool bNew, value_type& item, Q const& val );
};
\endcode
with arguments:
- \p bNew - \p true if the item has been inserted, \p false otherwise
- \p item - item of the list
- - \p val - argument \p key passed into the \p ensure function
+ - \p val - argument \p key passed into the \p %update() function
The functor may change non-key fields of the \p item; however, \p func must guarantee
that during changing no any other modifications could be made on this item by concurrent threads.
Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
\p second is true if new item has been added or \p false if the item with \p key
- already is in the list.
+ already exists.
@warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
*/
template <typename Q, typename Func>
+ std::pair<bool, bool> update( Q const& key, Func func, bool bAllowInsert = true )
+ {
+ return update_at( head(), key, func, bAllowInsert );
+ }
+ //@cond
+ // Deprecated, use update()
+ template <typename Q, typename Func>
std::pair<bool, bool> ensure( Q const& key, Func func )
{
- return ensure_at( head(), key, func );
+ return update( key, func );
}
+ //@endcond
/// Inserts data of type \p value_type constructed with <tt>std::forward<Args>(args)...</tt>
/**
return gp;
}
- /// Finds \p key
- /** \anchor cds_nonintrusive_MichaelList_hp_find_val
+ /// Checks whether the list contains \p key
+ /**
The function searches the item with key equal to \p key
- and returns \p true if it is found, and \p false otherwise
+ and returns \p true if it is found, and \p false otherwise.
*/
template <typename Q>
- bool find( Q const& key )
+ bool contains( Q const& key )
{
return find_at( head(), key, intrusive_key_comparator() );
}
+ //@cond
+ // Deprecated, use contains()
+ template <typename Q>
+ bool find( Q const& key )
+ {
+ return contains( key );
+ }
+ //@endcond
- /// Finds \p key using \p pred predicate for searching
+ /// Checks whether the list contains \p key using \p pred predicate for searching
/**
- The function is an analog of \ref cds_nonintrusive_MichaelList_hp_find_val "find(Q const&)"
- but \p pred is used for key comparing.
+ The function is an analog of <tt>contains( key )</tt> but \p pred is used for key comparing.
\p Less functor has the interface like \p std::less.
\p pred must imply the same element order as the comparator used for building the list.
*/
template <typename Q, typename Less>
- bool find_with( Q const& key, Less pred )
+ bool contains( Q const& key, Less pred )
{
CDS_UNUSED( pred );
return find_at( head(), key, typename maker::template less_wrapper<Less>::type() );
}
+ //@cond
+ // Deprecated, use contains()
+ template <typename Q, typename Less>
+ bool find_with( Q const& key, Less pred )
+ {
+ return contains( key, pred );
+ }
+ //@endcond
/// Finds \p key and perform an action with it
/** \anchor cds_nonintrusive_MichaelList_hp_find_func
}
template <typename Q, typename Func>
- std::pair<bool, bool> ensure_at( head_type& refHead, Q const& key, Func f )
+ std::pair<bool, bool> update_at( head_type& refHead, Q const& key, Func f, bool bAllowInsert )
{
scoped_node_ptr pNode( alloc_node( key ));
- std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode,
- [&f, &key](bool bNew, node_type& node, node_type&){ f( bNew, node_to_value(node), key ); });
+ std::pair<bool, bool> ret = base_class::update_at( refHead, *pNode,
+ [&f, &key](bool bNew, node_type& node, node_type&){ f( bNew, node_to_value(node), key );},
+ bAllowInsert );
if ( ret.first && ret.second )
pNode.release();