From 82c41f9cd6c72a53cdb7d50c948b4d489df835a0 Mon Sep 17 00:00:00 2001 From: khizmax Date: Tue, 18 Nov 2014 19:10:51 +0300 Subject: [PATCH] movable guarded_ptr: LazyList, MichaelList --- cds/container/impl/lazy_kvlist.h | 59 +++++++++-------- cds/container/impl/lazy_list.h | 59 +++++++++-------- cds/container/impl/michael_kvlist.h | 65 ++++++++++--------- cds/container/impl/michael_list.h | 59 +++++++++-------- cds/intrusive/impl/lazy_list.h | 58 +++++++++-------- cds/intrusive/impl/michael_list.h | 61 +++++++++-------- .../ordered_list/hdr_intrusive_lazy.h | 37 +++++------ .../ordered_list/hdr_intrusive_michael.h | 35 +++++----- tests/test-hdr/ordered_list/hdr_lazy.h | 34 +++++----- tests/test-hdr/ordered_list/hdr_lazy_kv.h | 34 +++++----- tests/test-hdr/ordered_list/hdr_michael.h | 34 +++++----- tests/test-hdr/ordered_list/hdr_michael_kv.h | 34 +++++----- 12 files changed, 309 insertions(+), 260 deletions(-) diff --git a/cds/container/impl/lazy_kvlist.h b/cds/container/impl/lazy_kvlist.h index 953b5bc1..e8b83f7a 100644 --- a/cds/container/impl/lazy_kvlist.h +++ b/cds/container/impl/lazy_kvlist.h @@ -118,7 +118,7 @@ namespace cds { namespace container { public: /// Guarded pointer - typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_map > guarded_ptr; + typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_map > guarded_ptr; protected: //@cond @@ -514,8 +514,8 @@ namespace cds { namespace container { /// Extracts the item from the list with specified \p key /** \anchor cds_nonintrusive_LazyKVList_hp_extract The function searches an item with key equal to \p key, - unlinks it from the list, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the list, and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. Note the compare functor should accept a parameter of type \p K that can be not the same as \p key_type. @@ -527,24 +527,26 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - theList.extract( gp, 5 ); - // Deal with gp - // ... - + ord_list::guarded_ptr gp( theList.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard and frees the item } \endcode */ template - bool extract( guarded_ptr& dest, K const& key ) + guarded_ptr extract( K const& key ) { - return extract_at( head(), dest.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Extracts the item from the list with comparing functor \p pred /** - The function is an analog of \ref cds_nonintrusive_LazyKVList_hp_extract "extract(guarded_ptr&, K const&)" + The function is an analog of \ref cds_nonintrusive_LazyKVList_hp_extract "extract(K const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref key_type and \p K @@ -552,10 +554,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool extract_with( guarded_ptr& dest, K const& key, Less pred ) + guarded_ptr extract_with( K const& key, Less pred ) { CDS_UNUSED( pred ); - return extract_at( head(), dest.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Finds the key \p key @@ -624,9 +628,8 @@ namespace cds { namespace container { /// Finds \p key and return the item found /** \anchor cds_nonintrusive_LazyKVList_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns the item found as a guarded pointer. + If \p key is not found the functions returns an empty \p guarded_ptr. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -636,8 +639,8 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - if ( theList.get( gp, 5 )) { + ord_list::guarded_ptr gp( theList.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -649,14 +652,16 @@ namespace cds { namespace container { should accept a parameter of type \p K that can be not the same as \p key_type. */ template - bool get( guarded_ptr& ptr, K const& key ) + guarded_ptr get( K const& key ) { - return get_at( head(), ptr.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Finds the key \p val and return the item found /** - The function is an analog of \ref cds_nonintrusive_LazyKVList_hp_get "get(guarded_ptr& ptr, K const&)" + The function is an analog of \ref cds_nonintrusive_LazyKVList_hp_get "get(K const&)" but \p pred is used for comparing the keys. \p Less functor has the semantics like \p std::less but should take arguments of type \ref key_type and \p K @@ -664,10 +669,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool get_with( guarded_ptr& ptr, K const& key, Less pred ) + guarded_ptr get_with( K const& key, Less pred ) { CDS_UNUSED( pred ); - return get_at( head(), ptr.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Checks if the list is empty @@ -753,9 +760,9 @@ namespace cds { namespace container { } template - bool extract_at( head_type& refHead, typename gc::Guard& dest, K const& key, Compare cmp ) + bool extract_at( head_type& refHead, typename guarded_ptr::native_guard& guard, K const& key, Compare cmp ) { - return base_class::extract_at( &refHead, dest, key, cmp ); + return base_class::extract_at( &refHead, guard, key, cmp ); } template @@ -784,7 +791,7 @@ namespace cds { namespace container { } template - bool get_at( head_type& refHead, typename gc::Guard& guard, K const& key, Compare cmp ) + bool get_at( head_type& refHead, typename guarded_ptr::native_guard& guard, K const& key, Compare cmp ) { return base_class::get_at( &refHead, guard, key, cmp ); } diff --git a/cds/container/impl/lazy_list.h b/cds/container/impl/lazy_list.h index c61f030a..be0cc0bc 100644 --- a/cds/container/impl/lazy_list.h +++ b/cds/container/impl/lazy_list.h @@ -125,7 +125,7 @@ namespace cds { namespace container { public: /// Guarded pointer - typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; + typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; private: //@cond @@ -490,8 +490,8 @@ namespace cds { namespace container { /// Extracts the item from the list with specified \p key /** \anchor cds_nonintrusive_LazyList_hp_extract The function searches an item with key equal to \p key, - unlinks it from the list, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the list, and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. @@ -503,24 +503,26 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - theList.extract( gp, 5 ); - // Deal with gp - // ... - + ord_list::guarded_ptr gp(theList.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard and frees the item } \endcode */ template - bool extract( guarded_ptr& dest, Q const& key ) + guarded_ptr extract( Q const& key ) { - return extract_at( head(), dest.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Extracts the item from the list with comparing functor \p pred /** - The function is an analog of \ref cds_nonintrusive_LazyList_hp_extract "extract(guarded_ptr&, Q const&)" + The function is an analog of \ref cds_nonintrusive_LazyList_hp_extract "extract(Q const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -528,10 +530,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool extract_with( guarded_ptr& dest, Q const& key, Less pred ) + guarded_ptr extract_with( Q const& key, Less pred ) { CDS_UNUSED( pred ); - return extract_at( head(), dest.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Finds the key \p key @@ -618,9 +622,8 @@ namespace cds { namespace container { /// Finds the key \p key and return the item found /** \anchor cds_nonintrusive_LazyList_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns the item found as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -630,8 +633,8 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - if ( theList.get( gp, 5 )) { + ord_list::guarded_ptr gp( theList.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -643,14 +646,16 @@ namespace cds { namespace container { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& key ) + guarded_ptr get( Q const& key ) { - return get_at( head(), ptr.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Finds the key \p key and return the item found /** - The function is an analog of \ref cds_nonintrusive_LazyList_hp_get "get( guarded_ptr& ptr, Q const&)" + The function is an analog of \ref cds_nonintrusive_LazyList_hp_get "get( Q const&)" but \p pred is used for comparing the keys. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -658,10 +663,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) + guarded_ptr get_with( Q const& key, Less pred ) { CDS_UNUSED( pred ); - return get_at( head(), ptr.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Checks whether the list is empty @@ -735,9 +742,9 @@ namespace cds { namespace container { } template - bool extract_at( head_type& refHead, typename gc::Guard& dest, Q const& key, Compare cmp ) + bool extract_at( head_type& refHead, typename guarded_ptr::native_guard& guard, Q const& key, Compare cmp ) { - return base_class::extract_at( &refHead, dest, key, cmp ); + return base_class::extract_at( &refHead, guard, key, cmp ); } template @@ -766,7 +773,7 @@ namespace cds { namespace container { } template - bool get_at( head_type& refHead, typename gc::Guard& guard, Q const& key, Compare cmp ) + bool get_at( head_type& refHead, typename guarded_ptr::native_guard& guard, Q const& key, Compare cmp ) { return base_class::get_at( &refHead, guard, key, cmp ); } diff --git a/cds/container/impl/michael_kvlist.h b/cds/container/impl/michael_kvlist.h index f0c766a6..a31103e4 100644 --- a/cds/container/impl/michael_kvlist.h +++ b/cds/container/impl/michael_kvlist.h @@ -121,7 +121,7 @@ namespace cds { namespace container { public: /// Guarded pointer - typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_map > guarded_ptr; + typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_map > guarded_ptr; protected: //@cond @@ -520,13 +520,13 @@ namespace cds { namespace container { /// Extracts the item from the list with specified \p key /** \anchor cds_nonintrusive_MichaelKVList_hp_extract The function searches an item with key equal to \p key, - unlinks it from the list, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the list, and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. Note the compare functor should accept a parameter of type \p K that can be not the same as \p key_type. - The \ref disposer specified in \p Traits class template parameter is called automatically - by garbage collector \p GC specified in class' template parameters when returned \ref guarded_ptr object + The \p disposer specified in \p Traits class template parameter is called automatically + by garbage collector \p GC specified in class' template parameters when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses the GC's guard that can be limited resource. @@ -536,24 +536,26 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - theList.extract( gp, 5 ); - // Deal with gp - // ... - + ord_list::guarded_ptr gp(theList.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard } \endcode */ template - bool extract( guarded_ptr& dest, K const& key ) + guarded_ptr extract( K const& key ) { - return extract_at( head(), dest.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Extracts the item from the list with comparing functor \p pred /** - The function is an analog of \ref cds_nonintrusive_MichaelKVList_hp_extract "extract(guarded_ptr&, K const&)" + The function is an analog of \ref cds_nonintrusive_MichaelKVList_hp_extract "extract(K const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref key_type and \p K @@ -561,10 +563,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool extract_with( guarded_ptr& dest, K const& key, Less pred ) + guarded_ptr extract_with( K const& key, Less pred ) { CDS_UNUSED( pred ); - return extract_at( head(), dest.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Finds the key \p key @@ -633,12 +637,11 @@ namespace cds { namespace container { /// Finds the \p key and return the item found /** \anchor cds_nonintrusive_MichaelKVList_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. - The \ref disposer specified in \p Traits class template parameter is called - by garbage collector \p GC automatically when returned \ref guarded_ptr object + The \p disposer specified in \p Traits class template parameter is called + by garbage collector \p GC automatically when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -648,8 +651,8 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - if ( theList.get( gp, 5 )) { + ord_list::guarded_ptr gp(theList.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -661,9 +664,11 @@ namespace cds { namespace container { should accept a parameter of type \p K that can be not the same as \p key_type. */ template - bool get( guarded_ptr& ptr, K const& key ) + guarded_ptr get( K const& key ) { - return get_at( head(), ptr.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Finds the \p key and return the item found @@ -676,10 +681,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool get_with( guarded_ptr& ptr, K const& key, Less pred ) + guarded_ptr get_with( K const& key, Less pred ) { CDS_UNUSED( pred ); - return get_at( head(), ptr.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Checks if the list is empty @@ -775,9 +782,9 @@ namespace cds { namespace container { return base_class::erase_at( refHead, key, cmp, [&f]( node_type const & node ){ f( const_cast(node.m_Data)); }); } template - bool extract_at( head_type& refHead, typename gc::Guard& dest, K const& key, Compare cmp ) + bool extract_at( head_type& refHead, typename guarded_ptr::native_guard& guard, K const& key, Compare cmp ) { - return base_class::extract_at( refHead, dest, key, cmp ); + return base_class::extract_at( refHead, guard, key, cmp ); } template @@ -793,7 +800,7 @@ namespace cds { namespace container { } template - bool get_at( head_type& refHead, typename gc::Guard& guard, K const& key, Compare cmp ) + bool get_at( head_type& refHead, typename guarded_ptr::native_guard& guard, K const& key, Compare cmp ) { return base_class::get_at( refHead, guard, key, cmp ); } diff --git a/cds/container/impl/michael_list.h b/cds/container/impl/michael_list.h index e4ac8e13..2420a334 100644 --- a/cds/container/impl/michael_list.h +++ b/cds/container/impl/michael_list.h @@ -121,7 +121,7 @@ namespace cds { namespace container { public: /// Guarded pointer - typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; + typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set > guarded_ptr; private: //@cond @@ -479,8 +479,8 @@ namespace cds { namespace container { /// Extracts the item from the list with specified \p key /** \anchor cds_nonintrusive_MichaelList_hp_extract The function searches an item with key equal to \p key, - unlinks it from the list, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the list, and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. @@ -492,24 +492,26 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - theList.extract( gp, 5 ); - // Deal with gp - // ... - + ord_list::guarded_ptr gp(theList.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard and frees the item } \endcode */ template - bool extract( guarded_ptr& dest, Q const& key ) + guarded_ptr extract( Q const& key ) { - return extract_at( head(), dest.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Extracts the item from the list with comparing functor \p pred /** - The function is an analog of \ref cds_nonintrusive_MichaelList_hp_extract "extract(guarded_ptr&, Q const&)" + The function is an analog of \ref cds_nonintrusive_MichaelList_hp_extract "extract(Q const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but it should accept arguments of type \p value_type and \p Q @@ -517,10 +519,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool extract_with( guarded_ptr& dest, Q const& key, Less pred ) + guarded_ptr extract_with( Q const& key, Less pred ) { CDS_UNUSED( pred ); - return extract_at( head(), dest.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + extract_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Finds \p key @@ -604,9 +608,8 @@ namespace cds { namespace container { /// Finds \p key and return the item found /** \anchor cds_nonintrusive_MichaelList_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -616,8 +619,8 @@ namespace cds { namespace container { ord_list theList; // ... { - ord_list::guarded_ptr gp; - if ( theList.get( gp, 5 )) { + ord_list::guarded_ptr gp(theList.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -629,14 +632,16 @@ namespace cds { namespace container { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& key ) + guarded_ptr get( Q const& key ) { - return get_at( head(), ptr.guard(), key, intrusive_key_comparator() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, intrusive_key_comparator() ); + return gp; } /// Finds \p key and return the item found /** - The function is an analog of \ref cds_nonintrusive_MichaelList_hp_get "get( guarded_ptr& ptr, Q const&)" + The function is an analog of \ref cds_nonintrusive_MichaelList_hp_get "get( Q const&)" but \p pred is used for comparing the keys. \p Less functor has the semantics like \p std::less but should accept arguments of type \p value_type and \p Q @@ -644,10 +649,12 @@ namespace cds { namespace container { \p pred must imply the same element order as the comparator used for building the list. */ template - bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) + guarded_ptr get_with( Q const& key, Less pred ) { CDS_UNUSED( pred ); - return get_at( head(), ptr.guard(), key, typename maker::template less_wrapper::type() ); + guarded_ptr gp; + get_at( head(), gp.guard(), key, typename maker::template less_wrapper::type() ); + return gp; } /// Check if the list is empty @@ -720,9 +727,9 @@ namespace cds { namespace container { } template - bool extract_at( head_type& refHead, typename gc::Guard& dest, Q const& key, Compare cmp ) + bool extract_at( head_type& refHead, typename guarded_ptr::native_guard& guard, Q const& key, Compare cmp ) { - return base_class::extract_at( refHead, dest, key, cmp ); + return base_class::extract_at( refHead, guard, key, cmp ); } template @@ -751,7 +758,7 @@ namespace cds { namespace container { } template - bool get_at( head_type& refHead, typename gc::Guard& guard, Q const& key, Compare cmp ) + bool get_at( head_type& refHead, typename guarded_ptr::native_guard& guard, Q const& key, Compare cmp ) { return base_class::get_at( refHead, guard, key, cmp ); } diff --git a/cds/intrusive/impl/lazy_list.h b/cds/intrusive/impl/lazy_list.h index eda3714e..f2c9eaf6 100644 --- a/cds/intrusive/impl/lazy_list.h +++ b/cds/intrusive/impl/lazy_list.h @@ -177,7 +177,7 @@ namespace cds { namespace intrusive { typedef typename traits::item_counter item_counter ; ///< Item counting policy used typedef typename traits::memory_model memory_model; ///< C++ memory ordering (see \p lazy_list::traits::memory_model) - typedef cds::gc::guarded_ptr< gc, value_type > guarded_ptr; ///< Guarded pointer + typedef typename gc::template guarded_ptr< value_type > guarded_ptr; ///< Guarded pointer //@cond // Rebind traits (split-list support) @@ -634,13 +634,13 @@ namespace cds { namespace intrusive { /// Extracts the item from the list with specified \p key /** \anchor cds_intrusive_LazyList_hp_extract The function searches an item with key equal to \p key, - unlinks it from the list, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the list, and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. The \ref disposer specified in \p Traits class template parameter is called automatically - by garbage collector \p GC specified in class' template parameters when returned \ref guarded_ptr object + by garbage collector \p GC specified in class' template parameters when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses the GC's guard that can be limited resource. @@ -650,8 +650,7 @@ namespace cds { namespace intrusive { ord_list theList; // ... { - ord_list::guarded_ptr gp; - theList.extract( gp, 5 ); + ord_list::guarded_ptr gp( theList.extract( 5 )); // Deal with gp // ... @@ -660,14 +659,16 @@ namespace cds { namespace intrusive { \endcode */ template - bool extract( guarded_ptr& dest, Q const& key ) + guarded_ptr extract( Q const& key ) { - return extract_at( &m_Head, dest.guard(), key, key_comparator() ); + guarded_ptr gp; + extract_at( &m_Head, gp.guard(), key, key_comparator() ); + return gp; } /// Extracts the item from the list with comparing functor \p pred /** - The function is an analog of \ref cds_intrusive_LazyList_hp_extract "extract(guarded_ptr&, Q const&)" + The function is an analog of \ref cds_intrusive_LazyList_hp_extract "extract(Q const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -675,9 +676,11 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the list. */ template - bool extract_with( guarded_ptr& dest, Q const& key, Less pred ) + guarded_ptr extract_with( Q const& key, Less pred ) { - return extract_at( &m_Head, dest.guard(), key, cds::opt::details::make_comparator_from_less() ); + guarded_ptr gp; + extract_at( &m_Head, gp.guard(), key, cds::opt::details::make_comparator_from_less() ); + return gp; } /// Finds the key \p key @@ -756,12 +759,11 @@ namespace cds { namespace intrusive { /// Finds \p key and return the item found /** \anchor cds_intrusive_LazyList_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns an guarded pointer to it. + If \p key is not found the function returns an empty guarded pointer. The \ref disposer specified in \p Traits class template parameter is called - by garbage collector \p GC automatically when returned \ref guarded_ptr object + by garbage collector \p GC automatically when returned \p guarded_ptr object will be destroyed or released. @note Each \p guarded_ptr object uses one GC's guard which can be limited resource. @@ -771,8 +773,8 @@ namespace cds { namespace intrusive { ord_list theList; // ... { - ord_list::guarded_ptr gp; - if ( theList.get( gp, 5 )) { + ord_list::guarded_ptr gp(theList.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -784,14 +786,16 @@ namespace cds { namespace intrusive { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& key ) + guarded_ptr get( Q const& key ) { - return get_at( &m_Head, ptr.guard(), key, key_comparator() ); + guarded_ptr gp; + get_at( &m_Head, gp.guard(), key, key_comparator() ); + return gp; } /// Finds \p key and return the item found /** - The function is an analog of \ref cds_intrusive_LazyList_hp_get "get( guarded_ptr& ptr, Q const&)" + The function is an analog of \ref cds_intrusive_LazyList_hp_get "get( Q const&)" but \p pred is used for comparing the keys. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -799,9 +803,11 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the list. */ template - bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) + guarded_ptr get_with( Q const& key, Less pred ) { - return get_at( &m_Head, ptr.guard(), key, cds::opt::details::make_comparator_from_less() ); + guarded_ptr gp; + get_at( &m_Head, gp.guard(), key, cds::opt::details::make_comparator_from_less() ); + return gp; } /// Clears the list @@ -1031,11 +1037,11 @@ namespace cds { namespace intrusive { } template - bool extract_at( node_type * pHead, typename gc::Guard& gp, const Q& val, Compare cmp ) + bool extract_at( node_type * pHead, typename guarded_ptr::native_guard& gp, const Q& val, Compare cmp ) { position pos; if ( erase_at( pHead, val, cmp, [](value_type const &){}, pos )) { - gp.assign( pos.guards.template get(position::guard_current_item) ); + gp.set( pos.guards.template get(position::guard_current_item) ); return true; } return false; @@ -1071,7 +1077,7 @@ namespace cds { namespace intrusive { } template - bool get_at( node_type * pHead, typename gc::Guard& gp, Q const& val, Compare cmp ) + bool get_at( node_type * pHead, typename guarded_ptr::native_guard& gp, Q const& val, Compare cmp ) { position pos; @@ -1080,7 +1086,7 @@ namespace cds { namespace intrusive { && !pos.pCur->is_marked() && cmp( *node_traits::to_value_ptr( *pos.pCur ), val ) == 0 ) { - gp.assign( pos.guards.template get( position::guard_current_item )); + gp.set( pos.guards.template get( position::guard_current_item )); return true; } return false; diff --git a/cds/intrusive/impl/michael_list.h b/cds/intrusive/impl/michael_list.h index 8c2eadf2..5f039362 100644 --- a/cds/intrusive/impl/michael_list.h +++ b/cds/intrusive/impl/michael_list.h @@ -181,7 +181,7 @@ namespace cds { namespace intrusive { typedef typename traits::item_counter item_counter; ///< Item counting policy used typedef typename traits::memory_model memory_model; ///< Memory ordering. See cds::opt::memory_model option - typedef cds::gc::guarded_ptr< gc, value_type > guarded_ptr; ///< Guarded pointer + typedef typename gc::template guarded_ptr< value_type > guarded_ptr; ///< Guarded pointer //@cond // Rebind traits (split-list support) @@ -633,8 +633,8 @@ namespace cds { namespace intrusive { /// Extracts the item from the list with specified \p key /** \anchor cds_intrusive_MichaelList_hp_extract The function searches an item with key equal to \p key, - unlinks it from the list, and returns it in \p dest parameter. - If the item with key equal to \p key is not found the function returns \p false. + unlinks it from the list, and returns it as \p guarded_ptr. + If \p key is not found returns an empty guarded pointer. Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type. @@ -648,24 +648,26 @@ namespace cds { namespace intrusive { ord_list theList; // ... { - ord_list::guarded_ptr gp; - theList.extract( gp, 5 ); - // Deal with gp - // ... - + ord_list::guarded_ptr gp(theList.extract( 5 )); + if ( gp ) { + // Deal with gp + // ... + } // Destructor of gp releases internal HP guard } \endcode */ template - bool extract( guarded_ptr& dest, Q const& key ) + guarded_ptr extract( Q const& key ) { - return extract_at( m_pHead, dest.guard(), key, key_comparator() ); + guarded_ptr gp; + extract_at( m_pHead, gp.guard(), key, key_comparator() ); + return gp; } /// Extracts the item using compare functor \p pred /** - The function is an analog of \ref cds_intrusive_MichaelList_hp_extract "extract(guarded_ptr&, Q const&)" + The function is an analog of \ref cds_intrusive_MichaelList_hp_extract "extract(Q const&)" but \p pred predicate is used for key comparing. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -673,9 +675,11 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the list. */ template - bool extract_with( guarded_ptr& dest, Q const& key, Less pred ) + guarded_ptr extract_with( Q const& key, Less pred ) { - return extract_at( m_pHead, dest.guard(), key, cds::opt::details::make_comparator_from_less() ); + guarded_ptr gp; + extract_at( m_pHead, gp.guard(), key, cds::opt::details::make_comparator_from_less() ); + return gp; } /// Finds \p key in the list @@ -759,9 +763,8 @@ namespace cds { namespace intrusive { /// Finds the \p key and return the item found /** \anchor cds_intrusive_MichaelList_hp_get The function searches the item with key equal to \p key - and assigns the item found to guarded pointer \p ptr. - The function returns \p true if \p key is found, and \p false otherwise. - If \p key is not found the \p ptr parameter is not changed. + and returns it as \p guarded_ptr. + If \p key is not found the function returns an empty guarded pointer. The \ref disposer specified in \p Traits class template parameter is called by garbage collector \p GC automatically when returned \ref guarded_ptr object @@ -774,8 +777,8 @@ namespace cds { namespace intrusive { ord_list theList; // ... { - ord_list::guarded_ptr gp; - if ( theList.get( gp, 5 )) { + ord_list::guarded_ptr gp(theList.get( 5 )); + if ( gp ) { // Deal with gp //... } @@ -787,14 +790,16 @@ namespace cds { namespace intrusive { should accept a parameter of type \p Q that can be not the same as \p value_type. */ template - bool get( guarded_ptr& ptr, Q const& key ) + guarded_ptr get( Q const& key ) { - return get_at( m_pHead, ptr.guard(), key, key_comparator() ); + guarded_ptr gp; + get_at( m_pHead, gp.guard(), key, key_comparator() ); + return gp; } /// Finds the \p key and return the item found /** - The function is an analog of \ref cds_intrusive_MichaelList_hp_get "get( guarded_ptr& ptr, Q const&)" + The function is an analog of \ref cds_intrusive_MichaelList_hp_get "get( Q const&)" but \p pred is used for comparing the keys. \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q @@ -802,9 +807,11 @@ namespace cds { namespace intrusive { \p pred must imply the same element order as the comparator used for building the list. */ template - bool get_with( guarded_ptr& ptr, Q const& key, Less pred ) + guarded_ptr get_with( Q const& key, Less pred ) { - return get_at( m_pHead, ptr.guard(), key, cds::opt::details::make_comparator_from_less() ); + guarded_ptr gp; + get_at( m_pHead, gp.guard(), key, cds::opt::details::make_comparator_from_less() ); + return gp; } /// Clears the list @@ -992,13 +999,13 @@ namespace cds { namespace intrusive { } template - bool extract_at( atomic_node_ptr& refHead, typename gc::Guard& dest, Q const& val, Compare cmp ) + bool extract_at( atomic_node_ptr& refHead, typename guarded_ptr::native_guard& dest, Q const& val, Compare cmp ) { position pos; back_off bkoff; while ( search( refHead, val, pos, cmp )) { if ( unlink_node( pos ) ) { - dest.assign( pos.guards.template get( position::guard_current_item ) ); + dest.set( pos.guards.template get( position::guard_current_item ) ); --m_ItemCounter; return true; } @@ -1027,11 +1034,11 @@ namespace cds { namespace intrusive { } template - bool get_at( atomic_node_ptr& refHead, typename gc::Guard& guard, Q const& val, Compare cmp ) + bool get_at( atomic_node_ptr& refHead, typename guarded_ptr::native_guard& guard, Q const& val, Compare cmp ) { position pos; if ( search( refHead, val, pos, cmp )) { - guard.assign( pos.guards.template get( position::guard_current_item )); + guard.set( pos.guards.template get( position::guard_current_item )); return true; } return false; diff --git a/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h b/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h index 4d9a3b34..a07c6b55 100644 --- a/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h +++ b/tests/test-hdr/ordered_list/hdr_intrusive_lazy.h @@ -439,7 +439,6 @@ namespace ordlist { static int const nLimit = 20; typename OrdList::value_type arrItem[nLimit]; - { int a[nLimit]; for (int i = 0; i < nLimit; ++i) @@ -456,28 +455,27 @@ namespace ordlist { CPPUNIT_ASSERT( l.insert( arrItem[i] ) ); for ( int i=0; i < nLimit; ++i ) { - CPPUNIT_ASSERT( l.get( gp, arrItem[i].nKey )); + gp = l.get( arrItem[i].nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( l.extract( gp, arrItem[i].nKey )); + gp = l.extract( arrItem[i].nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( !l.get( gp, arrItem[i].nKey )); + gp = l.get( arrItem[i].nKey ); + CPPUNIT_ASSERT( !gp ); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract( gp, arrItem[i].nKey )); + CPPUNIT_ASSERT( !l.extract( arrItem[i].nKey )); CPPUNIT_ASSERT( gp.empty()); } CPPUNIT_ASSERT( l.empty() ); - CPPUNIT_ASSERT( !l.get( gp, nLimit/2 )); - CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract( gp, nLimit/2 )); - CPPUNIT_ASSERT( gp.empty()); + CPPUNIT_ASSERT( !l.get( nLimit/2 )); + CPPUNIT_ASSERT( !l.extract( nLimit/2 )); // Apply retired pointer OrdList::gc::force_dispose(); @@ -488,27 +486,28 @@ namespace ordlist { for ( int i=0; i < nLimit; ++i ) { other_item itm( arrItem[i].nKey ); - CPPUNIT_ASSERT( l.get_with( gp, itm, other_less() )); + gp = l.get_with( itm, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( l.extract_with( gp, itm, other_less() )); + gp = l.extract_with( itm, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( !l.get_with( gp, itm, other_less() )); + gp = l.get_with( itm, other_less() ); + CPPUNIT_ASSERT( !gp ); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract_with( gp, itm, other_less() )); + CPPUNIT_ASSERT( !l.extract_with( itm, other_less() )); CPPUNIT_ASSERT( gp.empty()); } CPPUNIT_ASSERT( l.empty() ); - CPPUNIT_ASSERT( !l.get_with( gp, other_item(nLimit/2), other_less() )); + CPPUNIT_ASSERT( !l.get_with( other_item(nLimit/2), other_less() )); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract_with( gp, other_item(nLimit/2), other_less() )); + CPPUNIT_ASSERT( !l.extract_with( other_item(nLimit/2), other_less() )); CPPUNIT_ASSERT( gp.empty()); // Apply retired pointer diff --git a/tests/test-hdr/ordered_list/hdr_intrusive_michael.h b/tests/test-hdr/ordered_list/hdr_intrusive_michael.h index bbf23856..63ff419a 100644 --- a/tests/test-hdr/ordered_list/hdr_intrusive_michael.h +++ b/tests/test-hdr/ordered_list/hdr_intrusive_michael.h @@ -457,7 +457,6 @@ namespace ordlist { static int const nLimit = 20; typename OrdList::value_type arrItem[nLimit]; - { int a[nLimit]; for (int i = 0; i < nLimit; ++i) @@ -474,27 +473,28 @@ namespace ordlist { CPPUNIT_ASSERT( l.insert( arrItem[i] ) ); for ( int i=0; i < nLimit; ++i ) { - CPPUNIT_ASSERT( l.get( gp, arrItem[i].nKey )); + gp = l.get( arrItem[i].nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( l.extract( gp, arrItem[i].nKey )); + gp = l.extract( arrItem[i].nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( !l.get( gp, arrItem[i].nKey )); + gp = l.get( arrItem[i].nKey ); + CPPUNIT_ASSERT( !gp ); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract( gp, arrItem[i].nKey )); + CPPUNIT_ASSERT( !l.extract( arrItem[i].nKey )); CPPUNIT_ASSERT( gp.empty()); } CPPUNIT_ASSERT( l.empty() ); - CPPUNIT_ASSERT( !l.get( gp, nLimit/2 )); + CPPUNIT_ASSERT( !l.get( nLimit/2 )); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract( gp, nLimit/2 )); + CPPUNIT_ASSERT( !l.extract( nLimit/2 )); CPPUNIT_ASSERT( gp.empty()); // Apply retired pointer @@ -506,27 +506,28 @@ namespace ordlist { for ( int i=0; i < nLimit; ++i ) { other_item itm( arrItem[i].nKey ); - CPPUNIT_ASSERT( l.get_with( gp, itm, other_less() )); + gp = l.get_with( itm, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( l.extract_with( gp, itm, other_less() )); + gp = l.extract_with( itm, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_ASSERT( gp->nKey == arrItem[i].nKey ); CPPUNIT_ASSERT( gp->nVal == arrItem[i].nVal ); - gp.release(); - CPPUNIT_ASSERT( !l.get_with( gp, itm, other_less() )); + gp = l.get_with( itm, other_less() ); + CPPUNIT_ASSERT( !gp ); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract_with( gp, itm, other_less() )); + CPPUNIT_ASSERT( !l.extract_with( itm, other_less() )); CPPUNIT_ASSERT( gp.empty()); } CPPUNIT_ASSERT( l.empty() ); - CPPUNIT_ASSERT( !l.get_with( gp, other_item(nLimit/2), other_less() )); + CPPUNIT_ASSERT( !l.get_with( other_item(nLimit/2), other_less() )); CPPUNIT_ASSERT( gp.empty()); - CPPUNIT_ASSERT( !l.extract_with( gp, other_item(nLimit/2), other_less() )); + CPPUNIT_ASSERT( !l.extract_with( other_item(nLimit/2), other_less() )); CPPUNIT_ASSERT( gp.empty()); // Apply retired pointer diff --git a/tests/test-hdr/ordered_list/hdr_lazy.h b/tests/test-hdr/ordered_list/hdr_lazy.h index 9fc3d5d7..b472bdb6 100644 --- a/tests/test-hdr/ordered_list/hdr_lazy.h +++ b/tests/test-hdr/ordered_list/hdr_lazy.h @@ -469,27 +469,28 @@ namespace ordlist { for ( int i = 0; i < nLimit; ++i ) { int nKey = arr[i]; - CPPUNIT_ASSERT( l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract(gp, nKey)); + gp = l.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, nKey)); + CPPUNIT_CHECK( !l.extract( nKey)); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get(gp, arr[0])); + CPPUNIT_CHECK( !l.get(arr[0])); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, arr[0])); + CPPUNIT_CHECK( !l.extract( arr[0])); CPPUNIT_CHECK( gp.empty()); } @@ -502,27 +503,28 @@ namespace ordlist { int nKey = arr[i]; other_item key( nKey ); - CPPUNIT_ASSERT( l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract_with(gp, key, other_less())); + gp = l.extract_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, key, other_less())); + CPPUNIT_CHECK( !l.extract_with( key, other_less())); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get_with(gp, other_item(arr[0]), other_less())); + CPPUNIT_CHECK( !l.get_with(other_item(arr[0]), other_less())); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, other_item(arr[0]), other_less())); + CPPUNIT_CHECK( !l.extract_with( other_item(arr[0]), other_less())); CPPUNIT_CHECK( gp.empty()); } diff --git a/tests/test-hdr/ordered_list/hdr_lazy_kv.h b/tests/test-hdr/ordered_list/hdr_lazy_kv.h index bbe85da1..27f63969 100644 --- a/tests/test-hdr/ordered_list/hdr_lazy_kv.h +++ b/tests/test-hdr/ordered_list/hdr_lazy_kv.h @@ -297,27 +297,28 @@ namespace ordlist { for ( int i = 0; i < nLimit; ++i ) { int nKey = arr[i]; - CPPUNIT_ASSERT( l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract(gp, nKey)); + gp = l.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, nKey)); + CPPUNIT_CHECK( !l.extract( nKey)); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get(gp, arr[0])); + CPPUNIT_CHECK( !l.get(arr[0])); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, arr[0])); + CPPUNIT_CHECK( !l.extract( arr[0])); CPPUNIT_CHECK( gp.empty()); } @@ -330,27 +331,28 @@ namespace ordlist { int nKey = arr[i]; other_key key = float(nKey + 0.3); - CPPUNIT_ASSERT( l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract_with(gp, key, other_less())); + gp = l.extract_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, key, other_less())); + CPPUNIT_CHECK( !l.extract_with( key, other_less())); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get_with(gp, 3.4f, other_less())); + CPPUNIT_CHECK( !l.get_with(3.4f, other_less())); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, 3.4f, other_less())); + CPPUNIT_CHECK( !l.extract_with( 3.4f, other_less())); CPPUNIT_CHECK( gp.empty()); } } diff --git a/tests/test-hdr/ordered_list/hdr_michael.h b/tests/test-hdr/ordered_list/hdr_michael.h index 5ce56fc0..4f3665df 100644 --- a/tests/test-hdr/ordered_list/hdr_michael.h +++ b/tests/test-hdr/ordered_list/hdr_michael.h @@ -470,27 +470,28 @@ namespace ordlist { for ( int i = 0; i < nLimit; ++i ) { int nKey = arr[i]; - CPPUNIT_ASSERT( l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract(gp, nKey)); + gp = l.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, nKey)); + CPPUNIT_CHECK( !l.extract( nKey)); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get(gp, arr[0])); + CPPUNIT_CHECK( !l.get(arr[0])); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, arr[0])); + CPPUNIT_CHECK( !l.extract( arr[0])); CPPUNIT_CHECK( gp.empty()); } @@ -503,27 +504,28 @@ namespace ordlist { int nKey = arr[i]; other_item key( nKey ); - CPPUNIT_ASSERT( l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract_with(gp, key, other_less())); + gp = l.extract_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->nKey == nKey ); CPPUNIT_CHECK( gp->nVal == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, key, other_less())); + CPPUNIT_CHECK( !l.extract_with( key, other_less())); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get_with(gp, other_item(arr[0]), other_less())); + CPPUNIT_CHECK( !l.get_with(other_item(arr[0]), other_less())); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, other_item(arr[0]), other_less())); + CPPUNIT_CHECK( !l.extract_with( other_item(arr[0]), other_less())); CPPUNIT_CHECK( gp.empty()); } } diff --git a/tests/test-hdr/ordered_list/hdr_michael_kv.h b/tests/test-hdr/ordered_list/hdr_michael_kv.h index 68e9b921..c2b12e33 100644 --- a/tests/test-hdr/ordered_list/hdr_michael_kv.h +++ b/tests/test-hdr/ordered_list/hdr_michael_kv.h @@ -307,27 +307,28 @@ namespace ordlist { for ( int i = 0; i < nLimit; ++i ) { int nKey = arr[i]; - CPPUNIT_ASSERT( l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract(gp, nKey)); + gp = l.extract( nKey ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get(gp, nKey)); + gp = l.get( nKey ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, nKey)); + CPPUNIT_CHECK( !l.extract( nKey)); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get(gp, arr[0])); + CPPUNIT_CHECK( !l.get(arr[0])); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract( gp, arr[0])); + CPPUNIT_CHECK( !l.extract( arr[0])); CPPUNIT_CHECK( gp.empty()); } @@ -340,27 +341,28 @@ namespace ordlist { int nKey = arr[i]; other_key key = float(nKey + 0.3); - CPPUNIT_ASSERT( l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey * 2 ); - gp.release(); - CPPUNIT_ASSERT( l.extract_with(gp, key, other_less())); + gp = l.extract_with( key, other_less() ); + CPPUNIT_ASSERT( gp ); CPPUNIT_ASSERT( !gp.empty()); CPPUNIT_CHECK( gp->first == nKey ); CPPUNIT_CHECK( gp->second.m_val == nKey*2 ); - gp.release(); - CPPUNIT_CHECK( !l.get_with(gp, key, other_less())); + gp = l.get_with( key, other_less() ); + CPPUNIT_CHECK( !gp ); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, key, other_less())); + CPPUNIT_CHECK( !l.extract_with( key, other_less())); CPPUNIT_CHECK( gp.empty()); } CPPUNIT_ASSERT( l.empty()); - CPPUNIT_CHECK( !l.get_with(gp, 3.4f, other_less())); + CPPUNIT_CHECK( !l.get_with( 3.4f, other_less())); CPPUNIT_CHECK( gp.empty()); - CPPUNIT_CHECK( !l.extract_with( gp, 3.4f, other_less())); + CPPUNIT_CHECK( !l.extract_with( 3.4f, other_less())); CPPUNIT_CHECK( gp.empty()); } } -- 2.34.1