Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!spdcc!iecc!compilers-sender From: plx!plxsun!evan@Sun.COM (Evan Bigall) Newsgroups: comp.compilers Subject: Re: Hash specifics Keywords: design Message-ID: Date: 15 Dec 90 20:53:36 GMT References: <9012111512.AA14873@iecc.cambridge.ma.us> <1990Dec12.221425.569@zoo.toronto.edu> <2980@lupine.NCD.COM> Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: plx!plxsun!evan@Sun.COM (Evan Bigall) Organization: Plexus Software Inc. Lines: 35 Approved: compilers@iecc.cambridge.ma.us In article <2980@lupine.NCD.COM> rfg@ncd.com (Ron Guilmette) writes: Henry's point is well taken, however there are *some* places where I think that it is probably worth the effort to try to find a *perfect* hash function. Keyword tables in compilers and opcode tables in assemblers come to mind. The time when I always find myself looking for a perfect hash function, is when I am parsing long keyword options (ie: -ansi etc...) or some other case when I have a small set of possibilities but want to avoid using: if (!strcmp("hello", arg)) {} else if (!strcmp("there", arg)) {} else if (!strcmp("world", arg)) {} else error; Maybe I'm just being silly, but the above code, and the tiny hand crafted lexers I usually end up both make me gag. Because these situations often come up several times within one program I'd much rather put in a quick perfect hash, then have to put in the code to deal with collisions. I have one program where I ended up having 15 or so different instances of this situation. I ended up giving them start conditions and just calling the (already terribly complicated) flex lexer, but that seems like overkill for everyday use. /Evan -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.