3 #ifndef __CDS_CONTAINER_STRIPED_SET_H
4 #define __CDS_CONTAINER_STRIPED_SET_H
6 #include <cds/intrusive/striped_set.h>
7 #include <cds/container/striped_set/adapter.h>
9 namespace cds { namespace container {
12 /** @ingroup cds_nonintrusive_set
15 - [2008] Maurice Herlihy, Nir Shavit "The Art of Multiprocessor Programming"
17 Lock striping is very simple technique.
18 The set consists of the bucket table and the array of locks.
19 Initially, the capacity of lock array and bucket table is the same.
20 When set is resized, bucket table capacity will be doubled but lock array will not.
21 The lock \p i protects each bucket \p j, where <tt> j = i mod L </tt>,
22 where \p L - the size of lock array.
25 - \p Container - the container class that is used as bucket table entry. The \p Container class should support
26 an uniform interface described below.
27 - \p Options - options
29 The \p %StripedSet class does not exactly dictate the type of container that should be used as a \p Container bucket.
30 Instead, the class supports different container type for the bucket, for exampe, \p std::list, \p std::set and others.
32 Remember that \p %StripedSet class algorithm ensures sequential blocking access to its bucket through the mutex type you specify
33 among \p Options template arguments.
36 - opt::mutex_policy - concurrent access policy.
37 Available policies: intrusive::striped_set::striping, intrusive::striped_set::refinable.
38 Default is %striped_set::striping.
39 - opt::hash - hash functor. Default option value see opt::v::hash_selector<opt::none> which selects default hash functor for
41 - opt::compare - key comparison functor. No default functor is provided.
42 If the option is not specified, the opt::less is used.
43 - opt::less - specifies binary predicate used for key comparison. Default is \p std::less<T>.
44 - opt::item_counter - item counter type. Default is \p atomicity::item_counter since some operation on the counter is performed
45 without locks. Note that item counting is an essential part of the set algorithm, so dummy type like atomicity::empty_item_counter
47 - opt::allocator - the allocator type using for memory allocation of bucket table and lock array. Default is CDS_DEFAULT_ALLOCATOR.
48 - opt::resizing_policy - the resizing policy that is a functor that decides when to resize the hash set.
49 Default option value depends on bucket container type:
50 for sequential containers like \p std::list, \p std::vector the resizing policy is striped_set::load_factor_resizing<4>;
51 for other type of containers like \p std::set, \p std::unordered_set the resizing policy is striped_set::no_resizing.
52 See \ref striped_set namespace for list of all possible types of the option.
53 Note that the choose of resizing policy depends of \p Container type:
54 for sequential containers like \p std::list, \p std::vector and so on, right choosing of the policy can
55 significantly improve performance.
56 For other, non-sequential types of \p Container (like a \p std::set)
57 the resizing policy is not so important.
58 - opt::copy_policy - the copy policy which is used to copy items from the old set to the new one when resizing.
59 The policy can be optionally used in adapted bucket container for performance reasons of resizing.
60 The detail of copy algorithm depends on type of bucket container and explains below.
62 opt::compare or opt::less options are used in some \p Container class for searching an item.
63 opt::compare option has the highest priority: if opt::compare is specified, opt::less is not used.
65 You can pass other option that would be passed to <tt>adapt</tt> metafunction, see below.
67 <b>Internal details</b>
69 The \p %StripedSet class cannot utilize the \p Container container specified directly, but only its adapted variant which
70 supports an unified interface. Internally, the adaptation is made via striped_set::adapt metafunction that wraps bucket container
71 and provides the unified bucket interface suitable for \p %StripedSet. Such adaptation is completely transparent for you -
72 you don't need to call \p adapt metafunction directly, \p %StripedSet class's internal machinery itself invokes appropriate
73 \p adapt metafunction to adjust your \p Container container class to \p %StripedSet bucket's internal interface.
74 All you need is to include a right header before <tt>striped_hash_set.h</tt>.
76 By default, <tt>striped_set::adapt<AnyContainer, Options...> </tt> metafunction does not make any wrapping to \p AnyContainer,
77 so, the result <tt>%striped_set::adapt<AnyContainer, Options...>::type </tt> is the same as \p AnyContainer.
78 However, there are a lot of specializations of <tt>striped_set::adapt</tt> for well-known containers, see table below.
79 Any of this specialization wraps corresponding container making it suitable for the set's bucket.
80 Remember, you should include the proper header file for \p adapt <b>before</b> including <tt>striped_hash_set.h</tt>.
84 <th>.h-file for \p adapt</th>
89 <td> \p std::list</td>
90 <td><tt><cds/container/striped_set/std_list.h></tt></td>
92 #include <cds/container/striped_set/std_list.h>
93 #include <cds/container/striped_hash_set.h>
94 typedef cds::container::StripedSet<
96 cds::opt::less< std::less<T> >
102 Template argument pack \p Options <b>must</b> contain cds::opt::less or cds::opt::compare for type \p T stored in the list
106 <td> \p std::vector</td>
107 <td><tt><cds/container/striped_set/std_vector.h></tt></td>
109 #include <cds/container/striped_set/std_vector.h>
110 #include <cds/container/striped_hash_set.h>
111 typedef cds::container::StripedSet<
113 cds::opt::less< std::less<T> >
118 The vector is ordered.
119 Template argument pack \p Options <b>must</b> contain cds::opt::less or cds::opt::compare for type \p T stored in the list
123 <td> \p std::set</td>
124 <td><tt><cds/container/striped_set/std_set.h></tt></td>
126 #include <cds/container/striped_set/std_set.h>
127 #include <cds/container/striped_hash_set.h>
128 typedef cds::container::StripedSet<
129 std::set< T, std::less<T> >
137 <td> \p std::unordered_set</td>
138 <td><tt><cds/container/striped_set/std_hash_set.h></tt></td>
140 #include <cds/container/striped_set/std_hash_set.h>
141 #include <cds/container/striped_hash_set.h>
142 typedef cds::container::StripedSet<
152 You should provide two different hash function \p h1 and \p h2 - one for std::unordered_set and other for \p %StripedSet.
153 For the best result, \p h1 and \p h2 must be orthogonal i.e. <tt> h1(X) != h2(X) </tt> for any value \p X.
157 <td>\p stdext::hash_set (only for MS VC++ 2008)</td>
158 <td><tt><cds/container/striped_set/std_hash_set.h></tt></td>
160 #include <cds/container/striped_set/std_hash_set.h>
161 #include <cds/container/striped_hash_set.h>
162 typedef cds::container::StripedSet<
164 stdext::hash_compare<
173 You should provide two different hash function \p h1 and \p h2 - one for stdext::hash_set and other for \p %StripedSet.
174 For the best result, \p h1 and \p h2 must be orthogonal i.e. <tt> h1(X) != h2(X) </tt> for any value \p X.
178 <td> \p boost::container::slist</td>
179 <td><tt><cds/container/striped_set/boost_slist.h></tt></td>
181 #include <cds/container/striped_set/boost_slist.h>
182 #include <cds/container/striped_hash_set.h>
183 typedef cds::container::StripedSet<
184 boost::container::slist<T>
190 \p Options <b>must</b> contain cds::opt::less or cds::opt::compare.
194 <td> \p boost::container::list</td>
195 <td><tt><cds/container/striped_set/boost_list.h></tt></td>
197 #include <cds/container/striped_set/boost_list.h>
198 #include <cds/container/striped_hash_set.h>
199 typedef cds::container::StripedSet<
200 boost::container::list<T>
206 \p Options <b>must</b> contain cds::opt::less or cds::opt::compare.
210 <td> \p boost::container::vector</td>
211 <td><tt><cds/container/striped_set/boost_vector.h></tt></td>
213 #include <cds/container/striped_set/boost_vector.h>
214 #include <cds/container/striped_hash_set.h>
215 typedef cds::container::StripedSet<
216 boost::container::vector<T>,
217 cds::opt::less< std::less<T> >
222 The vector is ordered.
223 Template argument pack \p Options <b>must</b> contain cds::opt::less or cds::opt::compare for type \p T stored in the list
227 <td> \p boost::container::stable_vector</td>
228 <td><tt><cds/container/striped_set/boost_stable_vector.h></tt></td>
230 #include <cds/container/striped_set/boost_stable_vector.h>
231 #include <cds/container/striped_hash_set.h>
232 typedef cds::container::StripedSet<
233 boost::container::stable_vector<T>,
234 cds::opt::less< std::less<T> >
239 The vector is ordered.
240 Template argument pack \p Options <b>must</b> contain cds::opt::less or cds::opt::compare for type \p T stored in the list
244 <td> \p boost::container::set</td>
245 <td><tt><cds/container/striped_set/boost_set.h></tt></td>
247 #include <cds/container/striped_set/boost_set.h>
248 #include <cds/container/striped_hash_set.h>
249 typedef cds::container::StripedSet<
250 boost::container::set< T, std::less<T> >
258 <td> \p boost::container::flat_set</td>
259 <td><tt><cds/container/striped_set/boost_flat_set.h></tt></td>
261 #include <cds/container/striped_set/boost_flat_set.h>
262 #include <cds/container/striped_hash_set.h>
263 typedef cds::container::StripedSet<
264 boost::container::flat_set< T, std::less<T> >
272 <td> \p boost::unordered_set</td>
273 <td><tt><cds/container/striped_set/boost_unordered_set.h></tt></td>
275 #include <cds/container/striped_set/boost_unordered_set.h>
276 #include <cds/container/striped_hash_set.h>
277 typedef cds::container::StripedSet<
278 boost::unordered_set<
287 You should provide two different hash function \p h1 and \p h2 - one for boost::unordered_set and other for \p %StripedSet.
288 For the best result, \p h1 and \p h2 must be orthogonal i.e. <tt> h1(X) != h2(X) </tt> for any value \p X.
293 You can use another container type as set's bucket.
294 Suppose, you have a container class \p MyBestContainer and you want to integrate it with \p %StripedSet as bucket type.
295 There are two possibility:
296 - either your \p MyBestContainer class has native support of bucket's interface;
297 in this case, you can use default <tt>striped_set::adapt</tt> metafunction;
298 - or your \p MyBestContainer class does not support bucket's interface, which means, that you should develop a specialization
299 <tt>cds::container::striped_set::adapt<MyBestContainer> </tt> metafunction providing necessary interface.
301 The <tt>striped_set::adapt< Container, Options... ></tt> metafunction has two template argument:
302 - \p Container is the class that should be used as the bucket, for example, <tt>std::list< T ></tt>.
303 - \p Options pack is the options from \p %StripedSet declaration. The \p adapt metafunction can use
304 any option from \p Options for its internal use. For example, a \p compare option can be passed to \p adapt
305 metafunction via \p Options argument of \p %StripedSet declaration.
307 See striped_set::adapt metafunction for the description of interface that the bucket container must provide
308 to be %StripedSet compatible.
311 There are three predefined copy policy:
312 - \p cds::container::striped_set::copy_item - copy item from old bucket to new one when resizing using copy ctor. It is default policy for
313 any compiler that do not support move semantics
314 - \p cds::container::striped_set::move_item - move item from old bucket to new one when resizing using move semantics. It is default policy for
315 any compiler that support move semantics. If compiler does not support move semantics, the move policy is the same as \p copy_item
316 - \p cds::container::striped_set::swap_item - copy item from old bucket to new one when resizing using \p std::swap. Not all containers support
317 this copy policy, see details in table below.
319 You can define your own copy policy specifically for your case.
320 Note, right copy policy can significantly improve the performance of resizing.
333 - \p boost::stable_vector
337 void operator()( std::list<T>& list, std::list<T>::iterator itInsert, std::list<T>::iterator itWhat )
339 list.insert( itInsert, *itWhat );
344 // The type T stored in the list must be swappable
346 void operator()( std::list<T>& list, std::list<T>::iterator itInsert, std::list<T>::iterator itWhat )
348 std::swap( *list.insert( itInsert, T() ), *itWhat );
354 void operator()( std::list<T>& list, std::list<T>::iterator itInsert, std::list<T>::iterator itWhat )
356 list.insert( itInsert, std::move( *itWhat ) );
364 - \p std::unordered_set
365 - \p stdext::hash_set (only for MS VC++ 2008)
369 void operator()( std::set<T>& set, std::set<T>::iterator itWhat )
371 set.insert( *itWhat );
374 \p swap_item is not applicable (same as \p copy_item)
378 void operator()( std::set<T>& set, std::set<T>::iterator itWhat )
380 set.insert( std::move( *itWhat ));
386 - \p boost::container::slist
390 void operator()( bc::slist<T>& list, bc::slist<T>::iterator itInsert, bc::slist<T>::iterator itWhat )
392 list.insert_after( itInsert, *itWhat );
397 // The type T stored in the list must be swappable
399 void operator()( bc::slist<T>& list, bc::slist<T>::iterator itInsert, bc::slist<T>::iterator itWhat )
401 std::swap( *list.insert_after( itInsert, T() ), *itWhat );
407 void operator()( bc::slist<T>& list, bc::slist<T>::iterator itInsert, bc::slist<T>::iterator itWhat )
409 list.insert_after( itInsert, std::move( *itWhat ) );
416 <b>Advanced functions</b>
418 <b>libcds</b> provides some advanced functions like \p erase_with, \p find_with,
419 that cannot be supported by all underlying containers.
420 The table below shows whether underlying container supports those functions
421 (the sign "+" means "container supports the function"):
426 <th>\p find_with</th>
427 <th>\p erse_with</th>
430 <td> \p std::list</td>
435 <td> \p std::vector</td>
440 <td> \p std::set</td>
445 <td> \p std::unordered_set</td>
450 <td>\p stdext::hash_set (only for MS VC++ 2008)</td>
455 <td> \p boost::container::slist</td>
460 <td> \p boost::container::list</td>
465 <td> \p boost::container::vector</td>
470 <td> \p boost::container::stable_vector</td>
475 <td> \p boost::container::set</td>
480 <td> \p boost::container::flat_set</td>
485 <td> \p boost::unordered_set</td>
491 template <class Container, typename... Options>
492 class StripedSet: protected intrusive::StripedSet<Container, Options...>
495 typedef intrusive::StripedSet<Container, Options...> base_class;
499 typedef typename base_class::default_options default_options;
500 typedef typename base_class::options options;
503 typedef Container underlying_container_type ; ///< original intrusive container type for the bucket
504 typedef typename base_class::bucket_type bucket_type ; ///< container type adapted for hash set
505 typedef typename bucket_type::value_type value_type ; ///< value type stored in the set
507 typedef typename base_class::hash hash ; ///< Hash functor
508 typedef typename base_class::item_counter item_counter ; ///< Item counter
509 typedef typename base_class::resizing_policy resizing_policy ; ///< Resizing policy
510 typedef typename base_class::allocator_type allocator_type ; ///< allocator type specified in options.
511 typedef typename base_class::mutex_policy mutex_policy ; ///< Mutex policy
515 typedef typename base_class::scoped_cell_lock scoped_cell_lock;
516 typedef typename base_class::scoped_full_lock scoped_full_lock;
517 typedef typename base_class::scoped_resize_lock scoped_resize_lock;
521 /// Default ctor. The initial capacity is 16.
526 /// Ctor with initial capacity specified
528 size_t nCapacity ///< Initial size of bucket table and lock array. Must be power of two, the minimum is 16.
529 ) : base_class( nCapacity )
532 /// Ctor with resizing policy (copy semantics)
534 This constructor initializes m_ResizingPolicy member with copy of \p resizingPolicy parameter
537 size_t nCapacity ///< Initial size of bucket table and lock array. Must be power of two, the minimum is 16.
538 ,resizing_policy const& resizingPolicy ///< Resizing policy
539 ) : base_class( nCapacity, resizingPolicy )
542 /// Ctor with resizing policy (move semantics)
544 This constructor initializes m_ResizingPolicy member moving \p resizingPolicy parameter
545 Move semantics is used. Available only for the compilers that supports C++11 rvalue reference.
548 size_t nCapacity ///< Initial size of bucket table and lock array. Must be power of two, the minimum is 16.
549 ,resizing_policy&& resizingPolicy ///< Resizing policy
550 ) : base_class( nCapacity, std::forward<resizing_policy>(resizingPolicy) )
553 /// Destructor destroys internal data
560 The function creates a node with copy of \p val value
561 and then inserts the node created into the set.
563 The type \p Q should contain as minimum the complete key for the node.
564 The object of \ref value_type should be constructible from a value of type \p Q.
565 In trivial case, \p Q is equal to \ref value_type.
567 Returns \p true if \p val is inserted into the set, \p false otherwise.
569 template <typename Q>
570 bool insert( Q const& val )
572 return insert( val, []( value_type& ) {} );
577 The function allows to split creating of new item into two part:
578 - create item with key only
579 - insert new item into the set
580 - if inserting is success, calls \p f functor to initialize value-field of new item .
582 The functor signature is:
584 void func( value_type& item );
586 where \p item is the item inserted.
588 The type \p Q can differ from \ref value_type of items storing in the set.
589 Therefore, the \p value_type should be constructible from type \p Q.
591 The user-defined functor is called only if the inserting is success. It can be passed by reference
594 template <typename Q, typename Func>
595 bool insert( Q const& val, Func f )
599 size_t nHash = base_class::hashing( val );
600 bucket_type * pBucket;
602 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
603 pBucket = base_class::bucket( nHash );
604 bOk = pBucket->insert( val, f );
605 bResize = bOk && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
609 base_class::resize();
613 /// Inserts data of type \p %value_type constructed with <tt>std::forward<Args>(args)...</tt>
615 Returns \p true if inserting successful, \p false otherwise.
617 template <typename... Args>
618 bool emplace( Args&&... args )
622 size_t nHash = base_class::hashing( value_type( std::forward<Args>(args)...));
623 bucket_type * pBucket;
625 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
626 pBucket = base_class::bucket( nHash );
628 bOk = pBucket->emplace( std::forward<Args>(args)...);
629 bResize = bOk && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
633 base_class::resize();
637 /// Ensures that the \p val exists in the set
639 The operation performs inserting or changing data.
641 If the \p val key not found in the set, then the new item created from \p val
642 is inserted into the set. Otherwise, the functor \p func is called with the item found.
643 The functor \p Func should be a function with signature:
645 void func( bool bNew, value_type& item, const Q& val );
650 void operator()( bool bNew, value_type& item, const Q& val );
655 - \p bNew - \p true if the item has been inserted, \p false otherwise
656 - \p item - item of the list
657 - \p val - argument \p val passed into the \p ensure function
659 The functor can change non-key fields of the \p item.
661 You can pass \p func argument by value or by reference using \p std::ref
663 Returns <tt> std::pair<bool, bool> </tt> where \p first is true if operation is successfull,
664 \p second is true if new item has been added or \p false if the item with \p val key
667 template <typename Q, typename Func>
668 std::pair<bool, bool> ensure( Q const& val, Func func )
670 std::pair<bool, bool> result;
672 size_t nHash = base_class::hashing( val );
673 bucket_type * pBucket;
675 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
676 pBucket = base_class::bucket( nHash );
678 result = pBucket->ensure( val, func );
679 bResize = result.first && result.second && base_class::m_ResizingPolicy( ++base_class::m_ItemCounter, *this, *pBucket );
683 base_class::resize();
687 /// Delete \p key from the set
688 /** \anchor cds_nonintrusive_StripedSet_erase
690 The set item comparator should be able to compare the type \p value_type and the type \p Q.
691 Return \p true if key is found and deleted, \p false otherwise
693 template <typename Q>
694 bool erase( Q const& key )
696 return erase( key, [](value_type const&) {} );
699 /// Deletes the item from the set using \p pred predicate for searching
701 The function is an analog of \ref cds_nonintrusive_StripedSet_erase "erase(Q const&)"
702 but \p pred is used for key comparing.
703 \p Less functor has the interface like \p std::less.
704 \p pred must imply the same element order as the comparator used for building the set.
706 @note This function is enabled if the compiler supports C++11
707 default template arguments for function template <b>and</b> the underlying container
708 supports \p %erase_with feature.
710 template < typename Q, typename Less
711 ,typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_erase_with >::type >
712 bool erase_with( Q const& key, Less pred )
714 return erase_with( key, pred, [](value_type const&) {} );
717 /// Delete \p key from the set
718 /** \anchor cds_nonintrusive_StripedSet_erase_func
720 The function searches an item with key \p key, calls \p f functor with item found
721 and deletes it. If \p key is not found, the functor is not called.
723 The functor \p Func interface is:
726 void operator()(value_type const& val);
729 The functor can be passed by value or by reference using <tt>boost:ref</tt>
731 Return \p true if key is found and deleted, \p false otherwise
733 template <typename Q, typename Func>
734 bool erase( Q const& key, Func f )
737 size_t nHash = base_class::hashing( key );
739 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
740 bucket_type * pBucket = base_class::bucket( nHash );
742 bOk = pBucket->erase( key, f );
746 --base_class::m_ItemCounter;
750 /// Deletes the item from the set using \p pred predicate for searching
752 The function is an analog of \ref cds_nonintrusive_StripedSet_erase_func "erase(Q const&, Func)"
753 but \p pred is used for key comparing.
754 \p Less functor has the interface like \p std::less.
755 \p pred must imply the same element order as the comparator used for building the set.
757 @note This function is enabled if the compiler supports C++11
758 default template arguments for function template <b>and</b> the underlying container
759 supports \p %erase_with feature.
761 template < typename Q, typename Less, typename Func
762 , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_erase_with >::type >
763 bool erase_with( Q const& key, Less pred, Func f )
766 size_t nHash = base_class::hashing( key );
768 scoped_cell_lock sl( base_class::m_MutexPolicy, nHash );
769 bucket_type * pBucket = base_class::bucket( nHash );
771 bOk = pBucket->erase( key, pred, f );
775 --base_class::m_ItemCounter;
779 /// Find the key \p val
780 /** \anchor cds_nonintrusive_StripedSet_find_func
782 The function searches the item with key equal to \p val and calls the functor \p f for item found.
783 The interface of \p Func functor is:
786 void operator()( value_type& item, Q& val );
789 where \p item is the item found, \p val is the <tt>find</tt> function argument.
791 You can pass \p f argument by value or by reference using \p std::ref.
793 The functor can change non-key fields of \p item.
794 The \p val argument is non-const since it can be used as \p f functor destination i.e., the functor
795 can modify both arguments.
797 The type \p Q can differ from \ref value_type of items storing in the container.
798 Therefore, the \p value_type should be comparable with type \p Q.
800 The function returns \p true if \p val is found, \p false otherwise.
802 template <typename Q, typename Func>
803 bool find( Q& val, Func f )
805 return base_class::find( val, f );
808 /// Find the key \p val using \p pred predicate
810 The function is an analog of \ref cds_nonintrusive_StripedSet_find_func "find(Q&, Func)"
811 but \p pred is used for key comparing
812 \p Less has the interface like \p std::less.
813 \p pred must imply the same element order as the comparator used for building the set.
815 @note This function is enabled if the compiler supports C++11
816 default template arguments for function template <b>and</b> the underlying container
817 supports \p %find_with feature.
819 template <typename Q, typename Less, typename Func
820 , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type >
821 bool find_with( Q& val, Less pred, Func f )
823 return base_class::find_with( val, pred, f );
826 /// Find the key \p val
827 /** \anchor cds_nonintrusive_StripedSet_find_cfunc
829 The function searches the item with key equal to \p val and calls the functor \p f for item found.
830 The interface of \p Func functor is:
833 void operator()( value_type& item, Q const& val );
836 where \p item is the item found, \p val is the <tt>find</tt> function argument.
838 You can pass \p f argument by value or by reference using \p std::ref.
840 The functor can change non-key fields of \p item.
842 The type \p Q can differ from \ref value_type of items storing in the container.
843 Therefore, the \p value_type should be comparable with type \p Q.
845 The function returns \p true if \p val is found, \p false otherwise.
847 template <typename Q, typename Func>
848 bool find( Q const& val, Func f )
850 return base_class::find( val, f );
853 /// Find the key \p val using \p pred predicate
855 The function is an analog of \ref cds_nonintrusive_StripedSet_find_cfunc "find(Q const&, Func)"
856 but \p pred is used for key comparing
857 \p Less has the interface like \p std::less.
858 \p pred must imply the same element order as the comparator used for building the set.
860 @note This function is enabled if the compiler supports C++11
861 default template arguments for function template <b>and</b> the underlying container
862 supports \p %find_with feature.
864 template <typename Q, typename Less, typename Func
865 , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type >
866 bool find_with( Q const& val, Less pred, Func f )
868 return base_class::find_with( val, pred, f );
871 /// Find the key \p val
872 /** \anchor cds_nonintrusive_StripedSet_find_val
874 The function searches the item with key equal to \p val
875 and returns \p true if it is found, and \p false otherwise.
877 Note the hash functor specified for class \p Traits template parameter
878 should accept a parameter of type \p Q that can be not the same as \ref value_type.
880 template <typename Q>
881 bool find( Q const& val )
883 return base_class::find( val );
886 /// Find the key \p val using \p pred predicate
888 The function is an analog of \ref cds_nonintrusive_StripedSet_find_val "find(Q const&)"
889 but \p pred is used for key comparing
890 \p Less has the interface like \p std::less.
891 \p pred must imply the same element order as the comparator used for building the set.
893 @note This function is enabled if the compiler supports C++11
894 default template arguments for function template <b>and</b> the underlying container
895 supports \p %find_with feature.
897 template <typename Q, typename Less
898 , typename Bucket = bucket_type, typename = typename std::enable_if< Bucket::has_find_with >::type >
899 bool find_with( Q const& val, Less pred )
901 return base_class::find_with( val, pred );
906 The function erases all items from the set.
910 return base_class::clear();
913 /// Checks if the set is empty
915 Emptiness is checked by item counting: if item count is zero then the set is empty.
919 return base_class::empty();
922 /// Returns item count in the set
925 return base_class::size();
928 /// Returns the size of hash table
930 The hash table size is non-constant and can be increased via resizing.
932 size_t bucket_count() const
934 return base_class::bucket_count();
937 /// Returns lock array size
938 size_t lock_count() const
940 return base_class::lock_count();
943 /// Returns resizing policy object
944 resizing_policy& get_resizing_policy()
946 return base_class::get_resizing_policy();
949 /// Returns resizing policy (const version)
950 resizing_policy const& get_resizing_policy() const
952 return base_class::get_resizing_policy();
956 }} // namespace cds::container
959 #endif // #ifndef __CDS_CONTAINER_STRIPED_SET_H