os/ossrv/ossrv_pub/boost_apis/boost/pending/mutable_heap.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
//
sl@0
     2
//=======================================================================
sl@0
     3
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
sl@0
     4
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
sl@0
     5
//
sl@0
     6
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
     7
// accompanying file LICENSE_1_0.txt or copy at
sl@0
     8
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
     9
//=======================================================================
sl@0
    10
//
sl@0
    11
#ifndef BOOST_GRAPH_DETAIL_MUTABLE_HEAP_H
sl@0
    12
#define BOOST_GRAPH_DETAIL_MUTABLE_HEAP_H
sl@0
    13
sl@0
    14
/*
sl@0
    15
  There are a few things wrong with this set of functions.
sl@0
    16
sl@0
    17
  ExternalData should be removed, it is not part of the core
sl@0
    18
  algorithm. It can be handled inside the tree nodes.
sl@0
    19
sl@0
    20
  The swap() should be replaced by assignment since its use is causing
sl@0
    21
  the number of memory references to double.
sl@0
    22
sl@0
    23
  The min_element should be replaced by a fixed length loop
sl@0
    24
  (fixed at d for d-heaps).
sl@0
    25
sl@0
    26
  The member functions of TreeNode should be changed to global
sl@0
    27
  functions.
sl@0
    28
sl@0
    29
  These functions will be replaced by those in heap_tree.h
sl@0
    30
sl@0
    31
 */
sl@0
    32
sl@0
    33
namespace boost {
sl@0
    34
sl@0
    35
  template <class TreeNode, class Compare, class ExternalData>
sl@0
    36
  inline TreeNode up_heap(TreeNode x, const Compare& comp, ExternalData& edata) {
sl@0
    37
    while (x.has_parent() && comp(x, x.parent()))
sl@0
    38
      x.swap(x.parent(), edata);
sl@0
    39
    return x;
sl@0
    40
  }
sl@0
    41
sl@0
    42
  template <class TreeNode, class Compare, class ExternalData>
sl@0
    43
  inline TreeNode down_heap(TreeNode x, const Compare& comp, ExternalData& edata) {
sl@0
    44
    while (x.children().size() > 0) {
sl@0
    45
      typename TreeNode::children_type::iterator 
sl@0
    46
        child_iter = std::min_element(x.children().begin(),
sl@0
    47
                                      x.children().end(), 
sl@0
    48
                                      comp);
sl@0
    49
      if (comp(*child_iter, x))
sl@0
    50
        x.swap(*child_iter, edata);
sl@0
    51
      else
sl@0
    52
        break;
sl@0
    53
    }
sl@0
    54
    return x;
sl@0
    55
  }
sl@0
    56
sl@0
    57
  template <class TreeNode, class Compare, class ExternalData>
sl@0
    58
  inline void update_heap(TreeNode x, const Compare& comp, ExternalData& edata) {
sl@0
    59
    x = down_heap(x, comp, edata);
sl@0
    60
    (void)up_heap(x, comp, edata);
sl@0
    61
  }
sl@0
    62
sl@0
    63
}
sl@0
    64
#endif