options.hpp 11 KB

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