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