|go ahead... be a heretic|
Re^4: elsif chain vs. dispatchby Marshall (Prior)
|on Apr 27, 2009 at 19:58 UTC||Need Help??|
I don't know what is new in Perl 5.8.3 regarding new re-sizing algorithms based upon buckets used, but if you are curious as to what is happening, the scalar value of a hash, eg my $x = %hash; returns a string like "(10/1024)" showing number of buckets used/total buckets.
To pre-size a hash or force it get bigger, assign a scalar to keys %hash, eg: keys %hash=8192;.
The Perl hash algorithm is:
Perl cuts the above value to the hash array size of bits, which in Perl is always a power of 2. As mentioned above, this "(10/1024)" string shows number of "buckets" and total "buckets". There is another value, hxv_keys accessible to the Perl "guts" that contains the total number of hash entries.
If the total number of (typo update:)
So let's say that we have a hash with 8 buckets and for some reason only one of those buckets is being used. When the ninth one shows up, Perl will see (9>8) and will re-size the hash by adding one more bit to the hash key. In practice, this algorithm appears to work pretty well. I guess there are some improvement in >Perl 5.8.3.
Anyway I often work the hashes with say 100,000 things and haven't seen the need yet to override the Perl hash algorithm.