Re: heapq question

2008-07-13 Thread Giampaolo Rodola'
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

Re: heapq question

2008-07-13 Thread Miles
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

Re: heapq question

2008-07-13 Thread Miles
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

Re: heapq question

2008-07-13 Thread Duncan Booth
"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()

Re: heapq question

2008-07-13 Thread Giampaolo Rodola'
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

Re: heapq question

2008-07-13 Thread Martin v. Löwis
> 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

Re: heapq question

2008-07-13 Thread Giampaolo Rodola'
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. > >

Re: heapq question

2008-07-13 Thread Duncan Booth
"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

Re: heapq question

2008-07-12 Thread bearophileHUGS
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

Re: heapq question

2008-07-12 Thread Giampaolo Rodola'
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 * >

Re: heapq question

2008-07-12 Thread Duncan Booth
"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] #