Re: which data structure to use?

2014-01-22 Thread Robert Voigtländer
> Unlikely. Are you sure that .heap and .lookup contents are still in sync > with your modification? No it's not. Atfer having read about heapq it's clear why. Thanks for the hint. > allows you to delete random nodes, but the lowest() method will slow down as > it has to iterate over all dict v

Re: which data structure to use?

2014-01-21 Thread Peter Otten
Robert Voigtländer wrote: > >> > > def pop(self): >> > > f, node = heapq.heappop() >> > > del lookup[node.pos] >> > > return node > >> > That should be >> >> > def pop(self): >> >> > f, node = heapq.heappop(self.heap) >> > del self.lookup[node.po

Re: which data structure to use?

2014-01-21 Thread Mark Lawrence
On 21/01/2014 13:43, Robert Voigtländer wrote: [double spaced google disease snipped] I'm pleased to see the regular contributors helping out as usual. In response would you please be kind enough to read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
> > > def pop(self): > > > f, node = heapq.heappop() > > > del lookup[node.pos] > > > return node > > That should be > > > def pop(self): > > > f, node = heapq.heappop(self.heap) > > del self.lookup[node.pos] > > return node > > Hi Peter,

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
Am Dienstag, 21. Januar 2014 15:19:54 UTC+1 schrieb Peter Otten: > Peter Otten wrote: > > > > > def pop(self): > > > f, node = heapq.heappop() > > > del lookup[node.pos] > > > return node > > > > That should be > > > > def pop(self): > > f, node

Re: which data structure to use?

2014-01-21 Thread Peter Otten
Peter Otten wrote: > def pop(self): > f, node = heapq.heappop() > del lookup[node.pos] > return node That should be def pop(self): f, node = heapq.heappop(self.heap) del self.lookup[node.pos] return node -- https://mail.python.org/mailma

Re: which data structure to use?

2014-01-21 Thread Peter Otten
Robert Voigtländer wrote: > >> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: >> > >> > I have objects like this: >> >> > >> >> > class Node(object): >> >> > def __init__(self, pos, parent, g , h): >> >> > self.pos = pos >> >> > self.parent = par

Re: which data structure to use?

2014-01-21 Thread Oscar Benjamin
On Tue, Jan 21, 2014 at 05:38:34AM -0800, Robert Voigtländer wrote: > > > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: > > > > > > I have objects like this: > > > > > > > > > > class Node(object): > > > > > def __init__(self, pos, parent, g , h): > > > > >

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
Am Dienstag, 21. Januar 2014 14:38:34 UTC+1 schrieb Robert Voigtländer: > > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: > > > > > > > > > I have objects like this: > > > > > > > > > > > > > > class Node(object): > > > > > > > def __init__(self, pos, par

Re: which data structure to use?

2014-01-21 Thread Robert Voigtländer
> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl�nder wrote: > > > I have objects like this: > > > > > > class Node(object): > > > def __init__(self, pos, parent, g , h): > > > self.pos = pos > > > self.parent = parent > > > self.g = g > > >

Re: which data structure to use?

2014-01-21 Thread Oscar Benjamin
On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtländer wrote: > Hi, > > which would be the best data structure to use for the following case? > > I have objects like this: > > class Node(object): > def __init__(self, pos, parent, g , h): > self.pos = pos > self.paren

Re: which data structure to use?

2014-01-21 Thread Ben Finney
Robert Voigtländer writes: > which would be the best data structure to use for the following case? First up, I want to compliment you on asking exactly the right question. Getting the data structure right or wrong can often shape the solution dramatically. > I have objects like this: > > class

Re: which data structure to use?

2014-01-21 Thread Chris Angelico
On Tue, Jan 21, 2014 at 10:17 PM, Robert Voigtländer wrote: > 1. check if a specific item - identified by Node.pos - is in the list. > 2. find the object with the lowest Node.f attribute and update or remove it Are both those values constant once the Node is added? If so, the easiest way would be

which data structure to use?

2014-01-21 Thread Robert Voigtländer
Hi, which would be the best data structure to use for the following case? I have objects like this: class Node(object): def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h I need to bu