How to remove item from heap efficiently?

Paul Rubin no.email at nospam.invalid
Sat Jan 9 13:32:32 EST 2016


"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).

You could look up "timing wheels" for a simpler practical approach that
the Linux kernel scheduler used to use (I think it changed a few years
ago).



More information about the Python-list mailing list