Fixed -Wshadow warnings
[libcds.git] / cds / container / skip_list_set_rcu.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
15     * Redistributions in binary form must reproduce the above copyright notice,
16       this list of conditions and the following disclaimer in the documentation
17       and/or other materials provided with the distribution.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27     OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef CDSLIB_CONTAINER_SKIP_LIST_SET_RCU_H
32 #define CDSLIB_CONTAINER_SKIP_LIST_SET_RCU_H
33
34 #include <cds/intrusive/skip_list_rcu.h>
35 #include <cds/container/details/make_skip_list_set.h>
36
37 namespace cds { namespace container {
38
39     /// Lock-free skip-list set (template specialization for \ref cds_urcu_desc "RCU")
40     /** @ingroup cds_nonintrusive_set
41         \anchor cds_nonintrusive_SkipListSet_rcu
42
43         The implementation of well-known probabilistic data structure called skip-list
44         invented by W.Pugh in his papers:
45             - [1989] W.Pugh Skip Lists: A Probabilistic Alternative to Balanced Trees
46             - [1990] W.Pugh A Skip List Cookbook
47
48         A skip-list is a probabilistic data structure that provides expected logarithmic
49         time search without the need of rebalance. The skip-list is a collection of sorted
50         linked list. Nodes are ordered by key. Each node is linked into a subset of the lists.
51         Each list has a level, ranging from 0 to 32. The bottom-level list contains
52         all the nodes, and each higher-level list is a sublist of the lower-level lists.
53         Each node is created with a random top level (with a random height), and belongs
54         to all lists up to that level. The probability that a node has the height 1 is 1/2.
55         The probability that a node has the height N is 1/2 ** N (more precisely,
56         the distribution depends on an random generator provided, but our generators
57         have this property).
58
59         The lock-free variant of skip-list is implemented according to book
60             - [2008] M.Herlihy, N.Shavit "The Art of Multiprocessor Programming",
61                 chapter 14.4 "A Lock-Free Concurrent Skiplist"
62
63         Template arguments:
64         - \p RCU - one of \ref cds_urcu_gc "RCU type".
65         - \p T - type to be stored in the list.
66         - \p Traits - set traits, default is skip_list::traits for explanation.
67
68         It is possible to declare option-based list with cds::container::skip_list::make_traits metafunction istead of \p Traits template
69         argument.
70         Template argument list \p Options of cds::container::skip_list::make_traits metafunction are:
71         - opt::compare - key comparison functor. No default functor is provided.
72             If the option is not specified, the opt::less is used.
73         - opt::less - specifies binary predicate used for key comparison. Default is \p std::less<T>.
74         - opt::item_counter - the type of item counting feature. Default is \ref atomicity::empty_item_counter that is no item counting.
75         - opt::memory_model - C++ memory ordering model. Can be opt::v::relaxed_ordering (relaxed memory model, the default)
76             or opt::v::sequential_consistent (sequentially consisnent memory model).
77         - skip_list::random_level_generator - random level generator. Can be \p skip_list::xor_shift, \p skip_list::turbo or
78             user-provided one. See \p skip_list::random_level_generator option description for explanation.
79             Default is \p skip_list::turbo32.
80         - opt::allocator - allocator for skip-list node. Default is \ref CDS_DEFAULT_ALLOCATOR.
81         - opt::back_off - back-off strategy used. If the option is not specified, the cds::backoff::Default is used.
82         - opt::stat - internal statistics. Available types: skip_list::stat, skip_list::empty_stat (the default)
83         - opt::rcu_check_deadlock - a deadlock checking policy. Default is opt::v::rcu_throw_deadlock
84
85         @note Before including <tt><cds/container/skip_list_set_rcu.h></tt> you should include appropriate RCU header file,
86         see \ref cds_urcu_gc "RCU type" for list of existing RCU class and corresponding header files.
87
88         <b>Iterators</b>
89
90         The class supports a forward iterator (\ref iterator and \ref const_iterator).
91         The iteration is ordered.
92
93         You may iterate over skip-list set items only under RCU lock.
94         Only in this case the iterator is thread-safe since
95         while RCU is locked any set's item cannot be reclaimed.
96
97         The requirement of RCU lock during iterating means that deletion of the elements (i.e. \ref erase)
98         is not possible.
99
100         @warning The iterator object cannot be passed between threads
101
102         Example how to use skip-list set iterators:
103         \code
104         // First, you should include the header for RCU type you have chosen
105         #include <cds/urcu/general_buffered.h>
106         #include <cds/container/skip_list_set_rcu.h>
107
108         typedef cds::urcu::gc< cds::urcu::general_buffered<> > rcu_type;
109
110         struct Foo {
111             // ...
112         };
113
114         // Traits for your skip-list.
115         // At least, you should define cds::opt::less or cds::opt::compare for Foo struct
116         struct my_traits: public cds::continer::skip_list::traits
117         {
118             // ...
119         };
120         typedef cds::container::SkipListSet< rcu_type, Foo, my_traits > my_skiplist_set;
121
122         my_skiplist_set theSet;
123
124         // ...
125
126         // Begin iteration
127         {
128             // Apply RCU locking manually
129             typename rcu_type::scoped_lock sl;
130
131             for ( auto it = theList.begin(); it != theList.end(); ++it ) {
132                 // ...
133             }
134
135             // rcu_type::scoped_lock destructor releases RCU lock implicitly
136         }
137         \endcode
138
139         \warning Due to concurrent nature of skip-list set it is not guarantee that you can iterate
140         all elements in the set: any concurrent deletion can exclude the element
141         pointed by the iterator from the set, and your iteration can be terminated
142         before end of the set. Therefore, such iteration is more suitable for debugging purposes
143
144         The iterator class supports the following minimalistic interface:
145         \code
146         struct iterator {
147             // Default ctor
148             iterator();
149
150             // Copy ctor
151             iterator( iterator const& s);
152
153             value_type * operator ->() const;
154             value_type& operator *() const;
155
156             // Pre-increment
157             iterator& operator ++();
158
159             // Copy assignment
160             iterator& operator = (const iterator& src);
161
162             bool operator ==(iterator const& i ) const;
163             bool operator !=(iterator const& i ) const;
164         };
165         \endcode
166         Note, the iterator object returned by \ref end, \p cend member functions points to \p nullptr and should not be dereferenced.
167     */
168     template <
169         typename RCU,
170         typename T,
171 #ifdef CDS_DOXYGEN_INVOKED
172         typename Traits = skip_list::traits
173 #else
174         typename Traits
175 #endif
176     >
177     class SkipListSet< cds::urcu::gc< RCU >, T, Traits >:
178 #ifdef CDS_DOXYGEN_INVOKED
179         protected intrusive::SkipListSet< cds::urcu::gc< RCU >, T, Traits >
180 #else
181         protected details::make_skip_list_set< cds::urcu::gc< RCU >, T, Traits >::type
182 #endif
183     {
184         //@cond
185         typedef details::make_skip_list_set< cds::urcu::gc< RCU >, T, Traits >    maker;
186         typedef typename maker::type base_class;
187         //@endcond
188     public:
189         typedef typename base_class::gc gc  ; ///< Garbage collector used
190         typedef T       value_type  ;   ///< Value type stored in the set
191         typedef Traits  traits     ;   ///< Options specified
192
193         typedef typename base_class::back_off       back_off        ;   ///< Back-off strategy used
194         typedef typename traits::allocator         allocator_type  ;   ///< Allocator type used for allocate/deallocate the skip-list nodes
195         typedef typename base_class::item_counter   item_counter    ;   ///< Item counting policy used
196         typedef typename maker::key_comparator      key_comparator  ;   ///< key compare functor
197         typedef typename base_class::memory_model   memory_model    ;   ///< Memory ordering. See cds::opt::memory_model option
198         typedef typename traits::random_level_generator random_level_generator ; ///< random level generator
199         typedef typename traits::stat              stat            ;   ///< internal statistics type
200         typedef typename traits::rcu_check_deadlock    rcu_check_deadlock ; ///< Deadlock checking policy
201
202     protected:
203         //@cond
204         typedef typename maker::node_type           node_type;
205         typedef typename maker::node_allocator      node_allocator;
206
207         typedef std::unique_ptr< node_type, typename maker::node_deallocator >    scoped_node_ptr;
208         //@endcond
209
210     public:
211         typedef typename base_class::rcu_lock  rcu_lock;   ///< RCU scoped lock
212         /// Group of \p extract_xxx functions do not require external locking
213         static CDS_CONSTEXPR const bool c_bExtractLockExternal = base_class::c_bExtractLockExternal;
214
215         /// pointer to extracted node
216         using exempt_ptr = cds::urcu::exempt_ptr< gc, node_type, value_type, typename maker::intrusive_traits::disposer >;
217
218     private:
219         //@cond
220         struct raw_ptr_converter
221         {
222             value_type * operator()( node_type * p ) const
223             {
224                return p ? &p->m_Value : nullptr;
225             }
226
227             value_type& operator()( node_type& n ) const
228             {
229                 return n.m_Value;
230             }
231
232             value_type const& operator()( node_type const& n ) const
233             {
234                 return n.m_Value;
235             }
236         };
237         //@endcond
238
239     public:
240         /// Result of \p get(), \p get_with() functions - pointer to the node found
241         typedef cds::urcu::raw_ptr_adaptor< value_type, typename base_class::raw_ptr, raw_ptr_converter > raw_ptr;
242
243     protected:
244         //@cond
245         unsigned int random_level()
246         {
247             return base_class::random_level();
248         }
249         //@endcond
250
251     public:
252         /// Default ctor
253         SkipListSet()
254             : base_class()
255         {}
256
257         /// Destructor destroys the set object
258         ~SkipListSet()
259         {}
260
261     public:
262     ///@name Forward ordered iterators (thread-safe under RCU lock)
263     //@{
264         /// Forward iterator
265         /**
266             The forward iterator has some features:
267             - it has no post-increment operator
268             - it depends on iterator of underlying \p OrderedList
269
270             You may safely use iterators in multi-threaded environment only under RCU lock.
271             Otherwise, a crash is possible if another thread deletes the element the iterator points to.
272         */
273         typedef skip_list::details::iterator< typename base_class::iterator >  iterator;
274
275         /// Const iterator type
276         typedef skip_list::details::iterator< typename base_class::const_iterator >   const_iterator;
277
278         /// Returns a forward iterator addressing the first element in a set
279         iterator begin()
280         {
281             return iterator( base_class::begin());
282         }
283
284         /// Returns a forward const iterator addressing the first element in a set
285         const_iterator begin() const
286         {
287             return const_iterator( base_class::begin());
288         }
289
290         /// Returns a forward const iterator addressing the first element in a set
291         const_iterator cbegin() const
292         {
293             return const_iterator( base_class::cbegin());
294         }
295
296         /// Returns a forward iterator that addresses the location succeeding the last element in a set.
297         iterator end()
298         {
299             return iterator( base_class::end());
300         }
301
302         /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
303         const_iterator end() const
304         {
305             return const_iterator( base_class::end());
306         }
307
308         /// Returns a forward const iterator that addresses the location succeeding the last element in a set.
309         const_iterator cend() const
310         {
311             return const_iterator( base_class::cend());
312         }
313     //@}
314
315     public:
316         /// Inserts new node
317         /**
318             The function creates a node with copy of \p val value
319             and then inserts the node created into the set.
320
321             The type \p Q should contain as minimum the complete key for the node.
322             The object of \ref value_type should be constructible from a value of type \p Q.
323             In trivial case, \p Q is equal to \ref value_type.
324
325             RCU \p synchronize method can be called. RCU should not be locked.
326
327             Returns \p true if \p val is inserted into the set, \p false otherwise.
328         */
329         template <typename Q>
330         bool insert( Q const& val )
331         {
332             scoped_node_ptr sp( node_allocator().New( random_level(), val ));
333             if ( base_class::insert( *sp.get())) {
334                 sp.release();
335                 return true;
336             }
337             return false;
338         }
339
340         /// Inserts new node
341         /**
342             The function allows to split creating of new item into two part:
343             - create item with key only
344             - insert new item into the set
345             - if inserting is success, calls  \p f functor to initialize value-fields of \p val.
346
347             The functor signature is:
348             \code
349                 void func( value_type& val );
350             \endcode
351             where \p val is the item inserted. User-defined functor \p f should guarantee that during changing
352             \p val no any other changes could be made on this set's item by concurrent threads.
353             The user-defined functor is called only if the inserting is success.
354
355             RCU \p synchronize method can be called. RCU should not be locked.
356         */
357         template <typename Q, typename Func>
358         bool insert( Q const& val, Func f )
359         {
360             scoped_node_ptr sp( node_allocator().New( random_level(), val ));
361             if ( base_class::insert( *sp.get(), [&f]( node_type& v ) { f( v.m_Value ); } )) {
362                 sp.release();
363                 return true;
364             }
365             return false;
366         }
367
368         /// Updates the item
369         /**
370             The operation performs inserting or changing data with lock-free manner.
371
372             If \p val not found in the set, then the new item created from \p val
373             is inserted into the set iff \p bInsert is \p true.
374             Otherwise, the functor \p func is called with the item found.
375             The functor \p Func signature:
376             \code
377                 struct my_functor {
378                     void operator()( bool bNew, value_type& item, const Q& val );
379                 };
380             \endcode
381             where:
382             - \p bNew - \p true if the item has been inserted, \p false otherwise
383             - \p item - an item of the set
384             - \p val - argument \p val passed into the \p %update() function
385
386             The functor may change non-key fields of the \p item; however, \p func must guarantee
387             that during changing no any other modifications could be made on this item by concurrent threads.
388
389             RCU \p synchronize method can be called. RCU should not be locked.
390
391             Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successful,
392             \p second is true if new item has been added or \p false if the item with \p key
393             already exists.
394         */
395         template <typename Q, typename Func>
396         std::pair<bool, bool> update( const Q& val, Func func, bool bInsert = true )
397         {
398             scoped_node_ptr sp( node_allocator().New( random_level(), val ));
399             std::pair<bool, bool> bRes = base_class::update( *sp,
400                 [&func, &val](bool bNew, node_type& node, node_type&){ func( bNew, node.m_Value, val );}, bInsert );
401             if ( bRes.first && bRes.second )
402                 sp.release();
403             return bRes;
404         }
405         //@cond
406         template <typename Q, typename Func>
407         CDS_DEPRECATED("ensure() is deprecated, use update()")
408         std::pair<bool, bool> ensure( const Q& val, Func func )
409         {
410             return update( val, func, true );
411         }
412         //@endcond
413
414         /// Inserts data of type \ref value_type constructed with <tt>std::forward<Args>(args)...</tt>
415         /**
416             Returns \p true if inserting successful, \p false otherwise.
417
418             RCU \p synchronize method can be called. RCU should not be locked.
419         */
420         template <typename... Args>
421         bool emplace( Args&&... args )
422         {
423             scoped_node_ptr sp( node_allocator().New( random_level(), std::forward<Args>(args)... ));
424             if ( base_class::insert( *sp.get())) {
425                 sp.release();
426                 return true;
427             }
428             return false;
429         }
430
431         /// Delete \p key from the set
432         /** \anchor cds_nonintrusive_SkipListSet_rcu_erase_val
433
434             The item comparator should be able to compare the type \p value_type
435             and the type \p Q.
436
437             RCU \p synchronize method can be called. RCU should not be locked.
438
439             Return \p true if key is found and deleted, \p false otherwise
440         */
441         template <typename Q>
442         bool erase( Q const& key )
443         {
444             return base_class::erase( key );
445         }
446
447         /// Deletes the item from the set using \p pred predicate for searching
448         /**
449             The function is an analog of \ref cds_nonintrusive_SkipListSet_rcu_erase_val "erase(Q const&)"
450             but \p pred is used for key comparing.
451             \p Less functor has the interface like \p std::less.
452             \p Less must imply the same element order as the comparator used for building the set.
453         */
454         template <typename Q, typename Less>
455         bool erase_with( Q const& key, Less pred )
456         {
457             CDS_UNUSED( pred );
458             return base_class::erase_with( key, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >());
459         }
460
461         /// Delete \p key from the set
462         /** \anchor cds_nonintrusive_SkipListSet_rcu_erase_func
463
464             The function searches an item with key \p key, calls \p f functor
465             and deletes the item. If \p key is not found, the functor is not called.
466
467             The functor \p Func interface:
468             \code
469             struct extractor {
470                 void operator()(value_type const& val);
471             };
472             \endcode
473
474             Since the key of MichaelHashSet's \p value_type is not explicitly specified,
475             template parameter \p Q defines the key type searching in the list.
476             The list item comparator should be able to compare the type \p T of list item
477             and the type \p Q.
478
479             RCU \p synchronize method can be called. RCU should not be locked.
480
481             Return \p true if key is found and deleted, \p false otherwise
482
483             See also: \ref erase
484         */
485         template <typename Q, typename Func>
486         bool erase( Q const& key, Func f )
487         {
488             return base_class::erase( key, [&f]( node_type const& node) { f( node.m_Value ); } );
489         }
490
491         /// Deletes the item from the set using \p pred predicate for searching
492         /**
493             The function is an analog of \ref cds_nonintrusive_SkipListSet_rcu_erase_func "erase(Q const&, Func)"
494             but \p pred is used for key comparing.
495             \p Less functor has the interface like \p std::less.
496             \p Less must imply the same element order as the comparator used for building the set.
497         */
498         template <typename Q, typename Less, typename Func>
499         bool erase_with( Q const& key, Less pred, Func f )
500         {
501             CDS_UNUSED( pred );
502             return base_class::erase_with( key, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >(),
503                 [&f]( node_type const& node) { f( node.m_Value ); } );
504         }
505
506         /// Extracts the item from the set with specified \p key
507         /** \anchor cds_nonintrusive_SkipListSet_rcu_extract
508             The function searches an item with key equal to \p key in the set,
509             unlinks it from the set, and returns \ref cds::urcu::exempt_ptr "exempt_ptr" pointer to the item found.
510             If the item is not found the function returns an empty \p exempt_ptr
511
512             Note the compare functor from \p Traits class' template argument
513             should accept a parameter of type \p Q that can be not the same as \p value_type.
514
515             RCU \p synchronize method can be called. RCU should NOT be locked.
516
517             The function does not free the item found.
518             The item will be implicitly freed when the returned object is destroyed or when
519             its \p release() member function is called.
520         */
521         template <typename Q>
522         exempt_ptr extract( Q const& key )
523         {
524             return exempt_ptr( base_class::do_extract( key ));
525         }
526
527         /// Extracts the item from the set with comparing functor \p pred
528         /**
529             The function is an analog of \p extract(Q const&) but \p pred predicate is used for key comparing.
530             \p Less has the semantics like \p std::less.
531             \p pred must imply the same element order as the comparator used for building the set.
532         */
533         template <typename Q, typename Less>
534         exempt_ptr extract_with( Q const& key, Less pred )
535         {
536             CDS_UNUSED( pred );
537             return exempt_ptr( base_class::do_extract_with( key, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >()));
538         }
539
540         /// Extracts an item with minimal key from the set
541         /**
542             The function searches an item with minimal key, unlinks it,
543             and returns \ref cds::urcu::exempt_ptr "exempt_ptr" pointer to the item.
544             If the skip-list is empty the function returns an empty \p exempt_ptr.
545
546             RCU \p synchronize method can be called. RCU should NOT be locked.
547
548             The function does not free the item found.
549             The item will be implicitly freed when the returned object is destroyed or when
550             its \p release() member function is called.
551         */
552         exempt_ptr extract_min()
553         {
554             return exempt_ptr( base_class::do_extract_min());
555         }
556
557         /// Extracts an item with maximal key from the set
558         /**
559             The function searches an item with maximal key, unlinks it from the set,
560             and returns \ref cds::urcu::exempt_ptr "exempt_ptr" pointer to the item.
561             If the skip-list is empty the function returns an empty \p exempt_ptr.
562
563             RCU \p synchronize method can be called. RCU should NOT be locked.
564
565             The function does not free the item found.
566             The item will be implicitly freed when the returned object is destroyed or when
567             its \p release() member function is called.
568         */
569         exempt_ptr extract_max()
570         {
571             return exempt_ptr( base_class::do_extract_max());
572         }
573
574         /// Find the key \p val
575         /**
576             @anchor cds_nonintrusive_SkipListSet_rcu_find_func
577
578             The function searches the item with key equal to \p val and calls the functor \p f for item found.
579             The interface of \p Func functor is:
580             \code
581             struct functor {
582                 void operator()( value_type& item, Q& val );
583             };
584             \endcode
585             where \p item is the item found, \p val is the <tt>find</tt> function argument.
586
587             The functor may change non-key fields of \p item. Note that the functor is only guarantee
588             that \p item cannot be disposed during functor is executing.
589             The functor does not serialize simultaneous access to the set's \p item. If such access is
590             possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.
591
592             The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor
593             can modify both arguments.
594
595             Note the hash functor specified for class \p Traits template parameter
596             should accept a parameter of type \p Q that may be not the same as \p value_type.
597
598             The function applies RCU lock internally.
599
600             The function returns \p true if \p val is found, \p false otherwise.
601         */
602         template <typename Q, typename Func>
603         bool find( Q& val, Func f )
604         {
605             return base_class::find( val, [&f]( node_type& node, Q& v ) { f( node.m_Value, v ); });
606         }
607         //@cond
608         template <typename Q, typename Func>
609         bool find( Q const& val, Func f )
610         {
611             return base_class::find( val, [&f]( node_type& node, Q& v ) { f( node.m_Value, v ); } );
612         }
613         //@endcond
614
615         /// Finds the key \p val using \p pred predicate for searching
616         /**
617             The function is an analog of \ref cds_nonintrusive_SkipListSet_rcu_find_func "find(Q&, Func)"
618             but \p pred is used for key comparing.
619             \p Less functor has the interface like \p std::less.
620             \p Less must imply the same element order as the comparator used for building the set.
621         */
622         template <typename Q, typename Less, typename Func>
623         bool find_with( Q& val, Less pred, Func f )
624         {
625             CDS_UNUSED( pred );
626             return base_class::find_with( val, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >(),
627                 [&f]( node_type& node, Q& v ) { f( node.m_Value, v ); } );
628         }
629         //@cond
630         template <typename Q, typename Less, typename Func>
631         bool find_with( Q const& val, Less pred, Func f )
632         {
633             CDS_UNUSED( pred );
634             return base_class::find_with( val, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >(),
635                                           [&f]( node_type& node, Q const& v ) { f( node.m_Value, v ); } );
636         }
637         //@endcond
638
639         /// Checks whether the set contains \p key
640         /**
641             The function searches the item with key equal to \p key
642             and returns \p true if it is found, and \p false otherwise.
643
644             The function applies RCU lock internally.
645         */
646         template <typename Q>
647         bool contains( Q const & key )
648         {
649             return base_class::contains( key );
650         }
651         //@cond
652         template <typename Q>
653         CDS_DEPRECATED("deprecated, use contains()")
654         bool find( Q const & key )
655         {
656             return contains( key );
657         }
658         //@endcond
659
660         /// Checks whether the set contains \p key using \p pred predicate for searching
661         /**
662             The function is similar to <tt>contains( key )</tt> but \p pred is used for key comparing.
663             \p Less functor has the interface like \p std::less.
664             \p Less must imply the same element order as the comparator used for building the set.
665         */
666         template <typename Q, typename Less>
667         bool contains( Q const& key, Less pred )
668         {
669             CDS_UNUSED( pred );
670             return base_class::contains( key, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >());
671         }
672         //@cond
673         template <typename Q, typename Less>
674         CDS_DEPRECATED("deprecated, use contains()")
675         bool find_with( Q const& key, Less pred )
676         {
677             return contains( key, pred );
678         }
679         //@endcond
680
681         /// Finds \p key and return the item found
682         /** \anchor cds_nonintrusive_SkipListSet_rcu_get
683             The function searches the item with key equal to \p key and returns a \p raw_ptr object pointed to item found.
684             If \p key is not found it returns empty \p raw_ptr.
685
686             Note the compare functor in \p Traits class' template argument
687             should accept a parameter of type \p Q that can be not the same as \p value_type.
688
689             RCU should be locked before call of this function.
690             Returned item is valid only while RCU is locked:
691             \code
692             typedef cds::container::SkipListSet< cds::urcu::gc< cds::urcu::general_buffered<> >, foo, my_traits > skip_list;
693             skip_list theList;
694             // ...
695             typename skip_list::raw_ptr pVal;
696             {
697                 // Lock RCU
698                 skip_list::rcu_lock lock;
699
700                 pVal = theList.get( 5 );
701                 if ( pVal ) {
702                     // Deal with pVal
703                     //...
704                 }
705             }
706             // You can manually release pVal after RCU-locked section
707             pVal.release();
708             \endcode
709         */
710         template <typename Q>
711         raw_ptr get( Q const& key )
712         {
713             return raw_ptr( base_class::get( key ));
714         }
715
716         /// Finds the key \p val and return the item found
717         /**
718             The function is an analog of \ref cds_nonintrusive_SkipListSet_rcu_get "get(Q const&)"
719             but \p pred is used for comparing the keys.
720
721             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
722             in any order.
723             \p pred must imply the same element order as the comparator used for building the set.
724         */
725         template <typename Q, typename Less>
726         raw_ptr get_with( Q const& val, Less pred )
727         {
728             CDS_UNUSED( pred );
729             return raw_ptr( base_class::get_with( val, cds::details::predicate_wrapper< node_type, Less, typename maker::value_accessor >()));
730         }
731
732         /// Clears the set (non-atomic).
733         /**
734             The function deletes all items from the set.
735             The function is not atomic, thus, in multi-threaded environment with parallel insertions
736             this sequence
737             \code
738             set.clear();
739             assert( set.empty());
740             \endcode
741             the assertion could be raised.
742
743             For each item the \ref disposer provided by \p Traits template parameter will be called.
744         */
745         void clear()
746         {
747             base_class::clear();
748         }
749
750         /// Checks if the set is empty
751         bool empty() const
752         {
753             return base_class::empty();
754         }
755
756         /// Returns item count in the set
757         /**
758             The value returned depends on item counter type provided by \p Traits template parameter.
759             If it is atomicity::empty_item_counter this function always returns 0.
760             Therefore, the function is not suitable for checking the set emptiness, use \ref empty
761             member function for this purpose.
762         */
763         size_t size() const
764         {
765             return base_class::size();
766         }
767
768         /// Returns const reference to internal statistics
769         stat const& statistics() const
770         {
771             return base_class::statistics();
772         }
773     };
774
775 }} // namespace cds::container
776
777 #endif // #ifndef CDSLIB_CONTAINER_SKIP_LIST_SET_RCU_H