policies.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // boost heap
  2. //
  3. // Copyright (C) 2010-2011 Tim Blechmann
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_HEAP_POLICIES_HPP
  9. #define BOOST_HEAP_POLICIES_HPP
  10. #include <boost/parameter.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/mpl/int.hpp>
  13. #include <boost/mpl/void.hpp>
  14. #include <boost/concept_check.hpp>
  15. namespace boost {
  16. namespace heap {
  17. #ifndef BOOST_DOXYGEN_INVOKED
  18. BOOST_PARAMETER_TEMPLATE_KEYWORD(allocator)
  19. BOOST_PARAMETER_TEMPLATE_KEYWORD(compare)
  20. namespace tag { struct stable; }
  21. template <bool T>
  22. struct stable:
  23. boost::parameter::template_keyword<tag::stable, boost::mpl::bool_<T> >
  24. {};
  25. namespace tag { struct mutable_; }
  26. template <bool T>
  27. struct mutable_:
  28. boost::parameter::template_keyword<tag::mutable_, boost::mpl::bool_<T> >
  29. {};
  30. namespace tag { struct constant_time_size; }
  31. template <bool T>
  32. struct constant_time_size:
  33. boost::parameter::template_keyword<tag::constant_time_size, boost::mpl::bool_<T> >
  34. {};
  35. namespace tag { struct store_parent_pointer; }
  36. template <bool T>
  37. struct store_parent_pointer:
  38. boost::parameter::template_keyword<tag::store_parent_pointer, boost::mpl::bool_<T> >
  39. {};
  40. namespace tag { struct arity; }
  41. template <unsigned int T>
  42. struct arity:
  43. boost::parameter::template_keyword<tag::arity, boost::mpl::int_<T> >
  44. {};
  45. namespace tag { struct objects_per_page; }
  46. template <unsigned int T>
  47. struct objects_per_page:
  48. boost::parameter::template_keyword<tag::objects_per_page, boost::mpl::int_<T> >
  49. {};
  50. BOOST_PARAMETER_TEMPLATE_KEYWORD(stability_counter_type)
  51. namespace detail {
  52. namespace mpl = boost::mpl;
  53. template <typename bound_args, typename tag_type>
  54. struct has_arg
  55. {
  56. typedef typename boost::parameter::binding<bound_args, tag_type, mpl::void_>::type type;
  57. static const bool value = mpl::is_not_void_<type>::type::value;
  58. };
  59. template <typename bound_args>
  60. struct extract_stable
  61. {
  62. static const bool has_stable = has_arg<bound_args, tag::stable>::value;
  63. typedef typename mpl::if_c<has_stable,
  64. typename has_arg<bound_args, tag::stable>::type,
  65. mpl::bool_<false>
  66. >::type stable_t;
  67. static const bool value = stable_t::value;
  68. };
  69. template <typename bound_args>
  70. struct extract_mutable
  71. {
  72. static const bool has_mutable = has_arg<bound_args, tag::mutable_>::value;
  73. typedef typename mpl::if_c<has_mutable,
  74. typename has_arg<bound_args, tag::mutable_>::type,
  75. mpl::bool_<false>
  76. >::type mutable_t;
  77. static const bool value = mutable_t::value;
  78. };
  79. }
  80. #else
  81. /** \brief Specifies the predicate for the heap order
  82. */
  83. template <typename T>
  84. struct compare{};
  85. /** \brief Configure heap as mutable
  86. *
  87. * Certain heaps need to be configured specifically do be mutable.
  88. *
  89. * */
  90. template <bool T>
  91. struct mutable_{};
  92. /** \brief Specifies allocator for the internal memory management
  93. */
  94. template <typename T>
  95. struct allocator{};
  96. /** \brief Configure a heap as \b stable
  97. *
  98. * A priority queue is stable, if elements with the same priority are popped from the heap, in the same order as
  99. * they are inserted.
  100. * */
  101. template <bool T>
  102. struct stable{};
  103. /** \brief Specifies the type for stability counter
  104. *
  105. * */
  106. template <typename IntType>
  107. struct stability_counter_type{};
  108. /** \brief Configures complexity of <tt> size() </tt>
  109. *
  110. * Specifies, whether size() should have linear or constant complexity.
  111. * */
  112. template <bool T>
  113. struct constant_time_size{};
  114. /** \brief Store parent pointer in heap node.
  115. *
  116. * Maintaining a parent pointer adds some maintenance and size overhead, but iterating a heap is more efficient.
  117. * */
  118. template <bool T>
  119. struct store_parent_pointer{};
  120. /** \brief Specify arity.
  121. *
  122. * Specifies the arity of a D-ary heap
  123. * */
  124. template <unsigned int T>
  125. struct arity{};
  126. #endif
  127. } /* namespace heap */
  128. } /* namespace boost */
  129. #endif /* BOOST_HEAP_POLICIES_HPP */