12 typedef T element_type;
19 unsigned int link : 31;
26 std::vector<unsigned int>
heap;
28 bool valid(
unsigned int hp)
const {
return hp <
heap.size(); }
32 bool isBetter(
unsigned int hp1,
unsigned int hp2)
const {
49 void move(
unsigned int hp1,
unsigned int hp2)
57 if (hp !=
heap.size()-1) {
58 move((
unsigned int)
heap.size()-1,hp);
69 while (
valid(child = 2*hp+1)) {
70 unsigned int tmp = child+1;
81 unsigned int pa = (hp-1)/2;
102 unsigned int top()
const {
return heap[0]; }
109 unsigned int tmp =
top();
117 bool is_empty(
unsigned int idx)
const {
return elements[idx].is_empty; }
120 const element_type& operator [] (
unsigned int idx)
const {
return elements[idx].element; }
121 element_type& operator [] (
unsigned int idx) {
return elements[idx].element; }
123 unsigned int insert(
const element_type& e)
134 idx = (
unsigned int)
elements.size();
140 unsigned int hp = (
unsigned int)
heap.size();
size_t size() const
return the number of elements in the heap
Definition: dynamic_priority_queue.h:96
std::vector< extended_element > elements
container for elements
Definition: dynamic_priority_queue.h:22
bool exchangeIfBetter(unsigned int hp1, unsigned int hp2)
check if hp1 is less than hp2, if true, exchange elements
Definition: dynamic_priority_queue.h:36
std::vector< unsigned int > heap
store indices to the elements on the heap
Definition: dynamic_priority_queue.h:26
int last_empty_element
store index of last empty element or -1 if there is non
Definition: dynamic_priority_queue.h:24
bool empty() const
check if heap is empty
Definition: dynamic_priority_queue.h:94
void pop()
remove top element
Definition: dynamic_priority_queue.h:105
bool positionUpward(unsigned int &hp)
move an element upward to the correct position
Definition: dynamic_priority_queue.h:77
void update(unsigned int idx)
update after a change to the predicate
Definition: dynamic_priority_queue.h:148
bool valid(unsigned int hp) const
check if a position is outside of range
Definition: dynamic_priority_queue.h:28
Definition: dynamic_priority_queue.h:10
void remove(unsigned int idx)
remove element at location idx
Definition: dynamic_priority_queue.h:154
size_t size_of_element_container() const
return the number of elements in the heap
Definition: dynamic_priority_queue.h:98
void clear()
remove all elements
Definition: dynamic_priority_queue.h:92
int extract()
extract top element
Definition: dynamic_priority_queue.h:107
void move(unsigned int hp1, unsigned int hp2)
move one element to another position, that should be empty
Definition: dynamic_priority_queue.h:49
void positionDownward(unsigned int &hp)
move an element downward to the correct position
Definition: dynamic_priority_queue.h:66
void updateLink(unsigned int hp)
make sure that the link for hp is ok
Definition: dynamic_priority_queue.h:30
dynamic_priority_queue()
empty construction
Definition: dynamic_priority_queue.h:90
unsigned int insert(const element_type &e)
insert the given element and return its index in the element container
Definition: dynamic_priority_queue.h:123
store per element, whether it is empty and a link to the next empty element or to the heap location
Definition: dynamic_priority_queue.h:16
bool isBetter(unsigned int hp1, unsigned int hp2) const
check if hp1 is less than hp2, if true, exchange elements
Definition: dynamic_priority_queue.h:32
the cgv namespace
Definition: vr_calib.cxx:9
void removeHeap(unsigned int hp)
remove an element on a certain heap pos
Definition: dynamic_priority_queue.h:55
unsigned int top() const
return the top element
Definition: dynamic_priority_queue.h:103