#pragma once #include namespace cgv { namespace data { /** IndexHeap is a heap that allows changing of the elements */ template class dynamic_priority_queue { public: typedef T element_type; protected: /// store per element, whether it is empty and a link to the next empty element or to the heap location struct extended_element { element_type element; bool is_empty : 1; unsigned int link : 31; }; /// container for elements std::vector elements; /// store index of last empty element or -1 if there is non int last_empty_element; /// store indices to the elements on the heap std::vector heap; /// check if a position is outside of range bool valid(unsigned int hp) const { return hp < heap.size(); } /// make sure that the link for hp is ok void updateLink(unsigned int hp) { elements[heap[hp]].link = hp; } /// check if hp1 is less than hp2, if true, exchange elements bool isBetter(unsigned int hp1, unsigned int hp2) const { return elements[heap[hp1]].element