Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@101: // (C) Copyright Ion Gaztanaga 2007-2014 Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: // See http://www.boost.org/libs/intrusive for documentation. Chris@16: // Chris@16: ///////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #ifndef BOOST_INTRUSIVE_OPTIONS_HPP Chris@16: #define BOOST_INTRUSIVE_OPTIONS_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@16: #include Chris@16: Chris@101: #if defined(BOOST_HAS_PRAGMA_ONCE) Chris@101: # pragma once Chris@101: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace intrusive { Chris@16: Chris@101: #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@101: struct empty Chris@101: {}; Chris@101: Chris@101: template Chris@101: struct fhtraits; Chris@101: Chris@101: template Chris@101: struct mhtraits; Chris@101: Chris@101: struct dft_tag; Chris@16: struct member_tag; Chris@16: Chris@101: template Chris@101: struct is_default_hook_tag; Chris@16: Chris@101: #endif //#ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED Chris@16: Chris@16: //!This option setter specifies if the intrusive Chris@16: //!container stores its size as a member to Chris@16: //!obtain constant-time size() member. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(constant_time_size, bool, Enabled, constant_time_size) Chris@101: Chris@101: //!This option setter specifies a container header holder type Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(header_holder_type, HeaderHolder, HeaderHolder, header_holder_type) Chris@16: Chris@16: //!This option setter specifies the type that Chris@16: //!the container will use to store its size. Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(size_type, SizeType, SizeType, size_type) Chris@16: Chris@16: //!This option setter specifies the strict weak ordering Chris@16: //!comparison functor for the value type Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(compare, Compare, Compare, compare) Chris@16: Chris@16: //!This option setter for scapegoat containers specifies if Chris@16: //!the intrusive scapegoat container should use a non-variable Chris@16: //!alpha value that does not need floating-point operations. Chris@16: //! Chris@16: //!If activated, the fixed alpha value is 1/sqrt(2). This Chris@16: //!option also saves some space in the container since Chris@16: //!the alpha value and some additional data does not need Chris@16: //!to be stored in the container. Chris@16: //! Chris@16: //!If the user only needs an alpha value near 1/sqrt(2), this Chris@16: //!option also improves performance since avoids logarithm Chris@16: //!and division operations when rebalancing the tree. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(floating_point, bool, Enabled, floating_point) Chris@16: Chris@16: //!This option setter specifies the equality Chris@16: //!functor for the value type Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(equal, Equal, Equal, equal) Chris@16: Chris@16: //!This option setter specifies the equality Chris@16: //!functor for the value type Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(priority, Priority, Priority, priority) Chris@16: Chris@16: //!This option setter specifies the hash Chris@16: //!functor for the value type Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(hash, Hash, Hash, hash) Chris@16: Chris@16: //!This option setter specifies the relationship between the type Chris@16: //!to be managed by the container (the value type) and the node to be Chris@16: //!used in the node algorithms. It also specifies the linking policy. Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(value_traits, ValueTraits, ValueTraits, proto_value_traits) Chris@101: Chris@101: //#define BOOST_INTRUSIVE_COMMA , Chris@101: //#define BOOST_INTRUSIVE_LESS < Chris@101: //#define BOOST_INTRUSIVE_MORE > Chris@101: //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: //template< class Parent , class MemberHook , MemberHook Parent::* PtrToMember> Chris@101: //struct member_hook { Chris@101: // template struct pack : Base { Chris@101: // typedef mhtraits < Parent , MemberHook , PtrToMember > proto_value_traits; Chris@101: // }; Chris@101: //}; Chris@101: // Chris@101: //#undef BOOST_INTRUSIVE_COMMA Chris@101: //#undef BOOST_INTRUSIVE_LESS Chris@101: //#undef BOOST_INTRUSIVE_MORE Chris@16: Chris@16: //!This option setter specifies the member hook the Chris@16: //!container must use. Chris@16: template< typename Parent Chris@16: , typename MemberHook Chris@16: , MemberHook Parent::* PtrToMember> Chris@16: struct member_hook Chris@16: { Chris@101: // @cond Chris@101: // typedef typename MemberHook::hooktags::node_traits node_traits; Chris@101: // typedef typename node_traits::node node_type; Chris@101: // typedef node_type Parent::* Ptr2MemNode; Chris@101: // typedef mhtraits Chris@101: // < Parent Chris@101: // , node_traits Chris@101: // //This cast is really ugly but necessary to reduce template bloat. Chris@101: // //Since we control the layout between the hook and the node, and there is Chris@101: // //always single inheritance, the offset of the node is exactly the offset of Chris@101: // //the hook. Since the node type is shared between all member hooks, this saves Chris@101: // //quite a lot of symbol stuff. Chris@101: // , (Ptr2MemNode)PtrToMember Chris@101: // , MemberHook::hooktags::link_mode> member_value_traits; Chris@101: typedef mhtraits member_value_traits; Chris@16: template Chris@16: struct pack : Base Chris@16: { Chris@16: typedef member_value_traits proto_value_traits; Chris@16: }; Chris@16: /// @endcond Chris@16: }; Chris@16: Chris@16: //!This option setter specifies the function object that will Chris@16: //!be used to convert between values to be inserted in a container Chris@16: //!and the hook to be used for that purpose. Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(function_hook, Functor, fhtraits, proto_value_traits) Chris@16: Chris@16: //!This option setter specifies that the container Chris@16: //!must use the specified base hook Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(base_hook, BaseHook, BaseHook, proto_value_traits) Chris@16: Chris@16: //!This option setter specifies the type of Chris@16: //!a void pointer. This will instruct the hook Chris@16: //!to use this type of pointer instead of the Chris@16: //!default one Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(void_pointer, VoidPointer, VoidPointer, void_pointer) Chris@16: Chris@16: //!This option setter specifies the type of Chris@16: //!the tag of a base hook. A type cannot have two Chris@16: //!base hooks of the same type, so a tag can be used Chris@16: //!to differentiate two base hooks with otherwise same type Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(tag, Tag, Tag, tag) Chris@16: Chris@16: //!This option setter specifies the link mode Chris@16: //!(normal_link, safe_link or auto_unlink) Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(link_mode, link_mode_type, LinkType, link_mode) Chris@16: Chris@16: //!This option setter specifies if the hook Chris@16: //!should be optimized for size instead of for speed. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_size, bool, Enabled, optimize_size) Chris@16: Chris@101: //!This option setter specifies if the slist container should Chris@16: //!use a linear implementation instead of a circular one. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(linear, bool, Enabled, linear) Chris@16: Chris@101: //!If true, slist also stores a pointer to the last element of the singly linked list. Chris@101: //!This allows O(1) swap and splice_after(iterator, slist &) for circular slists and makes Chris@101: //!possible new functions like push_back(reference) and back(). Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(cache_last, bool, Enabled, cache_last) Chris@16: Chris@16: //!This option setter specifies the bucket traits Chris@16: //!class for unordered associative containers. When this option is specified, Chris@16: //!instead of using the default bucket traits, a user defined holder will be defined Chris@101: BOOST_INTRUSIVE_OPTION_TYPE(bucket_traits, BucketTraits, BucketTraits, bucket_traits) Chris@16: Chris@16: //!This option setter specifies if the unordered hook Chris@16: //!should offer room to store the hash value. Chris@16: //!Storing the hash in the hook will speed up rehashing Chris@16: //!processes in applications where rehashing is frequent, Chris@16: //!rehashing might throw or the value is heavy to hash. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(store_hash, bool, Enabled, store_hash) Chris@16: Chris@16: //!This option setter specifies if the unordered hook Chris@16: //!should offer room to store another link to another node Chris@16: //!with the same key. Chris@16: //!Storing this link will speed up lookups and insertions on Chris@16: //!unordered_multiset containers with a great number of elements Chris@16: //!with the same key. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(optimize_multikey, bool, Enabled, optimize_multikey) Chris@16: Chris@16: //!This option setter specifies if the bucket array will be always power of two. Chris@16: //!This allows using masks instead of the default modulo operation to determine Chris@16: //!the bucket number from the hash value, leading to better performance. Chris@16: //!In debug mode, if power of two buckets mode is activated, the bucket length Chris@16: //!will be checked to through assertions to assure the bucket length is power of two. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(power_2_buckets, bool, Enabled, power_2_buckets) Chris@16: Chris@16: //!This option setter specifies if the container will cache a pointer to the first Chris@16: //!non-empty bucket so that begin() is always constant-time. Chris@16: //!This is specially helpful when we can have containers with a few elements Chris@16: //!but with big bucket arrays (that is, hashtables with low load factors). Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(cache_begin, bool, Enabled, cache_begin) Chris@16: Chris@16: //!This option setter specifies if the container will compare the hash value Chris@16: //!before comparing objects. This option can't be specified if store_hash<> Chris@16: //!is not true. Chris@16: //!This is specially helpful when we have containers with a high load factor. Chris@16: //!and the comparison function is much more expensive that comparing already Chris@16: //!stored hash values. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(compare_hash, bool, Enabled, compare_hash) Chris@16: Chris@16: //!This option setter specifies if the hash container will use incremental Chris@16: //!hashing. With incremental hashing the cost of hash table expansion is spread Chris@16: //!out across each hash table insertion operation, as opposed to be incurred all at once. Chris@16: //!Therefore linear hashing is well suited for interactive applications or real-time Chris@16: //!appplications where the worst-case insertion time of non-incremental hash containers Chris@16: //!(rehashing the whole bucket array) is not admisible. Chris@101: BOOST_INTRUSIVE_OPTION_CONSTANT(incremental, bool, Enabled, incremental) Chris@16: Chris@16: /// @cond Chris@16: Chris@16: struct hook_defaults Chris@16: { Chris@16: typedef void* void_pointer; Chris@16: static const link_mode_type link_mode = safe_link; Chris@101: typedef dft_tag tag; Chris@16: static const bool optimize_size = false; Chris@16: static const bool store_hash = false; Chris@16: static const bool linear = false; Chris@16: static const bool optimize_multikey = false; Chris@16: }; Chris@16: Chris@16: /// @endcond Chris@16: Chris@16: } //namespace intrusive { Chris@16: } //namespace boost { Chris@16: Chris@16: #include Chris@16: Chris@16: #endif //#ifndef BOOST_INTRUSIVE_OPTIONS_HPP