in reply to Re^2: When does Perl double the number of buckets in hash?
in thread When does Perl double the number of buckets in hash?
In your example, doubling does not occur because there is no collision. As I understand, the Perl code in hv.c first checks if there is a collision. If there is, the code compares the total number of keys (including the one we just added) with the number of buckets. If the former is greater or equal to the latter, then the number of buckets is doubled. Otherwise, Perl checks the total number of keys in that particular bucket. If there are more than HV_MAX_LENGTH_BEFORE_SPLIT (set to 14) keys in that bucket, the number of buckets is also doubled.
I still don't understand one thing, though. In hv.c code we have the comparison (xhv->xhv_keys > (IV)xhv->xhv_max). This seems to suggest that doubling occurs only when the number of keys (including the new one) is more than the number of buckets. But as I shown in the original post, the doubling can occur even when the number of keys equals to the number of buckets.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: When does Perl double the number of buckets in hash?
by BrowserUk (Patriarch) on Dec 02, 2011 at 20:16 UTC | |
|
Re^4: When does Perl double the number of buckets in hash?
by ikegami (Patriarch) on Dec 03, 2011 at 02:05 UTC |