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


Groups > comp.lang.python > #101372 > unrolled thread

How to remove item from heap efficiently?

Started by"Sven R. Kunze" <srkunze@mail.de>
First post2016-01-07 23:52 +0100
Last post2016-01-07 23:52 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  How to remove item from heap efficiently? "Sven R. Kunze" <srkunze@mail.de> - 2016-01-07 23:52 +0100

#101372 — How to remove item from heap efficiently?

From"Sven R. Kunze" <srkunze@mail.de>
Date2016-01-07 23:52 +0100
SubjectHow to remove item from heap efficiently?
Message-ID<mailman.66.1452258649.2305.python-list@python.org>
Hi everybody,

suppose, I need items sorted by two criteria (say timestamp and 
priority). For that purpose, I use two heaps (heapq module):

heapA # items sorted by timestamp
heapB # items sorted by priority

Now my actual problem. When popping an item of heapA (that's the oldest 
item), I need to remove the very same item from heapB, regardlessly 
where it is in heapB. And vice versa.

Is there a datastructure or a simple trick to achieve that in an 
efficient matter?

Best,
Sven

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web