Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101402
| From | "Sven R. Kunze" <srkunze@mail.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: How to remove item from heap efficiently? |
| Date | 2016-01-08 17:45 +0100 |
| Message-ID | <mailman.84.1452351069.2305.python-list@python.org> (permalink) |
| References | <568EEC40.7070807@mail.de> <CACs7g=Bjccja67M3t4yL+07vO8iAcOB-dF5p2PgqqBwjFmbh=w@mail.gmail.com> |
Thanks for your suggestion. On 08.01.2016 14:21, srinivas devaki wrote: > 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) I think I cannot use that because I need the list sorted by both criteria. > If there is any underlying meaning for creating 2 heaps. please mention. I use two heaps because I need to insert arbitrary items fast and remove the ones fast which are too old (timestamp) or are next in order (priority). Basically a task scheduler where tasks can be thrown away once they are too long in the queue. > 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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: How to remove item from heap efficiently? "Sven R. Kunze" <srkunze@mail.de> - 2016-01-08 17:45 +0100
Re: How to remove item from heap efficiently? Paul Rubin <no.email@nospam.invalid> - 2016-01-09 10:32 -0800
Re: How to remove item from heap efficiently? "Sven R. Kunze" <srkunze@mail.de> - 2016-01-10 19:50 +0100
Re: How to remove item from heap efficiently? srinivas devaki <mr.eightnoteight@gmail.com> - 2016-01-12 08:38 +0530
Re: How to remove item from heap efficiently? Paul Rubin <no.email@nospam.invalid> - 2016-01-11 19:16 -0800
csiph-web