3 #ifndef CDSLIB_CONTAINER_DETAILS_CUCKOO_BASE_H
4 #define CDSLIB_CONTAINER_DETAILS_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
14 using cds::intrusive::cuckoo::implementation_tag;
16 #ifdef CDS_DOXYGEN_INVOKED
17 /// Lock striping concurrent access policy. This is typedef for intrusive::cuckoo::striping template
21 using intrusive::cuckoo::striping;
24 #ifdef CDS_DOXYGEN_INVOKED
25 /// Refinable concurrent access policy. This is typedef for intrusive::cuckoo::refinable template
29 using intrusive::cuckoo::refinable;
32 #ifdef CDS_DOXYGEN_INVOKED
33 /// Striping internal statistics. This is typedef for intrusive::cuckoo::striping_stat
37 using intrusive::cuckoo::striping_stat;
40 #ifdef CDS_DOXYGEN_INVOKED
41 /// Empty striping internal statistics. This is typedef for intrusive::cuckoo::empty_striping_stat
42 class empty_striping_stat
45 using intrusive::cuckoo::empty_striping_stat;
48 #ifdef CDS_DOXYGEN_INVOKED
49 /// Refinable internal statistics. This is typedef for intrusive::cuckoo::refinable_stat
53 using intrusive::cuckoo::refinable_stat;
56 #ifdef CDS_DOXYGEN_INVOKED
57 /// Empty refinable internal statistics. This is typedef for intrusive::cuckoo::empty_refinable_stat
58 class empty_refinable_stat
61 using intrusive::cuckoo::empty_refinable_stat;
64 #ifdef CDS_DOXYGEN_INVOKED
65 /// Cuckoo statistics. This is typedef for intrusive::cuckoo::stat
69 using intrusive::cuckoo::stat;
72 #ifdef CDS_DOXYGEN_INVOKED
73 /// Cuckoo empty statistics.This is typedef for intrusive::cuckoo::empty_stat
77 using intrusive::cuckoo::empty_stat;
80 /// Option specifying whether to store hash values in the node
82 This option reserves additional space in the hook to store the hash value of the object once it's introduced in the container.
83 When this option is used, the unordered container will store the calculated hash value in the hook and rehashing operations won't need
84 to recalculate the hash of the value. This option will improve the performance of unordered containers
85 when rehashing is frequent or hashing the value is a slow operation
87 The \p Enable template parameter toggles the feature:
88 - the value \p true enables storing the hash values
89 - the value \p false disables storing the hash values
91 template <bool Enable>
95 template <typename Base>
96 struct pack: public Base {
97 static bool const store_hash = Enable;
102 #ifdef CDS_DOXYGEN_INVOKED
103 /// Probe set type option
105 @copydetails cds::intrusive::cuckoo::probeset_type
107 template <typename Type>
111 using intrusive::cuckoo::probeset_type;
114 using intrusive::cuckoo::list;
115 using intrusive::cuckoo::vector;
117 /// Type traits for CuckooSet and CuckooMap classes
120 /// Hash functors tuple
122 This is mandatory type and has no predefined one.
124 At least, two hash functors should be provided. All hash functor
125 should be orthogonal (different): for each <tt> i,j: i != j => h[i](x) != h[j](x) </tt>.
126 The hash functors are defined as <tt> std::tuple< H1, H2, ... Hn > </tt>:
127 \@code cds::opt::hash< std::tuple< h1, h2 > > \@endcode
128 The number of hash functors specifies the number \p k - the count of hash tables in cuckoo hashing.
130 To specify hash tuple in traits you should use \p cds::opt::hash_tuple:
132 struct my_traits: public cds::container::cuckoo::traits {
133 typedef cds::opt::hash_tuple< hash1, hash2 > hash;
137 typedef cds::opt::none hash;
139 /// Concurrent access policy
141 Available opt::mutex_policy types:
142 - cuckoo::striping - simple, but the lock array is not resizable
143 - cuckoo::refinable - resizable lock array, but more complex access to set data.
145 Default is cuckoo::striping.
147 typedef cuckoo::striping<> mutex_policy;
149 /// Key equality functor
151 Default is <tt>std::equal_to<T></tt>
153 typedef opt::none equal_to;
155 /// Key comparison functor
157 No default functor is provided. If the option is not specified, the \p less is used.
159 typedef opt::none compare;
161 /// specifies binary predicate used for key comparison.
163 Default is \p std::less<T>.
165 typedef opt::none less;
169 The type for item counting feature.
170 Default is cds::atomicity::item_counter
172 Only atomic item counter type is allowed.
174 typedef cds::intrusive::cuckoo::traits::item_counter item_counter;
178 The allocator type for allocating bucket tables.
179 Default is \p CDS_DEFAULT_ALLOCATOR that is \p std::allocator
181 typedef CDS_DEFAULT_ALLOCATOR allocator;
183 /// Node allocator type
185 If this type is not set explicitly, the \ref allocator type is used.
187 typedef opt::none node_allocator;
189 /// Store hash value into items. See cuckoo::store_hash for explanation
190 static bool const store_hash = false;
192 /// Probe-set type. See \ref probeset_type option for explanation
193 typedef cuckoo::list probeset_type;
195 /// Internal statistics
196 typedef empty_stat stat;
199 /// Metafunction converting option list to CuckooSet/CuckooMap traits
201 Template argument list \p Options... are:
202 - \p opt::hash - hash functor tuple, mandatory option. At least, two hash functors should be provided. All hash functor
203 should be orthogonal (different): for each <tt> i,j: i != j => h[i](x) != h[j](x) </tt>.
204 The hash functors are passed as <tt> std::tuple< H1, H2, ... Hn > </tt>. The number of hash functors specifies
205 the number \p k - the count of hash tables in cuckoo hashing.
206 - \p opt::mutex_policy - concurrent access policy.
207 Available policies: \p cuckoo::striping, \p cuckoo::refinable.
208 Default is \p %cuckoo::striping.
209 - \p opt::equal_to - key equality functor like \p std::equal_to.
210 If this functor is defined then the probe-set will be unordered.
211 If \p %opt::compare or \p %opt::less option is specified too, then the probe-set will be ordered
212 and \p %opt::equal_to will be ignored.
213 - \p opt::compare - key comparison functor. No default functor is provided.
214 If the option is not specified, the \p %opt::less is used.
215 If \p %opt::compare or \p %opt::less option is specified, then the probe-set will be ordered.
216 - \p opt::less - specifies binary predicate used for key comparison. Default is \p std::less<T>.
217 If \p %opt::compare or \p %opt::less option is specified, then the probe-set will be ordered.
218 - \p opt::item_counter - the type of item counting feature. Default is \p opt::v::sequential_item_counter.
219 - \p opt::allocator - the allocator type using for allocating bucket tables.
220 Default is \ref CDS_DEFAULT_ALLOCATOR
221 - \p opt::node_allocator - the allocator type using for allocating set's items. If this option
222 is not specified then the type defined in \p %opt::allocator option is used.
223 - \p cuckoo::store_hash - this option reserves additional space in the node to store the hash value
224 of the object once it's introduced in the container. When this option is used,
225 the unordered container will store the calculated hash value in the node and rehashing operations won't need
226 to recalculate the hash of the value. This option will improve the performance of unordered containers
227 when rehashing is frequent or hashing the value is a slow operation. Default value is \p false.
228 - \ref intrusive::cuckoo::probeset_type "cuckoo::probeset_type" - type of probe set, may be \p cuckoo::list or <tt>cuckoo::vector<Capacity></tt>,
229 Default is \p cuckoo::list.
230 - \p opt::stat - internal statistics. Possibly types: \p cuckoo::stat, \p cuckoo::empty_stat.
231 Default is \p %cuckoo::empty_stat
233 template <typename... Options>
235 typedef typename cds::opt::make_options<
236 typename cds::opt::find_type_traits< cuckoo::traits, Options... >::type
238 >::type type ; ///< Result of metafunction
240 } // namespace cuckoo
241 }} // namespace cds::container
243 #endif // #ifndef CDSLIB_CONTAINER_DETAILS_CUCKOO_BASE_H