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;
109 unsigned int tmp =
top();
118 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();
IndexHeap is a heap that allows changing of the elements.
int extract()
extract top element
void remove(unsigned int idx)
remove element at location idx
unsigned int top() const
return the top element
unsigned int insert(const element_type &e)
insert the given element and return its index in the element container
void clear()
remove all elements
dynamic_priority_queue()
empty construction
std::vector< extended_element > elements
container for elements
void update(unsigned int idx)
update after a change to the predicate
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
bool exchangeIfBetter(unsigned int hp1, unsigned int hp2)
check if hp1 is less than hp2, if true, exchange elements
void move(unsigned int hp1, unsigned int hp2)
move one element to another position, that should be empty
void updateLink(unsigned int hp)
make sure that the link for hp is ok
void positionDownward(unsigned int &hp)
move an element downward to the correct position
void removeHeap(unsigned int hp)
remove an element on a certain heap pos
bool empty() const
check if heap is empty
bool positionUpward(unsigned int &hp)
move an element upward to the correct position
size_t size() const
return the number of elements in the heap
bool isBetter(unsigned int hp1, unsigned int hp2) const
check if hp1 is less than hp2, if true, exchange elements
size_t size_of_element_container() const
return the number of elements in the heap
bool valid(unsigned int hp) const
check if a position is outside of range
void pop()
remove top element
store per element, whether it is empty and a link to the next empty element or to the heap location