diff options
author | Sergey Poznyakoff <gray@nxc.no> | 2018-02-04 20:24:29 +0100 |
---|---|---|
committer | Sergey Poznyakoff <gray@nxc.no> | 2018-02-04 20:24:29 +0100 |
commit | 027e83b6f5dc6a63ed9c69e534c0b994041df14f (patch) | |
tree | 871f1355410e8ccfe51cf59ce542b13769fa3230 | |
parent | 7651936f80b1bc6f5b01477ee9e648843097d7b8 (diff) | |
download | varnish-mib-027e83b6f5dc6a63ed9c69e534c0b994041df14f.tar.gz varnish-mib-027e83b6f5dc6a63ed9c69e534c0b994041df14f.tar.bz2 |
Document HashTable
-rw-r--r-- | lib/VarnishMib/HashTable.pm | 62 |
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 { | |||
148 | return $self->{hash_table}; | 148 | return $self->{hash_table}; |
149 | } | 149 | } |
150 | 150 | ||
151 | =head2 format_input_table | ||
152 | |||
153 | $ht->format_input_table([FILEHANDLE]); | ||
154 | |||
155 | Outputs to I<FILEHANDLE> (default B<STDOUT>) a C array of input names. The | ||
156 | array is declared as | ||
157 | |||
158 | char const *PFXname_table[] | ||
159 | |||
160 | where I<PFX> is replaced by the prefix given when creating the HashTable | ||
161 | object. | ||
162 | |||
163 | =cut | ||
164 | |||
151 | sub format_input_table { | 165 | sub format_input_table { |
152 | my ($self, $fh) = @_; | 166 | my ($self, $fh) = @_; |
153 | $fh ||= \*STDOUT; | 167 | $fh ||= \*STDOUT; |
154 | croak "no input data to format" unless $self->{input}; | 168 | croak "no input data to format" unless $self->{input}; |
155 | print $fh 'char const *' . $self->{prefix} . "name_table[] = {\n"; | 169 | print $fh 'static char const *' . $self->{prefix} . "name_table[] = {\n"; |
156 | foreach my $name (@{$self->{input}}) { | 170 | foreach my $name (@{$self->{input}}) { |
157 | printf $fh $self->{indent} . '"' . $name . "\",\n"; | 171 | printf $fh $self->{indent} . '"' . $name . "\",\n"; |
158 | } | 172 | } |
@@ -160,14 +174,43 @@ sub format_input_table { | |||
160 | 174 | ||
161 | } | 175 | } |
162 | 176 | ||
177 | =head2 format_data_table | ||
178 | |||
179 | $ht->format_data_table(CTYPE [, FILEHANDLE]) | ||
180 | |||
181 | Outputs a C array of data associated with input strings. The array is declared | ||
182 | as | ||
183 | |||
184 | CTYPE PFXdata_table[N]; | ||
185 | |||
186 | where I<CTYPE> is the first parameter to the method, I<PFX> is the prefix and | ||
187 | I<N> is the dimension (number of strings for which the hash table is built). | ||
188 | Both B<name_table> and B<data_table> have the same dimension. | ||
189 | |||
190 | =cut | ||
191 | |||
163 | sub format_data_table { | 192 | sub format_data_table { |
164 | my ($self, $type, $fh) = @_; | 193 | my ($self, $type, $fh) = @_; |
165 | $fh ||= \*STDOUT; | 194 | $fh ||= \*STDOUT; |
166 | croak "no data to format" unless $self->{input}; | 195 | croak "no data to format" unless $self->{input}; |
167 | my $n = @{$self->{input}}; | 196 | my $n = @{$self->{input}}; |
168 | print $fh $type . ' ' . $self->{prefix} . "data_table[$n];\n"; | 197 | print $fh 'static '. $type . ' ' . $self->{prefix} . "data_table[$n];\n"; |
169 | } | 198 | } |
170 | 199 | ||
200 | =head2 format_hash_table | ||
201 | |||
202 | $ht->format_hash_table([FILEHANDLE]); | ||
203 | |||
204 | |||
205 | Outputs the hash table to I<FILEHANDLE> (B<STDOUT> by default). The table | ||
206 | is declared as | ||
207 | |||
208 | int PFXhash_table[] | ||
209 | |||
210 | where I<PFX> is the prefix. | ||
211 | |||
212 | =cut | ||
213 | |||
171 | sub format_hash_table { | 214 | sub format_hash_table { |
172 | my ($self, $fh) = @_; | 215 | my ($self, $fh) = @_; |
173 | $fh ||= \*STDOUT; | 216 | $fh ||= \*STDOUT; |
@@ -186,6 +229,21 @@ sub format_hash_table { | |||
186 | print $fh "unsigned ${pfx}_size = sizeof($pfx) / sizeof(${pfx}[0]);\n"; | 229 | print $fh "unsigned ${pfx}_size = sizeof($pfx) / sizeof(${pfx}[0]);\n"; |
187 | } | 230 | } |
188 | 231 | ||
232 | =head2 format_code | ||
233 | |||
234 | $ht->format_code([FILEHANDLE]) | ||
235 | |||
236 | Formats the supporting C code to the I<FILEHANDLE> (B<STDOUT>, if not given). | ||
237 | The code contains at least the following function: | ||
238 | |||
239 | unsigned string_hash(const char *str, unsigned size) | ||
240 | |||
241 | which, given the string I<str> and the size of the hash table (I<size>) | ||
242 | returns the index in the table starting from which the pointer to that | ||
243 | string and associated data can be located. | ||
244 | |||
245 | =cut | ||
246 | |||
189 | sub format_code { | 247 | sub format_code { |
190 | my ($self, $fh) = @_; | 248 | my ($self, $fh) = @_; |
191 | $fh ||= \*STDOUT; | 249 | $fh ||= \*STDOUT; |