Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_heap.h
Go to the documentation of this file.
1// -*- C++ -*-
2
47#ifndef _RWSTD_RW_HEAP_H_INCLUDED
48#define _RWSTD_RW_HEAP_H_INCLUDED
49
50#ifndef _RWSTD_RW_ALGOBASE_H_INCLUDED
51# include <rw/_algobase.h>
52#endif // _RWSTD_RW_ALGOBASE_H_INCLUDED
53
54#ifndef _RWSTD_RW_ITERBASE_H_INCLUDED
55# include <rw/_iterbase.h>
56#endif // _RWSTD_RW_ITERBASE_H_INCLUDED
57
58
60
61
62// 25.3.6 - Heap operations
63
64// helper to work around the lack of iterator_traits
66template <class _RandomAccessIter, class _Dist, class _TypeT,
67 class _Compare>
68void __push_heap (_RandomAccessIter, _Dist, _Dist, _TypeT, _Compare);
69
70
71template <class _RandomAccessIter, class _Dist, class _Compare>
72inline void
73__push_heap (_RandomAccessIter __first, _RandomAccessIter __last,
74 _Dist*, _Compare __comp)
75{
76 __push_heap (__first, _Dist (__last - __first), _Dist (), *__last, __comp);
77}
78
79// 25.3.6.1
80template <class _RandomAccessIter, class _Compare>
81inline void push_heap (_RandomAccessIter __first, _RandomAccessIter __last,
82 _Compare __comp)
83{
84 _RWSTD_ASSERT_RANGE (__first, __last);
85
86 if (!(__first == __last))
87 __push_heap (__first, --__last,
88 _RWSTD_DIFFERENCE_TYPE (_RandomAccessIter), __comp);
89}
90
91
92// 25.3.6.1
93template <class _RandomAccessIter>
94inline void push_heap (_RandomAccessIter __first, _RandomAccessIter __last)
95{
96 _STD::push_heap (__first, __last, _RWSTD_LESS (_RandomAccessIter));
97}
98
99
101template <class _RandomAccessIter, class _Dist, class _TypeT,
102 class _Compare>
103void __adjust_heap (_RandomAccessIter, _Dist, _Dist, _TypeT, _Compare);
104
105
106// helper to work around the lack of iterator_traits
107template <class _RandomAccessIter, class _TypeT, class _Compare, class _Dist>
108inline void
109__pop_heap (_RandomAccessIter __first, _RandomAccessIter __last,
110 _RandomAccessIter __res, _TypeT __val, _Compare __cmp, _Dist*)
111{
112 *__res = *__first;
113 __adjust_heap (__first, _Dist (), _Dist (__last - __first), __val, __cmp);
114}
115
116
117// 25.3.6.2
118template <class _RandomAccessIter, class _Compare>
119inline void
120pop_heap (_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp)
121{
122 _RWSTD_ASSERT_RANGE (__first, __last);
123
124 if (!(__first == __last)) {
125 --__last;
126 __pop_heap (__first, __last, __last, *__last, __comp,
127 _RWSTD_DIFFERENCE_TYPE (_RandomAccessIter));
128 }
129}
130
131
132// 25.3.6.2
133template <class _RandomAccessIter>
134inline void pop_heap (_RandomAccessIter __first, _RandomAccessIter __last)
135{
136 _STD::pop_heap (__first, __last, _RWSTD_LESS (_RandomAccessIter));
137}
138
139
141template <class _RandomAccessIter, class _Compare, class _Dist>
142void __make_heap (_RandomAccessIter, _RandomAccessIter, _Compare, _Dist*);
143
144
145// 25.3.6.3
146template <class _RandomAccessIter, class _Compare>
147inline void make_heap (_RandomAccessIter __first, _RandomAccessIter __last,
148 _Compare __comp)
149{
150 _RWSTD_ASSERT_RANGE (__first, __last);
151
152 if (!(__last - __first < 2))
153 __make_heap (__first, __last, __comp,
154 _RWSTD_DIFFERENCE_TYPE (_RandomAccessIter));
155}
156
157
158// 25.3.6.3
159template <class _RandomAccessIter>
160inline void make_heap (_RandomAccessIter __first, _RandomAccessIter __last)
161{
162 _STD::make_heap (__first, __last, _RWSTD_LESS (_RandomAccessIter));
163}
164
165
166// 25.3.6.4
167template <class _RandomAccessIter, class _Compare>
168inline void sort_heap (_RandomAccessIter __first, _RandomAccessIter __last,
169 _Compare __comp)
170{
171 _RWSTD_ASSERT_RANGE (__first, __last);
172
173 for (; __last - __first > 1; --__last)
174 _STD::pop_heap (__first, __last, __comp);
175}
176
177
178// 25.3.6.4
179template <class _RandomAccessIter>
180inline void sort_heap (_RandomAccessIter __first, _RandomAccessIter __last)
181{
182 _STD::sort_heap (__first, __last, _RWSTD_LESS (_RandomAccessIter));
183}
184
185
186} // namespace std
187
188
189#ifdef _RWSTD_NO_IMPLICIT_INCLUSION
190# include <rw/_heap.cc>
191#endif
192
193
194#endif // _RWSTD_RW_HEAP_H_INCLUDED
#define _RWSTD_LESS(ignore)
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_ASSERT_RANGE(ign1, ign2)
Definition _defs.h:1247
#define _RWSTD_DIFFERENCE_TYPE(iterT)
Definition _defs.h:1044
Definition json.h:5363