Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: performance of counting keys in a big hash

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

in reply to Re: performance of counting keys in a big hash
in thread performance of counting keys in a big hash

Use the force Luke!

/* hash structure: */ /* This structure must match the beginning of struct xpvmg in sv.h. */ struct xpvhv { HV* xmg_stash; /* class package */ union _xmgu xmg_u; STRLEN xhv_keys; /* total keys, including placeholders +*/ STRLEN xhv_max; /* subscript of last element of xhv_ar +ray */ };


/* the number of keys (including any placeholders) */ #define XHvTOTALKEYS(xhv) ((xhv)->xhv_keys) /* * HvKEYS gets the number of keys that actually exist(), and is provid +ed * for backwards compatibility with old XS code. The core uses HvUSEDK +EYS * (keys, excluding placeholders) and HvTOTALKEYS (including placehold +ers) */ #define HvKEYS(hv) HvUSEDKEYS(hv) #define HvUSEDKEYS(hv) (HvTOTALKEYS(hv) - HvPLACEHOLDERS_get( +hv)) #define HvTOTALKEYS(hv) XHvTOTALKEYS((XPVHV*) SvANY(hv)) #define HvPLACEHOLDERS(hv) (*Perl_hv_placeholders_p(aTHX_ MUTABLE +_HV(hv))) #define HvPLACEHOLDERS_get(hv) (SvMAGIC(hv) ? Perl_hv_placeholders_ge +t(aTHX_ (const HV *)hv) : 0)

HvKEYS(hv) is the thing that implements scalar keys %hash


Replies are listed 'Best First'.
Re^3: performance of counting keys in a big hash
by space_monk (Chaplain) on May 22, 2013 at 14:55 UTC

    Dammit Jim, I'm a doctor, not a C programmer! :-) ok it's a little cross genre, but what the hell

    If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
Re^3: performance of counting keys in a big hash
by hdb (Monsignor) on May 22, 2013 at 13:23 UTC

    I think I will have to carry you around the swamps of some unknown planet for much longer before I will ready to dive into Perl's source itself to answer questions in this community...


      Seriously tho, its not as hard as people think. In fact a lot of the time its easy. All of the code for perl's hash implementation lives in three files, hv.h, hv_func.h, hv.c.

      hv_func.h is the home of the new hash functions if you want to look at the options.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2021-01-20 13:46 GMT
Find Nodes?
    Voting Booth?