in reply to strange keys with a hash
Perl allocates a number of buckets per hash. Whenever a certain percentage of the buckets are filled with hash keys, the number of buckets gets doubled. Because of the hash algorithm a key then either stays in its bucket or has to go to the corresponding bucket of the new space.
When you print a hash in scalar context, it tells you how many buckets it has and how many are filled. Try this:
perl -e ' for $i (1..100) {$h{$e++}=1; print scalar(%h),"\n" }'
Note that not every key entry occupies a new bucket. That is the case when two different keys produce the same hash number and therefore occupy the same bucket.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: strange keys with a hash
by zwon (Abbot) on Jan 30, 2009 at 20:20 UTC | |
by Marshall (Canon) on Feb 01, 2009 at 16:13 UTC |