For Programmers: Free Programming Magazines  


Home > Archive > Ruby > August 2005 > Re: [ANN] Priority Queue 0.0.0.0. ... .0









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [ANN] Priority Queue 0.0.0.0. ... .0
Brian Schröder

2005-08-30, 7:02 pm

On 30/08/05, Levin Alexander <levin@grundeis.net> wrote:
> [snip]
>=20
> Why not "def push(priority, *args)"? That would make it easier to store
> multiple things in the queue.


What would that mean? Create n nodes with priority priority, or create
on node with an array of n entries. I think that would be unintuitive.

>=20
> q.push distance, x, y
> [...]
> x, y =3D q.pop_min
>=20
>=20
> It should be possible to add things to the queue multiple times and acces=

s
> them separately. This would not work in the current version:
>=20
> q.push :foo, 1
> q.push :foo, 100
> q.decrease_priority :foo, 0
>=20
> If you wrap everything into a new array when it is inserted into the queu=

e
> the following would be possible:
>=20
> h1 =3D q.push 1, :foo #=3D> [:foo]
> h2 =3D q.push 100, :foo #=3D> [:foo]
> q.decrease_priority(0, h1)
>=20
> I don't know if this is better, though


I could expose the nodes of the priority queue. I decided against
this, because that means that I can spare creating a ruby object for
each queue entry.
Maybe I should create two different types of queues, one with the hash
magick I'm using already and one where the user has to keep track of
the nodes himself.

>=20
>=20
> Viele Gr=FC=DFe,
> Levin
>=20
>=20


Danke,

Brian

--=20
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com