31#pragma GCC visibility push(default)
35template<
class Type,
class Key>
44template<
class Type,
class Key>
45AbaBHeap<Type, Key>::AbaBHeap(
46 const ArrayBuffer<Type> &elems,
47 const ArrayBuffer<Key> &keys)
53 for (
int i = father(n_-1); i>=0; --i)
58template<
class Type,
class Key>
59std::ostream&
operator<<(std::ostream& out,
const AbaBHeap<Type, Key>& rhs)
61 for(
int i = 0; i < rhs.n_; i ++)
62 out << rhs.heap_[i] <<
" (" << rhs.keys_[i] <<
") ";
68template<
class Type,
class Key>
69void AbaBHeap<Type, Key>::insert(Type elem, Key key)
85 while (i > 0 && keys_[f] > key) {
97template<
class Type,
class Key>
98Type AbaBHeap<Type, Key>::getMin()
const
110template<
class Type,
class Key>
111Key AbaBHeap<Type, Key>::getMinKey()
const
123template<
class Type,
class Key>
124Type AbaBHeap<Type, Key>::extractMin()
131 heap_[0] = heap_[n_];
132 keys_[0] = keys_[n_];
140template<
class Type,
class Key>
141void AbaBHeap<Type, Key>::clear()
147template<
class Type,
class Key>
148inline int AbaBHeap<Type, Key>::size()
const
154template <
class Type,
class Key>
155inline int AbaBHeap<Type, Key>::number()
const
161template<
class Type,
class Key>
162inline bool AbaBHeap<Type, Key>::empty()
const
164 if(n_ == 0)
return true;
169template<
class Type,
class Key>
170void AbaBHeap<Type, Key>::realloc(
int newSize)
172 heap_.realloc(newSize);
173 keys_.realloc(newSize);
177template<
class Type,
class Key>
178void AbaBHeap<Type, Key>::check()
const
180 for(
int i = 0; i < n_/2; i++)
181 if (keys_[i] > keys_[leftSon(i)] || (rightSon(i) < n_ && heap_[i] > heap_[rightSon(i)])) {
182 Logger::ifout() <<
"AbaBHeap:check(): " << i <<
" violates heap\n";
188template <
class Type,
class Key>
189inline int AbaBHeap<Type, Key>::leftSon(
int i)
const
195template <
class Type,
class Key>
196int AbaBHeap<Type, Key>::rightSon(
int i)
const
202template <
class Type,
class Key>
203inline int AbaBHeap<Type, Key>::father(
int i)
const
209template <
class Type,
class Key>
210void AbaBHeap<Type, Key>::heapify(
int i)
229 if (l < n_ && keys_[i] > keys_[l]) smallest = l;
231 if (
r < n_ && keys_[smallest] > keys_[
r]) smallest =
r;
236 heap_[i] = heap_[smallest];
237 heap_[smallest] = tmp;
240 keys_[i] = keys_[smallest];
241 keys_[smallest] = ktmp;
250#pragma GCC visibility pop
AbaBHeap(int size)
A constructor.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.