Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Searching for a name

Reply
Thread Tools

Searching for a name

 
 
Brian Schröder
Guest
Posts: n/a
 
      10-19-2005
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

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

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


 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      10-19-2005
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

 
Reply With Quote
 
 
 
 
Brian Schröder
Guest
Posts: n/a
 
      10-19-2005
On 19/10/05, Robert Klemme <(E-Mail Removed)> wrote:
> 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.

Thanks,

Brian

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

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


 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      10-19-2005
Brian Schröder wrote:
> On 19/10/05, Robert Klemme <(E-Mail Removed)> 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. Does this method return the prio of the last removed element
or the current min prio?

Kind regards

robert

 
Reply With Quote
 
Brian Schröder
Guest
Posts: n/a
 
      10-19-2005
On 19/10/05, Robert Klemme <(E-Mail Removed)> wrote:
> Brian Schr=F6der wrote:
> > On 19/10/05, Robert Klemme <(E-Mail Removed)> wrote:
> >> 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

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

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


 
Reply With Quote
 
ES
Guest
Posts: n/a
 
      10-19-2005
Brian Schr=F6der wrote:
> On 19/10/05, Robert Klemme <(E-Mail Removed)> wrote:
>=20
>>Brian Schr=F6der wrote:
>>
>>>On 19/10/05, Robert Klemme <(E-Mail Removed)> wrote:
>>>
>>>>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.


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.

>>Kind regards
>>
>> robert
>>

>=20
>=20
> best regards,
>=20
> Brian


E


 
Reply With Quote
 
Brian Schröder
Guest
Posts: n/a
 
      10-19-2005
On 19/10/05, ES <(E-Mail Removed)> wrote:
> Brian Schr=F6der wrote:
> > > [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. 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

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

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


 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      10-19-2005
Brian Schröder <(E-Mail Removed)> wrote:
> On 19/10/05, ES <(E-Mail Removed)> 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 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

 
Reply With Quote
 
Simon Strandgaard
Guest
Posts: n/a
 
      10-19-2005
On 10/19/05, Brian Schr=F6der <(E-Mail Removed)> wrote:
[snip]
> 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


--
Simon Strandgaard


 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      10-20-2005
Brian Schröder <(E-Mail Removed)> 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].


gsub('delete', 'extract') perhaps

martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Google search result to be URL-limited when searching site, but notwhen searching Web stumblng.tumblr Javascript 1 02-04-2008 09:01 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
name = name.substring(0, name.lastIndexOf('.')); Help please Jack-2 Javascript 3 12-24-2003 04:39 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments