On 13 Lug, 22:35, Miles <[EMAIL PROTECTED]> wrote:
> On Sun, Jul 13, 2008 at 3:05 PM, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote:
> > On 13 Lug, 19:31, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> >> > I understand that heapq is not that efficient to implement timeouts as
> >> > I thought at fir
On Sun, Jul 13, 2008 at 4:16 PM, Duncan Booth
<[EMAIL PROTECTED]> wrote:
> "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
>> I understand that heapq is not that efficient to implement timeouts as
>> I thought at first.
>> It would have been perfect if there were functions to remove arbitrary
>> ele
On Sun, Jul 13, 2008 at 3:05 PM, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote:
> On 13 Lug, 19:31, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>> > I understand that heapq is not that efficient to implement timeouts as
>> > I thought at first.
>> > It would have been perfect if there were functions
"Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
> Thanks, that's what I wanted to know.
> I understand that heapq is not that efficient to implement timeouts as
> I thought at first.
> It would have been perfect if there were functions to remove arbitrary
> elements withouth needing to re-heapify()
On 13 Lug, 19:31, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > I understand that heapq is not that efficient to implement timeouts as
> > I thought at first.
> > It would have been perfect if there were functions to remove arbitrary
> > elements withouth needing to re-heapify() the heap every t
> I understand that heapq is not that efficient to implement timeouts as
> I thought at first.
> It would have been perfect if there were functions to remove arbitrary
> elements withouth needing to re-heapify() the heap every time.
It is efficient for that - you just need to use it correctly.
To
On 13 Lug, 11:35, Duncan Booth <[EMAIL PROTECTED]> wrote:
> "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
> > Having said that I'd like to understand if there are cases where
> > deleting or moving an element of the heap, causes heappop() to return
> > an element which is not the smallest one.
>
>
"Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
> Having said that I'd like to understand if there are cases where
> deleting or moving an element of the heap, causes heappop() to return
> an element which is not the smallest one.
Yes, of course there are: any time you delete element 0 of the heap
Giampaolo Rodola':
> Even if I avoid to re-heapify() it seems that the first element
> returned by heappop() is always the smaller one.
Yes, the heappop() function keeps the heap invariant, so it will keep
giving you the smallest item.
> I'd like to understand if there are cases where
> deleting
On 12 Lug, 20:15, Duncan Booth <[EMAIL PROTECTED]> wrote:
> "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
>
> > My question is the following: is it safe to avoid to re-heapify() a
> > heap when I remove or move an element which is not the first one?
> > Example:
>
> from heapq import *
>
"Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote:
>
> My question is the following: is it safe to avoid to re-heapify() a
> heap when I remove or move an element which is not the first one?
> Example:
>
from heapq import *
heap = [2,4,6,7,1,2,3]
heapify(heap)
del heap[4]
#
11 matches
Mail list logo