Hey Ole,

since we have a similar issues (you with Timeouts, me with TimerTasks), I
would like to go more in deep, if you don't mind.
Below my point.

> Such a structure is quite useful, and I wonder why it has never
> become part of the library. I will most definitely have a look
> at it when you commit it, but I am afraid that it is hard to
> get around the problem that prohibited me from factoring out the
> priority queue into a seperate class in the first place:
> To remove an arbitrary node from the queue in time O(log(n))
> you have to know the position of the node in the heap tree, and
> since the heap is shuffled on inserts and removals, information
> in the node will have to be shuffled along with it. For this I
> have a field in the node that contains the node index in the
> queue array. Whenever the heap is shuffled, I update this field
> to keep it current. Without this field and the cooperation of
> the priority queue to keep it updated, I would have to do a linear
> search to find the index of the node.

Well, I had the same problem; I solved it just marking the node as CANCELED;
the time does the rest (ie when it comes the time for it to be executed, I
see that it is canceled and I remove it from the top of the heap - very
cheap).
If I have well unserstood, you cannot do anything with a Timeout but
cancel() it. You cannot re-queue it. So there is no issue on removing
immediately the timeout, it can be done later. Am I missing something ?

Bests,

Simon

Reply via email to