29#ifndef _STLP_INTERNAL_HEAP_H
33#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
39template <
class _RandomAccessIterator,
class _Distance,
class _Tp>
43 _Distance __holeIndex, _Distance __topIndex, _Tp
__val)
45 _Distance __parent = (__holeIndex - 1) / 2;
46 while (__holeIndex > __topIndex && *(__first + __parent) <
__val) {
47 *(__first + __holeIndex) = *(__first + __parent);
48 __holeIndex = __parent;
49 __parent = (__holeIndex - 1) / 2;
51 *(__first + __holeIndex) =
__val;
54template <
class _RandomAccessIterator,
class _Distance,
class _Tp>
57 _RandomAccessIterator
__last, _Distance*, _Tp*)
63template <
class _RandomAccessIterator>
72template <
class _RandomAccessIterator,
class _Distance,
class _Tp,
76__push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
77 _Distance __topIndex, _Tp
__val, _Compare __comp)
79 _Distance __parent = (__holeIndex - 1) / 2;
80 while (__holeIndex > __topIndex && __comp(*(__first + __parent),
__val)) {
82 *(__first + __holeIndex) = *(__first + __parent);
83 __holeIndex = __parent;
84 __parent = (__holeIndex - 1) / 2;
86 *(__first + __holeIndex) =
__val;
89template <
class _RandomAccessIterator,
class _Compare,
90 class _Distance,
class _Tp>
93 _RandomAccessIterator
__last, _Compare __comp,
97 _Tp(*(
__last - 1)), __comp);
100template <
class _RandomAccessIterator,
class _Compare>
109template <
class _RandomAccessIterator,
class _Distance,
class _Tp>
112 _Distance __len, _Tp
__val) {
113 _Distance __topIndex = __holeIndex;
114 _Distance __secondChild = 2 * __holeIndex + 2;
115 while (__secondChild < __len) {
116 if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
118 *(__first + __holeIndex) = *(__first + __secondChild);
119 __holeIndex = __secondChild;
120 __secondChild = 2 * (__secondChild + 1);
122 if (__secondChild == __len) {
123 *(__first + __holeIndex) = *(__first + (__secondChild - 1));
124 __holeIndex = __secondChild - 1;
130template <
class _RandomAccessIterator,
class _Tp>
137template <
class _RandomAccessIterator>
139 _RandomAccessIterator
__last) {
143template <
class _RandomAccessIterator,
class _Distance,
144 class _Tp,
class _Compare>
147 _Distance __len, _Tp
__val, _Compare __comp)
149 _Distance __topIndex = __holeIndex;
150 _Distance __secondChild = 2 * __holeIndex + 2;
151 while (__secondChild < __len) {
152 if (__comp(*(__first + __secondChild), *(__first + (__secondChild - 1)))) {
154 _StlMsg_INVALID_STRICT_WEAK_PREDICATE)
157 *(__first + __holeIndex) = *(__first + __secondChild);
158 __holeIndex = __secondChild;
159 __secondChild = 2 * (__secondChild + 1);
161 if (__secondChild == __len) {
162 *(__first + __holeIndex) = *(__first + (__secondChild - 1));
163 __holeIndex = __secondChild - 1;
169template <
class _RandomAccessIterator,
class _Tp,
class _Compare>
172 _RandomAccessIterator
__last, _Tp*, _Compare __comp)
179template <
class _RandomAccessIterator,
class _Compare>
182 _RandomAccessIterator
__last, _Compare __comp)
187template <
class _RandomAccessIterator,
class _Tp,
class _Distance>
191 _RandomAccessIterator
__last, _Tp*, _Distance*)
193 if (
__last - __first < 2)
return;
194 _Distance __len =
__last - __first;
195 _Distance __parent = (__len - 2)/2;
198 __adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)));
199 if (__parent == 0)
return;
204template <
class _RandomAccessIterator>
212template <
class _RandomAccessIterator,
class _Compare,
213 class _Tp,
class _Distance>
217 _Compare __comp, _Tp*, _Distance*)
219 if (
__last - __first < 2)
return;
220 _Distance __len =
__last - __first;
221 _Distance __parent = (__len - 2)/2;
224 __adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)),
226 if (__parent == 0)
return;
231template <
class _RandomAccessIterator,
class _Compare>
234 _RandomAccessIterator
__last, _Compare __comp)
_STLP_INLINE_LOOP _InputIter __last
_STLP_INLINE_LOOP _InputIter const _Tp & __val
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
void __pop_heap_aux(_RandomAccessIterator __first, _RandomAccessIterator __last, _Tp *)
void __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex, _Distance __len, _Tp __val)
_STLP_INLINE_LOOP void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Tp *, _Distance *)
void __push_heap_aux(_RandomAccessIterator __first, _RandomAccessIterator __last, _Distance *, _Tp *)
_STLP_BEGIN_NAMESPACE _STLP_INLINE_LOOP void __push_heap(_RandomAccessIterator __first, _Distance __holeIndex, _Distance __topIndex, _Tp __val)
void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __result, _Tp __val, _Distance *)
#define _STLP_VALUE_TYPE(_It, _Tp)
#define _STLP_DISTANCE_TYPE(_It, _Tp)
#define _STLP_INLINE_LOOP
#define _STLP_BEGIN_NAMESPACE
#define _STLP_END_NAMESPACE