pairing_heap.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. // boost heap: pairing heap
  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_PAIRING_HEAP_HPP
  9. #define BOOST_HEAP_PAIRING_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/heap_node.hpp>
  16. #include <boost/heap/policies.hpp>
  17. #include <boost/heap/detail/stable_heap.hpp>
  18. #include <boost/heap/detail/tree_iterator.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. typedef parameter::parameters<boost::parameter::optional<tag::allocator>,
  33. boost::parameter::optional<tag::compare>,
  34. boost::parameter::optional<tag::stable>,
  35. boost::parameter::optional<tag::constant_time_size>,
  36. boost::parameter::optional<tag::stability_counter_type>
  37. > pairing_heap_signature;
  38. template <typename T, typename Parspec>
  39. struct make_pairing_heap_base
  40. {
  41. static const bool constant_time_size = parameter::binding<Parspec,
  42. tag::constant_time_size,
  43. boost::mpl::true_
  44. >::type::value;
  45. typedef typename detail::make_heap_base<T, Parspec, constant_time_size>::type base_type;
  46. typedef typename detail::make_heap_base<T, Parspec, constant_time_size>::allocator_argument allocator_argument;
  47. typedef typename detail::make_heap_base<T, Parspec, constant_time_size>::compare_argument compare_argument;
  48. typedef heap_node<typename base_type::internal_type, false> node_type;
  49. typedef typename allocator_argument::template rebind<node_type>::other allocator_type;
  50. struct type:
  51. base_type,
  52. allocator_type
  53. {
  54. type(compare_argument const & arg):
  55. base_type(arg)
  56. {}
  57. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  58. type(type const & rhs):
  59. base_type(rhs), allocator_type(rhs)
  60. {}
  61. type(type && rhs):
  62. base_type(std::move(static_cast<base_type&>(rhs))),
  63. allocator_type(std::move(static_cast<allocator_type&>(rhs)))
  64. {}
  65. type & operator=(type && rhs)
  66. {
  67. base_type::operator=(std::move(static_cast<base_type&>(rhs)));
  68. allocator_type::operator=(std::move(static_cast<allocator_type&>(rhs)));
  69. return *this;
  70. }
  71. type & operator=(type const & rhs)
  72. {
  73. base_type::operator=(static_cast<base_type const &>(rhs));
  74. allocator_type::operator=(static_cast<const allocator_type&>(rhs));
  75. return *this;
  76. }
  77. #endif
  78. };
  79. };
  80. }
  81. /**
  82. * \class pairing_heap
  83. * \brief pairing heap
  84. *
  85. * Pairing heaps are self-adjusting binary heaps. Although design and implementation are rather simple,
  86. * the complexity analysis is yet unsolved. For details, consult:
  87. *
  88. * Pettie, Seth (2005), "Towards a final analysis of pairing heaps",
  89. * Proc. 46th Annual IEEE Symposium on Foundations of Computer Science, pp. 174-183
  90. *
  91. * The template parameter T is the type to be managed by the container.
  92. * The user can specify additional options and if no options are provided default options are used.
  93. *
  94. * The container supports the following options:
  95. * - \c boost::heap::compare<>, defaults to \c compare<std::less<T> >
  96. * - \c boost::heap::stable<>, defaults to \c stable<false>
  97. * - \c boost::heap::stability_counter_type<>, defaults to \c stability_counter_type<boost::uintmax_t>
  98. * - \c boost::heap::allocator<>, defaults to \c allocator<std::allocator<T> >
  99. * - \c boost::heap::constant_time_size<>, defaults to \c constant_time_size<true>
  100. *
  101. *
  102. */
  103. #ifdef BOOST_DOXYGEN_INVOKED
  104. template<class T, class ...Options>
  105. #else
  106. template <typename T,
  107. class A0 = boost::parameter::void_,
  108. class A1 = boost::parameter::void_,
  109. class A2 = boost::parameter::void_,
  110. class A3 = boost::parameter::void_,
  111. class A4 = boost::parameter::void_
  112. >
  113. #endif
  114. class pairing_heap:
  115. private detail::make_pairing_heap_base<T,
  116. typename detail::pairing_heap_signature::bind<A0, A1, A2, A3, A4>::type
  117. >::type
  118. {
  119. typedef typename detail::pairing_heap_signature::bind<A0, A1, A2, A3, A4>::type bound_args;
  120. typedef detail::make_pairing_heap_base<T, bound_args> base_maker;
  121. typedef typename base_maker::type super_t;
  122. typedef typename super_t::internal_type internal_type;
  123. typedef typename super_t::size_holder_type size_holder;
  124. typedef typename base_maker::allocator_argument allocator_argument;
  125. private:
  126. template <typename Heap1, typename Heap2>
  127. friend struct heap_merge_emulate;
  128. #ifndef BOOST_DOXYGEN_INVOKED
  129. struct implementation_defined:
  130. detail::extract_allocator_types<typename base_maker::allocator_argument>
  131. {
  132. typedef T value_type;
  133. typedef typename detail::extract_allocator_types<typename base_maker::allocator_argument>::size_type size_type;
  134. typedef typename detail::extract_allocator_types<typename base_maker::allocator_argument>::reference reference;
  135. typedef typename base_maker::compare_argument value_compare;
  136. typedef typename base_maker::allocator_type allocator_type;
  137. typedef typename allocator_type::pointer node_pointer;
  138. typedef typename allocator_type::const_pointer const_node_pointer;
  139. typedef detail::heap_node_list node_list_type;
  140. typedef typename node_list_type::iterator node_list_iterator;
  141. typedef typename node_list_type::const_iterator node_list_const_iterator;
  142. typedef typename base_maker::node_type node;
  143. typedef detail::value_extractor<value_type, internal_type, super_t> value_extractor;
  144. typedef typename super_t::internal_compare internal_compare;
  145. typedef detail::node_handle<node_pointer, super_t, reference> handle_type;
  146. typedef detail::tree_iterator<node,
  147. const value_type,
  148. allocator_type,
  149. value_extractor,
  150. detail::pointer_to_reference<node>,
  151. false,
  152. false,
  153. value_compare
  154. > iterator;
  155. typedef iterator const_iterator;
  156. typedef detail::tree_iterator<node,
  157. const value_type,
  158. allocator_type,
  159. value_extractor,
  160. detail::pointer_to_reference<node>,
  161. false,
  162. true,
  163. value_compare
  164. > ordered_iterator;
  165. };
  166. typedef typename implementation_defined::node node;
  167. typedef typename implementation_defined::node_pointer node_pointer;
  168. typedef typename implementation_defined::node_list_type node_list_type;
  169. typedef typename implementation_defined::node_list_iterator node_list_iterator;
  170. typedef typename implementation_defined::node_list_const_iterator node_list_const_iterator;
  171. typedef typename implementation_defined::internal_compare internal_compare;
  172. typedef boost::intrusive::list<detail::heap_node_base<true>,
  173. boost::intrusive::constant_time_size<false>
  174. > node_child_list;
  175. #endif
  176. public:
  177. typedef T value_type;
  178. typedef typename implementation_defined::size_type size_type;
  179. typedef typename implementation_defined::difference_type difference_type;
  180. typedef typename implementation_defined::value_compare value_compare;
  181. typedef typename implementation_defined::allocator_type allocator_type;
  182. typedef typename implementation_defined::reference reference;
  183. typedef typename implementation_defined::const_reference const_reference;
  184. typedef typename implementation_defined::pointer pointer;
  185. typedef typename implementation_defined::const_pointer const_pointer;
  186. /// \copydoc boost::heap::priority_queue::iterator
  187. typedef typename implementation_defined::iterator iterator;
  188. typedef typename implementation_defined::const_iterator const_iterator;
  189. typedef typename implementation_defined::ordered_iterator ordered_iterator;
  190. typedef typename implementation_defined::handle_type handle_type;
  191. static const bool constant_time_size = super_t::constant_time_size;
  192. static const bool has_ordered_iterators = true;
  193. static const bool is_mergable = true;
  194. static const bool is_stable = detail::extract_stable<bound_args>::value;
  195. static const bool has_reserve = false;
  196. /// \copydoc boost::heap::priority_queue::priority_queue(value_compare const &)
  197. explicit pairing_heap(value_compare const & cmp = value_compare()):
  198. super_t(cmp), root(NULL)
  199. {}
  200. /// \copydoc boost::heap::priority_queue::priority_queue(priority_queue const &)
  201. pairing_heap(pairing_heap const & rhs):
  202. super_t(rhs), root(NULL)
  203. {
  204. if (rhs.empty())
  205. return;
  206. clone_tree(rhs);
  207. size_holder::set_size(rhs.get_size());
  208. }
  209. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  210. /// \copydoc boost::heap::priority_queue::priority_queue(priority_queue &&)
  211. pairing_heap(pairing_heap && rhs):
  212. super_t(std::move(rhs)), root(rhs.root)
  213. {
  214. rhs.root = NULL;
  215. }
  216. /// \copydoc boost::heap::priority_queue::operator=(priority_queue &&)
  217. pairing_heap & operator=(pairing_heap && rhs)
  218. {
  219. super_t::operator=(std::move(rhs));
  220. root = rhs.root;
  221. rhs.root = NULL;
  222. return *this;
  223. }
  224. #endif
  225. /// \copydoc boost::heap::priority_queue::operator=(priority_queue const & rhs)
  226. pairing_heap & operator=(pairing_heap const & rhs)
  227. {
  228. clear();
  229. size_holder::set_size(rhs.get_size());
  230. static_cast<super_t&>(*this) = rhs;
  231. clone_tree(rhs);
  232. return *this;
  233. }
  234. ~pairing_heap(void)
  235. {
  236. while (!empty())
  237. pop();
  238. }
  239. /// \copydoc boost::heap::priority_queue::empty
  240. bool empty(void) const
  241. {
  242. return root == NULL;
  243. }
  244. /// \copydoc boost::heap::binomial_heap::size
  245. size_type size(void) const
  246. {
  247. if (constant_time_size)
  248. return size_holder::get_size();
  249. if (root == NULL)
  250. return 0;
  251. else
  252. return detail::count_nodes(root);
  253. }
  254. /// \copydoc boost::heap::priority_queue::max_size
  255. size_type max_size(void) const
  256. {
  257. return allocator_type::max_size();
  258. }
  259. /// \copydoc boost::heap::priority_queue::clear
  260. void clear(void)
  261. {
  262. if (empty())
  263. return;
  264. root->template clear_subtree<allocator_type>(*this);
  265. root->~node();
  266. allocator_type::deallocate(root, 1);
  267. root = NULL;
  268. size_holder::set_size(0);
  269. }
  270. /// \copydoc boost::heap::priority_queue::get_allocator
  271. allocator_type get_allocator(void) const
  272. {
  273. return *this;
  274. }
  275. /// \copydoc boost::heap::priority_queue::swap
  276. void swap(pairing_heap & rhs)
  277. {
  278. super_t::swap(rhs);
  279. std::swap(root, rhs.root);
  280. }
  281. /// \copydoc boost::heap::priority_queue::top
  282. const_reference top(void) const
  283. {
  284. BOOST_ASSERT(!empty());
  285. return super_t::get_value(root->value);
  286. }
  287. /**
  288. * \b Effects: Adds a new element to the priority queue. Returns handle to element
  289. *
  290. * \cond
  291. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  292. * \endcond
  293. *
  294. * \b Complexity: 2**2*log(log(N)) (amortized).
  295. *
  296. * */
  297. handle_type push(value_type const & v)
  298. {
  299. size_holder::increment();
  300. node_pointer n = allocator_type::allocate(1);
  301. new(n) node(super_t::make_node(v));
  302. merge_node(n);
  303. return handle_type(n);
  304. }
  305. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  306. /**
  307. * \b Effects: Adds a new element to the priority queue. The element is directly constructed in-place. Returns handle to element.
  308. *
  309. * \cond
  310. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  311. * \endcond
  312. *
  313. * \b Complexity: 2**2*log(log(N)) (amortized).
  314. *
  315. * */
  316. template <class... Args>
  317. handle_type emplace(Args&&... args)
  318. {
  319. size_holder::increment();
  320. node_pointer n = allocator_type::allocate(1);
  321. new(n) node(super_t::make_node(std::forward<Args>(args)...));
  322. merge_node(n);
  323. return handle_type(n);
  324. }
  325. #endif
  326. /**
  327. * \b Effects: Removes the top element from the priority queue.
  328. *
  329. * \b Complexity: Logarithmic (amortized).
  330. *
  331. * */
  332. void pop(void)
  333. {
  334. BOOST_ASSERT(!empty());
  335. erase(handle_type(root));
  336. }
  337. /**
  338. * \b Effects: Assigns \c v to the element handled by \c handle & updates the priority queue.
  339. *
  340. * \cond
  341. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  342. * \endcond
  343. *
  344. * \b Complexity: 2**2*log(log(N)) (amortized).
  345. *
  346. * */
  347. void update (handle_type handle, const_reference v)
  348. {
  349. handle.node_->value = super_t::make_node(v);
  350. update(handle);
  351. }
  352. /**
  353. * \b Effects: Updates the heap after the element handled by \c handle has been changed.
  354. *
  355. * \cond
  356. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  357. * \endcond
  358. *
  359. * \b Complexity: 2**2*log(log(N)) (amortized).
  360. *
  361. * \b Note: If this is not called, after a handle has been updated, the behavior of the data structure is undefined!
  362. * */
  363. void update (handle_type handle)
  364. {
  365. node_pointer n = handle.node_;
  366. n->unlink();
  367. if (!n->children.empty())
  368. n = merge_nodes(n, merge_node_list(n->children));
  369. if (n != root)
  370. merge_node(n);
  371. }
  372. /**
  373. * \b Effects: Assigns \c v to the element handled by \c handle & updates the priority queue.
  374. *
  375. * \cond
  376. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  377. * \endcond
  378. *
  379. * \b Complexity: 2**2*log(log(N)) (amortized).
  380. *
  381. * \b Note: The new value is expected to be greater than the current one
  382. * */
  383. void increase (handle_type handle, const_reference v)
  384. {
  385. update(handle, v);
  386. }
  387. /**
  388. * \b Effects: Updates the heap after the element handled by \c handle has been changed.
  389. *
  390. * \cond
  391. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  392. * \endcond
  393. *
  394. * \b Complexity: 2**2*log(log(N)) (amortized).
  395. *
  396. * \b Note: If this is not called, after a handle has been updated, the behavior of the data structure is undefined!
  397. * */
  398. void increase (handle_type handle)
  399. {
  400. update(handle);
  401. }
  402. /**
  403. * \b Effects: Assigns \c v to the element handled by \c handle & updates the priority queue.
  404. *
  405. * \cond
  406. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  407. * \endcond
  408. *
  409. * \b Complexity: 2**2*log(log(N)) (amortized).
  410. *
  411. * \b Note: The new value is expected to be less than the current one
  412. * */
  413. void decrease (handle_type handle, const_reference v)
  414. {
  415. update(handle, v);
  416. }
  417. /**
  418. * \b Effects: Updates the heap after the element handled by \c handle has been changed.
  419. *
  420. * \cond
  421. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  422. * \endcond
  423. *
  424. * \b Complexity: 2**2*log(log(N)) (amortized).
  425. *
  426. * \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!
  427. * */
  428. void decrease (handle_type handle)
  429. {
  430. update(handle);
  431. }
  432. /**
  433. * \b Effects: Removes the element handled by \c handle from the priority_queue.
  434. *
  435. * \cond
  436. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  437. * \endcond
  438. *
  439. * \b Complexity: 2**2*log(log(N)) (amortized).
  440. * */
  441. void erase(handle_type handle)
  442. {
  443. node_pointer n = handle.node_;
  444. if (n != root) {
  445. n->unlink();
  446. if (!n->children.empty())
  447. merge_node(merge_node_list(n->children));
  448. } else {
  449. if (!n->children.empty())
  450. root = merge_node_list(n->children);
  451. else
  452. root = NULL;
  453. }
  454. size_holder::decrement();
  455. n->~node();
  456. allocator_type::deallocate(n, 1);
  457. }
  458. /// \copydoc boost::heap::priority_queue::begin
  459. iterator begin(void) const
  460. {
  461. return iterator(root, super_t::value_comp());
  462. }
  463. /// \copydoc boost::heap::priority_queue::end
  464. iterator end(void) const
  465. {
  466. return iterator(super_t::value_comp());
  467. }
  468. /// \copydoc boost::heap::fibonacci_heap::ordered_begin
  469. ordered_iterator ordered_begin(void) const
  470. {
  471. return ordered_iterator(root, super_t::value_comp());
  472. }
  473. /// \copydoc boost::heap::fibonacci_heap::ordered_begin
  474. ordered_iterator ordered_end(void) const
  475. {
  476. return ordered_iterator(NULL, super_t::value_comp());
  477. }
  478. /// \copydoc boost::heap::d_ary_heap_mutable::s_handle_from_iterator
  479. static handle_type s_handle_from_iterator(iterator const & it)
  480. {
  481. node * ptr = const_cast<node *>(it.get_node());
  482. return handle_type(ptr);
  483. }
  484. /**
  485. * \b Effects: Merge all elements from rhs into this
  486. *
  487. * \cond
  488. * \b Complexity: \f$2^2log(log(N))\f$ (amortized).
  489. * \endcond
  490. *
  491. * \b Complexity: 2**2*log(log(N)) (amortized).
  492. *
  493. * */
  494. void merge(pairing_heap & rhs)
  495. {
  496. if (rhs.empty())
  497. return;
  498. merge_node(rhs.root);
  499. size_holder::add(rhs.get_size());
  500. rhs.set_size(0);
  501. rhs.root = NULL;
  502. super_t::set_stability_count((std::max)(super_t::get_stability_count(),
  503. rhs.get_stability_count()));
  504. rhs.set_stability_count(0);
  505. }
  506. /// \copydoc boost::heap::priority_queue::value_comp
  507. value_compare const & value_comp(void) const
  508. {
  509. return super_t::value_comp();
  510. }
  511. /// \copydoc boost::heap::priority_queue::operator<(HeapType const & rhs) const
  512. template <typename HeapType>
  513. bool operator<(HeapType const & rhs) const
  514. {
  515. return detail::heap_compare(*this, rhs);
  516. }
  517. /// \copydoc boost::heap::priority_queue::operator>(HeapType const & rhs) const
  518. template <typename HeapType>
  519. bool operator>(HeapType const & rhs) const
  520. {
  521. return detail::heap_compare(rhs, *this);
  522. }
  523. /// \copydoc boost::heap::priority_queue::operator>=(HeapType const & rhs) const
  524. template <typename HeapType>
  525. bool operator>=(HeapType const & rhs) const
  526. {
  527. return !operator<(rhs);
  528. }
  529. /// \copydoc boost::heap::priority_queue::operator<=(HeapType const & rhs) const
  530. template <typename HeapType>
  531. bool operator<=(HeapType const & rhs) const
  532. {
  533. return !operator>(rhs);
  534. }
  535. /// \copydoc boost::heap::priority_queue::operator==(HeapType const & rhs) const
  536. template <typename HeapType>
  537. bool operator==(HeapType const & rhs) const
  538. {
  539. return detail::heap_equality(*this, rhs);
  540. }
  541. /// \copydoc boost::heap::priority_queue::operator!=(HeapType const & rhs) const
  542. template <typename HeapType>
  543. bool operator!=(HeapType const & rhs) const
  544. {
  545. return !(*this == rhs);
  546. }
  547. private:
  548. #if !defined(BOOST_DOXYGEN_INVOKED)
  549. void clone_tree(pairing_heap const & rhs)
  550. {
  551. BOOST_HEAP_ASSERT(root == NULL);
  552. if (rhs.empty())
  553. return;
  554. root = allocator_type::allocate(1);
  555. new(root) node(static_cast<node const &>(*rhs.root), static_cast<allocator_type&>(*this));
  556. }
  557. void merge_node(node_pointer other)
  558. {
  559. BOOST_HEAP_ASSERT(other);
  560. if (root != NULL)
  561. root = merge_nodes(root, other);
  562. else
  563. root = other;
  564. }
  565. node_pointer merge_node_list(node_child_list & children)
  566. {
  567. BOOST_HEAP_ASSERT(!children.empty());
  568. node_pointer merged = merge_first_pair(children);
  569. if (children.empty())
  570. return merged;
  571. node_child_list node_list;
  572. node_list.push_back(*merged);
  573. do {
  574. node_pointer next_merged = merge_first_pair(children);
  575. node_list.push_back(*next_merged);
  576. } while (!children.empty());
  577. return merge_node_list(node_list);
  578. }
  579. node_pointer merge_first_pair(node_child_list & children)
  580. {
  581. BOOST_HEAP_ASSERT(!children.empty());
  582. node_pointer first_child = static_cast<node_pointer>(&children.front());
  583. children.pop_front();
  584. if (children.empty())
  585. return first_child;
  586. node_pointer second_child = static_cast<node_pointer>(&children.front());
  587. children.pop_front();
  588. return merge_nodes(first_child, second_child);
  589. }
  590. node_pointer merge_nodes(node_pointer node1, node_pointer node2)
  591. {
  592. if (super_t::operator()(node1->value, node2->value))
  593. std::swap(node1, node2);
  594. node2->unlink();
  595. node1->children.push_front(*node2);
  596. return node1;
  597. }
  598. node_pointer root;
  599. #endif
  600. };
  601. } /* namespace heap */
  602. } /* namespace boost */
  603. #undef BOOST_HEAP_ASSERT
  604. #endif /* BOOST_HEAP_PAIRING_HEAP_HPP */