Implement find_with in nonintrusive and k/v lists.
authorMike Krinkin <krinkin.m.u@gmail.com>
Sat, 28 Mar 2015 12:03:04 +0000 (15:03 +0300)
committerMike Krinkin <krinkin.m.u@gmail.com>
Sat, 28 Mar 2015 12:22:28 +0000 (15:22 +0300)
Implementation is pretty straightforward.

cds/container/details/make_lazy_kvlist.h
cds/container/details/make_lazy_list.h
cds/container/lazy_kvlist_nogc.h
cds/container/lazy_list_nogc.h

index f27f44602a2890a5be6463dcea954d3634b40feb..ff3ea15c2242507319ea0f1dc8cbc8df7bc3dba3 100644 (file)
@@ -71,6 +71,11 @@ namespace cds { namespace container {
                 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, key_field_accessor >    type;
             };
 
+            template <typename Equal>
+            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<gc> >  hook;
index 215d7ce467b800afbafa4732f13259e2de9cb697..578e484c14fd6b7d97ebd02667c336c40c7e8256 100644 (file)
@@ -60,6 +60,11 @@ namespace cds { namespace container {
                 typedef cds::details::compare_wrapper< node_type, cds::opt::details::make_comparator_from_less<Less>, value_accessor > type;
             };
 
+            template <typename Equal>
+            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<gc> >  hook;
index 3f8c67b0740b2b7f8b6c448c590241f9db68d829..d582180bd16dfb70be3355775c941ca92a30dc58 100644 (file)
@@ -426,6 +426,19 @@ namespace cds { namespace container {
             return node_to_iterator( find_at( head(), key, typename maker::template less_wrapper<Less>::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 Q, typename Equal, bool Sort = traits::sort>
+        typename std::enable_if<!Sort, iterator>::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<Equal>::type() ) );
+        }
+
         /// Check if the list is empty
         bool empty() const
         {
index 497c88c813ca57eb311013bdcc1f9bfbff8c1c32..88860169c5c63fcd0e384b25506f886e37ccdaab 100644 (file)
@@ -333,6 +333,19 @@ namespace cds { namespace container {
             return node_to_iterator( find_at( head(), key, typename maker::template less_wrapper<Less>::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 Q, typename Equal, bool Sort = traits::sort>
+        typename std::enable_if<!Sort, iterator>::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<Equal>::type() ));
+        }
+
         /// Check if the list is empty
         bool empty() const
         {