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