Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_heap.cc
Go to the documentation of this file.
1
45
46
48template <class _RandomAccessIter, class _Dist, class _TypeT, class _Compare>
49void __push_heap (_RandomAccessIter __first, _Dist __holeIndex,
50 _Dist __topIndex, _TypeT __val, _Compare __comp)
51{
52 for (_Dist __parent = (__holeIndex - 1) / 2;
53 __holeIndex > __topIndex
54 && !(__comp (*(__first + __parent), __val) == false);
55 __parent = ((__holeIndex = __parent) - 1) / 2) {
56 *(__first + __holeIndex) = *(__first + __parent);
57 }
58
59 *(__first + __holeIndex) = __val;
60}
61
62
64template <class _RandomAccessIter, class _Dist, class _TypeT, class _Compare>
65void __adjust_heap (_RandomAccessIter __first, _Dist __holeIndex,
66 _Dist __dist, _TypeT __val, _Compare __comp)
67{
68 const _Dist __topIndex = __holeIndex;
69
70 _Dist __2ndChild;
71
72 while ((__2ndChild = 2 * __holeIndex + 2) < __dist) {
73 if (__comp (*(__first + __2ndChild), *(__first + (__2ndChild - 1))))
74 --__2ndChild;
75
76 *(__first + __holeIndex) = *(__first + __2ndChild);
77 __holeIndex = __2ndChild;
78 }
79
80 if (__2ndChild == __dist) {
81 *(__first + __holeIndex) = *(__first + (__2ndChild - 1));
82 __holeIndex = __2ndChild - 1;
83 }
84
85 __push_heap (__first, __holeIndex, __topIndex, __val, __comp);
86}
87
88
90template <class _RandomAccessIter, class _Compare, class _Dist>
91void __make_heap (_RandomAccessIter __first, _RandomAccessIter __last,
92 _Compare __comp, _Dist*)
93{
94 _RWSTD_ASSERT_RANGE (__first, __last);
95
96 const _Dist __dist = __last - __first;
97
98 for (_Dist __parent = __dist / 2; 0 < __parent; ) {
99 --__parent;
100 __adjust_heap (__first, __parent, __dist, *(__first + __parent),
101 __comp);
102 }
103}
104
105
106} // namespace std
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _EXPORT
Definition _defs.h:498
#define _RWSTD_ASSERT_RANGE(ign1, ign2)
Definition _defs.h:1247
Definition json.h:5363