views:

609

answers:

3

I have a priority queue of events, but sometimes the event priorities change, so I'd like to maintain iterators from the event requesters into the heap. If the priority changes, I'd like the heap to be adjusted in log(n) time. I will always have exactly one iterator pointing to each element in the heap.

+1  A: 

That sounds like you need more indirection. Store pointer to the events in the priority queue instead. When priority of some element of the queue changes, remove it and reinsert.

wilx
+4  A: 

Take a look at Boost's mutable heaps.

Ferruccio
Thanks, if I end up having to roll my own, I'll use that snippet to start.
Neil G
ended up going with this solution
Neil G
A: 

A warning here is that you end up with unstable event sorting, i.e. ordering of the events with the same priority is undefined (read 'they will be reordered'.)

Nikolai N Fetissov
You can remove an arbitrary element from a heap in log(n) time.
Neil G
Yes, you're right, was thinking about something else :)
Nikolai N Fetissov
no problem :)
Neil G