policies.hpp 4.1 KB

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