34 template<
class Type,
class Key>
43 template<
class Type,
class Key>
45 const ArrayBuffer<Type> &elems,
46 const ArrayBuffer<Key> &keys)
52 for (
int i =
father(
n_-1); i>=0; --i)
57 template<
class Type,
class Key>
58 std::ostream& operator<<(std::ostream& out, const AbaBHeap<Type, Key>& rhs)
60 for(
int i = 0; i < rhs.n_; i ++)
61 out << rhs.heap_[i] <<
" (" << rhs.keys_[i] <<
") ";
67 template<
class Type,
class Key>
84 while (i > 0 &&
keys_[f] > key) {
96 template<
class Type,
class Key>
109 template<
class Type,
class Key>
122 template<
class Type,
class Key>
139 template<
class Type,
class Key>
146 template<
class Type,
class Key>
153 template <
class Type,
class Key>
160 template<
class Type,
class Key>
163 if(
n_ == 0)
return true;
168 template<
class Type,
class Key>
171 heap_.realloc(newSize);
172 keys_.realloc(newSize);
176 template<
class Type,
class Key>
179 for(
int i = 0; i <
n_/2; i++)
181 Logger::ifout() <<
"AbaBHeap:check(): " << i <<
" violates heap\n";
187 template <
class Type,
class Key>
194 template <
class Type,
class Key>
201 template <
class Type,
class Key>
208 template <
class Type,
class Key>
236 heap_[smallest] = tmp;
240 keys_[smallest] = ktmp;
void heapify(int i)
Is the central function to maintain the heap property.
bool empty() const
Return true if there are no elements in the heap, false otherwise.
Type getMin() const
Returns the minimum element of the heap.
void realloc(int newSize)
Changes the size of the heap.
int father(int i) const
Returns the index of the father of element i.
int size() const
Returns the maximal number of elements which can be stored in the heap.
int leftSon(int i) const
Returns the index of the left son of node i.
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
int number() const
Returns the number of elements in the heap.
INDEX size() const
Returns the size (number of elements) of the array.
void insert(Type elem, Key key)
Inserts an item with a key into the heap.
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
void check() const
Throws an exception if the heap properties are violated.
Type extractMin()
Accesses and removes the minimum element from the heap.
Key getMinKey() const
Returns the key of the minimum element of the heap.
void clear()
Empties the heap.
int rightSon(int i) const
Returns the index of the right son of node i.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
AbaBHeap(int size)
A constructor.