Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: To Hash or to Array--Uniqueness is the question.

by ikegami (Pope)
on Dec 01, 2005 at 22:51 UTC ( #513472=note: print w/ replies, xml ) Need Help??


in reply to To Hash or to Array--Uniqueness is the question.

Hash inserts are O(1) (or close to), while uniquely inserting into an array is O(N) (unless you insert everything and remove dups later).

The only reason you'd want something other than a hash is if you wanted something other than the string representation to be unique. And even then, it would be best if you could derive a unique string from the object and still use a hash.

For example, case-insensitive uniqueness:

$hash{lc($_)} = $_;

For example, unique object id:

$hash{$obj->{id}} = $obj;


Comment on Re: To Hash or to Array--Uniqueness is the question.
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-07-23 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (152 votes), past polls