Chris@16: // Chris@16: //======================================================================= Chris@16: // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. Chris@16: // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: //======================================================================= Chris@16: // Chris@16: #ifndef BOOST_GRAPH_DETAIL_MUTABLE_HEAP_H Chris@16: #define BOOST_GRAPH_DETAIL_MUTABLE_HEAP_H Chris@16: Chris@16: /* Chris@16: There are a few things wrong with this set of functions. Chris@16: Chris@16: ExternalData should be removed, it is not part of the core Chris@16: algorithm. It can be handled inside the tree nodes. Chris@16: Chris@16: The swap() should be replaced by assignment since its use is causing Chris@16: the number of memory references to double. Chris@16: Chris@16: The min_element should be replaced by a fixed length loop Chris@16: (fixed at d for d-heaps). Chris@16: Chris@16: The member functions of TreeNode should be changed to global Chris@16: functions. Chris@16: Chris@16: These functions will be replaced by those in heap_tree.h Chris@16: Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: template Chris@16: inline TreeNode up_heap(TreeNode x, const Compare& comp, ExternalData& edata) { Chris@16: while (x.has_parent() && comp(x, x.parent())) Chris@16: x.swap(x.parent(), edata); Chris@16: return x; Chris@16: } Chris@16: Chris@16: template Chris@16: inline TreeNode down_heap(TreeNode x, const Compare& comp, ExternalData& edata) { Chris@16: while (x.children().size() > 0) { Chris@16: typename TreeNode::children_type::iterator Chris@16: child_iter = std::min_element(x.children().begin(), Chris@16: x.children().end(), Chris@16: comp); Chris@16: if (comp(*child_iter, x)) Chris@16: x.swap(*child_iter, edata); Chris@16: else Chris@16: break; Chris@16: } Chris@16: return x; Chris@16: } Chris@16: Chris@16: template Chris@16: inline void update_heap(TreeNode x, const Compare& comp, ExternalData& edata) { Chris@16: x = down_heap(x, comp, edata); Chris@16: (void)up_heap(x, comp, edata); Chris@16: } Chris@16: Chris@16: } Chris@16: #endif