/** * Removes the item with maximum priority from the queue, and * returns it with its priority. */ std::pair<T, Priority> pop() { assert(!empty()); heap_element top = heap[1]; swap(1, size()); heap.pop_back(); heapify(1); index_map.erase(top.first); return top; }
//! Remove an item from the queue bool remove(T item) { // Ensure that the element is in the queue typename index_map_type::iterator iter = index_map.find(item); // only if the element is present in the first place do we need // remove it if(iter != index_map.end()) { size_t i = iter->second; swap(i, size()); heap.pop_back(); heapify(i); // erase the element from the index map index_map.erase(iter); return true; } return false; }