GPERF(1)
π¦ GPERF(1) β the FSF girlies' favourite hash generator π
okay bestie, sit down, hydrate, because today we're talking about gperf β the GNU one, living in the FSF manual pages, and she is iconic.
β¨ NAME β¨
gperf β generate a perfect hash function from a key set. yes. that's her whole job. slay.
πΈ SYNOPSIS πΈ
gperf [OPTION]... [INPUT-FILE]
π DESCRIPTION π
GNU gperf generates perfect hash functions. that's it, that's the vibe, no cap. π«Ά
heads up bestie: if a long option shows an argument as mandatory, then it's mandatory for the equivalent short option too. no skipping, no shortcuts. π€
π Output file location:
--output-file=FILEβ write the output to the file you named. if you don't specify an output file, or if it's-, the results go to standard output. easy peasy. β¨
π¦ Input file interpretation:
-e,--delimiters=DELIMITER-LISTβ you get to hand over a string of delimiters used to separate keywords from their attributes. default is,.-t,--struct-typeβ lets you include a structured type declaration for the generated code. any text before%%counts as part of that type declaration. key words and extra fields can follow, one group of fields per line.--ignore-caseβ treats upper and lower case ASCII characters as equivalent. note that locale dependent case mappings are ignored β we're ASCII-only here, babes. π€
π Language for the output code:
-L,--language=LANGUAGE-NAMEβ generates code in the language you pick. the languages she handles right now areC++,ANSI-C,C, andKR-C. the default isANSI-C.
β Details in the output code:
-K,--slot-name=NAMEβ pick the name of the keyword component inside the keyword structure.-F,--initializer-suffix=INITIALIZERSβ initializers for the additional components in the keyword structure.-H,--hash-function-name=NAMEβ specify the name of the generated hash function. default ishash.-N,--lookup-function-name=NAMEβ specify the name of the generated lookup function. default name isin_word_set.-Z,--class-name=NAMEβ specify the name of the generated C++ class. default name isPerfect_Hash.-7,--seven-bitβ assume 7-bit characters.-l,--compare-lengthsβ compare key lengths before even trying a string comparison. this is necessary if your keywords contain NUL bytes. it also helps cut down on the number of string comparisons made during the lookup. efficiency queen π-c,--compare-strncmpβ generate comparison code usingstrncmprather thanstrcmp.-C,--readonly-tablesβ makes the contents of the generated lookup tables constant, i.e., readonly. don't touch, she's protected. π-E,--enumβ define constant values using anenumlocal 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, instead of hiding it inside the lookup function (which is the default behavior). she's out and proud now. β¨-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 the name of the string pool generated by option--pic. default name isstringpool.--null-stringsβ use NULL strings instead of empty strings for empty keyword table entries.--constants-prefix=PREFIXβ specify a prefix for the constants likeTOTAL_KEYWORDS.-W,--word-array-name=NAMEβ specify the name of the word list array. default name iswordlist.--length-table-name=NAMEβ specify the name of the length table array. default name islengthtable.-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. theCOUNTargument determines how many switch statements are generated. a value of1generates 1 switch containing all the elements, a value of2generates 2 tables with 1/2 the elements in each table, etc. ifCOUNTis very large, say1000000, the generated C code does a binary search. π wild but okay-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 between1-255, inclusive. positions are separated by commas, ranges may be used, and key positions may occur in any order. also, the meta-character*makes the generated hash function consider ALL key positions, and$indicates the "final character" of a key, e.g.,$,1,2,4,6-10. okay miss flexibility π-D,--duplicatesβ handle keywords that hash to duplicate values. 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 ofITERATIONSbut does a good job minimizing the generated table size. worth it fr fr.-i,--initial-asso=Nβ provide an initial value for the associate values array. default is0. 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 is5.-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. chaotic but valid π²-s,--size-multiple=Nβ affects the size of the generated hash table. the numeric argumentNindicates "how many times larger or smaller" the associated value range should be, in relationship to the number of keys, e.g. a value of3means "allow the maximum associated value to be about 3 times larger than the number of input keys". conversely, a value of1/3means "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 is1.-h,--helpβ print this message. (hi.)-v,--versionβ print thegperfversion number.-d,--debugβ enables the debugging option, which produces verbose output to the standard error. not me watching her spill the tea to stderr π
okay tiny formatting note bestie:-h,-v, and-dare hanging out under "Informative output" in the original, so that's where they live. go look up. β¬οΈ
π AUTHOR π
Written by Douglas C. Schmidt and Bruno Haible. legends only.
π REPORTING BUGS π
Report bugs to <bug-gperf@gnu.org>. she wants to hear it, she wants the feedback, she's not fragile.
π COPYRIGHT π
Copyright Β© 2025 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. (translation: she's free and she's yours, but if something breaks, that's on you bestie. no cap.) π
π§ SEE ALSO π§
the full documentation for gperf is maintained as a Texinfo manual. if the info and gperf programs are properly installed at your site, the command
info gperf
should give you access to the complete manual. go read it, iykyk πβ¨
and that's the whole page, bestie. this manual page is GNU gperf 3.3, dated April 2025. mwah. π ππ¦ take care of her and she'll take care of your hash table. periodt. π
π¦ where this page comes from
- alpine 3.22: gperf-doc 3.3-r0 Β· GPL-3.0-or-later
- alpine 3.23: gperf-doc 3.3-r0 Β· GPL-3.0-or-later
- alpine 3.24: gperf-doc 3.3-r0 Β· GPL-3.0-or-later
- arch rolling: gperf 3.3-2 Β· GPL-3.0-or-later
- nixos 26.05: gperf 3.3
- nixpkgs unstable: gperf 3.3
- ubuntu resolute: gperf 3.3-1 Β· GPL-3.0-or-later
- ubuntu stonking: gperf 3.3-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms