Re: Hash specifics

plx!plxsun!evan@Sun.COM (Evan Bigall)
15 Dec 90 20:53:36 GMT

          From comp.compilers

Related articles
[6 earlier articles]
Re: Hash specifics lupine!rfg@uunet.UU.NET (1990-12-13)
Re: Hash specifics rfg@ncd.com (1990-12-13)
Re: Hash specifics rfg@ncd.com (1990-12-13)
Re: Hash specifics bart@cs.uoregon.edu (1990-12-13)
Re: Hash specifics roth@resi.rice.edu (1990-12-14)
Re: Hash specifics oz@nexus.yorku.ca (1990-12-14)
Re: Hash specifics plx!plxsun!evan@Sun.COM (1990-12-15)
Re: Hash specifics vern@horse.ee.lbl.gov (1990-12-16)
Re: Hash specifics schmidt@oberkampf.ICS.UCI.EDU (Doug Schmidt) (1990-12-17)
Re: Hash specifics preston@ariel.rice.edu (1990-12-17)
Re: Hash specifics brain@eos.ncsu.edu (1990-12-18)
Re: Hash specifics rfpfeifl@watcgl.uwaterloo.ca (Ron Pfeifle) (1990-12-21)
| List of all articles for this month |
Newsgroups: comp.compilers
From: plx!plxsun!evan@Sun.COM (Evan Bigall)
Keywords: design
Organization: Plexus Software Inc.
References: <9012111512.AA14873@iecc.cambridge.ma.us> <1990Dec12.221425.569@zoo.toronto.edu> <2980@lupine.NCD.COM>
Date: 15 Dec 90 20:53:36 GMT

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
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.