remove CDS_CONSTEXPR_CONST macro
[libcds.git] / cds / container / split_list_set_rcu.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_CONTAINER_SPLIT_LIST_SET_RCU_H
4 #define __CDS_CONTAINER_SPLIT_LIST_SET_RCU_H
5
6 #include <cds/intrusive/split_list_rcu.h>
7 #include <cds/container/details/make_split_list_set.h>
8
9 namespace cds { namespace container {
10
11     /// Split-ordered list set (template specialization for \ref cds_urcu_desc "RCU")
12     /** @ingroup cds_nonintrusive_set
13         \anchor cds_nonintrusive_SplitListSet_rcu
14
15         Hash table implementation based on split-ordered list algorithm discovered by Ori Shalev and Nir Shavit, see
16         - [2003] Ori Shalev, Nir Shavit "Split-Ordered Lists - Lock-free Resizable Hash Tables"
17         - [2008] Nir Shavit "The Art of Multiprocessor Programming"
18
19         See intrusive::SplitListSet for a brief description of the split-list algorithm.
20
21         Template parameters:
22         - \p RCU - one of \ref cds_urcu_gc "RCU type"
23         - \p T - type stored in the split-list. The type must be default- and copy-constructible.
24         - \p Traits - type traits, default is split_list::type_traits. Instead of declaring split_list::type_traits -based
25             struct you may apply option-based notation with split_list::make_traits metafunction.
26
27         <b>Iterators</b>
28
29         The class supports a forward iterator (\ref iterator and \ref const_iterator).
30         The iteration is ordered.
31
32         You may iterate over split-list set items only under RCU lock.
33         Only in this case the iterator is thread-safe since
34         while RCU is locked any set's item cannot be reclaimed.
35
36         The requirement of RCU lock during iterating means that deletion of the elements (i.e. \ref erase)
37         is not possible.
38
39         @warning The iterator object cannot be passed between threads
40
41         \warning Due to concurrent nature of skip-list set it is not guarantee that you can iterate
42         all elements in the set: any concurrent deletion can exclude the element
43         pointed by the iterator from the set, and your iteration can be terminated
44         before end of the set. Therefore, such iteration is more suitable for debugging purposes
45
46         The iterator class supports the following minimalistic interface:
47         \code
48         struct iterator {
49             // Default ctor
50             iterator();
51
52             // Copy ctor
53             iterator( iterator const& s);
54
55             value_type * operator ->() const;
56             value_type& operator *() const;
57
58             // Pre-increment
59             iterator& operator ++();
60
61             // Copy assignment
62             iterator& operator = (const iterator& src);
63
64             bool operator ==(iterator const& i ) const;
65             bool operator !=(iterator const& i ) const;
66         };
67         \endcode
68         Note, the iterator object returned by \ref end, \p cend member functions points to \p nullptr and should not be dereferenced.
69
70         \par Usage
71
72         You should decide what garbage collector you want, and what ordered list you want to use. Split-ordered list
73         is an original data structure based on an ordered list. Suppose, you want construct split-list set based on cds::urcu::general_buffered<> GC
74         and LazyList as ordered list implementation. So, you beginning your program with following include:
75         \code
76         #include <cds/urcu/general_buffered.h>
77         #include <cds/container/lazy_list_rcu.h>
78         #include <cds/container/split_list_set_rcu.h>
79
80         namespace cc = cds::container;
81
82         // The data belonged to split-ordered list
83         sturuct foo {
84             int     nKey;   // key field
85             std::string strValue    ;   // value field
86         };
87         \endcode
88         The inclusion order is important:
89         - first, include one of \ref cds_urcu_gc "RCU implementation" (<tt>cds/urcu/general_buffered.h</tt> in our case)
90         - second, include file for ordered-list implementation (for this example, <tt>cds/container/lazy_list_rcu.h</tt>),
91         - then, the header for RCU-based split-list set <tt>cds/container/split_list_set_rcu.h</tt>.
92
93         Now, you should declare traits for split-list set. The main parts of traits are a hash functor for the set and a comparing functor for ordered list.
94         Note that we define several function in <tt>foo_hash</tt> and <tt>foo_less</tt> functors for different argument types since we want call our \p %SplitListSet
95         object by the key of type <tt>int</tt> and by the value of type <tt>foo</tt>.
96
97         The second attention: instead of using LazyList in SplitListSet traits we use a tag <tt>cds::contaner::lazy_list_tag</tt> for the lazy list.
98         The split-list requires significant support from underlying ordered list class and it is not good idea to dive you
99         into deep implementation details of split-list and ordered list interrelations. The tag paradigm simplifies split-list interface.
100
101         \code
102         // foo hash functor
103         struct foo_hash {
104             size_t operator()( int key ) const { return std::hash( key ) ; }
105             size_t operator()( foo const& item ) const { return std::hash( item.nKey ) ; }
106         };
107
108         // foo comparator
109         struct foo_less {
110             bool operator()(int i, foo const& f ) const { return i < f.nKey ; }
111             bool operator()(foo const& f, int i ) const { return f.nKey < i ; }
112             bool operator()(foo const& f1, foo const& f2) const { return f1.nKey < f2.nKey; }
113         };
114
115         // SplitListSet traits
116         struct foo_set_traits: public cc::split_list::type_traits
117         {
118             typedef cc::lazy_list_tag   ordered_list    ;   // what type of ordered list we want to use
119             typedef foo_hash            hash            ;   // hash functor for our data stored in split-list set
120
121             // Type traits for our LazyList class
122             struct ordered_list_traits: public cc::lazy_list::type_traits
123             {
124                 typedef foo_less less   ;   // use our foo_less as comparator to order list nodes
125             };
126         };
127         \endcode
128
129         Now you are ready to declare our set class based on \p %SplitListSet:
130         \code
131         typedef cc::SplitListSet< cds::urcu::gc<cds::urcu::general_buffered<> >, foo, foo_set_traits > foo_set;
132         \endcode
133
134         You may use the modern option-based declaration instead of classic type-traits-based one:
135         \code
136         typedef cc:SplitListSet<
137             cds::urcu::gc<cds::urcu::general_buffered<> >   // RCU type used
138             ,foo                                            // type of data stored
139             ,cc::split_list::make_traits<      // metafunction to build split-list traits
140                 cc::split_list::ordered_list<cc::lazy_list_tag>     // tag for underlying ordered list implementation
141                 ,cc::opt::hash< foo_hash >              // hash functor
142                 ,cc::split_list::ordered_list_traits<   // ordered list traits desired
143                     cc::lazy_list::make_traits<         // metafunction to build lazy list traits
144                         cc::opt::less< foo_less >           // less-based compare functor
145                     >::type
146                 >
147             >::type
148         >  foo_set;
149         \endcode
150         In case of option-based declaration using split_list::make_traits metafunction
151         the struct \p foo_set_traits is not required.
152
153         Now, the set of type \p foo_set is ready to use in your program.
154
155         Note that in this example we show only mandatory type_traits parts, optional ones is the default and they are inherited
156         from cds::container::split_list::type_traits.
157         The <b>cds</b> library contains many other options for deep tuning of behavior of the split-list and
158         ordered-list containers.
159     */
160     template <
161         class RCU,
162         class T,
163 #ifdef CDS_DOXYGEN_INVOKED
164         class Traits = split_list::type_traits
165 #else
166         class Traits
167 #endif
168     >
169     class SplitListSet< cds::urcu::gc< RCU >, T, Traits >:
170 #ifdef CDS_DOXYGEN_INVOKED
171         protected intrusive::SplitListSet< cds::urcu::gc< RCU >, typename Traits::ordered_list, Traits >
172 #else
173         protected details::make_split_list_set< cds::urcu::gc< RCU >, T, typename Traits::ordered_list, split_list::details::wrap_set_traits<T, Traits> >::type
174 #endif
175     {
176     protected:
177         //@cond
178         typedef details::make_split_list_set< cds::urcu::gc< RCU >, T, typename Traits::ordered_list, split_list::details::wrap_set_traits<T, Traits> > maker;
179         typedef typename maker::type  base_class;
180         //@endcond
181
182     public:
183         typedef Traits                            options         ; ///< \p Traits template argument
184         typedef typename maker::gc                gc              ; ///< Garbage collector
185         typedef typename maker::value_type        value_type      ; ///< type of value stored in the list
186         typedef typename maker::ordered_list      ordered_list    ; ///< Underlying ordered list class
187         typedef typename base_class::key_comparator key_comparator; ///< key compare functor
188
189         /// Hash functor for \ref value_type and all its derivatives that you use
190         typedef typename base_class::hash           hash;
191         typedef typename base_class::item_counter   item_counter    ;   ///< Item counter type
192
193         typedef typename base_class::rcu_lock      rcu_lock   ; ///< RCU scoped lock
194         /// Group of \p extract_xxx functions require external locking if underlying ordered list requires that
195         static CDS_CONSTEXPR const bool c_bExtractLockExternal = base_class::c_bExtractLockExternal;
196
197     protected:
198         //@cond
199         typedef typename maker::cxx_node_allocator    cxx_node_allocator;
200         typedef typename maker::node_type             node_type;
201         //@endcond
202
203     public:
204         /// pointer to extracted node
205         typedef cds::urcu::exempt_ptr< gc, node_type, value_type, typename maker::ordered_list_traits::disposer > exempt_ptr;
206
207     protected:
208         //@cond
209
210         template <typename Q>
211         static node_type * alloc_node(Q const& v )
212         {
213             return cxx_node_allocator().New( v );
214         }
215
216         template <typename Q, typename Func>
217         bool find_( Q& val, Func f )
218         {
219             return base_class::find( val, [&f]( node_type& item, Q& val ) { f(item.m_Value, val) ; } );
220         }
221
222         template <typename Q, typename Less, typename Func>
223         bool find_with_( Q& val, Less pred, Func f )
224         {
225             return base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type(),
226                 [&f]( node_type& item, Q& val ) { f(item.m_Value, val) ; } );
227         }
228
229
230         template <typename... Args>
231         static node_type * alloc_node( Args&&... args )
232         {
233             return cxx_node_allocator().MoveNew( std::forward<Args>(args)...);
234         }
235
236         static void free_node( node_type * pNode )
237         {
238             cxx_node_allocator().Delete( pNode );
239         }
240
241         struct node_disposer {
242             void operator()( node_type * pNode )
243             {
244                 free_node( pNode );
245             }
246         };
247         typedef std::unique_ptr< node_type, node_disposer >     scoped_node_ptr;
248
249         bool insert_node( node_type * pNode )
250         {
251             assert( pNode != nullptr );
252             scoped_node_ptr p(pNode);
253
254             if ( base_class::insert( *pNode ) ) {
255                 p.release();
256                 return true;
257             }
258
259             return false;
260         }
261         //@endcond
262
263     protected:
264         /// Forward iterator
265         /**
266             \p IsConst - constness boolean flag
267
268             The forward iterator for a split-list has the following features:
269             - it has no post-increment operator
270             - it depends on underlying ordered list iterator
271             - it is safe to iterate only inside RCU critical section
272             - deleting an item pointed by the iterator can cause to deadlock
273
274             Therefore, the use of iterators in concurrent environment is not good idea.
275             Use it for debug purpose only.
276         */
277         template <bool IsConst>
278         class iterator_type: protected base_class::template iterator_type<IsConst>
279         {
280             //@cond
281             typedef typename base_class::template iterator_type<IsConst> iterator_base_class;
282             friend class SplitListSet;
283             //@endcond
284         public:
285             /// Value pointer type (const for const iterator)
286             typedef typename cds::details::make_const_type<value_type, IsConst>::pointer   value_ptr;
287             /// Value reference type (const for const iterator)
288             typedef typename cds::details::make_const_type<value_type, IsConst>::reference value_ref;
289
290         public:
291             /// Default ctor
292             iterator_type()
293             {}
294
295             /// Copy ctor
296             iterator_type( iterator_type const& src )
297                 : iterator_base_class( src )
298             {}
299
300         protected:
301             //@cond
302             explicit iterator_type( iterator_base_class const& src )
303                 : iterator_base_class( src )
304             {}
305             //@endcond
306
307         public:
308             /// Dereference operator
309             value_ptr operator ->() const
310             {
311                 return &(iterator_base_class::operator->()->m_Value);
312             }
313
314             /// Dereference operator
315             value_ref operator *() const
316             {
317                 return iterator_base_class::operator*().m_Value;
318             }
319
320             /// Pre-increment
321             iterator_type& operator ++()
322             {
323                 iterator_base_class::operator++();
324                 return *this;
325             }
326
327             /// Assignment operator
328             iterator_type& operator = (iterator_type const& src)
329             {
330                 iterator_base_class::operator=(src);
331                 return *this;
332             }
333
334             /// Equality operator
335             template <bool C>
336             bool operator ==(iterator_type<C> const& i ) const
337             {
338                 return iterator_base_class::operator==(i);
339             }
340
341             /// Equality operator
342             template <bool C>
343             bool operator !=(iterator_type<C> const& i ) const
344             {
345                 return iterator_base_class::operator!=(i);
346             }
347         };
348
349     public:
350         /// Initializes split-ordered list of default capacity
351         /**
352             The default capacity is defined in bucket table constructor.
353             See intrusive::split_list::expandable_bucket_table, intrusive::split_list::static_bucket_table
354             which selects by intrusive::split_list::dynamic_bucket_table option.
355         */
356         SplitListSet()
357             : base_class()
358         {}
359
360         /// Initializes split-ordered list
361         SplitListSet(
362             size_t nItemCount           ///< estimate average of item count
363             , size_t nLoadFactor = 1    ///< load factor - average item count per bucket. Small integer up to 8, default is 1.
364             )
365             : base_class( nItemCount, nLoadFactor )
366         {}
367
368     public:
369         typedef iterator_type<false>  iterator        ; ///< Forward iterator
370         typedef iterator_type<true>   const_iterator  ; ///< Forward const iterator
371
372         /// Returns a forward iterator addressing the first element in a set
373         /**
374             For empty set \code begin() == end() \endcode
375         */
376         iterator begin()
377         {
378             return iterator( base_class::begin() );
379         }
380
381         /// Returns an iterator that addresses the location succeeding the last element in a set
382         /**
383             Do not use the value returned by <tt>end</tt> function to access any item.
384             The returned value can be used only to control reaching the end of the set.
385             For empty set \code begin() == end() \endcode
386         */
387         iterator end()
388         {
389             return iterator( base_class::end() );
390         }
391
392         /// Returns a forward const iterator addressing the first element in a set
393         const_iterator begin() const
394         {
395             return const_iterator( base_class::begin() );
396         }
397
398         /// Returns an const iterator that addresses the location succeeding the last element in a set
399         const_iterator end() const
400         {
401             return const_iterator( base_class::end() );
402         }
403
404     public:
405         /// Inserts new node
406         /**
407             The function creates a node with copy of \p val value
408             and then inserts the node created into the set.
409
410             The type \p Q should contain as minimum the complete key for the node.
411             The object of \p value_type should be constructible from a value of type \p Q.
412             In trivial case, \p Q is equal to \p value_type.
413
414             The function applies RCU lock internally.
415
416             Returns \p true if \p val is inserted into the set, \p false otherwise.
417         */
418         template <typename Q>
419         bool insert( Q const& val )
420         {
421             return insert_node( alloc_node( val ) );
422         }
423
424         /// Inserts new node
425         /**
426             The function allows to split creating of new item into two part:
427             - create item with key only
428             - insert new item into the set
429             - if inserting is success, calls  \p f functor to initialize value-field of \p val.
430
431             The functor signature is:
432             \code
433                 void func( value_type& val );
434             \endcode
435             where \p val is the item inserted. User-defined functor \p f should guarantee that during changing
436             \p val no any other changes could be made on this set's item by concurrent threads.
437             The user-defined functor is called only if the inserting is success. It may be passed by reference
438             using \p std::ref
439
440             The function applies RCU lock internally.
441         */
442         template <typename Q, typename Func>
443         bool insert( Q const& val, Func f )
444         {
445             scoped_node_ptr pNode( alloc_node( val ));
446
447             if ( base_class::insert( *pNode, [&f](node_type& node) { f( node.m_Value ) ; } )) {
448                 pNode.release();
449                 return true;
450             }
451             return false;
452         }
453
454         /// Inserts data of type \p value_type constructed with <tt>std::forward<Args>(args)...</tt>
455         /**
456             Returns \p true if inserting successful, \p false otherwise.
457
458             The function applies RCU lock internally.
459         */
460         template <typename... Args>
461         bool emplace( Args&&... args )
462         {
463             return insert_node( alloc_node( std::forward<Args>(args)...));
464         }
465
466         /// Ensures that the \p item exists in the set
467         /**
468             The operation performs inserting or changing data with lock-free manner.
469
470             If the \p val key not found in the set, then the new item created from \p val
471             is inserted into the set. Otherwise, the functor \p func is called with the item found.
472             The functor \p Func should be a function with signature:
473             \code
474                 void func( bool bNew, value_type& item, const Q& val );
475             \endcode
476             or a functor:
477             \code
478                 struct my_functor {
479                     void operator()( bool bNew, value_type& item, const Q& val );
480                 };
481             \endcode
482
483             with arguments:
484             - \p bNew - \p true if the item has been inserted, \p false otherwise
485             - \p item - item of the set
486             - \p val - argument \p val passed into the \p ensure function
487
488             The functor may change non-key fields of the \p item; however, \p func must guarantee
489             that during changing no any other modifications could be made on this item by concurrent threads.
490
491             You may pass \p func argument by reference using \p std::ref
492
493             The function applies RCU lock internally.
494
495             Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
496             \p second is true if new item has been added or \p false if the item with \p key
497             already is in the set.
498         */
499         template <typename Q, typename Func>
500         std::pair<bool, bool> ensure( Q const& val, Func func )
501         {
502             scoped_node_ptr pNode( alloc_node( val ));
503
504             std::pair<bool, bool> bRet = base_class::ensure( *pNode,
505                 [&func, &val]( bool bNew, node_type& item,  node_type const& /*val*/ ) {
506                     func( bNew, item.m_Value, val );
507                 } );
508             if ( bRet.first && bRet.second )
509                 pNode.release();
510             return bRet;
511         }
512
513         /// Deletes \p key from the set
514         /** \anchor cds_nonintrusive_SplitListSet_rcu_erase_val
515
516             Since the key of SplitListSet's item type \p value_type is not explicitly specified,
517             template parameter \p Q defines the key type searching in the list.
518             The set item comparator should be able to compare the values of type \p value_type
519             and the type \p Q.
520
521             RCU \p synchronize method can be called. RCU should not be locked.
522
523             Return \p true if key is found and deleted, \p false otherwise
524         */
525         template <typename Q>
526         bool erase( Q const& key )
527         {
528             return base_class::erase( key );
529         }
530
531         /// Deletes the item from the set using \p pred predicate for searching
532         /**
533             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_erase_val "erase(Q const&)"
534             but \p pred is used for key comparing.
535             \p Less functor has the interface like \p std::less.
536             \p Less must imply the same element order as the comparator used for building the set.
537         */
538         template <typename Q, typename Less>
539         bool erase_with( Q const& key, Less pred )
540         {
541              return base_class::erase_with( key, typename maker::template predicate_wrapper<Less>::type() );
542         }
543
544         /// Deletes \p key from the set
545         /** \anchor cds_nonintrusive_SplitListSet_rcu_erase_func
546
547             The function searches an item with key \p key, calls \p f functor
548             and deletes the item. If \p key is not found, the functor is not called.
549
550             The functor \p Func interface:
551             \code
552             struct extractor {
553                 void operator()(value_type const& val);
554             };
555             \endcode
556             The functor may be passed by reference using <tt>boost:ref</tt>
557
558             Since the key of SplitListSet's \p value_type is not explicitly specified,
559             template parameter \p Q defines the key type searching in the list.
560             The list item comparator should be able to compare the values of the type \p value_type
561             and the type \p Q.
562
563             RCU \p synchronize method can be called. RCU should not be locked.
564
565             Return \p true if key is found and deleted, \p false otherwise
566         */
567         template <typename Q, typename Func>
568         bool erase( Q const& key, Func f )
569         {
570             return base_class::erase( key, [&f](node_type& node) { f( node.m_Value ); } );
571         }
572
573         /// Deletes the item from the set using \p pred predicate for searching
574         /**
575             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_erase_func "erase(Q const&, Func)"
576             but \p pred is used for key comparing.
577             \p Less functor has the interface like \p std::less.
578             \p Less must imply the same element order as the comparator used for building the set.
579         */
580         template <typename Q, typename Less, typename Func>
581         bool erase_with( Q const& key, Less pred, Func f )
582         {
583             return base_class::erase_with( key, typename maker::template predicate_wrapper<Less>::type(),
584                 [&f](node_type& node) { f( node.m_Value ); } );
585         }
586
587         /// Extracts an item from the set
588         /** \anchor cds_nonintrusive_SplitListSet_rcu_extract
589             The function searches an item with key equal to \p val in the set,
590             unlinks it from the set, places item pointer into \p dest argument, and returns \p true.
591             If the item with the key equal to \p val is not found the function return \p false.
592
593             @note The function does NOT call RCU read-side lock or synchronization,
594             and does NOT dispose the item found. It just excludes the item from the set
595             and returns a pointer to item found.
596             You should lock RCU before calling of the function, and you should synchronize RCU
597             outside the RCU lock to free extracted item
598
599             \code
600             typedef cds::urcu::gc< general_buffered<> > rcu;
601             typedef cds::container::SplitListSet< rcu, Foo > splitlist_set;
602
603             splitlist_set theSet;
604             // ...
605
606             splitlist_set::exempt_ptr p;
607             {
608                 // first, we should lock RCU
609                 splitlist_set::rcu_lock lock;
610
611                 // Now, you can apply extract function
612                 // Note that you must not delete the item found inside the RCU lock
613                 if ( theSet.extract( p, 10 )) {
614                     // do something with p
615                     ...
616                 }
617             }
618
619             // We may safely release p here
620             // release() passes the pointer to RCU reclamation cycle
621             p.release();
622             \endcode
623         */
624         template <typename Q>
625         bool extract( exempt_ptr& dest, Q const& val )
626         {
627             node_type * pNode = base_class::extract_( val, key_comparator() );
628             if ( pNode ) {
629                 dest = pNode;
630                 return true;
631             }
632             return false;
633         }
634
635         /// Extracts an item from the set using \p pred predicate for searching
636         /**
637             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_extract "extract(exempt_ptr&, Q const&)"
638             but \p pred is used for key comparing.
639             \p Less functor has the interface like \p std::less.
640             \p pred must imply the same element order as the comparator used for building the set.
641         */
642         template <typename Q, typename Less>
643         bool extract_with( exempt_ptr& dest, Q const& val, Less pred )
644         {
645             node_type * pNode = base_class::extract_with_( val, typename maker::template predicate_wrapper<Less>::type());
646             if ( pNode ) {
647                 dest = pNode;
648                 return true;
649             }
650             return false;
651         }
652
653         /// Finds the key \p val
654         /** \anchor cds_nonintrusive_SplitListSet_rcu_find_func
655
656             The function searches the item with key equal to \p val and calls the functor \p f for item found.
657             The interface of \p Func functor is:
658             \code
659             struct functor {
660                 void operator()( value_type& item, Q& val );
661             };
662             \endcode
663             where \p item is the item found, \p val is the <tt>find</tt> function argument.
664
665             You may pass \p f argument by reference using \p std::ref.
666
667             The functor may change non-key fields of \p item. Note that the functor is only guarantee
668             that \p item cannot be disposed during functor is executing.
669             The functor does not serialize simultaneous access to the set's \p item. If such access is
670             possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.
671
672             The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor
673             may modify both arguments.
674
675             Note the hash functor specified for class \p Traits template parameter
676             should accept a parameter of type \p Q that can be not the same as \p value_type.
677
678             The function makes RCU lock internally.
679
680             The function returns \p true if \p val is found, \p false otherwise.
681         */
682         template <typename Q, typename Func>
683         bool find( Q& val, Func f )
684         {
685             return find_( val, f );
686         }
687
688         /// Finds the key \p val using \p pred predicate for searching
689         /**
690             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_find_func "find(Q&, Func)"
691             but \p pred is used for key comparing.
692             \p Less functor has the interface like \p std::less.
693             \p Less must imply the same element order as the comparator used for building the set.
694         */
695         template <typename Q, typename Less, typename Func>
696         bool find_with( Q& val, Less pred, Func f )
697         {
698             return find_with_( val, pred, f );
699         }
700
701         /// Find the key \p val
702         /** \anchor cds_nonintrusive_SplitListSet_rcu_find_cfunc
703
704             The function searches the item with key equal to \p val and calls the functor \p f for item found.
705             The interface of \p Func functor is:
706             \code
707             struct functor {
708                 void operator()( value_type& item, Q const& val );
709             };
710             \endcode
711             where \p item is the item found, \p val is the <tt>find</tt> function argument.
712
713             You may pass \p f argument by reference using \p std::ref.
714
715             The functor may change non-key fields of \p item. Note that the functor is only guarantee
716             that \p item cannot be disposed during functor is executing.
717             The functor does not serialize simultaneous access to the set's \p item. If such access is
718             possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.
719
720             Note the hash functor specified for class \p Traits template parameter
721             should accept a parameter of type \p Q that can be not the same as \p value_type.
722
723             The function makes RCU lock internally.
724
725             The function returns \p true if \p val is found, \p false otherwise.
726         */
727         template <typename Q, typename Func>
728         bool find( Q const& val, Func f )
729         {
730             return find_( val, f );
731         }
732
733         /// Finds the key \p val using \p pred predicate for searching
734         /**
735             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_find_cfunc "find(Q const&, Func)"
736             but \p pred is used for key comparing.
737             \p Less functor has the interface like \p std::less.
738             \p Less must imply the same element order as the comparator used for building the set.
739         */
740         template <typename Q, typename Less, typename Func>
741         bool find_with( Q const& val, Less pred, Func f )
742         {
743             return find_with_( val, pred, f );
744         }
745
746         /// Finds the key \p val
747         /** \anchor cds_nonintrusive_SplitListSet_rcu_find_val
748
749             The function searches the item with key equal to \p val
750             and returns \p true if it is found, and \p false otherwise.
751
752             Note the hash functor specified for class \p Traits template parameter
753             should accept a parameter of type \p Q that can be not the same as \p value_type.
754
755             The function makes RCU lock internally.
756         */
757         template <typename Q>
758         bool find( Q const& val )
759         {
760             return base_class::find( val );
761         }
762
763         /// Finds the key \p val using \p pred predicate for searching
764         /**
765             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_find_val "find(Q const&)"
766             but \p pred is used for key comparing.
767             \p Less functor has the interface like \p std::less.
768             \p Less must imply the same element order as the comparator used for building the set.
769         */
770         template <typename Q, typename Less>
771         bool find_with( Q const& val, Less pred )
772         {
773             return base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type() );
774         }
775
776         /// Finds the key \p val and return the item found
777         /** \anchor cds_nonintrusive_SplitListSet_rcu_get
778             The function searches the item with key equal to \p val and returns the pointer to item found.
779             If \p val is not found it returns \p nullptr.
780
781             Note the compare functor should accept a parameter of type \p Q that can be not the same as \p value_type.
782
783             RCU should be locked before call of this function.
784             Returned item is valid only while RCU is locked:
785             \code
786             typedef cds::urcu::gc< general_buffered<> > rcu;
787             typedef cds::container::SplitListSet< rcu, Foo > splitlist_set;
788             splitlist_set theSet;
789             // ...
790             {
791                 // Lock RCU
792                 splitlist_set::rcu_lock lock;
793
794                 foo * pVal = theSet.get( 5 );
795                 if ( pVal ) {
796                     // Deal with pVal
797                     //...
798                 }
799                 // Unlock RCU by rcu_lock destructor
800                 // pVal can be retired by disposer at any time after RCU has been unlocked
801             }
802             \endcode
803         */
804         template <typename Q>
805         value_type * get( Q const& val )
806         {
807             node_type * pNode = base_class::get( val );
808             return pNode ? &pNode->m_Value : nullptr;
809         }
810
811         /// Finds the key \p val and return the item found
812         /**
813             The function is an analog of \ref cds_nonintrusive_SplitListSet_rcu_get "get(Q const&)"
814             but \p pred is used for comparing the keys.
815
816             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
817             in any order.
818             \p pred must imply the same element order as the comparator used for building the set.
819         */
820         template <typename Q, typename Less>
821         value_type * get_with( Q const& val, Less pred )
822         {
823             node_type * pNode = base_class::get_with( val, typename maker::template predicate_wrapper<Less>::type());
824             return pNode ? &pNode->m_Value : nullptr;
825         }
826
827         /// Clears the set (non-atomic)
828         /**
829             The function unlink all items from the set.
830             The function is not atomic and not lock-free and should be used for debugging only.
831
832             RCU \p synchronize method can be called. RCU should not be locked.
833         */
834         void clear()
835         {
836             base_class::clear();
837         }
838
839         /// Checks if the set is empty
840         /**
841             Emptiness is checked by item counting: if item count is zero then assume that the set is empty.
842             Thus, the correct item counting feature is an important part of split-list set implementation.
843         */
844         bool empty() const
845         {
846             return base_class::empty();
847         }
848
849         /// Returns item count in the set
850         size_t size() const
851         {
852             return base_class::size();
853         }
854     };
855
856
857 }}  // namespace cds::container
858
859 #endif // #ifndef __CDS_CONTAINER_SPLIT_LIST_SET_RCU_H