gperf1
Generate a perfect hash function from a key set
Usage
gperf [OPTION] ...
[INPUT-FILE]
Overview
GNU 'gperf' generates perfect hash functions.
If a long option shows an argument as mandatory, then it is mandatory for the equivalent short option also.
Output file location:
--output-file=FILE Write output to specified file.
The results are written to standard output if no output file is specified or if it is -.
Input file interpretation:
-
-e, --delimiters=DELIMITER-LIST -
Allow user to provide a string containing delimiters used to separate keywords from their attributes. Default is ",".
-
-t, --struct-type -
Allows the user to include a structured type declaration for generated code. Any text before %% is considered part of the type declaration. Key words and additional fields may follow this, one group of fields per line.
-
--ignore-case -
Consider upper and lower case ASCII characters as equivalent. Note that locale dependent case mappings are ignored.
Language for the output code:
-
-L, --language=LANGUAGE-NAME -
Generates code in the specified language. Languages handled are currently C++, ANSI-C, C, and KR-C. The default is ANSI-C.
Details in the output code:
-
-K, --slot-name=NAME -
Select name of the keyword component in the keyword structure.
-
-F, --initializer-suffix=INITIALIZERS -
Initializers for additional components in the keyword structure.
-
-H, --hash-function-name=NAME -
Specify name of generated hash function. Default is 'hash'.
-
-N, --lookup-function-name=NAME -
Specify name of generated lookup function. Default name is 'in_word_set'.
-
-Z, --class-name=NAME -
Specify name of generated C++ class. Default name is 'Perfect_Hash'.
-
-7, --seven-bit -
Assume 7-bit characters.
-
-l, --compare-lengths -
Compare key lengths before trying a string comparison. This is necessary if the keywords contain NUL bytes. It also helps cut down on the number of string comparisons made during the lookup.
-
-c, --compare-strncmp -
Generate comparison code using strncmp rather than strcmp.
-
-C, --readonly-tables -
Make the contents of generated lookup tables constant, i.e., readonly.
-
-E, --enum -
Define constant values using an enum local to the lookup function rather than with defines.
-
-I, --includes -
Include the necessary system include file <string.h> at the beginning of the code.
-
-G, --global-table -
Generate the static table of keywords as a static global variable, rather than hiding it inside of the lookup function (which is the default behavior).
-
-P, --pic -
Optimize the generated table for inclusion in shared libraries. This reduces the startup time of programs using a shared library containing the generated code.
-
-Q, --string-pool-name=NAME -
Specify name of string pool generated by option
--pic. Default name is 'stringpool'.
-
--null-strings -
Use NULL strings instead of empty strings for empty keyword table entries.
-
--constants-prefix=PREFIX -
Specify prefix for the constants like TOTAL_KEYWORDS.
-
-W, --word-array-name=NAME -
Specify name of word list array. Default name is 'wordlist'.
-
--length-table-name=NAME -
Specify name of length table array. Default name is 'lengthtable'.
-
-S, --switch=COUNT -
Causes the generated C code to use a switch statement scheme, rather than an array lookup table. This can lead to a reduction in both time and space requirements for some keyfiles. The COUNT argument determines how many switch statements are generated. A value of 1 generates 1 switch containing all the elements, a value of 2 generates 2 tables with 1/2 the elements in each table, etc. If COUNT is very large, say 1000000, the generated C code does a binary search.
-
-T, --omit-struct-type -
Prevents the transfer of the type declaration to the output file. Use this option if the type is already defined elsewhere.
Algorithm employed by gperf:
-
-k, --key-positions=KEYS -
Select the key positions used in the hash function. The allowable choices range between 1-255, inclusive. The positions are separated by commas, ranges may be used, and key positions may occur in any order. Also, the meta-character '*' causes the generated hash function to consider ALL key positions, and $ indicates the "final character" of a key, e.g., $,1,2,4,6-10.
-
-D, --duplicates -
Handle keywords that hash to duplicate values. This is useful for certain highly redundant keyword sets.
-
-m, --multiple-iterations=ITERATIONS -
Perform multiple choices of the
-iand-jvalues, and choose the best results. This increases the running time by a factor of ITERATIONS but does a good job minimizing the generated table size.
-
-i, --initial-asso=N -
Provide an initial value for the associate values array. Default is 0. Setting this value larger helps inflate the size of the final table.
-
-j, --jump=JUMP-VALUE -
Affects the "jump value", i.e., how far to advance the associated character value upon collisions. Must be an odd number, default is 5.
-
-n, --no-strlen -
Do not include the length of the keyword when computing the hash function.
-
-r, --random -
Utilizes randomness to initialize the associated values table.
-
-s, --size-multiple=N -
Affects the size of the generated hash table. The numeric argument N indicates "how many times larger or smaller" the associated value range should be, in relationship to the number of keys, e.g. a value of 3 means "allow the maximum associated value to be about 3 times larger than the number of input keys". Conversely, a value of 1/3 means "make the maximum associated value about 3 times smaller than the number of input keys". A larger table should decrease the time required for an unsuccessful search, at the expense of extra table space. Default value is 1.
Informative output:
-
-h, --help -
Print this message.
-
-v, --version -
Print the gperf version number.
-
-d, --debug -
Enables the debugging option (produces verbose output to the standard error).
Releases
18 releases since Debian 1.1 (Buzz); the text changed 10 times.
--class-name since Debian 3.0 (Woody);
--compare-lengths since Debian 3.1 (Sarge);
--compare-strncmp since Debian 2.1 (Slink);
--constants-prefix since Debian 10 (Buster);
--debug since Debian 2.1 (Slink);
--delimiters since Debian 3.0 (Woody);
--duplicates since Debian 2.1 (Slink);
--enum since Debian 2.1 (Slink);
--global-table since Debian 3.1 (Sarge);
--hash-function-name since Debian 3.1 (Sarge);
--help since Debian 2.1 (Slink);
--ignore-case since Debian 3.1 (Sarge);
--includes since Debian 2.1 (Slink);
--initial-asso since Debian 3.0 (Woody);
--initializer-suffix since Debian 3.0 (Woody);
--jump since Debian 3.0 (Woody);
--key-positions since Debian 3.0 (Woody);
--language since Debian 3.0 (Woody);
--length-table-name since Debian 4.0 (Etch);
--lookup-function-name since Debian 3.1 (Sarge);
--multiple-iterations since Debian 3.1 (Sarge);
--no-strlen since Debian 2.1 (Slink);
--null-strings since Debian 3.1 (Sarge);
--omit-struct-type since Debian 2.1 (Slink);
--pic since Debian 3.1 (Sarge);
--random since Debian 2.1 (Slink);
--readonly-tables since Debian 2.1 (Slink);
--seven-bit since Debian 2.1 (Slink);
--size-multiple since Debian 3.0 (Woody);
--slot-name since Debian 3.0 (Woody);
--string-pool-name since Debian 3.1 (Sarge);
--struct-type since Debian 2.1 (Slink);
--switch since Debian 3.0 (Woody);
--version since Debian 2.1 (Slink);
--word-array-name since Debian 3.0 (Woody);
-7 since Debian 2.1 (Slink);
-C since Debian 2.1 (Slink);
-D since Debian 2.1 (Slink);
-E since Debian 2.1 (Slink);
-F since Debian 3.0 (Woody);
-G since Debian 2.1 (Slink);
-H since Debian 3.0 (Woody);
-I since Debian 2.1 (Slink);
-K since Debian 3.0 (Woody);
-L since Debian 3.0 (Woody);
-N since Debian 3.0 (Woody);
-P since Debian 3.1 (Sarge);
-Q since Debian 3.1 (Sarge);
-S since Debian 3.0 (Woody);
-T since Debian 2.1 (Slink);
-W since Debian 3.0 (Woody);
-Z since Debian 3.0 (Woody);
-c since Debian 2.1 (Slink);
-d since Debian 2.1 (Slink);
-e since Debian 3.0 (Woody);
-h since Debian 2.1 (Slink);
-i since Debian 3.0 (Woody);
-j since Debian 3.0 (Woody);
-k since Debian 3.0 (Woody);
-l since Debian 2.1 (Slink);
-m since Debian 3.1 (Sarge);
-n since Debian 2.1 (Slink);
-r since Debian 2.1 (Slink);
-s since Debian 3.0 (Woody);
-t since Debian 2.1 (Slink);
-v since Debian 2.1 (Slink).
--compare-strlen until Debian 3.0 (Woody);
--fast until Debian 3.0 (Woody);
--global until Debian 3.0 (Woody);
--hash-fn-name until Debian 3.0 (Woody);
--lookup-fn-name until Debian 3.0 (Woody);
--occurrence-sort until Debian 3.0 (Woody);
-f until Debian 3.0 (Woody);
-o until Debian 3.0 (Woody).