Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2016-10-27 20:14 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (371 votes). Check out past polls.