williamr@4
|
1 |
/*
|
williamr@4
|
2 |
*
|
williamr@4
|
3 |
* Copyright (c) 1994
|
williamr@4
|
4 |
* Hewlett-Packard Company
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Permission to use, copy, modify, distribute and sell this software
|
williamr@4
|
7 |
* and its documentation for any purpose is hereby granted without fee,
|
williamr@4
|
8 |
* provided that the above copyright notice appear in all copies and
|
williamr@4
|
9 |
* that both that copyright notice and this permission notice appear
|
williamr@4
|
10 |
* in supporting documentation. Hewlett-Packard Company makes no
|
williamr@4
|
11 |
* representations about the suitability of this software for any
|
williamr@4
|
12 |
* purpose. It is provided "as is" without express or implied warranty.
|
williamr@4
|
13 |
*
|
williamr@4
|
14 |
* Copyright (c) 1997
|
williamr@4
|
15 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
16 |
*
|
williamr@4
|
17 |
* Permission to use, copy, modify, distribute and sell this software
|
williamr@4
|
18 |
* and its documentation for any purpose is hereby granted without fee,
|
williamr@4
|
19 |
* provided that the above copyright notice appear in all copies and
|
williamr@4
|
20 |
* that both that copyright notice and this permission notice appear
|
williamr@4
|
21 |
* in supporting documentation. Silicon Graphics makes no
|
williamr@4
|
22 |
* representations about the suitability of this software for any
|
williamr@4
|
23 |
* purpose. It is provided "as is" without express or implied warranty.
|
williamr@4
|
24 |
*/
|
williamr@4
|
25 |
|
williamr@4
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@4
|
27 |
* You should not attempt to use it directly.
|
williamr@4
|
28 |
*/
|
williamr@4
|
29 |
|
williamr@4
|
30 |
#ifndef _STLP_INTERNAL_HEAP_H
|
williamr@4
|
31 |
#define _STLP_INTERNAL_HEAP_H
|
williamr@4
|
32 |
|
williamr@4
|
33 |
#ifndef _STLP_CONFIG_H
|
williamr@4
|
34 |
#include <stl/_config.h>
|
williamr@4
|
35 |
#endif
|
williamr@4
|
36 |
|
williamr@4
|
37 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
38 |
|
williamr@4
|
39 |
// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap.
|
williamr@4
|
40 |
|
williamr@4
|
41 |
template <class _RandomAccessIterator>
|
williamr@4
|
42 |
void
|
williamr@4
|
43 |
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last);
|
williamr@4
|
44 |
|
williamr@4
|
45 |
|
williamr@4
|
46 |
template <class _RandomAccessIterator, class _Compare>
|
williamr@4
|
47 |
void
|
williamr@4
|
48 |
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
|
williamr@4
|
49 |
_Compare __comp);
|
williamr@4
|
50 |
|
williamr@4
|
51 |
template <class _RandomAccessIterator, class _Distance, class _Tp>
|
williamr@4
|
52 |
void
|
williamr@4
|
53 |
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
|
williamr@4
|
54 |
_Distance __len, _Tp __val);
|
williamr@4
|
55 |
|
williamr@4
|
56 |
template <class _RandomAccessIterator, class _Tp, class _Distance>
|
williamr@4
|
57 |
inline void
|
williamr@4
|
58 |
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
|
williamr@4
|
59 |
_RandomAccessIterator __result, _Tp __val, _Distance*)
|
williamr@4
|
60 |
{
|
williamr@4
|
61 |
*__result = *__first;
|
williamr@4
|
62 |
__adjust_heap(__first, _Distance(0), _Distance(__last - __first), __val);
|
williamr@4
|
63 |
}
|
williamr@4
|
64 |
|
williamr@4
|
65 |
template <class _RandomAccessIterator>
|
williamr@4
|
66 |
void pop_heap(_RandomAccessIterator __first,
|
williamr@4
|
67 |
_RandomAccessIterator __last);
|
williamr@4
|
68 |
|
williamr@4
|
69 |
template <class _RandomAccessIterator, class _Distance,
|
williamr@4
|
70 |
class _Tp, class _Compare>
|
williamr@4
|
71 |
void
|
williamr@4
|
72 |
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
|
williamr@4
|
73 |
_Distance __len, _Tp __val, _Compare __comp);
|
williamr@4
|
74 |
|
williamr@4
|
75 |
template <class _RandomAccessIterator, class _Tp, class _Compare,
|
williamr@4
|
76 |
class _Distance>
|
williamr@4
|
77 |
inline void
|
williamr@4
|
78 |
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
|
williamr@4
|
79 |
_RandomAccessIterator __result, _Tp __val, _Compare __comp,
|
williamr@4
|
80 |
_Distance*)
|
williamr@4
|
81 |
{
|
williamr@4
|
82 |
*__result = *__first;
|
williamr@4
|
83 |
__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
|
williamr@4
|
84 |
__val, __comp);
|
williamr@4
|
85 |
}
|
williamr@4
|
86 |
|
williamr@4
|
87 |
template <class _RandomAccessIterator, class _Compare>
|
williamr@4
|
88 |
void
|
williamr@4
|
89 |
pop_heap(_RandomAccessIterator __first,
|
williamr@4
|
90 |
_RandomAccessIterator __last, _Compare __comp);
|
williamr@4
|
91 |
|
williamr@4
|
92 |
template <class _RandomAccessIterator>
|
williamr@4
|
93 |
void
|
williamr@4
|
94 |
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last);
|
williamr@4
|
95 |
|
williamr@4
|
96 |
template <class _RandomAccessIterator, class _Compare>
|
williamr@4
|
97 |
void
|
williamr@4
|
98 |
make_heap(_RandomAccessIterator __first,
|
williamr@4
|
99 |
_RandomAccessIterator __last, _Compare __comp);
|
williamr@4
|
100 |
|
williamr@4
|
101 |
template <class _RandomAccessIterator>
|
williamr@4
|
102 |
_STLP_INLINE_LOOP
|
williamr@4
|
103 |
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
|
williamr@4
|
104 |
{
|
williamr@4
|
105 |
while (__last - __first > 1)
|
williamr@4
|
106 |
pop_heap(__first, __last--);
|
williamr@4
|
107 |
}
|
williamr@4
|
108 |
|
williamr@4
|
109 |
template <class _RandomAccessIterator, class _Compare>
|
williamr@4
|
110 |
_STLP_INLINE_LOOP
|
williamr@4
|
111 |
void
|
williamr@4
|
112 |
sort_heap(_RandomAccessIterator __first,
|
williamr@4
|
113 |
_RandomAccessIterator __last, _Compare __comp)
|
williamr@4
|
114 |
{
|
williamr@4
|
115 |
while (__last - __first > 1)
|
williamr@4
|
116 |
pop_heap(__first, __last--, __comp);
|
williamr@4
|
117 |
}
|
williamr@4
|
118 |
|
williamr@4
|
119 |
_STLP_END_NAMESPACE
|
williamr@4
|
120 |
|
williamr@4
|
121 |
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
|
williamr@4
|
122 |
# include <stl/_heap.c>
|
williamr@4
|
123 |
# endif
|
williamr@4
|
124 |
|
williamr@4
|
125 |
#endif /* _STLP_INTERNAL_HEAP_H */
|
williamr@4
|
126 |
|
williamr@4
|
127 |
// Local Variables:
|
williamr@4
|
128 |
// mode:C++
|
williamr@4
|
129 |
// End:
|