Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 wandering the Monastery: (4)
As of 2017-01-20 06:19 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (173 votes). Check out past polls.