3 #ifndef __CDS_CONTAINER_CUCKOO_BASE_H
4 #define __CDS_CONTAINER_CUCKOO_BASE_H
6 #include <cds/intrusive/cuckoo_set.h>
8 namespace cds { namespace container {
10 /// CuckooSet and CuckooMap related definitions
11 /** @ingroup cds_nonintrusive_helper
15 #ifdef CDS_DOXYGEN_INVOKED
16 /// Lock striping concurrent access policy. This is typedef for intrusive::cuckoo::striping template
20 using intrusive::cuckoo::striping;
23 #ifdef CDS_DOXYGEN_INVOKED
24 /// Refinable concurrent access policy. This is typedef for intrusive::cuckoo::refinable template
28 using intrusive::cuckoo::refinable;
31 #ifdef CDS_DOXYGEN_INVOKED
32 /// Striping internal statistics. This is typedef for intrusive::cuckoo::striping_stat
36 using intrusive::cuckoo::striping_stat;
39 #ifdef CDS_DOXYGEN_INVOKED
40 /// Empty striping internal statistics. This is typedef for intrusive::cuckoo::empty_striping_stat
41 class empty_striping_stat
44 using intrusive::cuckoo::empty_striping_stat;
47 #ifdef CDS_DOXYGEN_INVOKED
48 /// Refinable internal statistics. This is typedef for intrusive::cuckoo::refinable_stat
52 using intrusive::cuckoo::refinable_stat;
55 #ifdef CDS_DOXYGEN_INVOKED
56 /// Empty refinable internal statistics. This is typedef for intrusive::cuckoo::empty_refinable_stat
57 class empty_refinable_stat
60 using intrusive::cuckoo::empty_refinable_stat;
63 #ifdef CDS_DOXYGEN_INVOKED
64 /// Cuckoo statistics. This is typedef for intrusive::cuckoo::stat
68 using intrusive::cuckoo::stat;
71 #ifdef CDS_DOXYGEN_INVOKED
72 /// Cuckoo empty statistics.This is typedef for intrusive::cuckoo::empty_stat
76 using intrusive::cuckoo::empty_stat;
79 /// Option specifying whether to store hash values in the node
81 This option reserves additional space in the hook to store the hash value of the object once it's introduced in the container.
82 When this option is used, the unordered container will store the calculated hash value in the hook and rehashing operations won't need
83 to recalculate the hash of the value. This option will improve the performance of unordered containers
84 when rehashing is frequent or hashing the value is a slow operation
86 The \p Enable template parameter toggles the feature:
87 - the value \p true enables storing the hash values
88 - the value \p false disables storing the hash values
90 template <bool Enable>
94 template <typename Base>
95 struct pack: public Base {
96 static bool const store_hash = Enable;
101 #ifdef CDS_DOXYGEN_INVOKED
102 /// Probe set type option
104 The option specifies probe set type for the CuckooSet and CuckooMap.
106 - \p cuckoo::list - the probe-set is a single-linked list.
107 - \p cuckoo::vector<Capacity> - the probe-set is a vector
108 with constant-size \p Capacity where \p Capacity is an <tt>unsigned int</tt> constant.
110 template <typename Type>
114 using intrusive::cuckoo::probeset_type;
117 using intrusive::cuckoo::list;
118 using intrusive::cuckoo::vector;
120 /// Type traits for CuckooSet and CuckooMap classes
123 /// Hash functors tuple
125 This is mandatory type and has no predefined one.
127 At least, two hash functors should be provided. All hash functor
128 should be orthogonal (different): for each <tt> i,j: i != j => h[i](x) != h[j](x) </tt>.
129 The hash functors are defined as <tt> std::tuple< H1, H2, ... Hn > </tt>:
130 \@code cds::opt::hash< std::tuple< h1, h2 > > \@endcode
131 The number of hash functors specifies the number \p k - the count of hash tables in cuckoo hashing.
132 Up to 10 different hash functors are supported.
134 typedef cds::opt::none hash;
136 /// Concurrent access policy
138 Available opt::mutex_policy types:
139 - cuckoo::striping - simple, but the lock array is not resizable
140 - cuckoo::refinable - resizable lock array, but more complex access to set data.
142 Default is cuckoo::striping.
144 typedef cuckoo::striping<> mutex_policy;
146 /// Key equality functor
148 Default is <tt>std::equal_to<T></tt>
150 typedef opt::none equal_to;
152 /// Key comparison functor
154 No default functor is provided. If the option is not specified, the \p less is used.
156 typedef opt::none compare;
158 /// specifies binary predicate used for key comparison.
160 Default is \p std::less<T>.
162 typedef opt::none less;
166 The type for item counting feature.
167 Default is cds::atomicity::item_counter
169 Only atomic item counter type is allowed.
171 typedef cds::intrusive::cuckoo::type_traits::item_counter item_counter;
175 The allocator type for allocating bucket tables.
176 Default is \p CDS_DEFAULT_ALLOCATOR that is \p std::allocator
178 typedef CDS_DEFAULT_ALLOCATOR allocator;
180 /// Node allocator type
182 If this type is not set explicitly, the \ref allocator type is used.
184 typedef opt::none node_allocator;
186 /// Store hash value into items. See cuckoo::store_hash for explanation
187 static bool const store_hash = false;
189 /// Probe-set type. See \ref probeset_type option for explanation
190 typedef cuckoo::list probeset_type;
192 /// Internal statistics
193 typedef empty_stat stat;
196 /// Metafunction converting option list to CuckooSet/CuckooMap traits
198 This is a wrapper for <tt> cds::opt::make_options< type_traits, Options...> </tt>
199 \p Options list see CuckooSet and CuckooMap
201 template <CDS_DECL_OPTIONS12>
203 typedef typename cds::opt::make_options<
204 typename cds::opt::find_type_traits< cuckoo::type_traits, CDS_OPTIONS12 >::type
206 >::type type ; ///< Result of metafunction
208 } // namespace cuckoo
209 }} // namespace cds::container
211 #endif // #ifndef __CDS_CONTAINER_CUCKOO_BASE_H