Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

bheap.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <ogdf/basic/ArrayBuffer.h>
33 
34 
35 namespace abacus {
36 
37 template<class Type, class Key>
38 class AbaBHeap;
39 
40 template<class Type,class Key>
41 std::ostream&operator<< (std::ostream& out, const AbaBHeap<Type, Key>& heap);
42 
43 
45 
72 template<class Type, class Key> class AbaBHeap : public AbacusRoot {
73 public:
74 
76 
79  explicit AbaBHeap(int size);
80 
82 
90  AbaBHeap(
91  const ArrayBuffer<Type> &elems,
92  const ArrayBuffer<Key> &keys);
93 
95 
103  friend std::ostream& operator<< <> (std::ostream &out, const AbaBHeap<Type, Key> &heap);
104 
106 
113  void insert(Type elem, Key key);
114 
116 
121  Type getMin() const;
122 
124 
129  Key getMinKey() const;
130 
132 
143  Type extractMin();
144 
145 
147  void clear();
148 
150  int size() const;
151 
153  int number() const;
154 
156  bool empty() const;
157 
159 
162  void realloc(int newSize);
163 
165 
168  void check() const;
169 
170 private:
171 
173  int leftSon(int i) const;
174 
176  int rightSon(int i) const;
177 
179  int father(int i) const;
180 
182 
187  void heapify(int i);
188 
191  int n_;
192 };
193 
194 }
195 
196 #include <ogdf/lib/abacus/bheap.inc>
void heapify(int i)
Is the central function to maintain the heap property.
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:200
Base class of all other classes of ABACUS.
Definition: abacusroot.h:68
Declaration and implementation of ArrayBuffer class.
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.
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:45
Array< Type > heap_
Definition: bheap.h:189
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.
int number() const
Returns the number of elements in the heap.
void insert(Type elem, Key key)
Inserts an item with a key into the heap.
Array< Key > keys_
Definition: bheap.h:190
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.
Binary heaps.
Definition: bheap.h:38
AbaBHeap(int size)
A constructor.