 |
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
31 #pragma GCC visibility push(default)
35 template<
class Type,
class Key>
44 template<
class Type,
class Key>
46 const ArrayBuffer<Type> &elems,
47 const ArrayBuffer<Key> &keys)
53 for (
int i =
father(
n_-1); i>=0; --i)
58 template<
class Type,
class Key>
59 std::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] <<
") ";
68 template<
class Type,
class Key>
85 while (i > 0 && keys_[f] > key) {
97 template<
class Type,
class Key>
110 template<
class Type,
class Key>
123 template<
class Type,
class Key>
131 heap_[0] = heap_[n_];
132 keys_[0] = keys_[n_];
140 template<
class Type,
class Key>
147 template<
class Type,
class Key>
154 template <
class Type,
class Key>
161 template<
class Type,
class Key>
164 if(n_ == 0)
return true;
169 template<
class Type,
class Key>
172 heap_.realloc(newSize);
173 keys_.realloc(newSize);
177 template<
class Type,
class Key>
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";
188 template <
class Type,
class Key>
195 template <
class Type,
class Key>
202 template <
class Type,
class Key>
209 template <
class Type,
class Key>
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
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.