Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Opinions on adding functionality to Tie::Hash::Sorted

by Limbic~Region (Chancellor)
on Jul 17, 2004 at 16:56 UTC ( [id://375248]=perlquestion: print w/replies, xml ) Need Help??

Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All,
It has been some time (almost a year) since I contributed Tie::Hash::Sorted and have never received any feature requests or bug reports. This could be because no one is using it or because it does everything anyone wants. There are several minor POD nits that I have said I would fix if/when I posted a new release but that just hasn't happened. Here is a loose collection of ideas that I have thought about since releasing but don't want to add code bloat without good reason:
  • A backward method which would change the direction the hash was being traversed in
  • A forward method which would change the direction the hash was being traversed in
  • A start_key method which would allow you to specify which key to start iterating at
  • A end_key method which would allow you to specify which key to end iterating at
  • A couple of peek methods that would allow you to take a look at what the next/previous key will be/were without actually changing the iterator
Of course all method names are subject to change

I am just not sure if my idea of usefulness

# effectively for ( $start_key .. $end_key ) { }
is actually useful. So what do you think? If these are all garbage - are there any useful ideas you can think of that I should add or should I just leave it alone?

Cheers - L~R

Replies are listed 'Best First'.
Re: Opinions on adding functionality to Tie::Hash::Sorted
by gaal (Parson) on Jul 17, 2004 at 17:11 UTC
    Are backward and forward direction switches, or more like opposite iterate methods? If the latter, prev[ious] and next sound more standard to me. If the former, you only need one (reverse current order), *or* you need it as an addition (for completeness' sake).
      gaal,
      They would be direction switches. The reason for naming them explicitly would be so code that used them would be clear in what was going on but you are right - functionally only one is needed.

      A prev and next method were supposed to be coupled with the peek methods (which would actually change the iterator), but I got trigger happy and posted before the brain dump was complete. Thanks for mopping up the grey matter.

      Cheers - L~R

        Hmmm, I just thought of another method that might be useful: rewind, to reset the iterator. But that's probably low priority, seeing as there's no natural way to express that for unordered hashes in Perl.
Re: Opinions on adding functionality to Tie::Hash::Sorted
by brionius (Sexton) on Jul 17, 2004 at 17:33 UTC
    i think the backward/forward functionality sounds useful as well as the start/end keys. i personally haven't seen a need for the peek methods yet, but that doesn't mean that they wouldn't be useful. so i guess it depends on how much bloat they would add. =)
Re: Opinions on adding functionality to Tie::Hash::Sorted
by Limbic~Region (Chancellor) on Jul 17, 2004 at 20:49 UTC
    oh yeah...
    A get_index method. If the keys are sorted in a rank structure, it may be useful to be able to determine what rank $last_name happens to be.

    Cheers - L~R

      This could be because no one is using it or because it does everything anyone wants

      I have only used it once (several months ago) and it did everything for me. I know of a co-worker that uses it pretty frequently -- I will refer him to this thread and see what he might have to say. All the feedback I can give you is that direction switches would be quite useful. Don't really know about peek -- never needed to.

      CSUhockey3
Re: Opinions on adding functionality to Tie::Hash::Sorted
by Limbic~Region (Chancellor) on Jul 20, 2004 at 15:10 UTC
    Some more thoughts...,
    A wrap toggle should be added so that it is possible, if desired, to wrap around each end of the hash. This also begs the question should it be allowed to wrap in both directions.

    And what about....allowing the start/end key to be ordinal values (like with the get_rank idea) so you would not have to know the key names (show me 20th .. 25th place).

    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://375248]
Approved by meredith
Front-paged by biosysadmin
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-19 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found