[EMAIL PROTECTED] writes: > In an article I was linked to by Martin (http://www.perl.com/lpt/a/679) > the author, Abhjit Menon-Sen, recommends that hashes be given bucket > counts "Using a prime number that is not too close to a power of two..." > Well, that's all well and fine but, according to perldoc, the keys(%hash) > function, when used to preallocate buckets, rounds its assigned > value up to the nearest power of two. That is: > > keys( %baz) = 191; > > will allocate 256 buckets (the next nearest 2n) to %baz. So how do > I follow Menon-Sen's recommendation when the behavior of keys() > blatantly contradicts it? Is there nothing to be done?
No. The current Perl implementation will always round up to the nearest power of 2, and if the nearest power of 2 is less than 8 it will use 8 instead. I think the main reasons is that this allow for a cheaper implementation of the ($hash % @buckets) calculation. It can be reduced to a trivial bit masking operation when you know the array size to be a power of 2. Regards, Gisle _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
