Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102768

Re: Heap Implementation

From "Sven R. Kunze" <srkunze@mail.de>
Newsgroups comp.lang.python
Subject Re: Heap Implementation
Date 2016-02-10 19:23 +0100
Message-ID <mailman.17.1455128587.22075.python-list@python.org> (permalink)
References <56AD3D83.2050308@mail.de> <7C522D08-9D73-48D2-A71D-F1D1D34C02A5@gmail.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Heap Implementation "Sven R. Kunze" <srkunze@mail.de> - 2016-02-10 19:23 +0100

csiph-web