Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82534 - trunk/boost/heap
From: tim_at_[hidden]
Date: 2013-01-18 10:17:39


Author: timblechmann
Date: 2013-01-18 10:17:38 EST (Fri, 18 Jan 2013)
New Revision: 82534
URL: http://svn.boost.org/trac/boost/changeset/82534

Log:
heap: fix fibonacci_heap::erase

fixes #7903
Text files modified:
   trunk/boost/heap/fibonacci_heap.hpp | 41 +++++++++++++++++++--------------------
   1 files changed, 20 insertions(+), 21 deletions(-)

Modified: trunk/boost/heap/fibonacci_heap.hpp
==============================================================================
--- trunk/boost/heap/fibonacci_heap.hpp (original)
+++ trunk/boost/heap/fibonacci_heap.hpp 2013-01-18 10:17:38 EST (Fri, 18 Jan 2013)
@@ -397,16 +397,7 @@
         node_pointer element = top_element;
         roots.erase(node_list_type::s_iterator_to(*element));
 
- add_children_to_root(element);
-
- element->~node();
- allocator_type::deallocate(element, 1);
-
- size_holder::decrement();
- if (!empty())
- consolidate();
- else
- top_element = NULL;
+ finish_erase_or_pop(element);
     }
 
     /**
@@ -542,21 +533,15 @@
      * */
     void erase(handle_type const & handle)
     {
- node_pointer n = handle.node_;
- node_pointer parent = n->get_parent();
+ node_pointer element = handle.node_;
+ node_pointer parent = element->get_parent();
 
         if (parent)
- parent->children.erase(node_list_type::s_iterator_to(*n));
+ parent->children.erase(node_list_type::s_iterator_to(*element));
         else
- roots.erase(node_list_type::s_iterator_to(*n));
-
- add_children_to_root(n);
- consolidate();
+ roots.erase(node_list_type::s_iterator_to(*element));
 
- n->~node();
- allocator_type::deallocate(n, 1);
-
- size_holder::decrement();
+ finish_erase_or_pop(element);
     }
 
     /// \copydoc boost::heap::priority_queue::begin
@@ -757,6 +742,20 @@
         while (it != roots.end());
     }
 
+ void finish_erase_or_pop(node_pointer erased_node)
+ {
+ add_children_to_root(erased_node);
+
+ erased_node->~node();
+ allocator_type::deallocate(erased_node, 1);
+
+ size_holder::decrement();
+ if (!empty())
+ consolidate();
+ else
+ top_element = NULL;
+ }
+
     mutable node_pointer top_element;
     node_list_type roots;
 #endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk