Searching for a name

B

Brian Schröder

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 =3D PriorityQueue.new
q["0"] =3D 0
q["1"] =3D 1
q["2"] =3D 2
q.delete_min #=3D> ["0", 0]
q.delete_min_return_key #=3D> "1"
q.delete_min_return_priority #=3D> 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
 
R

Robert Klemme

Brian said:
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
 
B

Brian Schröder

Brian said:

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.

Thanks,

Brian
 
R

Robert Klemme

Brian said:
Brian said:

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. :) Does this method return the prio of the last removed element
or the current min prio?

Kind regards

robert
 
B

Brian Schröder

Brian said:
Brian Schr=F6der 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. :)

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
 
E

ES

Brian said:
Brian Schr=F6der 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. :)
=20
=20
Sorry if I was not clear, english is not my native language. I tried
to imply exactly what you said.
=20
=20
Does this method return the prio of the last removed element
or the current min prio?
=20
=20
"delete_min_return_priority" returns the priority of the element that
was removed by calling this method.[/QUOTE]

I am still not sure :) 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.
=20
=20
best regards,
=20
Brian

E
 
B

Brian Schröder

Brian said:

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

I am still not sure :) 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. 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"] =3D 0
assert_equal(["n1", 0], @q.delete_min)
@q["n1"] =3D 0
@q["n2"] =3D -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"] =3D 0
assert_equal("n1", @q.delete_min_return_key)
@q["n1"] =3D 0
@q["n2"] =3D -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"] =3D 0
assert_equal(0, @q.delete_min_return_priority)
@q["n1"] =3D 0
@q["n2"] =3D -1
assert_equal(-1, @q.delete_min_return_priority)
end

best regards,

Brian
 
R

Robert Klemme

Brian Schröder said:
Brian said:
[snip]

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

I am still not sure :) 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
 
S

Simon Strandgaard

On 10/19/05 said:
q.delete_min #=3D> ["0", 0]
q.delete_min_return_key #=3D> "1"
q.delete_min_return_priority #=3D> 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
 
M

Martin DeMello

Brian Schröder said:
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].

gsub('delete', 'extract') perhaps

martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top