From the perlguts manual:
The hash algorithm is defined in the "PERL_HASH(hash, key, klen)" macro:
hash = 0;
while (klen--)
hash = (hash * 33) + *key++;
hash = hash + (hash >> 5); /* after 5.6 */
The last step was added in version 5.6 to improve distribution of lower bits in the resulting hash value.
If you just want a look at the hashing function, this is it. A look at the full source might give you a better feel for it. If you want to call this from perl, you can use Inline::C which automatically includes perl.h. Alternatively, you can reimplement this function in pure perl and use it from there. |