Heap Implementation

Sven R. Kunze srkunze at mail.de
Wed Feb 10 13:23:01 EST 2016


Hi Cem,

On 08.02.2016 02:37, Cem Karan wrote:
> My apologies for not writing sooner, but work has been quite busy lately (and likely will be for some time to come).

no problem here. :)

> I read your approach, and it looks pretty good, but there may be one issue with it; how do you handle the same item being pushed into the heap more than once?  In my simple simulator, I'll push the same object into my event queue multiple times in a row.  The priority is the moment in the future when the object will be called.  As a result, items don't have unique priorities.  I know that there are methods of handling this from the client-side (tuples with unique counters come to mind), but if your library can handle it directly, then that could be useful to others as well.

I've pondered about that in the early design phase. I considered it a 
slowdown for my use-case without benefit.

Why? Because I always push a fresh object ALTHOUGH it might be equal 
comparing attributes (priority, deadline, etc.).


That's the reason why I need to ask again: why pushing the same item on 
a heap?


Are we talking about function objects? If so, then your concern is 
valid. Would you accept a solution that would involve wrapping the 
function in another object carrying the priority? Would you prefer a 
wrapper that's defined by xheap itself so you can just use it?


Best,
Sven


More information about the Python-list mailing list