Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2018-06-24 06:42 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.