|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
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>
130 heap_[0] = heap_[n_];
131 keys_[0] = keys_[n_];
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++)
180 if (keys_[i] > keys_[leftSon(i)] || (rightSon(i) < n_ && heap_[i] > heap_[rightSon(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>
228 if (l < n_ && keys_[i] > keys_[l]) smallest = l;
230 if (
r < n_ && keys_[smallest] > keys_[
r]) smallest =
r;
235 heap_[i] = heap_[smallest];
236 heap_[smallest] = tmp;
239 keys_[i] = keys_[smallest];
240 keys_[smallest] = ktmp;
void insert(Type elem, Key key)
Inserts an item with a key into the heap.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
AbaBHeap(int size)
A constructor.
std::ostream & operator<<(std::ostream &out, const Active< BaseType, CoType > &rhs)
Key getMinKey() const
Returns the key of the minimum element of the heap.
void clear()
Empties the heap.
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.
int father(int i) const
Returns the index of the father of element i.
int rightSon(int i) const
Returns the index of the right son of node i.
int leftSon(int i) const
Returns the index of the left son of node i.
Type getMin() const
Returns the minimum element of the heap.
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
void realloc(int newSize)
Changes the size of the heap.
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
int size() const
Returns the maximal number of elements which can be stored in the heap.
void check() const
Throws an exception if the heap properties are violated.
int number() const
Returns the number of elements in the heap.
Type extractMin()
Accesses and removes the minimum element from the heap.