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
Levin Alexander

2005-08-30, 7:02 pm

Brian Schr=F6der <ruby.brian@gmail.com> wrote:

> As I recently said, I'd like some more advanced datastructures in
> ruby. So I wrote a nice priority queue extension. Maybe it's not so
> nice c-code right now, because it is my first try on an extension, but
> it works really good. I created quite a quick quiz solver with it ;-)


Oooh nice ;) And a full blown Fibonacci Heap even. Thank you.

> As I have a problem with my webspace at the moment, this first release
> is mailing list only. The extension is not packaged for installation
> but it is easy to build and use.


> ## Usage
>
> require 'priority_queue'
>
> q =3D PriorityQueue.new
> q.push "node1", 0
> q.puts "node2", 1


Why not "def push(priority, *args)"? That would make it easier to store =
=20
multiple things in the queue.

q.push distance, x, y
[...]
x, y =3D q.pop_min

> q.decrease_priority("node2", -1)


It should be possible to add things to the queue multiple times and acces=
s =20
them separately. This would not work in the current version:

q.push :foo, 1
q.push :foo, 100
q.decrease_priority :foo, 0

If you wrap everything into a new array when it is inserted into the queu=
e =20
the following would be possible:

h1 =3D q.push 1, :foo #=3D> [:foo]
h2 =3D q.push 100, :foo #=3D> [:foo]
q.decrease_priority(0, h1)

I don't know if this is better, though


Viele Gr=FC=DFe,
Levin


Sponsored Links







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

Copyright 2008 codecomments.com