From 9ed62853e81a0791963c49a078867e26aade3120 Mon Sep 17 00:00:00 2001 From: Mike Krinkin Date: Sat, 28 Mar 2015 15:03:04 +0300 Subject: [PATCH] Implement find_with in nonintrusive and k/v lists. Implementation is pretty straightforward. --- cds/container/details/make_lazy_kvlist.h | 5 +++++ cds/container/details/make_lazy_list.h | 5 +++++ cds/container/lazy_kvlist_nogc.h | 13 +++++++++++++ cds/container/lazy_list_nogc.h | 13 +++++++++++++ 4 files changed, 36 insertions(+) diff --git a/cds/container/details/make_lazy_kvlist.h b/cds/container/details/make_lazy_kvlist.h index f27f4460..ff3ea15c 100644 --- a/cds/container/details/make_lazy_kvlist.h +++ b/cds/container/details/make_lazy_kvlist.h @@ -71,6 +71,11 @@ namespace cds { namespace container { typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less, key_field_accessor > type; }; + template + struct equal_to_wrapper { + typedef cds::details::predicate_wrapper< node_type, Equal, key_field_accessor > type; + }; + struct intrusive_traits: public original_type_traits { typedef intrusive::lazy_list::base_hook< opt::gc > hook; diff --git a/cds/container/details/make_lazy_list.h b/cds/container/details/make_lazy_list.h index 215d7ce4..578e484c 100644 --- a/cds/container/details/make_lazy_list.h +++ b/cds/container/details/make_lazy_list.h @@ -60,6 +60,11 @@ namespace cds { namespace container { typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less, value_accessor > type; }; + template + struct equal_to_wrapper { + typedef cds::details::predicate_wrapper< node_type, Equal, value_accessor > type; + }; + struct intrusive_traits: public original_type_traits { typedef intrusive::lazy_list::base_hook< opt::gc > hook; diff --git a/cds/container/lazy_kvlist_nogc.h b/cds/container/lazy_kvlist_nogc.h index 3f8c67b0..d582180b 100644 --- a/cds/container/lazy_kvlist_nogc.h +++ b/cds/container/lazy_kvlist_nogc.h @@ -426,6 +426,19 @@ namespace cds { namespace container { return node_to_iterator( find_at( head(), key, typename maker::template less_wrapper::type() ) ); } + /// Finds the key \p val using \p equal predicate for searching + /** + The function is an analog of \ref cds_nonintrusive_LazyKVList_nogc_find "find(Q const&)" + but \p equal is used for key comparing. + \p Equal functor has the interface like \p std::equal_to. + */ + template + typename std::enable_if::type find_with( Q const& key, Equal equal ) + { + CDS_UNUSED( equal ); + return node_to_iterator( find_at( head(), key, typename maker::template equal_to_wrapper::type() ) ); + } + /// Check if the list is empty bool empty() const { diff --git a/cds/container/lazy_list_nogc.h b/cds/container/lazy_list_nogc.h index 497c88c8..88860169 100644 --- a/cds/container/lazy_list_nogc.h +++ b/cds/container/lazy_list_nogc.h @@ -333,6 +333,19 @@ namespace cds { namespace container { return node_to_iterator( find_at( head(), key, typename maker::template less_wrapper::type() )); } + /// Finds the key \p val using \p equal predicate for searching + /** + The function is an analog of \ref cds_nonintrusive_LazyList_nogc_find "find(Q const&)" + but \p pred is used for key comparing. + \p Equal functor has the interface like \p std::equal_to. + */ + template + typename std::enable_if::type find_with( Q const& key, Equal equal ) + { + CDS_UNUSED( equal ); + return node_to_iterator( find_at( head(), key, typename maker::template equal_to_wrapper::type() )); + } + /// Check if the list is empty bool empty() const { -- 2.34.1