d_ary_heap.hpp 25 KB

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