~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to boost/boost/pending/is_heap.hpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
//=======================================================================
 
3
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
 
4
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
 
5
//
 
6
// This file is part of the Generic Graph Component Library
 
7
//
 
8
// You should have received a copy of the License Agreement for the
 
9
// Generic Graph Component Library along with the software;  see the
 
10
// file LICENSE.  If not, contact Office of Research, University of Notre
 
11
// Dame, Notre Dame, IN  46556.
 
12
//
 
13
// Permission to modify the code and to distribute modified code is
 
14
// granted, provided the text of this NOTICE is retained, a notice that
 
15
// the code was modified is included with the above COPYRIGHT NOTICE and
 
16
// with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
 
17
// file is distributed with the modified code.
 
18
//
 
19
// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
 
20
// By way of example, but not limitation, Licensor MAKES NO
 
21
// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
 
22
// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
 
23
// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
 
24
// OR OTHER RIGHTS.
 
25
//=======================================================================
 
26
//
 
27
#if __KCC
 
28
namespace std {
 
29
 
 
30
template <class RandomAccessIterator, class Distance>
 
31
bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
 
32
               Distance*)
 
33
{
 
34
  const Distance n = last - first;
 
35
 
 
36
  Distance parent = 0;
 
37
  for (Distance child = 1; child < n; ++child) {
 
38
    if (first[parent] < first[child]) 
 
39
      return false;
 
40
    if ((child & 1) == 0)
 
41
      ++parent;
 
42
  }
 
43
  return true;
 
44
}
 
45
 
 
46
template <class RandomAccessIterator>
 
47
inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last)
 
48
{
 
49
  return __is_heap(first, last, distance_type(first));
 
50
}
 
51
 
 
52
 
 
53
template <class RandomAccessIterator, class Distance, class StrictWeakOrdering>
 
54
bool __is_heap(RandomAccessIterator first, RandomAccessIterator last,
 
55
               StrictWeakOrdering comp,
 
56
               Distance*)
 
57
{
 
58
  const Distance n = last - first;
 
59
 
 
60
  Distance parent = 0;
 
61
  for (Distance child = 1; child < n; ++child) {
 
62
    if (comp(first[parent], first[child]))
 
63
      return false;
 
64
    if ((child & 1) == 0)
 
65
      ++parent;
 
66
  }
 
67
  return true;
 
68
}
 
69
 
 
70
template <class RandomAccessIterator, class StrictWeakOrdering>
 
71
inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last,
 
72
                    StrictWeakOrdering comp)
 
73
{
 
74
  return __is_heap(first, last, comp, distance_type(first));
 
75
}
 
76
 
 
77
}
 
78
#endif