return insert_with_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 (note that in this case the \p key_type should be
- copy-constructible from type \p K).
- Otherwise, the functor \p func is called with item found.
- The functor \p Func may be a function with signature:
- \code
- void func( bool bNew, value_type& item );
- \endcode
- or a functor:
+ will be inserted iff \p bAllowInsert is \p true.
+ (note that in this case the \ref key_type should be constructible from type \p K).
+ 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 );
};
\endcode
-
with arguments:
- \p bNew - \p true if the item has been inserted, \p false otherwise
- - \p item - item of the list
+ - \p item - the item found or inserted
The functor may change any fields of the \p item.second of \p mapped_type;
however, \p func must guarantee that during changing no any other modifications
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 K, typename Func>
- std::pair<bool, bool> ensure( const K& key, Func f )
+ std::pair<bool, bool> update( K const& key, Func f, bool bAllowInsert = true )
+ {
+ return update_at( head(), key, f, bAllowInsert );
+ }
+ //@cond
+ // Deprecated
+ template <typename K, typename Func>
+ std::pair<bool, bool> ensure( K const& key, Func f )
{
- return ensure_at( head(), key, f );
+ return update( key, f, true );
}
+ //@endcond
/// Inserts a new node using move semantics
/**
return gp;
}
- /// Finds the key \p key
- /** \anchor cds_nonintrusive_MichaelKVList_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
+ template <typename Q>
+ bool find( Q const& key )
+ {
+ return contains( key );
+ }
+ //@endcond
- /// Finds the key \p val using \p pred predicate for searching
+ /// Checks whether the map contains \p key using \p pred predicate for searching
/**
- The function is an analog of \ref cds_nonintrusive_MichaelKVList_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.
+ \p Less 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
+ template <typename Q, typename Less>
+ bool find_with( Q const& key, Less pred )
+ {
+ CDS_UNUSED( pred );
+ return contains( key, pred );
+ }
+ //@endcond
/// Finds the key \p key and performs an action with it
/** \anchor cds_nonintrusive_MichaelKVList_hp_find_func
}
template <typename K, typename Func>
- std::pair<bool, bool> ensure_at( head_type& refHead, const K& key, Func f )
+ std::pair<bool, bool> update_at( head_type& refHead, const K& key, Func f, bool bAllowInsert )
{
scoped_node_ptr pNode( alloc_node( key ));
- std::pair<bool, bool> ret = base_class::ensure_at( refHead, *pNode,
- [&f]( bool bNew, node_type& node, node_type& ){ f( bNew, node.m_Data ); });
+ std::pair<bool, bool> ret = base_class::update_at( refHead, *pNode,
+ [&f]( bool bNew, node_type& node, node_type& ){ f( bNew, node.m_Data ); },
+ bAllowInsert );
if ( ret.first && ret.second )
pNode.release();