Searching for a name

Hello Group,

I'm currently polishing my priority queue implementation, and I'm in
need for a name for some methods.

I have the following behaviour now

q = PriorityQueue.new
q["0"] = 0
q["1"] = 1
q["2"] = 2
q.delete_min #=> ["0", 0]
q.delete_min_return_key #=> "1"
q.delete_min_return_priority #=> 2

and wonder how I could call the last two methods. I want these,
because delete_min returns nil if the queue is empty, and I can't
index nil. So for some code these additional functions are quite
convenient.

thanks for the input,

Brian

···

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

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

Brian Schröder wrote:

Hello Group,

I'm currently polishing my priority queue implementation, and I'm in
need for a name for some methods.

I have the following behaviour now

q = PriorityQueue.new
q["0"] = 0
q["1"] = 1
q["2"] = 2
q.delete_min #=> ["0", 0]
q.delete_min_return_key #=> "1"
q.delete_min_return_priority #=> 2

and wonder how I could call the last two methods. I want these,
because delete_min returns nil if the queue is empty, and I can't
index nil. So for some code these additional functions are quite
convenient.

How about
#deq
#deq_key
#deq_prio

?

Kind regards

    robert

[snip]

q.delete_min #=> ["0", 0]
q.delete_min_return_key #=> "1"
q.delete_min_return_priority #=> 2

and wonder how I could call the last two methods. I want these,
because delete_min returns nil if the queue is empty, and I can't
index nil. So for some code these additional functions are quite
convenient.

Array#shift is a nice name.

delete_min -> shift
delete_min_return_key -> shift_key
delete_min_return_priority -> shift_prio

···

On 10/19/05, Brian Schröder <ruby.brian@gmail.com> wrote:

--
Simon Strandgaard

Hello Robert,

I assume you use deq as a short for dequeue. In this case I have the
problem that the name
dequeue_key would somehow imply that the key was removed while
deq_prio would imply removing the priority. This does not make sense
if one knows the datastructure, but I'm not too happy with it.

Thanks,

Brian

···

On 19/10/05, Robert Klemme <bob.news@gmx.net> wrote:

Brian Schröder wrote:
> [snip]

How about
#deq
#deq_key
#deq_prio

?

Kind regards

    robert

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

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

Brian Schröder wrote:

···

On 19/10/05, Robert Klemme <bob.news@gmx.net> wrote:

Brian Schröder wrote:

[snip]

How about
#deq
#deq_key
#deq_prio

?

Kind regards

    robert

Hello Robert,

I assume you use deq as a short for dequeue. In this case I have the
problem that the name
dequeue_key would somehow imply that the key was removed while
deq_prio would imply removing the priority. This does not make sense
if one knows the datastructure, but I'm not too happy with it.

OTOH: if you know the data structure, you know that the prio is not
removed. :slight_smile: Does this method return the prio of the last removed element
or the current min prio?

Kind regards

    robert

Brian Schröder wrote:
>> Brian Schröder wrote:
>>> [snip]
>>
>> How about
>> #deq
>> #deq_key
>> #deq_prio
>>
>> ?
>>
>> Kind regards
>>
>> robert
>>
>
> Hello Robert,
>
> I assume you use deq as a short for dequeue. In this case I have the
> problem that the name
> dequeue_key would somehow imply that the key was removed while
> deq_prio would imply removing the priority. This does not make sense
> if one knows the datastructure, but I'm not too happy with it.

OTOH: if you know the data structure, you know that the prio is not
removed. :slight_smile:

Sorry if I was not clear, english is not my native language. I tried
to imply exactly what you said.

Does this method return the prio of the last removed element
or the current min prio?

"delete_min_return_priority" returns the priority of the element that
was removed by calling this method.

Kind regards

    robert

best regards,

Brian

···

On 19/10/05, Robert Klemme <bob.news@gmx.net> wrote:

> On 19/10/05, Robert Klemme <bob.news@gmx.net> wrote:

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

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

Brian Schröder wrote:

Brian Schröder wrote:

Brian Schröder wrote:

[snip]

How about
#deq
#deq_key
#deq_prio

?

Kind regards

   robert

Hello Robert,

I assume you use deq as a short for dequeue. In this case I have the
problem that the name
dequeue_key would somehow imply that the key was removed while
deq_prio would imply removing the priority. This does not make sense
if one knows the datastructure, but I'm not too happy with it.

