diff options
author | Karl Williamson <khw@cpan.org> | 2018-07-20 21:34:16 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-07-20 21:57:59 -0600 |
commit | db027c8ad0058ce857031ce7fc8586ca9151f5f1 (patch) | |
tree | 78535ed435aab6e3cee029bfe229bfbd87437dbc /regen | |
parent | 8a6698d780e9f46d4c64b65eaa6928cd7d0e16ce (diff) | |
download | perl-db027c8ad0058ce857031ce7fc8586ca9151f5f1.tar.gz |
regen/mph.pl: Add comments
These are from http://nntp.perl.org/group/perl.perl5.porters/251395
Diffstat (limited to 'regen')
-rw-r--r-- | regen/mph.pl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/regen/mph.pl b/regen/mph.pl index 5ed392a1ea..11af00911e 100644 --- a/regen/mph.pl +++ b/regen/mph.pl @@ -10,6 +10,28 @@ my $DEBUG= 0; my $RSHIFT= 8; my $FNV_CONST= 16777619; +# The basic idea is that you have a two level structure, and effectively +# hash the key twice. +# +# The first hash finds a bucket in the array which contains a seed which +# is used for the second hash, which then leads to a bucket with key +# data which is compared against to determine if the key is a match. +# +# If the first hash finds no seed, then the key cannot match. +# +# In our case we cheat a bit, and hash the key only once, but use the +# low bits for the first lookup and the high-bits for the second. +# +# So for instance: +# +# h= (h >> RSHIFT) ^ s; +# +# is how the second hash is computed. We right shift the original hash +# value and then xor in the seed2, which will be non-zero. +# +# That then gives us the bucket which contains the key data we need to +# match for a valid key. + sub _fnv { my ($key, $seed)= @_; my $hash = 0+$seed; |