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

Re: maintaining a sorted structure

by Sinistral (Prior)
on Jan 26, 2011 at 16:38 UTC ( #884379=note: print w/ replies, xml ) Need Help??


in reply to maintaining a sorted structure

First of all Yes, even you can use CPAN. The basic equivalent of a C++ std::map is the hash. However, as you know, Perl hashes do not maintain order. For an ordered hash, there's Tie::IxHash, which doesn't have specific search functions, but does let you reorder the data structure by key. Even though you mention std::map (hash), you might want to check out the options in List::MoreUtils and List::Util.


Comment on Re: maintaining a sorted structure
Re^2: maintaining a sorted structure
by Limbic~Region (Chancellor) on Jan 26, 2011 at 19:01 UTC
    Sinistral,
    For an ordered hash, there's Tie::IxHash, which doesn't have specific search functions, but does let you reorder the data structure by key

    Tie::IxHash maintains insertion order which is very unlikely to be sorted order indicated by the OP. Yes, it does have rudimentary manual sort capability (asciibetical sort by keys or values). It also has the ability to manually reorder the keys arbitrarily but the user must first do the sort. If what you need is a sorted hash and not an insertion order hash, then you should use Tie::Hash::Sorted which is designed for that purpose and also has a number of optimizations.

    Disclaimer: I am the author of Tie::Hash::Sorted

    Cheers - L~R

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://884379]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-28 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls