From: "Brian Schröder" Date: 2005-08-31T04:11:39+09:00 Subject: Re: [ANN] Priority Queue 0.0.0.0. ... .0 On 30/08/05, Levin Alexander wrote: > [snip] > > ## Usage > > > > require 'priority_queue' > > > > q = PriorityQueue.new > > q.push "node1", 0 > > q.puts "node2", 1 > > 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. > > q.push distance, x, y > [...] > x, y = q.pop_min > > > q.decrease_priority("node2", -1) > > It should be possible to add things to the queue multiple times and access > 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 queue > the following would be possible: > > h1 = q.push 1, :foo #=> [:foo] > h2 = q.push 100, :foo #=> [:foo] > q.decrease_priority(0, h1) > > 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. > > > Viele Gr��e, > Levin > > Danke, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/