Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

bheap.h
Go to the documentation of this file.
1 
29 #pragma once
30 
31 #include <ogdf/basic/ArrayBuffer.h>
33 
34 
35 #pragma GCC visibility push(default)
36 namespace abacus {
37 
38 template<class Type, class Key>
39 class AbaBHeap;
40 
41 template<class Type,class Key>
42 std::ostream&operator<< (std::ostream& out, const AbaBHeap<Type, Key>& heap);
43 
44 
46 
73 template<class Type, class Key> class AbaBHeap : public AbacusRoot {
74 public:
75 
77 
80  explicit AbaBHeap(int size);
81 
83 
91  AbaBHeap(
92  const ArrayBuffer<Type> &elems,
93  const ArrayBuffer<Key> &keys);
94 
96 
104  friend std::ostream& operator<< <> (std::ostream &out, const AbaBHeap<Type, Key> &heap);
105 
107 
114  void insert(Type elem, Key key);
115 
117 
122  Type getMin() const;
123 
125 
130  Key getMinKey() const;
131 
133 
144  Type extractMin();
145 
146 
148  void clear();
149 
151  int size() const;
152 
154  int number() const;
155 
157  bool empty() const;
158 
160 
163  void realloc(int newSize);
164 
166 
169  void check() const;
170 
171 private:
172 
174  int leftSon(int i) const;
175 
177  int rightSon(int i) const;
178 
180  int father(int i) const;
181 
183 
188  void heapify(int i);
189 
192  int n_;
193 };
194 
195 }
196 
197 #include <ogdf/lib/abacus/bheap.inc>
198 #pragma GCC visibility pop
ogdf::ArrayBuffer
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition: Array.h:53
ArrayBuffer.h
Declaration and implementation of ArrayBuffer class.
abacus::AbaBHeap::insert
void insert(Type elem, Key key)
Inserts an item with a key into the heap.
abacus::AbaBHeap::AbaBHeap
AbaBHeap(int size)
A constructor.
abacus::AbaBHeap
Binary heaps.
Definition: bheap.h:39
abacus::operator<<
std::ostream & operator<<(std::ostream &out, const Active< BaseType, CoType > &rhs)
abacusroot.h
abacus::AbaBHeap::heap_
Array< Type > heap_
Definition: bheap.h:190
abacus::AbaBHeap::getMinKey
Key getMinKey() const
Returns the key of the minimum element of the heap.
abacus
Definition: ILPClusterPlanarity.h:50
abacus::AbaBHeap::n_
int n_
Definition: bheap.h:192
abacus::AbaBHeap::clear
void clear()
Empties the heap.
abacus::AbaBHeap::heapify
void heapify(int i)
Is the central function to maintain the heap property.
abacus::AbaBHeap::empty
bool empty() const
Return true if there are no elements in the heap, false otherwise.
abacus::AbaBHeap::father
int father(int i) const
Returns the index of the father of element i.
abacus::AbaBHeap::rightSon
int rightSon(int i) const
Returns the index of the right son of node i.
abacus::AbaBHeap::leftSon
int leftSon(int i) const
Returns the index of the left son of node i.
abacus::AbaBHeap::getMin
Type getMin() const
Returns the minimum element of the heap.
abacus::AbacusRoot
Base class of all other classes of ABACUS.
Definition: abacusroot.h:69
ogdf::Array
The parameterized class Array implements dynamic arrays of type E.
Definition: Array.h:219
abacus::AbaBHeap::keys_
Array< Key > keys_
Definition: bheap.h:191
abacus::AbaBHeap::realloc
void realloc(int newSize)
Changes the size of the heap.
abacus::AbaBHeap::size
int size() const
Returns the maximal number of elements which can be stored in the heap.
abacus::AbaBHeap::check
void check() const
Throws an exception if the heap properties are violated.
abacus::AbaBHeap::number
int number() const
Returns the number of elements in the heap.
abacus::AbaBHeap::extractMin
Type extractMin()
Accesses and removes the minimum element from the heap.
bheap.inc