⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gperf.texinfo

📁 早期freebsd实现
💻 TEXINFO
📖 第 1 页 / 共 4 页
字号:
specifies a version number of the license which applies to it and ``anylater version'', you have the option of following the terms and conditionseither of that version or of any later version published by the FreeSoftware Foundation.  If the Program does not specify a version number ofthe license, you may choose any version ever published by the Free SoftwareFoundation.@itemIf you wish to incorporate parts of the Program into other freeprograms whose distribution conditions are different, write to the authorto ask for permission.  For software which is copyrighted by the FreeSoftware Foundation, write to the Free Software Foundation; we sometimesmake exceptions for this.  Our decision will be guided by the two goalsof preserving the free status of all derivatives of our free software andof promoting the sharing and reuse of software generally.@iftex@heading NO WARRANTY@end iftex@ifinfo@center NO WARRANTY@end ifinfo@itemBECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTYFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHENOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIESPROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSEDOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OFMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK ASTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THEPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,REPAIR OR CORRECTION.@itemIN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILLANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/ORREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGESARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOTLIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSESSUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATEWITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEENADVISED OF THE POSSIBILITY OF SUCH DAMAGES.@end enumerate@iftex@heading END OF TERMS AND CONDITIONS@end iftex@ifinfo@center END OF TERMS AND CONDITIONS@end ifinfo@page@unnumberedsec Appendix: How to Apply These Terms to Your New Programs  If you develop a new program, and you want it to be of the greatestpossible use to humanity, the best way to achieve this is to make itfree software which everyone can redistribute and change under theseterms.  To do so, attach the following notices to the program.  It is safest toattach them to the start of each source file to most effectively conveythe exclusion of warranty; and each file should have at least the``copyright'' line and a pointer to where the full notice is found.@smallexample@var{one line to give the program's name and a brief idea of what it does.}Copyright (C) 19@var{yy}  @var{name of author}This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 1, or (at your option)any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.@end smallexampleAlso add information on how to contact you by electronic and paper mail.If the program is interactive, make it output a short notice like thiswhen it starts in an interactive mode:@smallexampleGnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.This is free software, and you are welcome to redistribute itunder certain conditions; type `show c' for details.@end smallexampleThe hypothetical commands `show w' and `show c' should show theappropriate parts of the General Public License.  Of course, thecommands you use may be called something other than `show w' and `showc'; they could even be mouse-clicks or menu items---whatever suits yourprogram.You should also get your employer (if you work as a programmer) or yourschool, if any, to sign a ``copyright disclaimer'' for the program, ifnecessary.  Here a sample; alter the names:@exampleYoyodyne, Inc., hereby disclaims all copyright interest in theprogram `Gnomovision' (a program to direct compilers to make passesat assemblers) written by James Hacker.@var{signature of Ty Coon}, 1 April 1989Ty Coon, President of Vice@end exampleThat's all there is to it!@node Contributors, Motivation, Copying, Top@unnumbered Contributors to GNU @code{gperf} Utility@itemize @bullet@itemThe GNU @code{gperf} perfect hash function generator utility wasoriginally written in GNU C++ by Douglas C. Schmidt.  It is now alsoavailable in a highly-portable ``old-style'' C version.  The generalidea for the perfect hash function generator was inspired by KeithBostic's algorithm written in C, and distributed to net.sources around1984.  The current program is a heavily modified, enhanced, and extendedimplementation of Keith's basic idea, created at the University ofCalifornia, Irvine.  Bugs, patches, and suggestions should be reportedto schmidt at ics.uci.edu.@itemSpecial thanks is extended to Michael Tiemann and Doug Lea, forproviding a useful compiler, and for giving me a forum to exhibit mycreation.In addition, Adam de Boor and Nels Olson provided many tips and insightsthat greatly helped improve the quality and functionality of @code{gperf}.@end itemize@node Motivation, Search Structures, Contributors, Top@chapter Introduction@code{gperf} is a perfect hash function generator written in C++.  Ittransforms an @emph{n} element user-specified keyword set @emph{W} intoa perfect hash function @emph{F}.  @emph{F} uniquely maps keywords in@emph{W} onto the range 0..@emph{k}, where @emph{k} >= @emph{n}.  If@emph{k = n} then @emph{F} is a @emph{minimal} perfect hash function.@code{gperf} generates a 0..@emph{k} element static lookup table and apair of C functions.  These functions determine whether a givencharacter string @emph{s} occurs in @emph{W}, using at most one probeinto the lookup table.@code{gperf} currently generates the reserved keyword recognizer forlexical analyzers in several production and research compilers andlanguage processing tools, including GNU C, GNU C++, GNU Pascal, GNUModula 3, and GNU indent.  Complete C++ source code for @code{gperf} isavailable via anonymous ftp from ics.uci.edu.  @code{gperf} also isdistributed along with the GNU libg++ library.  A highly portable,functionally equivalent K&R C version of @code{gperf} is archived incomp.sources.unix, volume 20.  Finally, a paper describing@code{gperf}'s design and implementation in greater detail is availablein the Second USENIX C++ Conference proceedings.@node Search Structures, Description, Motivation, Top@chapter Static search structures and GNU @code{gperf}A @dfn{static search structure} is an Abstract Data Type with certainfundamental operations, @emph{e.g.}, @emph{initialize}, @emph{insert},and @emph{retrieve}.  Conceptually, all insertions occur before anyretrievals.  In practice, @code{gperf} generates a @code{static} arraycontaining search set keywords and any associated attributes specifiedby the user.  Thus, there is essentially no execution-time cost for theinsertions.  It is a useful data structure for representing @emph{staticsearch sets}.  Static search sets occur frequently in software systemapplications.  Typical static search sets include compiler reservedwords, assembler instruction opcodes, and built-in shell interpretercommands.  Search set members, called @dfn{keywords}, are inserted intothe structure only once, usually during program initialization, and arenot generally modified at run-time.Numerous static search structure implementations exist, @emph{e.g.},arrays, linked lists, binary search trees, digital search tries, andhash tables.  Different approaches offer trade-offs between spaceutilization and search time efficiency.  For example, an @emph{n} elementsorted array is space efficient, though the average-case timecomplexity for retrieval operations using binary search isproportional to log @emph{n}.  Conversely, hash table implementationsoften locate a table entry in constant time, but typically imposeadditional memory overhead and exhibit poor worst case performance.@emph{Minimal perfect hash functions} provide an optimal solution for aparticular class of static search sets.  A minimal perfect hashfunction is defined by two properties:@itemize @bullet@item It allows keyword recognition in a static search set using at most@emph{one} probe into the hash table.  This represents the ``perfect''property.@item The actual memory allocated to store the keywords is precisely largeenough for the keyword set, and @emph{no larger}.  This is the``minimal'' property.@end itemizeFor most applications it is far easier to generate @emph{perfect} hashfunctions than @emph{minimal perfect} hash functions.  Moreover,non-minimal perfect hash functions frequently execute faster thanminimal ones in practice.  This phenomena occurs since searching asparse keyword table increases the probability of locating a ``null''entry, thereby reducing string comparisons.  @code{gperf}'s defaultbehavior generates @emph{near-minimal} perfect hash functions forkeyword sets.  However, @code{gperf} provides many options that permituser control over the degree of minimality and perfection.Static search sets often exhibit relative stability over time.  Forexample, Ada's 63 reserved words have remained constant for nearly adecade.  It is therefore frequently worthwhile to expend concertedeffort building an optimal search structure @emph{once}, if itsubsequently receives heavy use multiple times.  @code{gperf} removesthe drudgery associated with constructing time- and space-efficientsearch structures by hand.  It has proven a useful and practical toolfor serious programming projects.  Output from @code{gperf} is currentlyused in several production and research compilers, including GNU C, GNUC++, GNU Pascal, and GNU Modula 3.  The latter two compilers are not yetpart of the official GNU distr ibution.  Each compiler utilizes@code{gperf} to automatically generate static search structures thatefficiently identify their respective reserved keywords.@node Description, Options, Search Structures, Top@chapter High-Level Description of GNU @code{gperf}@menu* Input Format::		Input Format to @code{gperf}* Output Format::		Output Format for Generated C Code with @code{gperf}@end menuThe perfect hash function generator @code{gperf} reads a set of``keywords'' from a @dfn{keyfile} (or from the standard input bydefault).  It attempts to derive a perfect hashing function thatrecognizes a member of the @dfn{static keyword set} with at most asingle probe into the lookup table.  If @code{gperf} succeeds ingenerating such a function it produces a pair of C source code routinesthat perform hashing and table lookup recognition.  All generated C codeis directed to the standard output.  Command-line options describedbelow allow you to modify the input and output format to @code{gperf}.By default, @code{gperf} attempts to produce time-efficient code, withless emphasis on efficient space utilization.  However, several optionsexist that permit trading-off execution time for storage space and viceversa.  In particular, expanding the generated table size produces asparse search structure, generally yielding faster searches.Conversely, you can direct @code{gperf} to utilize a C @code{switch}statement scheme that minimizes data space storage size.  Furthermore,using a C @code{switch} may actually speed up the keyword retrieval timesomewhat.  Actual results depend on your C compiler, of course.In general, @code{gperf} assigns values to the characters it is usingfor hashing until some set of values gives each keyword a unique value.A helpful heuristic is that the larger the hash value range, the easierit is for @code{gperf} to find and generate a perfect hash function.Experimentation is the key to getting the most from @code{gperf}.@node Input Format, Output Format, Description, Description@section Input Format to @code{gperf}You can control the input keyfile format by varying certain command-linearguments, in particular the @samp{-t} option.  The input's appearanceis similar to GNU utilities @code{flex} and @code{bison} (or UNIXutilities @code{lex} and @code{yacc}).  Here's an outline of the generalformat:@group@exampledeclarations%%keywords%%functions@end example@end group@emph{Unlike} @code{flex} or @code{bison}, all sections of @code{gperf}'s inputare optional.  The following sections describe the input format for eachsection.@menu* Declarations::		@code{struct} Declarations and C Code Inclusion.* Keywords::			Format for Keyword Entries.* Functions::			Including Additional C Functions.@end menu@node Declarations, Keywords, Input Format, Input Format@subsection @code{struct} Declarations and C Code Inclusion

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -