d_ary_heap.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. // // boost heap: d-ary heap as container adaptor
  2. //
  3. // Copyright (C) 2010 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_D_ARY_HEAP_HPP
  9. #define BOOST_HEAP_D_ARY_HEAP_HPP
  10. #include <algorithm>
  11. #include <utility>
  12. #include <vector>
  13. #include <boost/assert.hpp>
  14. #include <boost/mem_fn.hpp>
  15. #include <boost/heap/detail/heap_comparison.hpp>
  16. #include <boost/heap/detail/ordered_adaptor_iterator.hpp>
  17. #include <boost/heap/detail/stable_heap.hpp>
  18. #include <boost/heap/detail/mutable_heap.hpp>
  19. #ifdef BOOST_HAS_PRAGMA_ONCE
  20. #pragma once
  21. #endif
  22. #ifndef BOOST_DOXYGEN_INVOKED
  23. #ifdef BOOST_HEAP_SANITYCHECKS
  24. #define BOOST_HEAP_ASSERT BOOST_ASSERT
  25. #else
  26. #define BOOST_HEAP_ASSERT(expression)
  27. #endif
  28. #endif
  29. namespace boost {
  30. namespace heap {
  31. namespace detail {
  32. struct nop_index_updater
  33. {
  34. template <typename T>
  35. static void run(T &, std::size_t)
  36. {}
  37. };
  38. typedef parameter::parameters<boost::parameter::required<tag::arity>,
  39. boost::parameter::optional<tag::allocator>,
  40. boost::parameter::optional<tag::compare>,
  41. boost::parameter::optional<tag::stable>,
  42. boost::parameter::optional<tag::stability_counter_type>,
  43. boost::parameter::optional<tag::constant_time_size>
  44. > d_ary_heap_signature;
  45. /* base class for d-ary heap */
  46. template <typename T,
  47. class BoundArgs,
  48. class IndexUpdater>
  49. class d_ary_heap:
  50. private make_heap_base<T, BoundArgs, false>::type
  51. {
  52. typedef make_heap_base<T, BoundArgs, false> heap_base_maker;
  53. typedef typename heap_base_maker::type super_t;
  54. typedef typename super_t::internal_type internal_type;
  55. typedef typename boost::allocator_rebind<typename heap_base_maker::allocator_argument, internal_type>::type internal_type_allocator;
  56. typedef std::vector<internal_type, internal_type_allocator> container_type;
  57. typedef typename container_type::const_iterator container_iterator;
  58. typedef IndexUpdater index_updater;
  59. container_type q_;
  60. static const unsigned int D = parameter::binding<BoundArgs, tag::arity>::type::value;
  61. template <typename Heap1, typename Heap2>
  62. friend struct heap_merge_emulate;
  63. struct implementation_defined:
  64. extract_allocator_types<typename heap_base_maker::allocator_argument>
  65. {
  66. typedef T value_type;
  67. typedef typename detail::extract_allocator_types<typename heap_base_maker::allocator_argument>::size_type size_type;
  68. typedef typename heap_base_maker::compare_argument value_compare;
  69. typedef typename heap_base_maker::allocator_argument allocator_type;
  70. struct ordered_iterator_dispatcher
  71. {
  72. static size_type max_index(const d_ary_heap * heap)
  73. {
  74. return heap->q_.size() - 1;
  75. }
  76. static bool is_leaf(const d_ary_heap * heap, size_type index)
  77. {
  78. return !heap->not_leaf(index);
  79. }
  80. static std::pair<size_type, size_type> get_child_nodes(const d_ary_heap * heap, size_type index)
  81. {
  82. BOOST_HEAP_ASSERT(!is_leaf(heap, index));
  83. return std::make_pair(d_ary_heap::first_child_index(index),
  84. heap->last_child_index(index));
  85. }
  86. static internal_type const & get_internal_value(const d_ary_heap * heap, size_type index)
  87. {
  88. return heap->q_[index];
  89. }
  90. static value_type const & get_value(internal_type const & arg)
  91. {
  92. return super_t::get_value(arg);
  93. }
  94. };
  95. typedef detail::ordered_adaptor_iterator<const value_type,
  96. internal_type,
  97. d_ary_heap,
  98. allocator_type,
  99. typename super_t::internal_compare,
  100. ordered_iterator_dispatcher
  101. > ordered_iterator;
  102. typedef detail::stable_heap_iterator<const value_type, container_iterator, super_t> iterator;
  103. typedef iterator const_iterator;
  104. typedef void * handle_type;
  105. };
  106. typedef typename implementation_defined::ordered_iterator_dispatcher ordered_iterator_dispatcher;
  107. public:
  108. typedef T value_type;
  109. typedef typename implementation_defined::size_type size_type;
  110. typedef typename implementation_defined::difference_type difference_type;
  111. typedef typename implementation_defined::value_compare value_compare;
  112. typedef typename implementation_defined::allocator_type allocator_type;
  113. typedef typename implementation_defined::reference reference;
  114. typedef typename implementation_defined::const_reference const_reference;
  115. typedef typename implementation_defined::pointer pointer;
  116. typedef typename implementation_defined::const_pointer const_pointer;
  117. typedef typename implementation_defined::iterator iterator;
  118. typedef typename implementation_defined::const_iterator const_iterator;
  119. typedef typename implementation_defined::ordered_iterator ordered_iterator;
  120. typedef typename implementation_defined::handle_type handle_type;
  121. static const bool is_stable = extract_stable<BoundArgs>::value;
  122. explicit d_ary_heap(value_compare const & cmp = value_compare()):
  123. super_t(cmp)
  124. {}
  125. d_ary_heap(d_ary_heap const & rhs):
  126. super_t(rhs), q_(rhs.q_)
  127. {}
  128. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  129. d_ary_heap(d_ary_heap && rhs):
  130. super_t(std::move(rhs)), q_(std::move(rhs.q_))
  131. {}
  132. d_ary_heap & operator=(d_ary_heap && rhs)
  133. {
  134. super_t::operator=(std::move(rhs));
  135. q_ = std::move(rhs.q_);
  136. return *this;
  137. }
  138. #endif
  139. d_ary_heap & operator=(d_ary_heap const & rhs)
  140. {
  141. static_cast<super_t&>(*this) = static_cast<super_t const &>(rhs);
  142. q_ = rhs.q_;
  143. return *this;
  144. }
  145. bool empty(void) const
  146. {
  147. return q_.empty();
  148. }
  149. size_type size(void) const
  150. {
  151. return q_.size();
  152. }
  153. size_type max_size(void) const
  154. {
  155. return q_.max_size();
  156. }
  157. void clear(void)
  158. {
  159. q_.clear();
  160. }
  161. allocator_type get_allocator(void) const
  162. {
  163. return q_.get_allocator();
  164. }
  165. value_type const & top(void) const
  166. {
  167. BOOST_ASSERT(!empty());
  168. return super_t::get_value(q_.front());
  169. }
  170. void push(value_type const & v)
  171. {
  172. q_.push_back(super_t::make_node(v));
  173. reset_index(size() - 1, size() - 1);
  174. siftup(q_.size() - 1);
  175. }
  176. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  177. template <class... Args>
  178. void emplace(Args&&... args)
  179. {
  180. q_.emplace_back(super_t::make_node(std::forward<Args>(args)...));
  181. reset_index(size() - 1, size() - 1);
  182. siftup(q_.size() - 1);
  183. }
  184. #endif
  185. void pop(void)
  186. {
  187. BOOST_ASSERT(!empty());
  188. std::swap(q_.front(), q_.back());
  189. q_.pop_back();
  190. if (q_.empty())
  191. return;
  192. reset_index(0, 0);
  193. siftdown(0);
  194. }
  195. void swap(d_ary_heap & rhs)
  196. {
  197. super_t::swap(rhs);
  198. q_.swap(rhs.q_);
  199. }
  200. iterator begin(void) const
  201. {
  202. return iterator(q_.begin());
  203. }
  204. iterator end(void) const
  205. {
  206. return iterator(q_.end());
  207. }
  208. ordered_iterator ordered_begin(void) const
  209. {
  210. return ordered_iterator(0, this, super_t::get_internal_cmp());
  211. }
  212. ordered_iterator ordered_end(void) const
  213. {
  214. return ordered_iterator(size(), this, super_t::get_internal_cmp());
  215. }
  216. void reserve (size_type element_count)
  217. {
  218. q_.reserve(element_count);
  219. }
  220. value_compare const & value_comp(void) const
  221. {
  222. return super_t::value_comp();
  223. }
  224. private:
  225. void reset_index(size_type index, size_type new_index)
  226. {
  227. BOOST_HEAP_ASSERT(index < q_.size());
  228. index_updater::run(q_[index], new_index);
  229. }
  230. void siftdown(size_type index)
  231. {
  232. while (not_leaf(index)) {
  233. size_type max_child_index = top_child_index(index);
  234. if (!super_t::operator()(q_[max_child_index], q_[index])) {
  235. reset_index(index, max_child_index);
  236. reset_index(max_child_index, index);
  237. std::swap(q_[max_child_index], q_[index]);
  238. index = max_child_index;
  239. }
  240. else
  241. return;
  242. }
  243. }
  244. /* returns new index */
  245. void siftup(size_type index)
  246. {
  247. while (index != 0) {
  248. size_type parent = parent_index(index);
  249. if (super_t::operator()(q_[parent], q_[index])) {
  250. reset_index(index, parent);
  251. reset_index(parent, index);
  252. std::swap(q_[parent], q_[index]);
  253. index = parent;
  254. }
  255. else
  256. return;
  257. }
  258. }
  259. bool not_leaf(size_type index) const
  260. {
  261. const size_t first_child = first_child_index(index);
  262. return first_child < q_.size();
  263. }
  264. size_type top_child_index(size_type index) const
  265. {
  266. // invariant: index is not a leaf, so the iterator range is not empty
  267. const size_t first_index = first_child_index(index);
  268. typedef typename container_type::const_iterator container_iterator;
  269. const container_iterator first_child = q_.begin() + first_index;
  270. const container_iterator end = q_.end();
  271. const size_type max_elements = std::distance(first_child, end);
  272. const container_iterator last_child = (max_elements > D) ? first_child + D
  273. : end;
  274. const container_iterator min_element = std::max_element(first_child, last_child, static_cast<super_t const &>(*this));
  275. return min_element - q_.begin();
  276. }
  277. static size_type parent_index(size_type index)
  278. {
  279. return (index - 1) / D;
  280. }
  281. static size_type first_child_index(size_type index)
  282. {
  283. return index * D + 1;
  284. }
  285. size_type last_child_index(size_type index) const
  286. {
  287. const size_t first_index = first_child_index(index);
  288. const size_type last_index = (std::min)(first_index + D - 1, size() - 1);
  289. return last_index;
  290. }
  291. template<typename U,
  292. typename V,
  293. typename W,
  294. typename X>
  295. struct rebind {
  296. typedef d_ary_heap<U, typename d_ary_heap_signature::bind<boost::heap::stable<heap_base_maker::is_stable>,
  297. boost::heap::stability_counter_type<typename heap_base_maker::stability_counter_type>,
  298. boost::heap::arity<D>,
  299. boost::heap::compare<V>,
  300. boost::heap::allocator<W>
  301. >::type,
  302. X
  303. > other;
  304. };
  305. template <class U> friend class priority_queue_mutable_wrapper;
  306. void update(size_type index)
  307. {
  308. if (index == 0) {
  309. siftdown(index);
  310. return;
  311. }
  312. size_type parent = parent_index(index);
  313. if (super_t::operator()(q_[parent], q_[index]))
  314. siftup(index);
  315. else
  316. siftdown(index);
  317. }
  318. void erase(size_type index)
  319. {
  320. while (index != 0)
  321. {
  322. size_type parent = parent_index(index);
  323. reset_index(index, parent);
  324. reset_index(parent, index);
  325. std::swap(q_[parent], q_[index]);
  326. index = parent;
  327. }
  328. pop();
  329. }
  330. void increase(size_type index)
  331. {
  332. siftup(index);
  333. }
  334. void decrease(size_type index)
  335. {
  336. siftdown(index);
  337. }
  338. };
  339. template <typename T, typename BoundArgs>
  340. struct select_dary_heap
  341. {
  342. static const bool is_mutable = extract_mutable<BoundArgs>::value;
  343. typedef typename boost::conditional< is_mutable,
  344. priority_queue_mutable_wrapper<d_ary_heap<T, BoundArgs, nop_index_updater > >,
  345. d_ary_heap<T, BoundArgs, nop_index_updater >
  346. >::type type;
  347. };
  348. } /* namespace detail */
  349. /**
  350. * \class d_ary_heap
  351. * \brief d-ary heap class
  352. *
  353. * This class implements an immutable priority queue. Internally, the d-ary heap is represented
  354. * as dynamically sized array (std::vector), that directly stores the values.
  355. *
  356. * The template parameter T is the type to be managed by the container.
  357. * The user can specify additional options and if no options are provided default options are used.
  358. *
  359. * The container supports the following options:
  360. * - \c boost::heap::arity<>, required
  361. * - \c boost::heap::compare<>, defaults to \c compare<std::less<T> >
  362. * - \c boost::heap::stable<>, defaults to \c stable<false>
  363. * - \c boost::heap::stability_counter_type<>, defaults to \c stability_counter_type<boost::uintmax_t>
  364. * - \c boost::heap::allocator<>, defaults to \c allocator<std::allocator<T> >
  365. * - \c boost::heap::mutable_<>, defaults to \c mutable_<false>
  366. *
  367. */
  368. #ifdef BOOST_DOXYGEN_INVOKED
  369. template<class T, class ...Options>
  370. #else
  371. template <typename T,
  372. class A0 = boost::parameter::void_,
  373. class A1 = boost::parameter::void_,
  374. class A2 = boost::parameter::void_,
  375. class A3 = boost::parameter::void_,
  376. class A4 = boost::parameter::void_,
  377. class A5 = boost::parameter::void_
  378. >
  379. #endif
  380. class d_ary_heap:
  381. public detail::select_dary_heap<T, typename detail::d_ary_heap_signature::bind<A0, A1, A2, A3, A4, A5>::type>::type
  382. {
  383. typedef typename detail::d_ary_heap_signature::bind<A0, A1, A2, A3, A4, A5>::type bound_args;
  384. typedef typename detail::select_dary_heap<T, bound_args>::type super_t;
  385. template <typename Heap1, typename Heap2>
  386. friend struct heap_merge_emulate;
  387. #ifndef BOOST_DOXYGEN_INVOKED
  388. static const bool is_mutable = detail::extract_mutable<bound_args>::value;
  389. #define BOOST_HEAP_TYPEDEF_FROM_SUPER_T(NAME) \
  390. typedef typename super_t::NAME NAME;
  391. struct implementation_defined
  392. {
  393. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(size_type)
  394. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(difference_type)
  395. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(value_compare)
  396. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(allocator_type)
  397. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(reference)
  398. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(const_reference)
  399. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(pointer)
  400. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(const_pointer)
  401. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(iterator)
  402. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(const_iterator)
  403. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(ordered_iterator)
  404. BOOST_HEAP_TYPEDEF_FROM_SUPER_T(handle_type)
  405. };
  406. #undef BOOST_HEAP_TYPEDEF_FROM_SUPER_T
  407. #endif
  408. public:
  409. static const bool constant_time_size = true;
  410. static const bool has_ordered_iterators = true;
  411. static const bool is_mergable = false;
  412. static const bool has_reserve = true;
  413. static const bool is_stable = super_t::is_stable;
  414. typedef T value_type;
  415. typedef typename implementation_defined::size_type size_type;
  416. typedef typename implementation_defined::difference_type difference_type;
  417. typedef typename implementation_defined::value_compare value_compare;
  418. typedef typename implementation_defined::allocator_type allocator_type;
  419. typedef typename implementation_defined::reference reference;
  420. typedef typename implementation_defined::const_reference const_reference;
  421. typedef typename implementation_defined::pointer pointer;
  422. typedef typename implementation_defined::const_pointer const_pointer;
  423. /// \copydoc boost::heap::priority_queue::iterator
  424. typedef typename implementation_defined::iterator iterator;
  425. typedef typename implementation_defined::const_iterator const_iterator;
  426. typedef typename implementation_defined::ordered_iterator ordered_iterator;
  427. typedef typename implementation_defined::handle_type handle_type;
  428. /// \copydoc boost::heap::priority_queue::priority_queue(value_compare const &)
  429. explicit d_ary_heap(value_compare const & cmp = value_compare()):
  430. super_t(cmp)
  431. {}
  432. /// \copydoc boost::heap::priority_queue::priority_queue(priority_queue const &)
  433. d_ary_heap(d_ary_heap const & rhs):
  434. super_t(rhs)
  435. {}
  436. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  437. /// \copydoc boost::heap::priority_queue::priority_queue(priority_queue &&)
  438. d_ary_heap(d_ary_heap && rhs):
  439. super_t(std::move(rhs))
  440. {}
  441. /// \copydoc boost::heap::priority_queue::operator=(priority_queue &&)
  442. d_ary_heap & operator=(d_ary_heap && rhs)
  443. {
  444. super_t::operator=(std::move(rhs));
  445. return *this;
  446. }
  447. #endif
  448. /// \copydoc boost::heap::priority_queue::operator=(priority_queue const &)
  449. d_ary_heap & operator=(d_ary_heap const & rhs)
  450. {
  451. super_t::operator=(rhs);
  452. return *this;
  453. }
  454. /// \copydoc boost::heap::priority_queue::empty
  455. bool empty(void) const
  456. {
  457. return super_t::empty();
  458. }
  459. /// \copydoc boost::heap::priority_queue::size
  460. size_type size(void) const
  461. {
  462. return super_t::size();
  463. }
  464. /// \copydoc boost::heap::priority_queue::max_size
  465. size_type max_size(void) const
  466. {
  467. return super_t::max_size();
  468. }
  469. /// \copydoc boost::heap::priority_queue::clear
  470. void clear(void)
  471. {
  472. super_t::clear();
  473. }
  474. /// \copydoc boost::heap::priority_queue::get_allocator
  475. allocator_type get_allocator(void) const
  476. {
  477. return super_t::get_allocator();
  478. }
  479. /// \copydoc boost::heap::priority_queue::top
  480. value_type const & top(void) const
  481. {
  482. return super_t::top();
  483. }
  484. /// \copydoc boost::heap::priority_queue::push
  485. typename boost::conditional<is_mutable, handle_type, void>::type push(value_type const & v)
  486. {
  487. return super_t::push(v);
  488. }
  489. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  490. /// \copydoc boost::heap::priority_queue::emplace
  491. template <class... Args>
  492. typename boost::conditional<is_mutable, handle_type, void>::type emplace(Args&&... args)
  493. {
  494. return super_t::emplace(std::forward<Args>(args)...);
  495. }
  496. #endif
  497. /// \copydoc boost::heap::priority_queue::operator<(HeapType const & rhs) const
  498. template <typename HeapType>
  499. bool operator<(HeapType const & rhs) const
  500. {
  501. return detail::heap_compare(*this, rhs);
  502. }
  503. /// \copydoc boost::heap::priority_queue::operator>(HeapType const & rhs) const
  504. template <typename HeapType>
  505. bool operator>(HeapType const & rhs) const
  506. {
  507. return detail::heap_compare(rhs, *this);
  508. }
  509. /// \copydoc boost::heap::priority_queue::operator>=(HeapType const & rhs) const
  510. template <typename HeapType>
  511. bool operator>=(HeapType const & rhs) const
  512. {
  513. return !operator<(rhs);
  514. }
  515. /// \copydoc boost::heap::priority_queue::operator<=(HeapType const & rhs) const
  516. template <typename HeapType>
  517. bool operator<=(HeapType const & rhs) const
  518. {
  519. return !operator>(rhs);
  520. }
  521. /// \copydoc boost::heap::priority_queue::operator==(HeapType const & rhs) const
  522. template <typename HeapType>
  523. bool operator==(HeapType const & rhs) const
  524. {
  525. return detail::heap_equality(*this, rhs);
  526. }
  527. /// \copydoc boost::heap::priority_queue::operator!=(HeapType const & rhs) const
  528. template <typename HeapType>
  529. bool operator!=(HeapType const & rhs) const
  530. {
  531. return !(*this == rhs);
  532. }
  533. /**
  534. * \b Effects: Assigns \c v to the element handled by \c handle & updates the priority queue.
  535. *
  536. * \b Complexity: Logarithmic.
  537. *
  538. * \b Requirement: data structure must be configured as mutable
  539. * */
  540. void update(handle_type handle, const_reference v)
  541. {
  542. BOOST_STATIC_ASSERT(is_mutable);
  543. super_t::update(handle, v);
  544. }
  545. /**
  546. * \b Effects: Updates the heap after the element handled by \c handle has been changed.
  547. *
  548. * \b Complexity: Logarithmic.
  549. *
  550. * \b Note: If this is not called, after a handle has been updated, the behavior of the data structure is undefined!
  551. *
  552. * \b Requirement: data structure must be configured as mutable
  553. * */
  554. void update(handle_type handle)
  555. {
  556. BOOST_STATIC_ASSERT(is_mutable);
  557. super_t::update(handle);
  558. }
  559. /**
  560. * \b Effects: Assigns \c v to the element handled by \c handle & updates the priority queue.
  561. *
  562. * \b Complexity: Logarithmic.
  563. *
  564. * \b Note: The new value is expected to be greater than the current one
  565. *
  566. * \b Requirement: data structure must be configured as mutable
  567. * */
  568. void increase(handle_type handle, const_reference v)
  569. {
  570. BOOST_STATIC_ASSERT(is_mutable);
  571. super_t::increase(handle, v);
  572. }
  573. /**
  574. * \b Effects: Updates the heap after the element handled by \c handle has been changed.
  575. *
  576. * \b Complexity: Logarithmic.
  577. *
  578. * \b Note: The new value is expected to be greater than the current one. If this is not called, after a handle has been updated, the behavior of the data structure is undefined!
  579. *
  580. * \b Requirement: data structure must be configured as mutable
  581. * */
  582. void increase(handle_type handle)
  583. {
  584. BOOST_STATIC_ASSERT(is_mutable);
  585. super_t::increase(handle);
  586. }
  587. /**
  588. * \b Effects: Assigns \c v to the element handled by \c handle & updates the priority queue.
  589. *
  590. * \b Complexity: Logarithmic.
  591. *
  592. * \b Note: The new value is expected to be less than the current one
  593. *
  594. * \b Requirement: data structure must be configured as mutable
  595. * */
  596. void decrease(handle_type handle, const_reference v)
  597. {
  598. BOOST_STATIC_ASSERT(is_mutable);
  599. super_t::decrease(handle, v);
  600. }
  601. /**
  602. * \b Effects: Updates the heap after the element handled by \c handle has been changed.
  603. *
  604. * \b Complexity: Logarithmic.
  605. *
  606. * \b Note: The new value is expected to be less than the current one. If this is not called, after a handle has been updated, the behavior of the data structure is undefined!
  607. *
  608. * \b Requirement: data structure must be configured as mutable
  609. * */
  610. void decrease(handle_type handle)
  611. {
  612. BOOST_STATIC_ASSERT(is_mutable);
  613. super_t::decrease(handle);
  614. }
  615. /**
  616. * \b Effects: Removes the element handled by \c handle from the priority_queue.
  617. *
  618. * \b Complexity: Logarithmic.
  619. *
  620. * \b Requirement: data structure must be configured as mutable
  621. * */
  622. void erase(handle_type handle)
  623. {
  624. BOOST_STATIC_ASSERT(is_mutable);
  625. super_t::erase(handle);
  626. }
  627. /**
  628. * \b Effects: Casts an iterator to a node handle.
  629. *
  630. * \b Complexity: Constant.
  631. *
  632. * \b Requirement: data structure must be configured as mutable
  633. * */
  634. static handle_type s_handle_from_iterator(iterator const & it)
  635. {
  636. BOOST_STATIC_ASSERT(is_mutable);
  637. return super_t::s_handle_from_iterator(it);
  638. }
  639. /// \copydoc boost::heap::priority_queue::pop
  640. void pop(void)
  641. {
  642. super_t::pop();
  643. }
  644. /// \copydoc boost::heap::priority_queue::swap
  645. void swap(d_ary_heap & rhs)
  646. {
  647. super_t::swap(rhs);
  648. }
  649. /// \copydoc boost::heap::priority_queue::begin
  650. const_iterator begin(void) const
  651. {
  652. return super_t::begin();
  653. }
  654. /// \copydoc boost::heap::priority_queue::begin
  655. iterator begin(void)
  656. {
  657. return super_t::begin();
  658. }
  659. /// \copydoc boost::heap::priority_queue::end
  660. iterator end(void)
  661. {
  662. return super_t::end();
  663. }
  664. /// \copydoc boost::heap::priority_queue::end
  665. const_iterator end(void) const
  666. {
  667. return super_t::end();
  668. }
  669. /// \copydoc boost::heap::fibonacci_heap::ordered_begin
  670. ordered_iterator ordered_begin(void) const
  671. {
  672. return super_t::ordered_begin();
  673. }
  674. /// \copydoc boost::heap::fibonacci_heap::ordered_end
  675. ordered_iterator ordered_end(void) const
  676. {
  677. return super_t::ordered_end();
  678. }
  679. /// \copydoc boost::heap::priority_queue::reserve
  680. void reserve (size_type element_count)
  681. {
  682. super_t::reserve(element_count);
  683. }
  684. /// \copydoc boost::heap::priority_queue::value_comp
  685. value_compare const & value_comp(void) const
  686. {
  687. return super_t::value_comp();
  688. }
  689. };
  690. } /* namespace heap */
  691. } /* namespace boost */
  692. #undef BOOST_HEAP_ASSERT
  693. #endif /* BOOST_HEAP_D_ARY_HEAP_HPP */