Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

bprioqueue.inc
Go to the documentation of this file.
1 
29 #pragma once
30 
31 namespace abacus {
32 
33 
34 template<class Type, class Key>
35 AbaPrioQueue<Type, Key>::AbaPrioQueue(int size) : heap_(size)
36 { }
37 
38 
39 template<class Type, class Key>
40 void AbaPrioQueue<Type, Key>::insert(Type elem, Key key)
41 {
42  heap_.insert(elem, key);
43 }
44 
45 
46 template<class Type, class Key>
47 int AbaPrioQueue<Type, Key>::getMin(Type &min) const
48 {
50  if (heap_.empty()) return 1;
51 
52  min = heap_.getMin();
53  return 0;
54 }
55 
56 
57 template<class Type, class Key>
58 int AbaPrioQueue<Type, Key>::getMinKey(Key &minKey) const
59 {
61  if (heap_.empty()) return 1;
62 
63  minKey = heap_.getMinKey();
64  return 0;
65 }
66 
67 
68 template<class Type, class Key>
70 {
72  if (heap_.empty()) return 1;
73 
74  min = heap_.extractMin();
75  return 0;
76 }
77 
78 
79 template<class Type, class Key>
81 {
82  heap_.clear();
83 }
84 
85 
86 template<class Type, class Key>
87 inline int AbaPrioQueue<Type, Key>::size() const
88 {
89  return heap_.size();
90 }
91 
92 
93 template<class Type, class Key>
94 inline int AbaPrioQueue<Type, Key>::number() const
95 {
96  return heap_.number();
97 }
98 
99 
100 template<class Type, class Key>
101 void AbaPrioQueue<Type, Key>::realloc(int newSize)
102 {
103  if (newSize < size()) {
104  Logger::ifout() << "AbaPrioQueue::realloc : priority queue cannot be decreased\n";
105  OGDF_THROW_PARAM(AlgorithmFailureException, ogdf::AlgorithmFailureCode::BPrioQueue);
106  }
107 
108  heap_.realloc(newSize);
109 }
110 
111 }
int number() const
Returns the number of elements stored in the priority queue.
int getMin(Type &min) const
Retrieves the element with minimal key from the priority queue.
int extractMin(Type &min)
Retrieves and removes the minimal element from the priority queue.
AbaPrioQueue(int size)
The constructor of an empty priority queue.
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:194
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition: exceptions.h:55
AbaBHeap< Type, Key > heap_
The heap implementing the priority queue.
Definition: bprioqueue.h:122
int size() const
Returns the maximal number of elements which can be stored in the priority queue. ...
void clear()
Makes the priority queue empty.
int getMinKey(Key &minKey) const
Retrieves the key of the minimal element in the priority queue.
void insert(Type elem, Key key)
Inserts an element in the priority queue.
void realloc(int newSize)
Increases the size of the priority queue.