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


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

Re: Heap Implementation

Started byCem Karan <cfkaran2@gmail.com>
First post2016-02-09 19:41 -0500
Last post2016-02-09 19:41 -0500
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: Heap Implementation Cem Karan <cfkaran2@gmail.com> - 2016-02-09 19:41 -0500

#102740 — Re: Heap Implementation

FromCem Karan <cfkaran2@gmail.com>
Date2016-02-09 19:41 -0500
SubjectRe: Heap Implementation
Message-ID<mailman.4.1455064888.7749.python-list@python.org>
On Feb 9, 2016, at 9:27 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:

> On 09/02/2016 11:44, Cem Karan wrote:
>> 
>> On Feb 9, 2016, at 4:40 AM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> 
>>> On 09/02/2016 04:25, Cem Karan wrote:
>>>> 
>>>> No problem, that's what I thought happened.  And you're right, I'm looking for a priority queue (not the only reason to use a heap, but a pretty important reason!)
>>>> 
>>> 
>>> I'm assuming I've missed the explanation, so what is the problem again with https://docs.python.org/3/library/queue.html#queue.PriorityQueue or even https://docs.python.org/3/library/asyncio-queue.html#asyncio.PriorityQueue ?
>> 
>> Efficiently changing the the priority of items already in the queue/deleting items in the queue (not the first item).  This comes up a LOT in event-based simulators where it's easier to tentatively add an event knowing that you might need to delete it or change it later.
>> 
>> Thanks,
>> Cem Karan
>> 
> 
> Thanks for that, but from the sounds of it sooner you than me :)

Eh, its not too bad once you figure out how to do it.  It's easier in C though; you can use pointer tricks that let you find the element in constant time, and then removal will involve figuring out how to fix up your heap after you've removed the element.

Thanks,
Cem Karan

[toc] | [standalone]


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


csiph-web