X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=cds%2Fcontainer%2Fsplit_list_set.h;h=f6a7831e993213c766dad735530c01debd6dd514;hb=65f7355b1eaa63b1a46d2172d10d45e400e6d862;hp=f67609e5f472b302dbb48565ef2c9bba49e43d71;hpb=305da3404a293d5e5c4e76eb6660eeda5a7d4413;p=libcds.git diff --git a/cds/container/split_list_set.h b/cds/container/split_list_set.h index f67609e5..f6a7831e 100644 --- a/cds/container/split_list_set.h +++ b/cds/container/split_list_set.h @@ -1,7 +1,7 @@ /* This file is a part of libcds - Concurrent Data Structures library - (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016 + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 Source code repo: http://github.com/khizmax/libcds/ Download: http://sourceforge.net/projects/libcds/files/ @@ -389,9 +389,9 @@ namespace cds { namespace container { Returns \p true if \p val is inserted into the set, \p false otherwise. */ template - bool insert( Q const& val ) + bool insert( Q&& val ) { - return insert_node( alloc_node( val )); + return insert_node( alloc_node( std::forward( val ))); } /// Inserts new node @@ -414,9 +414,9 @@ namespace cds { namespace container { synchronization. */ template - bool insert( Q const& val, Func f ) + bool insert( Q&& val, Func f ) { - scoped_node_ptr pNode( alloc_node( val )); + scoped_node_ptr pNode( alloc_node( std::forward( val ))); if ( base_class::insert( *pNode, [&f](node_type& node) { f( node.m_Value ) ; } )) { pNode.release(); @@ -457,7 +457,7 @@ namespace cds { namespace container { #endif upsert( Q&& val, bool bAllowInsert = true ) { - scoped_node_ptr pNode( alloc_node( val ) ); + scoped_node_ptr pNode( alloc_node( std::forward( val ))); auto bRet = base_class::upsert( *pNode, bAllowInsert ); @@ -514,9 +514,9 @@ namespace cds { namespace container { std::pair >::type #endif - update( Q const& val, Func func, bool bAllowInsert = true ) + update( Q&& val, Func func, bool bAllowInsert = true ) { - scoped_node_ptr pNode( alloc_node( val )); + scoped_node_ptr pNode( alloc_node( std::forward( val ))); auto bRet = base_class::update( *pNode, [&func, &val]( bool bNew, node_type& item, node_type const& /*val*/ ) { @@ -533,9 +533,9 @@ namespace cds { namespace container { std::is_same::value && is_iterable_list::value, std::pair >::type - update( Q const& val, Func func, bool bAllowInsert = true ) + update( Q&& val, Func func, bool bAllowInsert = true ) { - scoped_node_ptr pNode( alloc_node( val ) ); + scoped_node_ptr pNode( alloc_node( std::forward( val ))); auto bRet = base_class::update( *pNode, [&func]( node_type& item, node_type* old ) { @@ -626,6 +626,28 @@ namespace cds { namespace container { [&f](node_type& node) { f( node.m_Value ); } ); } + /// Deletes the item pointed by iterator \p iter (only for \p IterableList based set) + /** + Returns \p true if the operation is successful, \p false otherwise. + The function can return \p false if the node the iterator points to has already been deleted + by other thread. + + The function does not invalidate the iterator, it remains valid and can be used for further traversing. + + @note \p %erase_at() is supported only for \p %SplitListSet based on \p IterableList. + */ +#ifdef CDS_DOXYGEN_INVOKED + bool erase_at( iterator const& iter ) +#else + template + typename std::enable_if< std::is_same::value && is_iterable_list< ordered_list >::value, bool >::type + erase_at( Iterator const& iter ) +#endif + { + return base_class::erase_at( static_cast( iter )); + } + + /// Extracts the item with specified \p key /** \anchor cds_nonintrusive_SplitListSet_hp_extract The function searches an item with key equal to \p key, @@ -900,12 +922,6 @@ namespace cds { namespace container { using base_class::extract_; using base_class::get_; - template - static node_type * alloc_node( Q const& v ) - { - return cxx_node_allocator().New( v ); - } - template static node_type * alloc_node( Args&&... args ) { @@ -927,7 +943,7 @@ namespace cds { namespace container { typename std::enable_if< std::is_same::value && is_iterable_list< ordered_list >::value, iterator>::type find_iterator_( Q& val ) { - return iterator( base_class::find( val ) ); + return iterator( base_class::find( val )); } template @@ -943,7 +959,7 @@ namespace cds { namespace container { find_iterator_with_( Q& val, Less pred ) { CDS_UNUSED( pred ); - return iterator( base_class::find_with( val, typename maker::template predicate_wrapper::type() )); + return iterator( base_class::find_with( val, typename maker::template predicate_wrapper::type())); } struct node_disposer { @@ -959,7 +975,7 @@ namespace cds { namespace container { assert( pNode != nullptr ); scoped_node_ptr p( pNode ); - if ( base_class::insert( *pNode ) ) { + if ( base_class::insert( *pNode )) { p.release(); return true; }