cgv
|
IndexHeap is a heap that allows changing of the elements. More...
#include <dynamic_priority_queue.h>
Classes | |
struct | extended_element |
store per element, whether it is empty and a link to the next empty element or to the heap location More... | |
Public Types | |
typedef T | element_type |
Public Member Functions | |
dynamic_priority_queue () | |
empty construction | |
void | clear () |
remove all elements | |
bool | empty () const |
check if heap is empty | |
size_t | size () const |
return the number of elements in the heap | |
size_t | size_of_element_container () const |
return the number of elements in the heap | |
queue interface | |
unsigned int | top () const |
return the top element | |
void | pop () |
remove top element | |
int | extract () |
extract top element | |
dynamic element access | |
bool | is_empty (unsigned int idx) const |
const element_type & | operator[] (unsigned int idx) const |
element_type & | operator[] (unsigned int idx) |
unsigned int | insert (const element_type &e) |
insert the given element and return its index in the element container | |
void | update (unsigned int idx) |
update after a change to the predicate | |
void | remove (unsigned int idx) |
remove element at location idx | |
Protected Member Functions | |
bool | valid (unsigned int hp) const |
check if a position is outside of range | |
void | updateLink (unsigned int hp) |
make sure that the link for hp is ok | |
bool | isBetter (unsigned int hp1, unsigned int hp2) const |
check if hp1 is less than hp2, if true, exchange elements | |
bool | exchangeIfBetter (unsigned int hp1, unsigned int hp2) |
check if hp1 is less than hp2, if true, exchange elements | |
void | heapify (unsigned int hp) |
void | move (unsigned int hp1, unsigned int hp2) |
move one element to another position, that should be empty | |
void | removeHeap (unsigned int hp) |
remove an element on a certain heap pos | |
void | positionDownward (unsigned int &hp) |
move an element downward to the correct position | |
bool | positionUpward (unsigned int &hp) |
move an element upward to the correct position | |
Protected Attributes | |
std::vector< extended_element > | elements |
container for elements | |
int | last_empty_element |
store index of last empty element or -1 if there is non | |
std::vector< unsigned int > | heap |
store indices to the elements on the heap | |
IndexHeap is a heap that allows changing of the elements.
Definition at line 9 of file dynamic_priority_queue.h.
typedef T cgv::data::dynamic_priority_queue< T >::element_type |
Definition at line 12 of file dynamic_priority_queue.h.
|
inline |
empty construction
Definition at line 90 of file dynamic_priority_queue.h.
|
inline |
remove all elements
Definition at line 92 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements, cgv::data::dynamic_priority_queue< T >::heap, and cgv::data::dynamic_priority_queue< T >::last_empty_element.
|
inline |
check if heap is empty
Definition at line 94 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap.
|
inlineprotected |
check if hp1 is less than hp2, if true, exchange elements
Definition at line 36 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap, cgv::data::dynamic_priority_queue< T >::isBetter(), and cgv::data::dynamic_priority_queue< T >::updateLink().
Referenced by cgv::data::dynamic_priority_queue< T >::positionDownward(), and cgv::data::dynamic_priority_queue< T >::positionUpward().
|
inline |
extract top element
Definition at line 107 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::pop(), and cgv::data::dynamic_priority_queue< T >::top().
|
inlineprotected |
Definition at line 47 of file dynamic_priority_queue.h.
|
inline |
insert the given element and return its index in the element container
Definition at line 123 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements, cgv::data::dynamic_priority_queue< T >::heap, cgv::data::dynamic_priority_queue< T >::last_empty_element, cgv::data::dynamic_priority_queue< T >::positionUpward(), and cgv::data::dynamic_priority_queue< T >::updateLink().
|
inline |
Definition at line 118 of file dynamic_priority_queue.h.
|
inlineprotected |
check if hp1 is less than hp2, if true, exchange elements
Definition at line 32 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements, and cgv::data::dynamic_priority_queue< T >::heap.
Referenced by cgv::data::dynamic_priority_queue< T >::exchangeIfBetter(), and cgv::data::dynamic_priority_queue< T >::positionDownward().
|
inlineprotected |
move one element to another position, that should be empty
Definition at line 49 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap, and cgv::data::dynamic_priority_queue< T >::updateLink().
Referenced by cgv::data::dynamic_priority_queue< T >::removeHeap().
|
inline |
Definition at line 121 of file dynamic_priority_queue.h.
|
inline |
Definition at line 120 of file dynamic_priority_queue.h.
|
inline |
remove top element
Definition at line 105 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::remove(), and cgv::data::dynamic_priority_queue< T >::top().
Referenced by cgv::data::dynamic_priority_queue< T >::extract().
|
inlineprotected |
move an element downward to the correct position
Definition at line 66 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::exchangeIfBetter(), cgv::data::dynamic_priority_queue< T >::isBetter(), and cgv::data::dynamic_priority_queue< T >::valid().
|
inlineprotected |
move an element upward to the correct position
Definition at line 77 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::exchangeIfBetter().
Referenced by cgv::data::dynamic_priority_queue< T >::insert().
|
inline |
remove element at location idx
Definition at line 154 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements, cgv::data::dynamic_priority_queue< T >::last_empty_element, and cgv::data::dynamic_priority_queue< T >::removeHeap().
Referenced by cgv::data::dynamic_priority_queue< T >::pop().
|
inlineprotected |
remove an element on a certain heap pos
Definition at line 55 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap, and cgv::data::dynamic_priority_queue< T >::move().
Referenced by cgv::data::dynamic_priority_queue< T >::remove().
|
inline |
return the number of elements in the heap
Definition at line 96 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap.
|
inline |
return the number of elements in the heap
Definition at line 98 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements.
|
inline |
return the top element
Definition at line 103 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap.
Referenced by cgv::data::dynamic_priority_queue< T >::extract(), and cgv::data::dynamic_priority_queue< T >::pop().
|
inline |
update after a change to the predicate
Definition at line 148 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements.
|
inlineprotected |
make sure that the link for hp is ok
Definition at line 30 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::elements, and cgv::data::dynamic_priority_queue< T >::heap.
Referenced by cgv::data::dynamic_priority_queue< T >::exchangeIfBetter(), cgv::data::dynamic_priority_queue< T >::insert(), and cgv::data::dynamic_priority_queue< T >::move().
|
inlineprotected |
check if a position is outside of range
Definition at line 28 of file dynamic_priority_queue.h.
References cgv::data::dynamic_priority_queue< T >::heap.
Referenced by cgv::data::dynamic_priority_queue< T >::positionDownward().
|
protected |
container for elements
Definition at line 22 of file dynamic_priority_queue.h.
Referenced by cgv::data::dynamic_priority_queue< T >::clear(), cgv::data::dynamic_priority_queue< T >::insert(), cgv::data::dynamic_priority_queue< T >::isBetter(), cgv::data::dynamic_priority_queue< T >::remove(), cgv::data::dynamic_priority_queue< T >::size_of_element_container(), cgv::data::dynamic_priority_queue< T >::update(), and cgv::data::dynamic_priority_queue< T >::updateLink().
|
protected |
store indices to the elements on the heap
Definition at line 26 of file dynamic_priority_queue.h.
Referenced by cgv::data::dynamic_priority_queue< T >::clear(), cgv::data::dynamic_priority_queue< T >::empty(), cgv::data::dynamic_priority_queue< T >::exchangeIfBetter(), cgv::data::dynamic_priority_queue< T >::insert(), cgv::data::dynamic_priority_queue< T >::isBetter(), cgv::data::dynamic_priority_queue< T >::move(), cgv::data::dynamic_priority_queue< T >::removeHeap(), cgv::data::dynamic_priority_queue< T >::size(), cgv::data::dynamic_priority_queue< T >::top(), cgv::data::dynamic_priority_queue< T >::updateLink(), and cgv::data::dynamic_priority_queue< T >::valid().
|
protected |
store index of last empty element or -1 if there is non
Definition at line 24 of file dynamic_priority_queue.h.
Referenced by cgv::data::dynamic_priority_queue< T >::clear(), cgv::data::dynamic_priority_queue< T >::insert(), and cgv::data::dynamic_priority_queue< T >::remove().