maxmin_heap.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Boost.Geometry
  2. // Copyright (c) 2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_MAXMIN_HEAP_HPP
  7. #define BOOST_GEOMETRY_INDEX_DETAIL_MAXMIN_HEAP_HPP
  8. #include <boost/geometry/index/detail/minmax_heap.hpp>
  9. namespace boost { namespace geometry { namespace index { namespace detail
  10. {
  11. template <typename It, typename Compare>
  12. inline void push_maxmin_heap(It first, It last, Compare comp)
  13. {
  14. using namespace minmax_heap_detail;
  15. minmax_heap_detail::push_heap<max_call, min_call>(first, last, comp);
  16. }
  17. template <typename It>
  18. inline void push_maxmin_heap(It first, It last)
  19. {
  20. using namespace minmax_heap_detail;
  21. minmax_heap_detail::push_heap<max_call, min_call>(first, last, std::less<>());
  22. }
  23. template <typename It, typename Compare>
  24. inline void pop_top_maxmin_heap(It first, It last, Compare comp)
  25. {
  26. using namespace minmax_heap_detail;
  27. pop_heap<max_call, min_call>(first, first, last, comp);
  28. }
  29. template <typename It>
  30. inline void pop_top_maxmin_heap(It first, It last)
  31. {
  32. using namespace minmax_heap_detail;
  33. pop_heap<max_call, min_call>(first, first, last, std::less<>());
  34. }
  35. template <typename It, typename Compare>
  36. inline void pop_bottom_maxmin_heap(It first, It last, Compare comp)
  37. {
  38. using namespace minmax_heap_detail;
  39. It bottom = minmax_heap_detail::bottom_heap<max_call>(first, last, comp);
  40. pop_heap<max_call, min_call>(first, bottom, last, comp);
  41. }
  42. template <typename It>
  43. inline void pop_bottom_maxmin_heap(It first, It last)
  44. {
  45. using namespace minmax_heap_detail;
  46. auto&& comp = std::less<>();
  47. It bottom = minmax_heap_detail::bottom_heap<max_call>(first, last, comp);
  48. pop_heap<max_call, min_call>(first, bottom, last, comp);
  49. }
  50. template <typename It, typename Compare>
  51. inline void make_maxmin_heap(It first, It last, Compare comp)
  52. {
  53. using namespace minmax_heap_detail;
  54. return minmax_heap_detail::make_heap<max_call, min_call>(first, last, comp);
  55. }
  56. template <typename It>
  57. inline void make_maxmin_heap(It first, It last)
  58. {
  59. using namespace minmax_heap_detail;
  60. return minmax_heap_detail::make_heap<max_call, min_call>(first, last, std::less<>());
  61. }
  62. template <typename It, typename Compare>
  63. inline bool is_maxmin_heap(It first, It last, Compare comp)
  64. {
  65. using namespace minmax_heap_detail;
  66. return minmax_heap_detail::is_heap<max_call>(first, last, comp);
  67. }
  68. template <typename It>
  69. inline bool is_maxmin_heap(It first, It last)
  70. {
  71. using namespace minmax_heap_detail;
  72. return minmax_heap_detail::is_heap<max_call>(first, last, std::less<>());
  73. }
  74. template <typename It, typename Compare>
  75. inline decltype(auto) bottom_maxmin_heap(It first, It last, Compare comp)
  76. {
  77. using namespace minmax_heap_detail;
  78. return *minmax_heap_detail::bottom_heap<max_call>(first, last, comp);
  79. }
  80. template <typename It>
  81. inline decltype(auto) bottom_maxmin_heap(It first, It last)
  82. {
  83. using namespace minmax_heap_detail;
  84. return *minmax_heap_detail::bottom_heap<max_call>(first, last, std::less<>());
  85. }
  86. }}}} // namespace boost::geometry::index::detail
  87. #endif // BOOST_GEOMETRY_INDEX_DETAIL_MAXMIN_HEAP_HPP