X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTie%2FSubstrHash.pm;h=4b18a58e122cc62cbfe03173151773400c78b445;hb=19799a22062ef658e4ac543ea06fa9193323512a;hp=a01c66ef8d53b649ed35d7331a96369fbcd0c264;hpb=64d0c9732b520ac8f3a9448f7c3f9f5b4209bd6d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Tie/SubstrHash.pm b/lib/Tie/SubstrHash.pm index a01c66e..4b18a58 100644 --- a/lib/Tie/SubstrHash.pm +++ b/lib/Tie/SubstrHash.pm @@ -8,7 +8,7 @@ Tie::SubstrHash - Fixed-table-size, fixed-key-length hashing require Tie::SubstrHash; - tie %myhash, Tie::SubstrHash, $key_len, $value_len, $table_size; + tie %myhash, 'Tie::SubstrHash', $key_len, $value_len, $table_size; =head1 DESCRIPTION @@ -69,7 +69,7 @@ sub FETCH { sub STORE { local($self,$key,$val) = @_; local($klen, $vlen, $tsize, $rlen) = @$self[1..4]; - croak("Table is full") if $self[5] == $tsize; + croak("Table is full") if $$self[5] == $tsize; croak(qq/Value "$val" is not $vlen characters long./) if length($val) != $vlen; my $writeoffset; @@ -144,13 +144,17 @@ sub hashkey { $hash = 2; for (unpack('C*', $key)) { $hash = $hash * 33 + $_; + &_hashwrap if $hash >= 1e13; } - $hash = $hash - int($hash / $tsize) * $tsize - if $hash >= $tsize; + &_hashwrap if $hash >= $tsize; $hash = 1 unless $hash; $hashbase = $hash; } +sub _hashwrap { + $hash -= int($hash / $tsize) * $tsize; +} + sub rehash { $hash += $hashbase; $hash -= $tsize if $hash >= $tsize;