Path: utzoo!attcan!uunet!ginosko!gem.mps.ohio-state.edu!uwm.edu!bionet!ames!claris!sts!cohesive!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: Perfect HASH functions..... Message-ID: <8248@goofy.megatest.UUCP> Date: 23 Sep 89 02:16:19 GMT References: <9900014@bradley> Organization: Megatest Corporation, San Jose, Ca Lines: 54 From article <9900014@bradley>, by vijay@bradley.UUCP: > > Hello, > > I hope you can help me. Does anyone out there have a perfect > hash function? The key is a string of characters (maximum length > is 4, minimum is 2) ... How about another idea? For a similar application, I recently wrote a little program which generates a big switch statement for recognizing strings. You give it a list of strings, each paired with its enumeration value, and it spits out the switch. It's real fast. It helps if you optimize away jumps to jumps, of course. It only took about an hour to write the thing. Here's the first few lines of a switch it generated for recognizing Pascal keywords in lower case: switch(*str++) /* */ { default: break; case 'a': /* a */ switch(*str++) /* a */ { default: break; case 'n': /* an */ switch(*str++) /* an */ { default: break; case 'd': /* and */ if(length==3)type = 307; break; } break; case 'r': /* ar */ switch(*str++) /* ar */ { default: break; case 'r': /* arr */ switch(*str++) /* arr */ { default: break; case 'a': /* arra */ switch(*str++) /* arra */ { default: break; case 'y': /* array */ if(length==5)type = 257; break; } break; } break; } break; } break; etc...