OTOH: if you know the data structure, you know that the prio is not
removed. :slight_smile:

Sorry if I was not clear, english is not my native language. I tried
to imply exactly what you said.

Does this method return the prio of the last removed element
or the current min prio?

"delete_min_return_priority" returns the priority of the element that
was removed by calling this method.

I am still not sure :slight_smile: By 'this method', do you mean delete/dequeue?
Or does delete_min_return_priority itself delete?

If it does not delete, then #last_(deleted_)priority is fine; otherwise
you might do something like #dequeue_by and document the return value.
It would get excessively verbose to include all that information in the
method name.

Kind regards

   robert

best regards,

Brian

E

···

On 19/10/05, Robert Klemme <bob.news@gmx.net> wrote:

On 19/10/05, Robert Klemme <bob.news@gmx.net> wrote:

delete_min_return_priority deletes the key that has the lowest
assigned priority and returns this priority. delete_min_return_key
does the same but returns the key that had the lowest assigned
priority. Finally delete_min deletes the same key and returns a pair
[key, priority].

Maybe the testcases will make it all clear. If I'm not able to express
myself in english, maybe my ruby is more adequate. All the three tests
should do the same. Only the return value should differ.

  def test_delete_min
    assert_equal(nil, @q.delete_min, "Empty queue should pop nil")
    @q["n1"] = 0
    assert_equal(["n1", 0], @q.delete_min)
    @q["n1"] = 0
    @q["n2"] = -1
    assert_equal(["n2", -1], @q.delete_min)
  end

  def test_delete_min_return_key
    assert_equal(nil, @q.delete_min_return_key, "Empty queue should pop nil")
    @q["n1"] = 0
    assert_equal("n1", @q.delete_min_return_key)
    @q["n1"] = 0
    @q["n2"] = -1
    assert_equal("n2", @q.delete_min_return_key)
  end

  def test_delete_min_return_priority
    assert_equal(nil, @q.delete_min_return_priority, "Empty queue
should pop nil")
    @q["n1"] = 0
    assert_equal(0, @q.delete_min_return_priority)
    @q["n1"] = 0
    @q["n2"] = -1
    assert_equal(-1, @q.delete_min_return_priority)
  end

best regards,

Brian

···

On 19/10/05, ES <ruby-ml@magical-cat.org> wrote:

Brian Schröder wrote:
> > [snip]
>
> "delete_min_return_priority" returns the priority of the element that
> was removed by calling this method.

I am still not sure :slight_smile: By 'this method', do you mean delete/dequeue?
Or does delete_min_return_priority itself delete?

If it does not delete, then #last_(deleted_)priority is fine; otherwise
you might do something like #dequeue_by and document the return value.
It would get excessively verbose to include all that information in the
method name.

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

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

Brian Schröder wrote:

[snip]

"delete_min_return_priority" returns the priority of the element
that was removed by calling this method.

I am still not sure :slight_smile: By 'this method', do you mean delete/dequeue?
Or does delete_min_return_priority itself delete?

If it does not delete, then #last_(deleted_)priority is fine;
otherwise you might do something like #dequeue_by and document the
return value. It would get excessively verbose to include all that
information in the method name.

delete_min_return_priority deletes the key that has the lowest
assigned priority and returns this priority.

Honestly, what would anyone do with this method? Removing the key and getting ignoring the prio is fine, but removing an element from the PK without knowing which element sounds pretty much useless to me. I would not keep it - not even for symmetry reasons...

delete_min_return_key
does the same but returns the key that had the lowest assigned
priority. Finally delete_min deletes the same key and returns a pair
[key, priority].

Both of these seem useful to me. In that case the deq_* approach would make sense IMHO.

Kind regards

    robert

···

Brian Schröder <ruby.brian@gmail.com> wrote:

On 19/10/05, ES <ruby-ml@magical-cat.org> wrote:

gsub('delete', 'extract') perhaps

martin

···

Brian Schröder <ruby.brian@gmail.com> wrote:

delete_min_return_priority deletes the key that has the lowest
assigned priority and returns this priority. delete_min_return_key
does the same but returns the key that had the lowest assigned
priority. Finally delete_min deletes the same key and returns a pair
[key, priority].