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