Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: performance of counting keys in a big hash

by demerphq (Chancellor)
on May 22, 2013 at 09:14 UTC ( #1034709=note: print w/replies, xml ) Need Help??

in reply to performance of counting keys in a big hash

Perl stores the number of keys in the hash as an independent property. So accessing this data is always O(1).

Note that this is not true of code that does if (%hash){} or otherwise inspects the *fill* of a hash using scalar %hash (note the omission of the keys() function). Such code, depending on the version, will be inefficient. In later perls the if() case is special cased to not use "fill", and in 5.20 scalar %hash will likely be equivalent to scalar keys %hash.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034709]
[LanX]: # Pestis Africana Suum
[erix]: that's an old plan, I think. Isn't there already a danewal (or some such name)?
[marto]: Build with -Wall
[erix]: Danewerk
[LanX]: I seem to remember that the danewall was build by the Frankish empire against the Danes
[erix]: 500 AD thru viking age
[erix]: that would make sense but wikipedia thinks otherwise
[LanX]: oh me was wrong ...
[erix]: but it always works both ways of course
[LanX]: Funny some weeks ago, I met people from the Cimbrian peninsula who didn't know it's called the Cimbrian peninsula ...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2018-03-22 18:38 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (283 votes). Check out past polls.