d_ary_heap.hpp 25 KB

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