C<-x>.
[p5sagit/p5-mst-13.2.git] / lib / Tie / SubstrHash.pm
index a01c66e..44c2140 100644 (file)
@@ -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
 
@@ -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;