blob: 03f500f3d9b0dcf144d819f81695276950ace685 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/perl
#
# Perfect Minimal Hash Generator written in Perl, which produces
# C output.
#
require 'phash.ph';
#
# Main program
#
sub main() {
my $n;
my %data;
my @hashinfo;
my $x, $i;
%data = read_input();
@hashinfo = gen_perfect_hash(\%data);
if (!defined(@hashinfo)) {
die "$0: no hash found\n";
}
verify_hash_table(\%data, \@hashinfo);
($n, $sv, $f1, $f2, $g) = @hashinfo;
print "static int HASHNAME_fg1[$n] =\n";
print "{\n";
for ($i = 0; $i < $n; $i++) {
print "\t", ${$g}[${$f1}[$i]], "\n";
}
print "};\n\n";
print "static int HASHNAME_fg2[$n] =\n";
print "{\n";
for ($i = 0; $i < $n; $i++) {
print "\t", ${$g}[${$f2}[$i]], "\n";
}
print "};\n\n";
print "struct p_hash HASHNAME =\n";
print "{\n";
print "\t$n\n";
print "\t$sv\n";
print "\tHASHNAME_fg1,\n";
print "\tHASHNAME_fg2,\n";
print "};\n";
}
main();
|