6 my ($klen, $vlen, $tsize) = @_;
7 my $rlen = 1 + $klen + $vlen;
8 $tsize = findprime($tsize * 1.1); # Allow 10% empty.
9 $self = bless ["\0", $klen, $vlen, $tsize, $rlen, 0, -1];
10 $$self[0] x= $rlen * $tsize;
15 local($self,$key) = @_;
16 local($klen, $vlen, $tsize, $rlen) = @$self[1..4];
19 $offset = $hash * $rlen;
20 $record = substr($$self[0], $offset, $rlen);
21 if (ord($record) == 0) {
24 elsif (ord($record) == 1) {
26 elsif (substr($record, 1, $klen) eq $key) {
27 return substr($record, 1+$klen, $vlen);
34 local($self,$key,$val) = @_;
35 local($klen, $vlen, $tsize, $rlen) = @$self[1..4];
36 croak("Table is full") if $self[5] == $tsize;
37 croak(qq/Value "$val" is not $vlen characters long./)
38 if length($val) != $vlen;
43 $offset = $hash * $rlen;
44 $record = substr($$self[0], $offset, $rlen);
45 if (ord($record) == 0) {
46 $record = "\2". $key . $val;
47 die "panic" unless length($record) == $rlen;
48 $writeoffset = $offset unless defined $writeoffset;
49 substr($$self[0], $writeoffset, $rlen) = $record;
53 elsif (ord($record) == 1) {
54 $writeoffset = $offset unless defined $writeoffset;
56 elsif (substr($record, 1, $klen) eq $key) {
57 $record = "\2". $key . $val;
58 die "panic" unless length($record) == $rlen;
59 substr($$self[0], $offset, $rlen) = $record;
67 local($self,$key) = @_;
68 local($klen, $vlen, $tsize, $rlen) = @$self[1..4];
71 $offset = $hash * $rlen;
72 $record = substr($$self[0], $offset, $rlen);
73 if (ord($record) == 0) {
76 elsif (ord($record) == 1) {
78 elsif (substr($record, 1, $klen) eq $key) {
79 substr($$self[0], $offset, 1) = "\1";
80 return substr($record, 1+$klen, $vlen);
95 local($klen, $vlen, $tsize, $rlen, $entries, $iterix) = @$self[1..6];
96 for (++$iterix; $iterix < $tsize; ++$iterix) {
97 next unless substr($$self[0], $iterix * $rlen, 1) eq "\2";
99 return substr($$self[0], $iterix * $rlen + 1, $klen);
106 croak(qq/Key "$key" is not $klen characters long.\n/)
107 if length($key) != $klen;
109 for (unpack('C*', $key)) {
110 $hash = $hash * 33 + $_;
112 $hash = $hash - int($hash / $tsize) * $tsize
114 $hash = 1 unless $hash;
120 $hash -= $tsize if $hash >= $tsize;
127 $num++ unless $num % 2;
129 $max = int sqrt $num;
133 for ($i = 3; $i <= $max; $i += 2) {
134 next NUM unless $num % $i;