Hi all,
I take now a refresher on algorithms with the coursera course https://class.coursera.org/algo-005 given by Tim Roughgarden.
There is a whole week devoted to hash tables and bloom filters.
He mentioned there that the numbers of buckets in a hash should be a prime number, which is not close to a power of 2 or 10.
I use hashes in a perl on a daily basis and wanted to see how the theory is translated to the real world :-).
Firs i created a small hash %c= (a=>3,4=>5)
and saw that the number of buckets are 8.
Then i wrote a small code:
use strict;
use warnings;
my %h;
foreach my $i (0..10000) {
$h{$i} = $i+10;
}
my $j = %h;
print "$j";
and got the result 7391/16384.
Apparently the number of buckets are not prime and are divided by two.
I know from my experience that the perl hashes work amazingly fast and efficient. So how can this be explained?
Thanks,
David
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.