Remove an element from the middle of an std::heap

后端 未结 6 2133
离开以前
离开以前 2021-02-07 05:17

I\'m using a priority queue as a scheduler with one extra requirement. I need to be able to cancel scheduled items. This equates to removing an item from the middle of the pri

6条回答
  •  别跟我提以往
    2021-02-07 05:55

    It seems to me that removing from the middle of a heap might mean the entire heap has to be rebuilt: The reason there's no repair_heap is because it would have to do the same (big-oh) work as make_heap.

    Are you able to do something like put std::pair in the heap and just invalidate items instead of removing them? Then when they finally get to the top just ignore the item and move along.

提交回复
热议问题