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