Refactored Set_DelOdd MT-test
[libcds.git] / cds / container / impl / michael_list.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_CONTAINER_IMPL_MICHAEL_LIST_H
4 #define CDSLIB_CONTAINER_IMPL_MICHAEL_LIST_H
5
6 #include <memory>
7 #include <cds/container/details/guarded_ptr_cast.h>
8
9 namespace cds { namespace container {
10
11     /// Michael's ordered list
12     /** @ingroup cds_nonintrusive_list
13         \anchor cds_nonintrusive_MichaelList_gc
14
15         Usually, ordered single-linked list is used as a building block for the hash table implementation.
16         The complexity of searching is <tt>O(N)</tt>, where \p N is the item count in the list, not in the
17         hash table.
18
19         Source:
20         - [2002] Maged Michael "High performance dynamic lock-free hash tables and list-based sets"
21
22         This class is non-intrusive version of cds::intrusive::MichaelList class
23
24         Template arguments:
25         - \p GC - garbage collector used
26         - \p T - type stored in the list. The type must be default- and copy-constructible.
27         - \p Traits - type traits, default is \p michael_list::traits
28
29         Unlike standard container, this implementation does not divide type \p T into key and value part and
30         may be used as a main building block for hash set algorithms.
31         The key is a function (or a part) of type \p T, and this function is specified by <tt>Traits::compare</tt> functor
32         or <tt>Traits::less</tt> predicate
33
34         MichaelKVList is a key-value version of Michael's non-intrusive list that is closer to the C++ std library approach.
35
36         It is possible to declare option-based list with cds::container::michael_list::make_traits metafunction istead of \p Traits template
37         argument. For example, the following traits-based declaration of gc::HP Michael's list
38         \code
39         #include <cds/container/michael_list_hp.h>
40         // Declare comparator for the item
41         struct my_compare {
42             int operator ()( int i1, int i2 )
43             {
44                 return i1 - i2;
45             }
46         };
47
48         // Declare traits
49         struct my_traits: public cds::container::michael_list::traits
50         {
51             typedef my_compare compare;
52         };
53
54         // Declare traits-based list
55         typedef cds::container::MichaelList< cds::gc::HP, int, my_traits >     traits_based_list;
56         \endcode
57
58         is equivalent for the following option-based list
59         \code
60         #include <cds/container/michael_list_hp.h>
61
62         // my_compare is the same
63
64         // Declare option-based list
65         typedef cds::container::MichaelList< cds::gc::HP, int,
66             typename cds::container::michael_list::make_traits<
67                 cds::container::opt::compare< my_compare >     // item comparator option
68             >::type
69         >     option_based_list;
70         \endcode
71
72         \par Usage
73         There are different specializations of this template for each garbage collecting schema used.
74         You should include appropriate .h-file depending on GC you are using:
75         - for gc::HP: \code #include <cds/container/michael_list_hp.h> \endcode
76         - for gc::DHP: \code #include <cds/container/michael_list_dhp.h> \endcode
77         - for \ref cds_urcu_desc "RCU": \code #include <cds/container/michael_list_rcu.h> \endcode
78         - for gc::nogc: \code #include <cds/container/michael_list_nogc.h> \endcode
79     */
80     template <
81         typename GC,
82         typename T,
83 #ifdef CDS_DOXYGEN_INVOKED
84         typename Traits = michael_list::traits
85 #else
86         typename Traits
87 #endif
88     >
89     class MichaelList:
90 #ifdef CDS_DOXYGEN_INVOKED
91         protected intrusive::MichaelList< GC, T, Traits >
92 #else
93         protected details::make_michael_list< GC, T, Traits >::type
94 #endif
95     {
96         //@cond
97         typedef details::make_michael_list< GC, T, Traits > maker;
98         typedef typename maker::type base_class;
99         //@endcond
100
101     public:
102         typedef T value_type;   ///< Type of value stored in the list
103         typedef Traits traits;  ///< List traits
104
105         typedef typename base_class::gc             gc;             ///< Garbage collector used
106         typedef typename base_class::back_off       back_off;       ///< Back-off strategy used
107         typedef typename maker::allocator_type      allocator_type; ///< Allocator type used for allocate/deallocate the nodes
108         typedef typename base_class::item_counter   item_counter;   ///< Item counting policy used
109         typedef typename maker::key_comparator      key_comparator; ///< key comparison functor
110         typedef typename base_class::memory_model   memory_model;   ///< Memory ordering. See \p cds::opt::memory_model option
111
112     protected:
113         //@cond
114         typedef typename base_class::value_type      node_type;
115         typedef typename maker::cxx_allocator        cxx_allocator;
116         typedef typename maker::node_deallocator     node_deallocator;
117         typedef typename maker::intrusive_traits::compare intrusive_key_comparator;
118
119         typedef typename base_class::atomic_node_ptr head_type;
120         //@endcond
121
122     public:
123         /// Guarded pointer
124         typedef typename gc::template guarded_ptr< node_type, value_type, details::guarded_ptr_cast_set<node_type, value_type> > guarded_ptr;
125
126     private:
127         //@cond
128         static value_type& node_to_value( node_type& n )
129         {
130             return n.m_Value;
131         }
132         static value_type const& node_to_value( node_type const& n )
133         {
134             return n.m_Value;
135         }
136         //@endcond
137
138     protected:
139         //@cond
140         template <typename Q>
141         static node_type * alloc_node( Q const& v )
142         {
143             return cxx_allocator().New( v );
144         }
145
146         template <typename... Args>
147         static node_type * alloc_node( Args&&... args )
148         {
149             return cxx_allocator().MoveNew( std::forward<Args>(args)... );
150         }
151
152         static void free_node( node_type * pNode )
153         {
154             cxx_allocator().Delete( pNode );
155         }
156
157         struct node_disposer {
158             void operator()( node_type * pNode )
159             {
160                 free_node( pNode );
161             }
162         };
163         typedef std::unique_ptr< node_type, node_disposer > scoped_node_ptr;
164
165         head_type& head()
166         {
167             return base_class::m_pHead;
168         }
169
170         head_type const& head() const
171         {
172             return base_class::m_pHead;
173         }
174         //@endcond
175
176     protected:
177         //@cond
178         template <bool IsConst>
179         class iterator_type: protected base_class::template iterator_type<IsConst>
180         {
181             typedef typename base_class::template iterator_type<IsConst>    iterator_base;
182
183             iterator_type( head_type const& pNode )
184                 : iterator_base( pNode )
185             {}
186
187             friend class MichaelList;
188
189         public:
190             typedef typename cds::details::make_const_type<value_type, IsConst>::pointer   value_ptr;
191             typedef typename cds::details::make_const_type<value_type, IsConst>::reference value_ref;
192
193             iterator_type()
194             {}
195
196             iterator_type( iterator_type const& src )
197                 : iterator_base( src )
198             {}
199
200             value_ptr operator ->() const
201             {
202                 typename iterator_base::value_ptr p = iterator_base::operator ->();
203                 return p ? &(p->m_Value) : nullptr;
204             }
205
206             value_ref operator *() const
207             {
208                 return (iterator_base::operator *()).m_Value;
209             }
210
211             /// Pre-increment
212             iterator_type& operator ++()
213             {
214                 iterator_base::operator ++();
215                 return *this;
216             }
217
218             template <bool C>
219             bool operator ==(iterator_type<C> const& i ) const
220             {
221                 return iterator_base::operator ==(i);
222             }
223             template <bool C>
224             bool operator !=(iterator_type<C> const& i ) const
225             {
226                 return iterator_base::operator !=(i);
227             }
228         };
229         //@endcond
230
231     public:
232         /// Forward iterator
233         /**
234             The forward iterator for Michael's list has some features:
235             - it has no post-increment operator
236             - to protect the value, the iterator contains a GC-specific guard + another guard is required locally for increment operator.
237               For some GC (\p gc::HP), a guard is limited resource per thread, so an exception (or assertion) "no free guard"
238               may be thrown if a limit of guard count per thread is exceeded.
239             - The iterator cannot be moved across thread boundary since it contains GC's guard that is thread-private GC data.
240             - Iterator ensures thread-safety even if you delete the item that iterator points to. However, in case of concurrent
241               deleting operations it is no guarantee that you iterate all item in the list.
242
243             Therefore, the use of iterators in concurrent environment is not good idea. Use the iterator on the concurrent container
244             for debug purpose only.
245         */
246         typedef iterator_type<false>    iterator;
247
248         /// Const forward iterator
249         /**
250             For iterator's features and requirements see \ref iterator
251         */
252         typedef iterator_type<true>     const_iterator;
253
254         /// Returns a forward iterator addressing the first element in a list
255         /**
256             For empty list \code begin() == end() \endcode
257         */
258         iterator begin()
259         {
260             return iterator( head() );
261         }
262
263         /// Returns an iterator that addresses the location succeeding the last element in a list
264         /**
265             Do not use the value returned by <tt>end</tt> function to access any item.
266             Internally, <tt>end</tt> returning value equals to \p nullptr.
267
268             The returned value can be used only to control reaching the end of the list.
269             For empty list \code begin() == end() \endcode
270         */
271         iterator end()
272         {
273             return iterator();
274         }
275
276         /// Returns a forward const iterator addressing the first element in a list
277         //@{
278         const_iterator begin() const
279         {
280             return const_iterator( head() );
281         }
282         const_iterator cbegin() const
283         {
284             return const_iterator( head() );
285         }
286         //@}
287
288         /// Returns an const iterator that addresses the location succeeding the last element in a list
289         //@{
290         const_iterator end() const
291         {
292             return const_iterator();
293         }
294         const_iterator cend() const
295         {
296             return const_iterator();
297         }
298         //@}
299
300     public:
301         /// Default constructor
302         /**
303             Initialize empty list
304         */
305         MichaelList()
306         {}
307
308         /// List destructor
309         /**
310             Clears the list
311         */
312         ~MichaelList()
313         {
314             clear();
315         }
316
317         /// Inserts new node
318         /**
319             The function creates a node with copy of \p val value
320             and then inserts the node created into the list.
321
322             The type \p Q should contain least the complete key of the node.
323             The object of \ref value_type should be constructible from \p val of type \p Q.
324             In trivial case, \p Q is equal to \ref value_type.
325
326             Returns \p true if inserting successful, \p false otherwise.
327         */
328         template <typename Q>
329         bool insert( Q const& val )
330         {
331             return insert_at( head(), val );
332         }
333
334         /// Inserts new node
335         /**
336             This function inserts new node with default-constructed value and then it calls
337             \p func functor with signature
338             \code void func( value_type& itemValue ) ;\endcode
339
340             The argument \p itemValue of user-defined functor \p func is the reference
341             to the list's item inserted. User-defined functor \p func should guarantee that during changing
342             item's value no any other changes could be made on this list's item by concurrent threads.
343             The user-defined functor is called only if inserting is success.
344
345             The type \p Q should contain the complete key of the node.
346             The object of \p value_type should be constructible from \p key of type \p Q.
347
348             The function allows to split creating of new item into two part:
349             - create item from \p key with initializing key-fields only;
350             - insert new item into the list;
351             - if inserting is successful, initialize non-key fields of item by calling \p func functor
352
353             The method can be useful if complete initialization of object of \p value_type is heavyweight and
354             it is preferable that the initialization should be completed only if inserting is successful.
355
356             @warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
357         */
358         template <typename Q, typename Func>
359         bool insert( Q const& key, Func func )
360         {
361             return insert_at( head(), key, func );
362         }
363
364         /// Updates data by \p key
365         /**
366             The operation performs inserting or replacing the element with lock-free manner.
367
368             If the \p key not found in the list, then the new item created from \p key
369             will be inserted iff \p bAllowInsert is \p true.
370             Otherwise, if \p key is found, the functor \p func is called with item found.
371
372             The functor \p Func signature is:
373             \code
374                 struct my_functor {
375                     void operator()( bool bNew, value_type& item, Q const& val );
376                 };
377             \endcode
378
379             with arguments:
380             - \p bNew - \p true if the item has been inserted, \p false otherwise
381             - \p item - item of the list
382             - \p val - argument \p key passed into the \p %update() function
383
384             The functor may change non-key fields of the \p item; however, \p func must guarantee
385             that during changing no any other modifications could be made on this item by concurrent threads.
386
387             Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
388             \p second is true if new item has been added or \p false if the item with \p key
389             already exists.
390
391             @warning See \ref cds_intrusive_item_creating "insert item troubleshooting"
392         */
393         template <typename Q, typename Func>
394         std::pair<bool, bool> update( Q const& key, Func func, bool bAllowInsert = true )
395         {
396             return update_at( head(), key, func, bAllowInsert );
397         }
398         //@cond
399         template <typename Q, typename Func>
400         CDS_DEPRECATED("ensure() is deprecated, use update()")
401         std::pair<bool, bool> ensure( Q const& key, Func func )
402         {
403             return update( key, func );
404         }
405         //@endcond
406
407         /// Inserts data of type \p value_type constructed with <tt>std::forward<Args>(args)...</tt>
408         /**
409             Returns \p true if inserting successful, \p false otherwise.
410         */
411         template <typename... Args>
412         bool emplace( Args&&... args )
413         {
414             return emplace_at( head(), std::forward<Args>(args)... );
415         }
416
417         /// Delete \p key from the list
418         /** \anchor cds_nonintrusive_MichealList_hp_erase_val
419             Since the key of MichaelList's item type \p value_type is not explicitly specified,
420             template parameter \p Q sould contain the complete key to search in the list.
421             The list item comparator should be able to compare the type \p value_type
422             and the type \p Q.
423
424             Return \p true if key is found and deleted, \p false otherwise
425         */
426         template <typename Q>
427         bool erase( Q const& key )
428         {
429             return erase_at( head(), key, intrusive_key_comparator(), [](value_type const&){} );
430         }
431
432         /// Deletes the item from the list using \p pred predicate for searching
433         /**
434             The function is an analog of \ref cds_nonintrusive_MichealList_hp_erase_val "erase(Q const&)"
435             but \p pred is used for key comparing.
436             \p Less functor has the interface like \p std::less.
437             \p pred must imply the same element order as the comparator used for building the list.
438         */
439         template <typename Q, typename Less>
440         bool erase_with( Q const& key, Less pred )
441         {
442             CDS_UNUSED( pred );
443             return erase_at( head(), key, typename maker::template less_wrapper<Less>::type(), [](value_type const&){} );
444         }
445
446         /// Deletes \p key from the list
447         /** \anchor cds_nonintrusive_MichaelList_hp_erase_func
448             The function searches an item with key \p key, calls \p f functor with item found
449             and deletes it. If \p key is not found, the functor is not called.
450
451             The functor \p Func interface:
452             \code
453             struct extractor {
454                 void operator()(const value_type& val) { ... }
455             };
456             \endcode
457
458             Since the key of MichaelList's item type \p value_type is not explicitly specified,
459             template parameter \p Q should contain the complete key to search in the list.
460             The list item comparator should be able to compare the type \p value_type of list item
461             and the type \p Q.
462
463             Return \p true if key is found and deleted, \p false otherwise
464         */
465         template <typename Q, typename Func>
466         bool erase( Q const& key, Func f )
467         {
468             return erase_at( head(), key, intrusive_key_comparator(), f );
469         }
470
471         /// Deletes the item from the list using \p pred predicate for searching
472         /**
473             The function is an analog of \ref cds_nonintrusive_MichaelList_hp_erase_func "erase(Q const&, Func)"
474             but \p pred is used for key comparing.
475             \p Less functor has the interface like \p std::less.
476             \p pred must imply the same element order as the comparator used for building the list.
477         */
478         template <typename Q, typename Less, typename Func>
479         bool erase_with( Q const& key, Less pred, Func f )
480         {
481             CDS_UNUSED( pred );
482             return erase_at( head(), key, typename maker::template less_wrapper<Less>::type(), f );
483         }
484
485         /// Extracts the item from the list with specified \p key
486         /** \anchor cds_nonintrusive_MichaelList_hp_extract
487             The function searches an item with key equal to \p key,
488             unlinks it from the list, and returns it as \p guarded_ptr.
489             If \p key is not found the function returns an empty guarded pointer.
490
491             Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type.
492
493             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
494
495             Usage:
496             \code
497             typedef cds::container::MichaelList< cds::gc::HP, foo, my_traits >  ord_list;
498             ord_list theList;
499             // ...
500             {
501                 ord_list::guarded_ptr gp(theList.extract( 5 ));
502                 if ( gp ) {
503                     // Deal with gp
504                     // ...
505                 }
506                 // Destructor of gp releases internal HP guard and frees the item
507             }
508             \endcode
509         */
510         template <typename Q>
511         guarded_ptr extract( Q const& key )
512         {
513             guarded_ptr gp;
514             extract_at( head(), gp.guard(), key, intrusive_key_comparator() );
515             return gp;
516         }
517
518         /// Extracts the item from the list with comparing functor \p pred
519         /**
520             The function is an analog of \ref cds_nonintrusive_MichaelList_hp_extract "extract(Q const&)"
521             but \p pred predicate is used for key comparing.
522
523             \p Less functor has the semantics like \p std::less but it should accept arguments of type \p value_type and \p Q
524             in any order.
525             \p pred must imply the same element order as the comparator used for building the list.
526         */
527         template <typename Q, typename Less>
528         guarded_ptr extract_with( Q const& key, Less pred )
529         {
530             CDS_UNUSED( pred );
531             guarded_ptr gp;
532             extract_at( head(), gp.guard(), key, typename maker::template less_wrapper<Less>::type() );
533             return gp;
534         }
535
536         /// Checks whether the list contains \p key
537         /**
538             The function searches the item with key equal to \p key
539             and returns \p true if it is found, and \p false otherwise.
540         */
541         template <typename Q>
542         bool contains( Q const& key )
543         {
544             return find_at( head(), key, intrusive_key_comparator() );
545         }
546         //@cond
547         // Deprecated, use contains()
548         template <typename Q>
549         bool find( Q const& key )
550         {
551             return contains( key );
552         }
553         //@endcond
554
555         /// Checks whether the list contains \p key using \p pred predicate for searching
556         /**
557             The function is an analog of <tt>contains( key )</tt> but \p pred is used for key comparing.
558             \p Less functor has the interface like \p std::less.
559             \p pred must imply the same element order as the comparator used for building the list.
560         */
561         template <typename Q, typename Less>
562         bool contains( Q const& key, Less pred )
563         {
564             CDS_UNUSED( pred );
565             return find_at( head(), key, typename maker::template less_wrapper<Less>::type() );
566         }
567         //@cond
568         // Deprecated, use contains()
569         template <typename Q, typename Less>
570         bool find_with( Q const& key, Less pred )
571         {
572             return contains( key, pred );
573         }
574         //@endcond
575
576         /// Finds \p key and perform an action with it
577         /** \anchor cds_nonintrusive_MichaelList_hp_find_func
578             The function searches an item with key equal to \p key and calls the functor \p f for the item found.
579             The interface of \p Func functor is:
580             \code
581             struct functor {
582                 void operator()( value_type& item, Q& key );
583             };
584             \endcode
585             where \p item is the item found, \p key is the <tt>find</tt> function argument.
586
587             The functor may change non-key fields of \p item. Note that the function is only guarantee
588             that \p item cannot be deleted during functor is executing.
589             The function does not serialize simultaneous access to the list \p item. If such access is
590             possible you must provide your own synchronization schema to exclude unsafe item modifications.
591
592             The function returns \p true if \p key is found, \p false otherwise.
593         */
594         template <typename Q, typename Func>
595         bool find( Q& key, Func f )
596         {
597             return find_at( head(), key, intrusive_key_comparator(), f );
598         }
599         //@cond
600         template <typename Q, typename Func>
601         bool find( Q const& key, Func f )
602         {
603             return find_at( head(), key, intrusive_key_comparator(), f );
604         }
605         //@endcond
606
607         /// Finds \p key using \p pred predicate for searching
608         /**
609             The function is an analog of \ref cds_nonintrusive_MichaelList_hp_find_func "find(Q&, Func)"
610             but \p pred is used for key comparing.
611             \p Less functor has the interface like \p std::less.
612             \p pred must imply the same element order as the comparator used for building the list.
613         */
614         template <typename Q, typename Less, typename Func>
615         bool find_with( Q& key, Less pred, Func f )
616         {
617             CDS_UNUSED( pred );
618             return find_at( head(), key, typename maker::template less_wrapper<Less>::type(), f );
619         }
620         //@cond
621         template <typename Q, typename Less, typename Func>
622         bool find_with( Q const& key, Less pred, Func f )
623         {
624             CDS_UNUSED( pred );
625             return find_at( head(), key, typename maker::template less_wrapper<Less>::type(), f );
626         }
627         //@endcond
628
629         /// Finds \p key and return the item found
630         /** \anchor cds_nonintrusive_MichaelList_hp_get
631             The function searches the item with key equal to \p key
632             and returns it as \p guarded_ptr.
633             If \p key is not found the function returns an empty guarded pointer.
634
635             @note Each \p guarded_ptr object uses one GC's guard which can be limited resource.
636
637             Usage:
638             \code
639             typedef cds::container::MichaelList< cds::gc::HP, foo, my_traits >  ord_list;
640             ord_list theList;
641             // ...
642             {
643                 ord_list::guarded_ptr gp(theList.get( 5 ));
644                 if ( gp ) {
645                     // Deal with gp
646                     //...
647                 }
648                 // Destructor of guarded_ptr releases internal HP guard and frees the item
649             }
650             \endcode
651
652             Note the compare functor specified for class \p Traits template parameter
653             should accept a parameter of type \p Q that can be not the same as \p value_type.
654         */
655         template <typename Q>
656         guarded_ptr get( Q const& key )
657         {
658             guarded_ptr gp;
659             get_at( head(), gp.guard(), key, intrusive_key_comparator() );
660             return gp;
661         }
662
663         /// Finds \p key and return the item found
664         /**
665             The function is an analog of \ref cds_nonintrusive_MichaelList_hp_get "get( Q const&)"
666             but \p pred is used for comparing the keys.
667
668             \p Less functor has the semantics like \p std::less but should accept arguments of type \p value_type and \p Q
669             in any order.
670             \p pred must imply the same element order as the comparator used for building the list.
671         */
672         template <typename Q, typename Less>
673         guarded_ptr get_with( Q const& key, Less pred )
674         {
675             CDS_UNUSED( pred );
676             guarded_ptr gp;
677             get_at( head(), gp.guard(), key, typename maker::template less_wrapper<Less>::type() );
678             return gp;
679         }
680
681         /// Check if the list is empty
682         bool empty() const
683         {
684             return base_class::empty();
685         }
686
687         /// Returns list's item count
688         /**
689             The value returned depends on item counter provided by \p Traits. For \p atomicity::empty_item_counter,
690             this function always returns 0.
691
692             @note Even if you use real item counter and it returns 0, this fact is not mean that the list
693             is empty. To check list emptyness use \p empty() method.
694         */
695         size_t size() const
696         {
697             return base_class::size();
698         }
699
700         /// Clears the list
701         void clear()
702         {
703             base_class::clear();
704         }
705
706     protected:
707         //@cond
708         bool insert_node_at( head_type& refHead, node_type * pNode )
709         {
710             assert( pNode );
711             scoped_node_ptr p(pNode);
712             if ( base_class::insert_at( refHead, *pNode )) {
713                 p.release();
714                 return true;
715             }
716
717             return false;
718         }
719
720         template <typename Q>
721         bool insert_at( head_type& refHead, Q const& val )
722         {
723             return insert_node_at( refHead, alloc_node( val ));
724         }
725
726         template <typename Q, typename Func>
727         bool insert_at( head_type& refHead, Q const& key, Func f )
728         {
729             scoped_node_ptr pNode( alloc_node( key ));
730
731             if ( base_class::insert_at( refHead, *pNode, [&f]( node_type& node ) { f( node_to_value(node) ); } )) {
732                 pNode.release();
733                 return true;
734             }
735             return false;
736         }
737
738         template <typename... Args>
739         bool emplace_at( head_type& refHead, Args&&... args )
740         {
741             return insert_node_at( refHead, alloc_node( std::forward<Args>(args) ... ));
742         }
743
744         template <typename Q, typename Compare, typename Func>
745         bool erase_at( head_type& refHead, Q const& key, Compare cmp, Func f )
746         {
747             return base_class::erase_at( refHead, key, cmp, [&f](node_type const& node){ f( node_to_value(node) ); } );
748         }
749
750         template <typename Q, typename Compare>
751         bool extract_at( head_type& refHead, typename guarded_ptr::native_guard& guard, Q const& key, Compare cmp )
752         {
753             return base_class::extract_at( refHead, guard, key, cmp );
754         }
755
756         template <typename Q, typename Func>
757         std::pair<bool, bool> update_at( head_type& refHead, Q const& key, Func f, bool bAllowInsert )
758         {
759             scoped_node_ptr pNode( alloc_node( key ));
760
761             std::pair<bool, bool> ret = base_class::update_at( refHead, *pNode,
762                 [&f, &key](bool bNew, node_type& node, node_type&){ f( bNew, node_to_value(node), key );},
763                 bAllowInsert );
764             if ( ret.first && ret.second )
765                 pNode.release();
766
767             return ret;
768         }
769
770         template <typename Q, typename Compare>
771         bool find_at( head_type& refHead, Q const& key, Compare cmp )
772         {
773             return base_class::find_at( refHead, key, cmp );
774         }
775
776         template <typename Q, typename Compare, typename Func>
777         bool find_at( head_type& refHead, Q& val, Compare cmp, Func f )
778         {
779             return base_class::find_at( refHead, val, cmp, [&f](node_type& node, Q& v){ f( node_to_value(node), v ); });
780         }
781
782         template <typename Q, typename Compare>
783         bool get_at( head_type& refHead, typename guarded_ptr::native_guard& guard, Q const& key, Compare cmp )
784         {
785             return base_class::get_at( refHead, guard, key, cmp );
786         }
787
788         //@endcond
789     };
790
791 }}  // namespace cds::container
792
793 #endif  // #ifndef CDSLIB_CONTAINER_IMPL_MICHAEL_LIST_H