ensure() and find(key) member functions are declared using [[deprecated]] attribute
[libcds.git] / cds / container / split_list_set.h
1 //$$CDS-header$$
2
3 #ifndef CDSLIB_CONTAINER_SPLIT_LIST_SET_H
4 #define CDSLIB_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::DHP, 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::DHP             // 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 typename gc::template guarded_ptr< 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             CDS_UNUSED( pred );
194             return base_class::find_with( val, typename maker::template predicate_wrapper<Less>::type(),
195                 [&f]( node_type& item, Q& val ) { f(item.m_Value, val) ; } );
196         }
197
198         struct node_disposer {
199             void operator()( node_type * pNode )
200             {
201                 free_node( pNode );
202             }
203         };
204         typedef std::unique_ptr< node_type, node_disposer >     scoped_node_ptr;
205
206         bool insert_node( node_type * pNode )
207         {
208             assert( pNode != nullptr );
209             scoped_node_ptr p(pNode);
210
211             if ( base_class::insert( *pNode ) ) {
212                 p.release();
213                 return true;
214             }
215             return false;
216         }
217
218         //@endcond
219
220     protected:
221         /// Forward iterator
222         /**
223             \p IsConst - constness boolean flag
224
225             The forward iterator for a split-list has the following features:
226             - it has no post-increment operator
227             - it depends on underlying ordered list iterator
228             - The iterator object cannot be moved across thread boundary since it contains GC's guard that is thread-private GC data.
229             - Iterator ensures thread-safety even if you delete the item that iterator points to. However, in case of concurrent
230               deleting operations it is no guarantee that you iterate all item in the split-list.
231
232             Therefore, the use of iterators in concurrent environment is not good idea. Use it for debug purpose only.
233         */
234         template <bool IsConst>
235         class iterator_type: protected base_class::template iterator_type<IsConst>
236         {
237             //@cond
238             typedef typename base_class::template iterator_type<IsConst> iterator_base_class;
239             friend class SplitListSet;
240             //@endcond
241         public:
242             /// Value pointer type (const for const iterator)
243             typedef typename cds::details::make_const_type<value_type, IsConst>::pointer   value_ptr;
244             /// Value reference type (const for const iterator)
245             typedef typename cds::details::make_const_type<value_type, IsConst>::reference value_ref;
246
247         public:
248             /// Default ctor
249             iterator_type()
250             {}
251
252             /// Copy ctor
253             iterator_type( iterator_type const& src )
254                 : iterator_base_class( src )
255             {}
256
257         protected:
258             //@cond
259             explicit iterator_type( iterator_base_class const& src )
260                 : iterator_base_class( src )
261             {}
262             //@endcond
263
264         public:
265             /// Dereference operator
266             value_ptr operator ->() const
267             {
268                 return &(iterator_base_class::operator->()->m_Value);
269             }
270
271             /// Dereference operator
272             value_ref operator *() const
273             {
274                 return iterator_base_class::operator*().m_Value;
275             }
276
277             /// Pre-increment
278             iterator_type& operator ++()
279             {
280                 iterator_base_class::operator++();
281                 return *this;
282             }
283
284             /// Assignment operator
285             iterator_type& operator = (iterator_type const& src)
286             {
287                 iterator_base_class::operator=(src);
288                 return *this;
289             }
290
291             /// Equality operator
292             template <bool C>
293             bool operator ==(iterator_type<C> const& i ) const
294             {
295                 return iterator_base_class::operator==(i);
296             }
297
298             /// Equality operator
299             template <bool C>
300             bool operator !=(iterator_type<C> const& i ) const
301             {
302                 return iterator_base_class::operator!=(i);
303             }
304         };
305
306     public:
307         /// Initializes split-ordered list of default capacity
308         /**
309             The default capacity is defined in bucket table constructor.
310             See \p intrusive::split_list::expandable_bucket_table, \p intrusive::split_list::static_bucket_table
311             which selects by \p split_list::dynamic_bucket_table option.
312         */
313         SplitListSet()
314             : base_class()
315         {}
316
317         /// Initializes split-ordered list
318         SplitListSet(
319             size_t nItemCount           ///< estimated average of item count
320             , size_t nLoadFactor = 1    ///< the load factor - average item count per bucket. Small integer up to 8, default is 1.
321             )
322             : base_class( nItemCount, nLoadFactor )
323         {}
324
325     public:
326         /// Forward iterator
327         typedef iterator_type<false>  iterator;
328
329         /// Const forward iterator
330         typedef iterator_type<true>    const_iterator;
331
332         /// Returns a forward iterator addressing the first element in a set
333         /**
334             For empty set \code begin() == end() \endcode
335         */
336         iterator begin()
337         {
338             return iterator( base_class::begin() );
339         }
340
341         /// Returns an iterator that addresses the location succeeding the last element in a set
342         /**
343             Do not use the value returned by <tt>end</tt> function to access any item.
344             The returned value can be used only to control reaching the end of the set.
345             For empty set \code begin() == end() \endcode
346         */
347         iterator end()
348         {
349             return iterator( base_class::end() );
350         }
351
352         /// Returns a forward const iterator addressing the first element in a set
353         const_iterator begin() const
354         {
355             return cbegin();
356         }
357         /// Returns a forward const iterator addressing the first element in a set
358         const_iterator cbegin() const
359         {
360             return const_iterator( base_class::cbegin() );
361         }
362
363         /// Returns an const iterator that addresses the location succeeding the last element in a set
364         const_iterator end() const
365         {
366             return cend();
367         }
368         /// Returns an const iterator that addresses the location succeeding the last element in a set
369         const_iterator cend() const
370         {
371             return const_iterator( base_class::cend() );
372         }
373
374     public:
375         /// Inserts new node
376         /**
377             The function creates a node with copy of \p val value
378             and then inserts the node created into the set.
379
380             The type \p Q should contain as minimum the complete key for the node.
381             The object of \ref value_type should be constructible from a value of type \p Q.
382             In trivial case, \p Q is equal to \ref value_type.
383
384             Returns \p true if \p val is inserted into the set, \p false otherwise.
385         */
386         template <typename Q>
387         bool insert( Q const& val )
388         {
389             return insert_node( alloc_node( val ) );
390         }
391
392         /// Inserts new node
393         /**
394             The function allows to split creating of new item into two part:
395             - create item with key only
396             - insert new item into the set
397             - if inserting is success, calls  \p f functor to initialize value-field of \p val.
398
399             The functor signature is:
400             \code
401                 void func( value_type& val );
402             \endcode
403             where \p val is the item inserted.
404
405             The user-defined functor is called only if the inserting is success.
406
407             @warning For \ref cds_intrusive_MichaelList_hp "MichaelList" as the bucket see \ref cds_intrusive_item_creating "insert item troubleshooting".
408             \ref cds_intrusive_LazyList_hp "LazyList" provides exclusive access to inserted item and does not require any node-level
409             synchronization.
410         */
411         template <typename Q, typename Func>
412         bool insert( Q const& val, Func f )
413         {
414             scoped_node_ptr pNode( alloc_node( val ));
415
416             if ( base_class::insert( *pNode, [&f](node_type& node) { f( node.m_Value ) ; } )) {
417                 pNode.release();
418                 return true;
419             }
420             return false;
421         }
422
423         /// Inserts data of type \p value_type created from \p args
424         /**
425             Returns \p true if inserting successful, \p false otherwise.
426         */
427         template <typename... Args>
428         bool emplace( Args&&... args )
429         {
430             return insert_node( alloc_node( std::forward<Args>(args)...));
431         }
432
433         /// Updates the node
434         /**
435             The operation performs inserting or changing data with lock-free manner.
436
437             If \p key is not found in the set, then \p key is inserted iff \p bAllowInsert is \p true.
438             Otherwise, the functor \p func is called with item found.
439
440             The functor signature is:
441             \code
442                 struct my_functor {
443                     void operator()( bool bNew, value_type& item, const Q& val );
444                 };
445             \endcode
446             with arguments:
447             - \p bNew - \p true if the item has been inserted, \p false otherwise
448             - \p item - item of the set
449             - \p val - argument \p val passed into the \p %update() function
450
451             The functor may change non-key fields of the \p item.
452
453             Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
454             \p second is true if new item has been added or \p false if the item with \p key
455             already is in the map.
456
457             @warning For \ref cds_intrusive_MichaelList_hp "MichaelList" as the bucket see \ref cds_intrusive_item_creating "insert item troubleshooting".
458             \ref cds_intrusive_LazyList_hp "LazyList" provides exclusive access to inserted item and does not require any node-level
459             synchronization.
460         */
461         template <typename Q, typename Func>
462         std::pair<bool, bool> update( Q const& val, Func func, bool bAllowInsert = true )
463         {
464             scoped_node_ptr pNode( alloc_node( val ));
465
466             std::pair<bool, bool> bRet = base_class::update( *pNode,
467                 [&func, &val]( bool bNew, node_type& item,  node_type const& /*val*/ ) {
468                     func( bNew, item.m_Value, val );
469                 }, bAllowInsert );
470
471             if ( bRet.first && bRet.second )
472                 pNode.release();
473             return bRet;
474         }
475         //@cond
476         template <typename Q, typename Func>
477         CDS_DEPRECATED("ensure() is deprecated, use update()")
478         std::pair<bool, bool> ensure( Q const& val, Func func )
479         {
480             return update( val, func, true );
481         }
482         //@endcond
483
484         /// Deletes \p key from the set
485         /** \anchor cds_nonintrusive_SplitListSet_erase_val
486
487             The item comparator should be able to compare the values of type \p value_type
488             and the type \p Q.
489
490             Return \p true if key is found and deleted, \p false otherwise
491         */
492         template <typename Q>
493         bool erase( Q const& key )
494         {
495             return base_class::erase( key );
496         }
497
498         /// Deletes the item from the set using \p pred predicate for searching
499         /**
500             The function is an analog of \ref cds_nonintrusive_SplitListSet_erase_val "erase(Q const&)"
501             but \p pred is used for key comparing.
502             \p Less functor has the interface like \p std::less.
503             \p Less must imply the same element order as the comparator used for building the set.
504         */
505         template <typename Q, typename Less>
506         bool erase_with( Q const& key, Less pred )
507         {
508             CDS_UNUSED( pred );
509             return base_class::erase_with( key, typename maker::template predicate_wrapper<Less>::type() );
510         }
511
512         /// Deletes \p key from the set
513         /** \anchor cds_nonintrusive_SplitListSet_erase_func
514
515             The function searches an item with key \p key, calls \p f functor
516             and deletes the item. If \p key is not found, the functor is not called.
517
518             The functor \p Func interface:
519             \code
520             struct extractor {
521                 void operator()(value_type const& val);
522             };
523             \endcode
524
525             Since the key of split-list \p value_type is not explicitly specified,
526             template parameter \p Q defines the key type searching in the list.
527             The list item comparator should be able to compare the values of the type \p value_type
528             and the type \p Q.
529
530             Return \p true if key is found and deleted, \p false otherwise
531         */
532         template <typename Q, typename Func>
533         bool erase( Q const& key, Func f )
534         {
535             return base_class::erase( key, [&f](node_type& node) { f( node.m_Value ); } );
536         }
537
538         /// Deletes the item from the set using \p pred predicate for searching
539         /**
540             The function is an analog of \ref cds_nonintrusive_SplitListSet_erase_func "erase(Q const&, Func)"
541             but \p pred is used for key comparing.
542             \p Less functor has the interface like \p std::less.
543             \p Less must imply the same element order as the comparator used for building the set.
544         */
545         template <typename Q, typename Less, typename Func>
546         bool erase_with( Q const& key, Less pred, Func f )
547         {
548             CDS_UNUSED( pred );
549             return base_class::erase_with( key, typename maker::template predicate_wrapper<Less>::type(),
550                 [&f](node_type& node) { f( node.m_Value ); } );
551         }
552
553         /// Extracts the item with specified \p key
554         /** \anchor cds_nonintrusive_SplitListSet_hp_extract
555             The function searches an item with key equal to \p key,
556             unlinks it from the set, and returns it as \p guarded_ptr.
557             If \p key is not found the function returns an empty guarded pointer.
558
559             Note the compare functor should accept a parameter of type \p Q that may be not the same as \p value_type.
560
561             The extracted item is freed automatically when returned \p guarded_ptr object will be destroyed or released.
562             @note Each \p guarded_ptr object uses the GC's guard that can be limited resource.
563
564             Usage:
565             \code
566             typedef cds::container::SplitListSet< your_template_args > splitlist_set;
567             splitlist_set theSet;
568             // ...
569             {
570                 splitlist_set::guarded_ptr gp(theSet.extract( 5 ));
571                 if ( gp ) {
572                     // Deal with gp
573                     // ...
574                 }
575                 // Destructor of gp releases internal HP guard
576             }
577             \endcode
578         */
579         template <typename Q>
580         guarded_ptr extract( Q const& key )
581         {
582             guarded_ptr gp;
583             extract_( gp.guard(), key );
584             return gp;
585         }
586
587         /// Extracts the item using compare functor \p pred
588         /**
589             The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_extract "extract(Q const&)"
590             but \p pred predicate is used for key comparing.
591
592             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
593             in any order.
594             \p pred must imply the same element order as the comparator used for building the set.
595         */
596         template <typename Q, typename Less>
597         guarded_ptr extract_with( Q const& key, Less pred )
598         {
599             guarded_ptr gp;
600             extract_with_( gp.guard(), key, pred );
601             return gp;
602         }
603
604         /// Finds the key \p key
605         /** \anchor cds_nonintrusive_SplitListSet_find_func
606
607             The function searches the item with key equal to \p key and calls the functor \p f for item found.
608             The interface of \p Func functor is:
609             \code
610             struct functor {
611                 void operator()( value_type& item, Q& key );
612             };
613             \endcode
614             where \p item is the item found, \p key is the <tt>find</tt> function argument.
615
616             The functor may change non-key fields of \p item. Note that the functor is only guarantee
617             that \p item cannot be disposed during functor is executing.
618             The functor does not serialize simultaneous access to the set's \p item. If such access is
619             possible you must provide your own synchronization schema on item level to exclude unsafe item modifications.
620
621             The \p key argument is non-const since it can be used as \p f functor destination i.e., the functor
622             may modify both arguments.
623
624             Note the hash functor specified for class \p Traits template parameter
625             should accept a parameter of type \p Q that can be not the same as \p value_type.
626
627             The function returns \p true if \p key is found, \p false otherwise.
628         */
629         template <typename Q, typename Func>
630         bool find( Q& key, Func f )
631         {
632             return find_( key, f );
633         }
634         //@cond
635         template <typename Q, typename Func>
636         bool find( Q const& key, Func f )
637         {
638             return find_( key, f );
639         }
640         //@endcond
641
642         /// Finds the key \p key using \p pred predicate for searching
643         /**
644             The function is an analog of \ref cds_nonintrusive_SplitListSet_find_func "find(Q&, Func)"
645             but \p pred is used for key comparing.
646             \p Less functor has the interface like \p std::less.
647             \p Less must imply the same element order as the comparator used for building the set.
648         */
649         template <typename Q, typename Less, typename Func>
650         bool find_with( Q& key, Less pred, Func f )
651         {
652             return find_with_( key, pred, f );
653         }
654         //@cond
655         template <typename Q, typename Less, typename Func>
656         bool find_with( Q const& key, Less pred, Func f )
657         {
658             return find_with_( key, pred, f );
659         }
660         //@endcond
661
662         /// Checks whether the set contains \p key
663         /**
664             The function searches the item with key equal to \p key
665             and returns \p true if it is found, and \p false otherwise.
666
667             Note the hash functor specified for class \p Traits template parameter
668             should accept a parameter of type \p Q that can be not the same as \p value_type.
669             Otherwise, you may use \p contains( Q const&, Less pred ) functions with explicit predicate for key comparing.
670         */
671         template <typename Q>
672         bool contains( Q const& key )
673         {
674             return base_class::contains( key );
675         }
676         //@cond
677         template <typename Q>
678         CDS_DEPRECATED("deprecated, use contains()")
679         bool find( Q const& key )
680         {
681             return contains( key );
682         }
683         //@endcond
684
685         /// Checks whether the map contains \p key using \p pred predicate for searching
686         /**
687             The function is similar to <tt>contains( key )</tt> 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 map.
690         */
691         template <typename Q, typename Less>
692         bool contains( Q const& key, Less pred )
693         {
694             CDS_UNUSED( pred );
695             return base_class::contains( key, typename maker::template predicate_wrapper<Less>::type() );
696         }
697         //@cond
698         template <typename Q, typename Less>
699         CDS_DEPRECATED("deprecated, use contains()")
700         bool find_with( Q const& key, Less pred )
701         {
702             return contains( key, pred );
703         }
704         //@endcond
705
706         /// Finds the key \p key and return the item found
707         /** \anchor cds_nonintrusive_SplitListSet_hp_get
708             The function searches the item with key equal to \p key
709             and returns the item found as \p guarded_ptr.
710             If \p key is not found the function returns an empty guarded pointer.
711
712             @note Each \p guarded_ptr object uses one GC's guard which can be limited resource.
713
714             Usage:
715             \code
716             typedef cds::container::SplitListSet< your_template_params >  splitlist_set;
717             splitlist_set theSet;
718             // ...
719             {
720                 splitlist_set::guarded_ptr gp(theSet.get( 5 ));
721                 if ( gp ) {
722                     // Deal with gp
723                     //...
724                 }
725                 // Destructor of guarded_ptr releases internal HP guard
726             }
727             \endcode
728
729             Note the compare functor specified for split-list set
730             should accept a parameter of type \p Q that can be not the same as \p value_type.
731         */
732         template <typename Q>
733         guarded_ptr get( Q const& key )
734         {
735             guarded_ptr gp;
736             get_( gp.guard(), key );
737             return gp;
738         }
739
740         /// Finds \p key and return the item found
741         /**
742             The function is an analog of \ref cds_nonintrusive_SplitListSet_hp_get "get( Q const&)"
743             but \p pred is used for comparing the keys.
744
745             \p Less functor has the semantics like \p std::less but should take arguments of type \ref value_type and \p Q
746             in any order.
747             \p pred must imply the same element order as the comparator used for building the set.
748         */
749         template <typename Q, typename Less>
750         guarded_ptr get_with( Q const& key, Less pred )
751         {
752             guarded_ptr gp;
753             get_with_( gp.guard(), key, pred );
754             return gp;
755         }
756
757         /// Clears the set (not atomic)
758         void clear()
759         {
760             base_class::clear();
761         }
762
763         /// Checks if the set is empty
764         /**
765             Emptiness is checked by item counting: if item count is zero then assume that the set is empty.
766             Thus, the correct item counting feature is an important part of split-list set implementation.
767         */
768         bool empty() const
769         {
770             return base_class::empty();
771         }
772
773         /// Returns item count in the set
774         size_t size() const
775         {
776             return base_class::size();
777         }
778
779         /// Returns internal statistics
780         stat const& statistics() const
781         {
782             return base_class::statistics();
783         }
784
785     protected:
786         //@cond
787         using base_class::extract_;
788         using base_class::get_;
789
790         template <typename Q, typename Less>
791         bool extract_with_( typename guarded_ptr::native_guard& guard, Q const& key, Less pred )
792         {
793             CDS_UNUSED( pred );
794             return base_class::extract_with_( guard, key, typename maker::template predicate_wrapper<Less>::type() );
795         }
796
797         template <typename Q, typename Less>
798         bool get_with_( typename guarded_ptr::native_guard& guard, Q const& key, Less pred )
799         {
800             CDS_UNUSED( pred );
801             return base_class::get_with_( guard, key, typename maker::template predicate_wrapper<Less>::type() );
802         }
803
804         //@endcond
805
806     };
807
808
809 }}  // namespace cds::container
810
811 #endif // #ifndef CDSLIB_CONTAINER_SPLIT_LIST_SET_H