Chris@16
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@101
|
3 // (C) Copyright Ion Gaztanaga 2007-2014
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@16
|
10 //
|
Chris@16
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_INTRUSIVE_OPTIONS_HPP
|
Chris@16
|
14 #define BOOST_INTRUSIVE_OPTIONS_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/intrusive/detail/config_begin.hpp>
|
Chris@16
|
17 #include <boost/intrusive/intrusive_fwd.hpp>
|
Chris@16
|
18 #include <boost/intrusive/link_mode.hpp>
|
Chris@101
|
19 #include <boost/intrusive/pack_options.hpp>
|
Chris@16
|
20 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@16
|
21
|
Chris@101
|
22 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
23 # pragma once
|
Chris@101
|
24 #endif
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost {
|
Chris@16
|
27 namespace intrusive {
|
Chris@16
|
28
|
Chris@101
|
29 #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
30
|
Chris@101
|
31 struct empty
|
Chris@101
|
32 {};
|
Chris@101
|
33
|
Chris@101
|
34 template<class Functor>
|
Chris@101
|
35 struct fhtraits;
|
Chris@101
|
36
|
Chris@101
|
37 template<class T, class Hook, Hook T::* P>
|
Chris@101
|
38 struct mhtraits;
|
Chris@101
|
39
|
Chris@101
|
40 struct dft_tag;
|
Chris@16
|
41 struct member_tag;
|
Chris@16
|
42
|
Chris@101
|
43 template<class SupposedValueTraits>
|
Chris@101
|
44 struct is_default_hook_tag;
|
Chris@16
|
45
|
Chris@101
|
46 #endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
|
Chris@16
|
47
|
Chris@16
|
48 //!This option setter specifies if the intrusive
|
Chris@16
|
49 //!container stores its size as a member to
|
Chris@16
|
50 //!obtain constant-time size() member.
|
Chris@101
|
51 BOOST_INTRUSIVE_OPTION_CONSTANT(constant_time_size, bool, Enabled, constant_time_size)
|
Chris@101
|
52
|
Chris@101
|
53 //!This option setter specifies a container header holder type
|
Chris@101
|
54 BOOST_INTRUSIVE_OPTION_TYPE(header_holder_type, HeaderHolder, HeaderHolder, header_holder_type)
|
Chris@16
|
55
|
Chris@16
|
56 //!This option setter specifies the type that
|
Chris@16
|
57 //!the container will use to store its size.
|
Chris@101
|
58 BOOST_INTRUSIVE_OPTION_TYPE(size_type, SizeType, SizeType, size_type)
|
Chris@16
|
59
|
Chris@16
|
60 //!This option setter specifies the strict weak ordering
|
Chris@16
|
61 //!comparison functor for the value type
|
Chris@101
|
62 BOOST_INTRUSIVE_OPTION_TYPE(compare, Compare, Compare, compare)
|
Chris@16
|
63
|
Chris@16
|
64 //!This option setter for scapegoat containers specifies if
|
Chris@16
|
65 //!the intrusive scapegoat container should use a non-variable
|
Chris@16
|
66 //!alpha value that does not need floating-point operations.
|
Chris@16
|
67 //!
|
Chris@16
|
68 //!If activated, the fixed alpha value is 1/sqrt(2). This
|
Chris@16
|
69 //!option also saves some space in the container since
|
Chris@16
|
70 //!the alpha value and some additional data does not need
|
Chris@16
|
71 //!to be stored in the container.
|
Chris@16
|
72 //!
|
Chris@16
|
73 //!If the user only needs an alpha value near 1/sqrt(2), this
|
Chris@16
|
74 //!option also improves performance since avoids logarithm
|
Chris@16
|
75 //!and division operations when rebalancing the tree.
|
Chris@101
|
76 BOOST_INTRUSIVE_OPTION_CONSTANT(floating_point, bool, Enabled, floating_point)
|
Chris@16
|
77
|
Chris@16
|
78 //!This option setter specifies the equality
|
Chris@16
|
79 //!functor for the value type
|
Chris@101
|
80 BOOST_INTRUSIVE_OPTION_TYPE(equal, Equal, Equal, equal)
|
Chris@16
|
81
|
Chris@16
|
82 //!This option setter specifies the equality
|
Chris@16
|
83 //!functor for the value type
|
Chris@101
|
84 BOOST_INTRUSIVE_OPTION_TYPE(priority, Priority, Priority, priority)
|
Chris@16
|
85
|
Chris@16
|
86 //!This option setter specifies the hash
|
Chris@16
|
87 //!functor for the value type
|
Chris@101
|
88 BOOST_INTRUSIVE_OPTION_TYPE(hash, Hash, Hash, hash)
|
Chris@16
|
89
|
Chris@16
|
90 //!This option setter specifies the relationship between the type
|
Chris@16
|
91 //!to be managed by the container (the value type) and the node to be
|
Chris@16
|
92 //!used in the node algorithms. It also specifies the linking policy.
|
Chris@101
|
93 BOOST_INTRUSIVE_OPTION_TYPE(value_traits, ValueTraits, ValueTraits, proto_value_traits)
|
Chris@101
|
94
|
Chris@101
|
95 //#define BOOST_INTRUSIVE_COMMA ,
|
Chris@101
|
96 //#define BOOST_INTRUSIVE_LESS <
|
Chris@101
|
97 //#define BOOST_INTRUSIVE_MORE >
|
Chris@101
|
98 //BOOST_INTRUSIVE_OPTION_TYPE (member_hook, Parent BOOST_INTRUSIVE_COMMA class MemberHook BOOST_INTRUSIVE_COMMA MemberHook Parent::* PtrToMember , mhtraits BOOST_INTRUSIVE_LESS Parent BOOST_INTRUSIVE_COMMA MemberHook BOOST_INTRUSIVE_COMMA PtrToMember BOOST_INTRUSIVE_MORE , proto_value_traits)
|
Chris@101
|
99 //template< class Parent , class MemberHook , MemberHook Parent::* PtrToMember>
|
Chris@101
|
100 //struct member_hook {
|
Chris@101
|
101 // template<class Base> struct pack : Base {
|
Chris@101
|
102 // typedef mhtraits < Parent , MemberHook , PtrToMember > proto_value_traits;
|
Chris@101
|
103 // };
|
Chris@101
|
104 //};
|
Chris@101
|
105 //
|
Chris@101
|
106 //#undef BOOST_INTRUSIVE_COMMA
|
Chris@101
|
107 //#undef BOOST_INTRUSIVE_LESS
|
Chris@101
|
108 //#undef BOOST_INTRUSIVE_MORE
|
Chris@16
|
109
|
Chris@16
|
110 //!This option setter specifies the member hook the
|
Chris@16
|
111 //!container must use.
|
Chris@16
|
112 template< typename Parent
|
Chris@16
|
113 , typename MemberHook
|
Chris@16
|
114 , MemberHook Parent::* PtrToMember>
|
Chris@16
|
115 struct member_hook
|
Chris@16
|
116 {
|
Chris@101
|
117 // @cond
|
Chris@101
|
118 // typedef typename MemberHook::hooktags::node_traits node_traits;
|
Chris@101
|
119 // typedef typename node_traits::node node_type;
|
Chris@101
|
120 // typedef node_type Parent::* Ptr2MemNode;
|
Chris@101
|
121 // typedef mhtraits
|
Chris@101
|
122 // < Parent
|
Chris@101
|
123 // , node_traits
|
Chris@101
|
124 // //This cast is really ugly but necessary to reduce template bloat.
|
Chris@101
|
125 // //Since we control the layout between the hook and the node, and there is
|
Chris@101
|
126 // //always single inheritance, the offset of the node is exactly the offset of
|
Chris@101
|
127 // //the hook. Since the node type is shared between all member hooks, this saves
|
Chris@101
|
128 // //quite a lot of symbol stuff.
|
Chris@101
|
129 // , (Ptr2MemNode)PtrToMember
|
Chris@101
|
130 // , MemberHook::hooktags::link_mode> member_value_traits;
|
Chris@101
|
131 typedef mhtraits <Parent, MemberHook, PtrToMember> member_value_traits;
|
Chris@16
|
132 template<class Base>
|
Chris@16
|
133 struct pack : Base
|
Chris@16
|
134 {
|
Chris@16
|
135 typedef member_value_traits proto_value_traits;
|
Chris@16
|
136 };
|
Chris@16
|
137 /// @endcond
|
Chris@16
|
138 };
|
Chris@16
|
139
|
Chris@16
|
140 //!This option setter specifies the function object that will
|
Chris@16
|
141 //!be used to convert between values to be inserted in a container
|
Chris@16
|
142 //!and the hook to be used for that purpose.
|
Chris@101
|
143 BOOST_INTRUSIVE_OPTION_TYPE(function_hook, Functor, fhtraits<Functor>, proto_value_traits)
|
Chris@16
|
144
|
Chris@16
|
145 //!This option setter specifies that the container
|
Chris@16
|
146 //!must use the specified base hook
|
Chris@101
|
147 BOOST_INTRUSIVE_OPTION_TYPE(base_hook, BaseHook, BaseHook, proto_value_traits)
|
Chris@16
|
148
|
Chris@16
|
149 //!This option setter specifies the type of
|
Chris@16
|
150 //!a void pointer. This will instruct the hook
|
Chris@16
|
151 //!to use this type of pointer instead of the
|
Chris@16
|
152 //!default one
|
Chris@101
|
153 BOOST_INTRUSIVE_OPTION_TYPE(void_pointer, VoidPointer, VoidPointer, void_pointer)
|
Chris@16
|
154
|
Chris@16
|
155 //!This option setter specifies the type of
|
Chris@16
|
156 //!the tag of a base hook. A type cannot have two
|
Chris@16
|
157 //!base hooks of the same type, so a tag can be used
|
Chris@16
|
158 //!to differentiate two base hooks with otherwise same type
|
Chris@101
|
159 BOOST_INTRUSIVE_OPTION_TYPE(tag, Tag, Tag, tag)
|
Chris@16
|
160
|
Chris@16
|
161 //!This option setter specifies the link mode
|
Chris@16
|
162 //!(normal_link, safe_link or auto_unlink)
|
Chris@101
|
163 BOOST_INTRUSIVE_OPTION_CONSTANT(link_mode, link_mode_type, LinkType, link_mode)
|
Chris@16
|
164
|
Chris@16
|
165 //!This option setter specifies if the hook
|
Chris@16
|
166 //!should be optimized for size instead of for speed.
|
Chris@101
|
167 BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_size, bool, Enabled, optimize_size)
|
Chris@16
|
168
|
Chris@101
|
169 //!This option setter specifies if the slist container should
|
Chris@16
|
170 //!use a linear implementation instead of a circular one.
|
Chris@101
|
171 BOOST_INTRUSIVE_OPTION_CONSTANT(linear, bool, Enabled, linear)
|
Chris@16
|
172
|
Chris@101
|
173 //!If true, slist also stores a pointer to the last element of the singly linked list.
|
Chris@101
|
174 //!This allows O(1) swap and splice_after(iterator, slist &) for circular slists and makes
|
Chris@101
|
175 //!possible new functions like push_back(reference) and back().
|
Chris@101
|
176 BOOST_INTRUSIVE_OPTION_CONSTANT(cache_last, bool, Enabled, cache_last)
|
Chris@16
|
177
|
Chris@16
|
178 //!This option setter specifies the bucket traits
|
Chris@16
|
179 //!class for unordered associative containers. When this option is specified,
|
Chris@16
|
180 //!instead of using the default bucket traits, a user defined holder will be defined
|
Chris@101
|
181 BOOST_INTRUSIVE_OPTION_TYPE(bucket_traits, BucketTraits, BucketTraits, bucket_traits)
|
Chris@16
|
182
|
Chris@16
|
183 //!This option setter specifies if the unordered hook
|
Chris@16
|
184 //!should offer room to store the hash value.
|
Chris@16
|
185 //!Storing the hash in the hook will speed up rehashing
|
Chris@16
|
186 //!processes in applications where rehashing is frequent,
|
Chris@16
|
187 //!rehashing might throw or the value is heavy to hash.
|
Chris@101
|
188 BOOST_INTRUSIVE_OPTION_CONSTANT(store_hash, bool, Enabled, store_hash)
|
Chris@16
|
189
|
Chris@16
|
190 //!This option setter specifies if the unordered hook
|
Chris@16
|
191 //!should offer room to store another link to another node
|
Chris@16
|
192 //!with the same key.
|
Chris@16
|
193 //!Storing this link will speed up lookups and insertions on
|
Chris@16
|
194 //!unordered_multiset containers with a great number of elements
|
Chris@16
|
195 //!with the same key.
|
Chris@101
|
196 BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_multikey, bool, Enabled, optimize_multikey)
|
Chris@16
|
197
|
Chris@16
|
198 //!This option setter specifies if the bucket array will be always power of two.
|
Chris@16
|
199 //!This allows using masks instead of the default modulo operation to determine
|
Chris@16
|
200 //!the bucket number from the hash value, leading to better performance.
|
Chris@16
|
201 //!In debug mode, if power of two buckets mode is activated, the bucket length
|
Chris@16
|
202 //!will be checked to through assertions to assure the bucket length is power of two.
|
Chris@101
|
203 BOOST_INTRUSIVE_OPTION_CONSTANT(power_2_buckets, bool, Enabled, power_2_buckets)
|
Chris@16
|
204
|
Chris@16
|
205 //!This option setter specifies if the container will cache a pointer to the first
|
Chris@16
|
206 //!non-empty bucket so that begin() is always constant-time.
|
Chris@16
|
207 //!This is specially helpful when we can have containers with a few elements
|
Chris@16
|
208 //!but with big bucket arrays (that is, hashtables with low load factors).
|
Chris@101
|
209 BOOST_INTRUSIVE_OPTION_CONSTANT(cache_begin, bool, Enabled, cache_begin)
|
Chris@16
|
210
|
Chris@16
|
211 //!This option setter specifies if the container will compare the hash value
|
Chris@16
|
212 //!before comparing objects. This option can't be specified if store_hash<>
|
Chris@16
|
213 //!is not true.
|
Chris@16
|
214 //!This is specially helpful when we have containers with a high load factor.
|
Chris@16
|
215 //!and the comparison function is much more expensive that comparing already
|
Chris@16
|
216 //!stored hash values.
|
Chris@101
|
217 BOOST_INTRUSIVE_OPTION_CONSTANT(compare_hash, bool, Enabled, compare_hash)
|
Chris@16
|
218
|
Chris@16
|
219 //!This option setter specifies if the hash container will use incremental
|
Chris@16
|
220 //!hashing. With incremental hashing the cost of hash table expansion is spread
|
Chris@16
|
221 //!out across each hash table insertion operation, as opposed to be incurred all at once.
|
Chris@16
|
222 //!Therefore linear hashing is well suited for interactive applications or real-time
|
Chris@16
|
223 //!appplications where the worst-case insertion time of non-incremental hash containers
|
Chris@16
|
224 //!(rehashing the whole bucket array) is not admisible.
|
Chris@101
|
225 BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, incremental)
|
Chris@16
|
226
|
Chris@16
|
227 /// @cond
|
Chris@16
|
228
|
Chris@16
|
229 struct hook_defaults
|
Chris@16
|
230 {
|
Chris@16
|
231 typedef void* void_pointer;
|
Chris@16
|
232 static const link_mode_type link_mode = safe_link;
|
Chris@101
|
233 typedef dft_tag tag;
|
Chris@16
|
234 static const bool optimize_size = false;
|
Chris@16
|
235 static const bool store_hash = false;
|
Chris@16
|
236 static const bool linear = false;
|
Chris@16
|
237 static const bool optimize_multikey = false;
|
Chris@16
|
238 };
|
Chris@16
|
239
|
Chris@16
|
240 /// @endcond
|
Chris@16
|
241
|
Chris@16
|
242 } //namespace intrusive {
|
Chris@16
|
243 } //namespace boost {
|
Chris@16
|
244
|
Chris@16
|
245 #include <boost/intrusive/detail/config_end.hpp>
|
Chris@16
|
246
|
Chris@16
|
247 #endif //#ifndef BOOST_INTRUSIVE_OPTIONS_HPP
|