31ec11ff13a3844517e63745c63535e133759cd3
[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
9 namespace cds { namespace container {
10
11     /// Split-ordered list set
12     /** @ingroup cds_nonintrusive_set
13         \anchor cds_nonintrusive_SplitListSet_hp
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 \p intrusive::SplitListSet for a brief description of the split-list algorithm.
20
21         Template parameters:
22         - \p GC - Garbage collector used
23         - \p T - type to be stored in the split-list.
24         - \p Traits - type traits, default is \p split_list::traits. Instead of declaring \p split_list::traits -based
25             struct you may apply option-based notation with \p split_list::make_traits metafunction.
26
27         There are the specializations:
28         - for \ref cds_urcu_desc "RCU" - declared in <tt>cd/container/split_list_set_rcu.h</tt>,
29             see \ref cds_nonintrusive_SplitListSet_rcu "SplitListSet<RCU>".
30         - for \ref cds::gc::nogc declared in <tt>cds/container/split_list_set_nogc.h</tt>,
31             see \ref cds_nonintrusive_SplitListSet_nogc "SplitListSet<gc::nogc>".
32
33         \par Usage
34
35         You should decide what garbage collector you want, and what ordered list you want to use as a base. Split-ordered list
36         is original data structure based on an ordered list. 
37
38         Suppose, you want construct split-list set based on \p gc::DHP GC
39         and \p LazyList as ordered list implementation. So, you beginning your program with following include:
40         \code
41         #include <cds/container/lazy_list_dhp.h>
42         #include <cds/container/split_list_set.h>
43
44         namespace cc = cds::container;
45
46         // The data belonged to split-ordered list
47         sturuct foo {
48             int     nKey;   // key field
49             std::string strValue    ;   // value field
50         };
51         \endcode
52         The inclusion order is important: first, include header for ordered-list implementation (for this example, <tt>cds/container/lazy_list_dhp.h</tt>),
53         then the header for split-list set <tt>cds/container/split_list_set.h</tt>.
54
55         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.
56         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
57         object by the key of type <tt>int</tt> and by the value of type <tt>foo</tt>.
58
59         The second attention: instead of using \p %LazyList in \p %SplitListSet traits we use a tag \p cds::contaner::lazy_list_tag for the lazy list.
60         The split-list requires significant support from underlying ordered list class and it is not good idea to dive you
61         into deep implementation details of split-list and ordered list interrelations. The tag paradigm simplifies split-list interface.
62
63         \code
64         // foo hash functor
65         struct foo_hash {
66             size_t operator()( int key ) const { return std::hash( key ) ; }
67             size_t operator()( foo const& item ) const { return std::hash( item.nKey ) ; }
68         };
69
70         // foo comparator
71         struct foo_less {
72             bool operator()(int i, foo const& f ) const { return i < f.nKey ; }
73             bool operator()(foo const& f, int i ) const { return f.nKey < i ; }
74             bool operator()(foo const& f1, foo const& f2) const { return f1.nKey < f2.nKey; }
75         };
76
77         // SplitListSet traits
78         struct foo_set_traits: public cc::split_list::traits
79         {
80             typedef cc::lazy_list_tag   ordered_list; // what type of ordered list we want to use
81             typedef foo_hash            hash;         // hash functor for our data stored in split-list set
82
83             // Type traits for our LazyList class
84             struct ordered_list_traits: public cc::lazy_list::traits
85             {
86                 typedef foo_less less   ;   // use our foo_less as comparator to order list nodes
87             };
88         };
89         \endcode
90
91         Now you are ready to declare our set class based on \p %SplitListSet:
92         \code
93         typedef cc::SplitListSet< cds::gc::PTB, foo, foo_set_traits > foo_set;
94         \endcode
95
96         You may use the modern option-based declaration instead of classic traits-based one:
97         \code
98         typedef cc:SplitListSet<
99             cs::gc::PTB             // GC used
100             ,foo                    // type of data stored
101             ,cc::split_list::make_traits<      // metafunction to build split-list traits
102                 cc::split_list::ordered_list<cc::lazy_list_tag>  // tag for underlying ordered list implementation
103                 ,cc::opt::hash< foo_hash >               // hash functor
104                 ,cc::split_list::ordered_list_traits<    // ordered list traits desired
105                     cc::lazy_list::make_traits<          // metafunction to build lazy list traits
106                         cc::opt::less< foo_less >        // less-based compare functor
107                     >::type
108                 >
109             >::type
110         >  foo_set;
111         \endcode
112         In case of option-based declaration using split_list::make_traits metafunction
113         the struct \p foo_set_traits is not required.
114
115         Now, the set of type \p foo_set is ready to use in your program.
116
117         Note that in this example we show only mandatory \p traits parts, optional ones is the default and they are inherited
118         from \p cds::container::split_list::traits.
119         There are many other options for deep tuning the split-list and ordered-list containers.
120     */
121     template <
122         class GC,
123         class T,
124 #ifdef CDS_DOXYGEN_INVOKED
125         class Traits = split_list::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 GC      gc;         ///< Garbage collector
145         typedef T       value_type; ///< Type of vlue to be stored in split-list
146         typedef Traits  traits;     ///< \p Traits template argument
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         typedef typename base_class::stat         stat; ///< Internal statistics
154
155     protected:
156         //@cond
157         typedef typename maker::cxx_node_allocator    cxx_node_allocator;
158         typedef typename maker::node_type             node_type;
159         //@endcond
160
161     public:
162         /// Guarded pointer
163         typedef cds::gc::guarded_ptr< gc, node_type, value_type, details::guarded_ptr_cast_set<node_type, value_type> > guarded_ptr;
164
165     protected:
166         //@cond
167         template <typename Q>
168         static node_type * alloc_node(Q const& v )
169         {
170             return cxx_node_allocator().New( v );
171         }
172
173         template <typename... Args>
174         static node_type * alloc_node( Args&&... args )
175         {
176             return cxx_node_allocator().MoveNew( std::forward<Args>( args )... );
177         }
178
179         static void free_node( node_type * pNode )
180         {
181             cxx_node_allocator().Delete( pNode );
182         }
183
184         template <typename Q, typename Func>
185         bool find_( Q& val, Func f )
186         {
187             return base_class::find( val, [&f]( node_type& item, Q& val ) { f(item.m_Value, val) ; } );
188         }
189
190         template <typename Q, typename Less, typename Func>
191         bool find_with_( Q& val, Less pred, Func f )
192         {
193             return base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type(),
194                 [&f]( node_type& item, Q& val ) { f(item.m_Value, val) ; } );
195         }
196
197         struct node_disposer {
198             void operator()( node_type * pNode )
199             {
200                 free_node( pNode );
201             }
202         };
203         typedef std::unique_ptr< node_type, node_disposer >     scoped_node_ptr;
204
205         bool insert_node( node_type * pNode )
206         {
207             assert( pNode != nullptr );
208             scoped_node_ptr p(pNode);
209
210             if ( base_class::insert( *pNode ) ) {
211                 p.release();
212                 return true;
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 \p intrusive::split_list::expandable_bucket_table, \p intrusive::split_list::static_bucket_table
310             which selects by \p 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           ///< estimated average of item count
319             , size_t nLoadFactor = 1    ///< the 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 cbegin();
355         }
356         /// Returns a forward const iterator addressing the first element in a set
357         const_iterator cbegin() const
358         {
359             return const_iterator( base_class::cbegin() );
360         }
361
362         /// Returns an const iterator that addresses the location succeeding the last element in a set
363         const_iterator end() const
364         {
365             return cend();
366         }
367         /// Returns an const iterator that addresses the location succeeding the last element in a set
368         const_iterator cend() const
369         {
370             return const_iterator( base_class::cend() );
371         }
372
373     public:
374         /// Inserts new node
375         /**
376             The function creates a node with copy of \p val value
377             and then inserts the node created into the set.
378
379             The type \p Q should contain as minimum the complete key for the node.
380             The object of \ref value_type should be constructible from a value of type \p Q.
381             In trivial case, \p Q is equal to \ref value_type.
382
383             Returns \p true if \p val is inserted into the set, \p false otherwise.
384         */
385         template <typename Q>
386         bool insert( Q const& val )
387         {
388             return insert_node( alloc_node( val ) );
389         }
390
391         /// Inserts new node
392         /**
393             The function allows to split creating of new item into two part:
394             - create item with key only
395             - insert new item into the set
396             - if inserting is success, calls  \p f functor to initialize value-field of \p val.
397
398             The functor signature is:
399             \code
400                 void func( value_type& val );
401             \endcode
402             where \p val is the item inserted.
403
404             The user-defined functor is called only if the inserting is success.
405
406             @warning For \ref cds_intrusive_MichaelList_hp "MichaelList" as the bucket see \ref cds_intrusive_item_creating "insert item troubleshooting".
407             \ref cds_intrusive_LazyList_hp "LazyList" provides exclusive access to inserted item and does not require any node-level
408             synchronization.
409         */
410         template <typename Q, typename Func>
411         bool insert( Q const& val, Func f )
412         {
413             scoped_node_ptr pNode( alloc_node( val ));
414
415             if ( base_class::insert( *pNode, [&f](node_type& node) { f( node.m_Value ) ; } )) {
416                 pNode.release();
417                 return true;
418             }
419             return false;
420         }
421
422         /// Inserts data of type \p value_type created from \p args
423         /**
424             Returns \p true if inserting successful, \p false otherwise.
425         */
426         template <typename... Args>
427         bool emplace( Args&&... args )
428         {
429             return insert_node( alloc_node( std::forward<Args>(args)...));
430         }
431
432         /// Ensures that the \p item exists in the set
433         /**
434             The operation performs inserting or changing data with lock-free manner.
435
436             If the \p val key not found in the set, then the new item created from \p val
437             is inserted into the set. Otherwise, the functor \p func is called with the item found.
438             The functor \p Func should be a function with signature:
439             \code
440                 void func( bool bNew, value_type& item, const Q& val );
441             \endcode
442             or a functor:
443             \code
444                 struct my_functor {
445                     void operator()( bool bNew, value_type& item, const Q& val );
446                 };
447             \endcode
448
449             with arguments:
450             - \p bNew - \p true if the item has been inserted, \p false otherwise
451             - \p item - item of the set
452             - \p val - argument \p val passed into the \p ensure function
453
454             The functor may change non-key fields of the \p item.
455
456             Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
457             \p second is true if new item has been added or \p false if the item with \p key
458             already is in the set.
459
460             @warning For \ref cds_intrusive_MichaelList_hp "MichaelList" as the bucket see \ref cds_intrusive_item_creating "insert item troubleshooting".
461             \ref cds_intrusive_LazyList_hp "LazyList" provides exclusive access to inserted item and does not require any node-level
462             synchronization.
463         */
464         template <typename Q, typename Func>
465         std::pair<bool, bool> ensure( Q const& val, Func func )
466         {
467             scoped_node_ptr pNode( alloc_node( val ));
468
469             std::pair<bool, bool> bRet = base_class::ensure( *pNode,
470                 [&func, &val]( bool bNew, node_type& item,  node_type const& /*val*/ ) {
471                     func( bNew, item.m_Value, val );
472                 } );
473
474             if ( bRet.first && bRet.second )
475                 pNode.release();
476             return bRet;
477         }
478
479         /// Deletes \p key from the set
480         /** \anchor cds_nonintrusive_SplitListSet_erase_val
481
482             The item comparator should be able to compare the values of type \p value_type
483             and the type \p Q.
484
485             Return \p true if key is found and deleted, \p false otherwise
486         */
487         template <typename Q>
488         bool erase( Q const& key )
489         {
490             return base_class::erase( key );
491         }
492
493         /// Deletes the item from the set using \p pred predicate for searching
494         /**
495             The function is an analog of \ref cds_nonintrusive_SplitListSet_erase_val "erase(Q const&)"
496             but \p pred is used for key comparing.
497             \p Less functor has the interface like \p std::less.
498             \p Less must imply the same element order as the comparator used for building the set.
499         */
500         template <typename Q, typename Less>
501         bool erase_with( Q const& key, Less pred )
502         {
503             return base_class::erase_with( key, typename maker::template predicate_wrapper<Less>::type() );
504         }
505
506         /// Deletes \p key from the set
507         /** \anchor cds_nonintrusive_SplitListSet_erase_func
508
509             The function searches an item with key \p key, calls \p f functor
510             and deletes the item. If \p key is not found, the functor is not called.
511
512             The functor \p Func interface:
513             \code
514             struct extractor {
515                 void operator()(value_type const& val);
516             };
517             \endcode
518
519             Since the key of split-list \p value_type is not explicitly specified,
520             template parameter \p Q defines the key type searching in the list.
521             The list item comparator should be able to compare the values of the type \p value_type
522             and the type \p Q.
523
524             Return \p true if key is found and deleted, \p false otherwise
525         */
526         template <typename Q, typename Func>
527         bool erase( Q const& key, Func f )
528         {
529             return base_class::erase( key, [&f](node_type& node) { f( node.m_Value ); } );
530         }
531
532         /// Deletes the item from the set using \p pred predicate for searching
533         /**
534             The function is an analog of \ref cds_nonintrusive_SplitListSet_erase_func "erase(Q const&, Func)"
535             but \p pred is used for key comparing.
536             \p Less functor has the interface like \p std::less.
537             \p Less must imply the same element order as the comparator used for building the set.
538         */
539         template <typename Q, typename Less, typename Func>
540         bool erase_with( Q const& key, Less pred, Func f )
541         {
542             return base_class::erase_with( key, typename maker::template predicate_wrapper<Less>::type(),
543                 [&f](node_type& node) { f( node.m_Value ); } );
544         }
545
546         /// Extracts the item with specified \p key
547         /** \anchor cds_nonintrusive_SplitListSet_hp_extract
548             The function searches an item with key equal to \p key,
549             unlinks it from the set, and returns it in \p dest parameter.
550             If the item with key equal to \p key is not found the function returns \p false.
551
552             Note the compare functor should accept a parameter of type \p Q that may be not the same as \p value_type.
553
554             The extracted item is freed automatically when returned \ref guarded_ptr object will be destroyed or released.
555             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
556
557             Usage:
558             \code
559             typedef cds::container::SplitListSet< your_template_args > splitlist_set;
560             splitlist_set theSet;
561             // ...
562             {
563                 splitlist_set::guarded_ptr gp;
564                 theSet.extract( gp, 5 );
565                 // Deal with gp
566                 // ...
567
568                 // Destructor of gp releases internal HP guard
569             }
570             \endcode
571         */
572         template <typename Q>
573         bool extract( guarded_ptr& dest, Q const& key )
574         {
575             return extract_( dest.guard(), key );
576         }
577
578         /// Extracts the item using compare functor \p pred
579         /**
580             The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_extract "extract(guarded_ptr&, Q const&)"
581             but \p pred predicate is used for key comparing.
582
583             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
584             in any order.
585             \p pred must imply the same element order as the comparator used for building the set.
586         */
587         template <typename Q, typename Less>
588         bool extract_with( guarded_ptr& dest, Q const& key, Less pred )
589         {
590             return extract_with_( dest.guard(), key, pred );
591         }
592
593         /// Finds the key \p key
594         /** \anchor cds_nonintrusive_SplitListSet_find_func
595
596             The function searches the item with key equal to \p key and calls the functor \p f for item found.
597             The interface of \p Func functor is:
598             \code
599             struct functor {
600                 void operator()( value_type& item, Q& key );
601             };
602             \endcode
603             where \p item is the item found, \p key is the <tt>find</tt> function argument.
604
605             You may pass \p f argument by reference using \p std::ref.
606
607             The functor may change non-key fields of \p item. Note that the functor is only guarantee
608             that \p item cannot be disposed during functor is executing.
609             The functor does not serialize simultaneous access to the set's \p item. If such access is
610             possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.
611
612             The \p key argument is non-const since it can be used as \p f functor destination i.e., the functor
613             may modify both arguments.
614
615             Note the hash functor specified for class \p Traits template parameter
616             should accept a parameter of type \p Q that can be not the same as \p value_type.
617
618             The function returns \p true if \p key is found, \p false otherwise.
619         */
620         template <typename Q, typename Func>
621         bool find( Q& key, Func f )
622         {
623             return find_( key, f );
624         }
625
626         /// Finds the key \p key using \p pred predicate for searching
627         /**
628             The function is an analog of \ref cds_nonintrusive_SplitListSet_find_func "find(Q&, Func)"
629             but \p pred is used for key comparing.
630             \p Less functor has the interface like \p std::less.
631             \p Less must imply the same element order as the comparator used for building the set.
632         */
633         template <typename Q, typename Less, typename Func>
634         bool find_with( Q& key, Less pred, Func f )
635         {
636             return find_with_( key, pred, f );
637         }
638
639         /// Finds the key \p key
640         /** \anchor cds_nonintrusive_SplitListSet_find_val
641
642             The function searches the item with key equal to \p key
643             and returns \p true if it is found, and \p false otherwise.
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 \ref value_type.
647         */
648         template <typename Q>
649         bool find( Q const& key )
650         {
651             return base_class::find( key );
652         }
653
654         /// Finds the key \p key using \p pred predicate for searching
655         /**
656             The function is an analog of \ref cds_nonintrusive_SplitListSet_find_val "find(Q const&)"
657             but \p pred is used for key comparing.
658             \p Less functor has the interface like \p std::less.
659             \p Less must imply the same element order as the comparator used for building the set.
660         */
661         template <typename Q, typename Less>
662         bool find_with( Q const& key, Less pred )
663         {
664             return base_class::find_with( key, typename maker::template predicate_wrapper<Less>::type() );
665         }
666
667         /// Finds the key \p key and return the item found
668         /** \anchor cds_nonintrusive_SplitListSet_hp_get
669             The function searches the item with key equal to \p key
670             and assigns the item found to guarded pointer \p ptr.
671             The function returns \p true if \p key is found, and \p false otherwise.
672             If \p key is not found the \p ptr parameter is not changed.
673
674             @note Each \p guarded_ptr object uses one GC's guard which can be limited resource.
675
676             Usage:
677             \code
678             typedef cds::container::SplitListSet< your_template_params >  splitlist_set;
679             splitlist_set theSet;
680             // ...
681             {
682                 splitlist_set::guarded_ptr gp;
683                 if ( theSet.get( gp, 5 )) {
684                     // Deal with gp
685                     //...
686                 }
687                 // Destructor of guarded_ptr releases internal HP guard
688             }
689             \endcode
690
691             Note the compare functor specified for split-list set
692             should accept a parameter of type \p Q that can be not the same as \p value_type.
693         */
694         template <typename Q>
695         bool get( guarded_ptr& ptr, Q const& key )
696         {
697             return get_( ptr.guard(), key );
698         }
699
700         /// Finds \p key and return the item found
701         /**
702             The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_get "get( guarded_ptr&, Q const&)"
703             but \p pred is used for comparing the keys.
704
705             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
706             in any order.
707             \p pred must imply the same element order as the comparator used for building the set.
708         */
709         template <typename Q, typename Less>
710         bool get_with( guarded_ptr& ptr, Q const& key, Less pred )
711         {
712             return get_with_( ptr.guard(), key, pred );
713         }
714
715         /// Clears the set (not atomic)
716         void clear()
717         {
718             base_class::clear();
719         }
720
721         /// Checks if the set is empty
722         /**
723             Emptiness is checked by item counting: if item count is zero then assume that the set is empty.
724             Thus, the correct item counting feature is an important part of split-list set implementation.
725         */
726         bool empty() const
727         {
728             return base_class::empty();
729         }
730
731         /// Returns item count in the set
732         size_t size() const
733         {
734             return base_class::size();
735         }
736
737         /// Returns internal statistics
738         stat const& statistics() const
739         {
740             return base_class::statistics();
741         }
742
743     protected:
744         //@cond
745         using base_class::extract_;
746         using base_class::get_;
747
748         template <typename Q, typename Less>
749         bool extract_with_( typename gc::Guard& guard, Q const& key, Less pred )
750         {
751             return base_class::extract_with_( guard, key, typename maker::template predicate_wrapper<Less>::type() );
752         }
753
754         template <typename Q, typename Less>
755         bool get_with_( typename gc::Guard& guard, Q const& key, Less pred )
756         {
757             return base_class::get_with_( guard, key, typename maker::template predicate_wrapper<Less>::type() );
758         }
759
760         //@endcond
761
762     };
763
764
765 }}  // namespace cds::container
766
767 #endif // #ifndef __CDS_CONTAINER_SPLIT_LIST_SET_H