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


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

Re: How to remove item from heap efficiently?

Started bysrinivas devaki <mr.eightnoteight@gmail.com>
First post2016-01-08 18:51 +0530
Last post2016-01-08 18:51 +0530
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to remove item from heap efficiently? srinivas devaki <mr.eightnoteight@gmail.com> - 2016-01-08 18:51 +0530

#101374 — Re: How to remove item from heap efficiently?

Fromsrinivas devaki <mr.eightnoteight@gmail.com>
Date2016-01-08 18:51 +0530
SubjectRe: How to remove item from heap efficiently?
Message-ID<mailman.67.1452259339.2305.python-list@python.org>
You can create a single heap with primary key as timestamp and
secondary key as priority, i.e by creating a tuple
insert the elements into the heap as
(timestamp, priority)


If there is any underlying meaning for creating 2 heaps. please mention.


On Fri, Jan 8, 2016 at 4:22 AM, Sven R. Kunze <srkunze@mail.de> wrote:
> 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
> --
> https://mail.python.org/mailman/listinfo/python-list

[toc] | [standalone]


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


csiph-web