How to remove item from heap efficiently?

Sven R. Kunze srkunze at mail.de
Sun Jan 10 13:50:18 EST 2016


On 09.01.2016 19:32, Paul Rubin wrote:
> "Sven R. Kunze" <srkunze at mail.de> writes:
>> Basically a task scheduler where tasks can be thrown away once they
>> are too long in the queue.
> I don't think there's a real nice way to do this with heapq.  The
> computer-sciencey way would involve separate balanced tree structures
> for the two sorting keys (think of a database table with indexes on two
> different columns).

Others suggested using an additional dict where to store the indexes of 
the items. Then, when removing an item, I just need to query the dict.

Best,
Sven



More information about the Python-list mailing list