aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@nxc.no>2018-02-04 20:24:29 +0100
committerSergey Poznyakoff <gray@nxc.no>2018-02-04 20:24:29 +0100
commit027e83b6f5dc6a63ed9c69e534c0b994041df14f (patch)
tree871f1355410e8ccfe51cf59ce542b13769fa3230
parent7651936f80b1bc6f5b01477ee9e648843097d7b8 (diff)
downloadvarnish-mib-027e83b6f5dc6a63ed9c69e534c0b994041df14f.tar.gz
varnish-mib-027e83b6f5dc6a63ed9c69e534c0b994041df14f.tar.bz2
Document HashTable
-rw-r--r--lib/VarnishMib/HashTable.pm62
1 files changed, 60 insertions, 2 deletions
diff --git a/lib/VarnishMib/HashTable.pm b/lib/VarnishMib/HashTable.pm
index 0f3b47e..1faef96 100644
--- a/lib/VarnishMib/HashTable.pm
+++ b/lib/VarnishMib/HashTable.pm
@@ -148,11 +148,25 @@ sub create {
return $self->{hash_table};
}
+=head2 format_input_table
+
+ $ht->format_input_table([FILEHANDLE]);
+
+Outputs to I<FILEHANDLE> (default B<STDOUT>) a C array of input names. The
+array is declared as
+
+ char const *PFXname_table[]
+
+where I<PFX> is replaced by the prefix given when creating the HashTable
+object.
+
+=cut
+
sub format_input_table {
my ($self, $fh) = @_;
$fh ||= \*STDOUT;
croak "no input data to format" unless $self->{input};
- print $fh 'char const *' . $self->{prefix} . "name_table[] = {\n";
+ print $fh 'static char const *' . $self->{prefix} . "name_table[] = {\n";
foreach my $name (@{$self->{input}}) {
printf $fh $self->{indent} . '"' . $name . "\",\n";
}
@@ -160,14 +174,43 @@ sub format_input_table {
}
+=head2 format_data_table
+
+ $ht->format_data_table(CTYPE [, FILEHANDLE])
+
+Outputs a C array of data associated with input strings. The array is declared
+as
+
+ CTYPE PFXdata_table[N];
+
+where I<CTYPE> is the first parameter to the method, I<PFX> is the prefix and
+I<N> is the dimension (number of strings for which the hash table is built).
+Both B<name_table> and B<data_table> have the same dimension.
+
+=cut
+
sub format_data_table {
my ($self, $type, $fh) = @_;
$fh ||= \*STDOUT;
croak "no data to format" unless $self->{input};
my $n = @{$self->{input}};
- print $fh $type . ' ' . $self->{prefix} . "data_table[$n];\n";
+ print $fh 'static '. $type . ' ' . $self->{prefix} . "data_table[$n];\n";
}
+=head2 format_hash_table
+
+ $ht->format_hash_table([FILEHANDLE]);
+
+
+Outputs the hash table to I<FILEHANDLE> (B<STDOUT> by default). The table
+is declared as
+
+ int PFXhash_table[]
+
+where I<PFX> is the prefix.
+
+=cut
+
sub format_hash_table {
my ($self, $fh) = @_;
$fh ||= \*STDOUT;
@@ -186,6 +229,21 @@ sub format_hash_table {
print $fh "unsigned ${pfx}_size = sizeof($pfx) / sizeof(${pfx}[0]);\n";
}
+=head2 format_code
+
+ $ht->format_code([FILEHANDLE])
+
+Formats the supporting C code to the I<FILEHANDLE> (B<STDOUT>, if not given).
+The code contains at least the following function:
+
+ unsigned string_hash(const char *str, unsigned size)
+
+which, given the string I<str> and the size of the hash table (I<size>)
+returns the index in the table starting from which the pointer to that
+string and associated data can be located.
+
+=cut
+
sub format_code {
my ($self, $fh) = @_;
$fh ||= \*STDOUT;

Return to:

Send suggestions and report system problems to the System administrator.