12 #ifndef BINARYHEAP_HPP
13 #define BINARYHEAP_HPP
15 #include "../core/alloc_func.hpp"
18 #define BINARYHEAP_CHECK 0
22 #define CHECK_CONSISTY() this->CheckConsistency()
25 #define CHECK_CONSISTY() ;
68 this->
data = MallocT<T *>(max_items + 1);
96 while (child <= this->
items) {
98 if (child < this->items && *this->
data[child + 1] < *this->
data[child]) {
102 if (!(*this->
data[child] < *item)) {
107 this->
data[gap] = this->
data[child];
133 if (!(*item < *this->
data[parent])) {
137 this->
data[gap] = this->
data[parent];
145 inline void CheckConsistency()
147 for (uint child = 2; child <= this->
items; child++) {
148 uint parent = child / 2;
149 assert(!(*this->
data[child] < *this->
data[parent]));
172 return this->
items == 0;
193 return this->
data[1];
216 assert(this->
capacity < UINT_MAX / 2);
224 this->
data[gap] = new_item;
238 T *first = this->
Begin();
242 T *last = this->
End();
258 if (index < this->
items) {
263 T *last = this->
End();
270 assert(index == this->items);
287 for (T **ppI = this->
data + 1, **ppLast = ppI + this->
items; ppI <= ppLast; ppI++) {
289 return ppI - this->
data;