<!-- MHonArc v2.4.4 --> <!--X-Subject: [MUD-Dev] Re: Question on c++ switch optimization, and parsers in general. --> <!--X-From-R13: Quevf Uenl <ptNnzv-pt.UenlEntr.Sqzbagba.OP.QO> --> <!--X-Date: Mon, 8 Feb 1999 19:54:25 -0800 --> <!--X-Message-Id: 199902090353.UAA00877@ami-cg.GraySage.Edmonton.AB.CA --> <!--X-Content-Type: text/plain --> <!--X-Head-End--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title>MUD-Dev message, [MUD-Dev] Re: Question on c++ switch optimization, and parsers</title> <!-- meta name="robots" content="noindex,nofollow" --> <link rev="made" href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA"> </head> <body background="/backgrounds/paperback.gif" bgcolor="#ffffff" text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000"> <font size="+4" color="#804040"> <strong><em>MUD-Dev<br>mailing list archive</em></strong> </font> <br> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00367.html">Previous</a> | <a href="msg00369.html">Next</a> ] Thread: [ <a href="msg00372.html">Previous</a> | <a href="msg00370.html">Next</a> ] Index: [ <A HREF="author.html#00368">Author</A> | <A HREF="#00368">Date</A> | <A HREF="thread.html#00368">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</H1> <HR> <!--X-Subject-Header-End--> <!--X-Head-of-Message--> <UL> <LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> <LI><em>Subject</em>: [MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</LI> <LI><em>From</em>: Chris Gray <<A HREF="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</A>></LI> <LI><em>Date</em>: Mon, 8 Feb 1999 20:53:19 -0700</LI> <LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> </UL> <!--X-Head-of-Message-End--> <!--X-Head-Body-Sep-Begin--> <HR> <!--X-Head-Body-Sep-End--> <!--X-Body-of-Message--> <PRE> [Ben Greear:] >I'd do that, but I want the user to be able to abbreviate any command. >I couldn't figure out a way to hash and still get that feature. I recommend against allowing any unambiguous abbreviation for any command. The problem here is that when you add a command, you can break what was previously an unambiguous abbreviation. Now you either have to make a special-case exception, or you have just removed an abbreviation that users have gotten used to. I think its better to select one or two abbreviations for each command (if any are really needed), and hardcode them along with the commands. That way you can have n,s,e,w,u,p mean what people expect them to mean without special casing them. However if you insist on minimal unambiguous abbreviations, and don't want a linear search, how about this: At startup time, scan your table of commands, and build some auxilliary data structures. Have the code determine the minimum unambiguous form of all commands. Enter all of those into a hash table (could even try a mostly minimal one). Include in your data structures the full name of the commands. Then, lookup consists of looking up longer and longer portions of the input command until you find a match, or you have tried the full command. Search is O(length of input command) rather than O(number of commands). -- Don't design inefficiency in - it'll happen in the implementation. - me Chris Gray cg#ami-cg,GraySage.Edmonton.AB.CA <A HREF="http://www.GraySage.Edmonton.AB.CA/cg/">http://www.GraySage.Edmonton.AB.CA/cg/</A> </PRE> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <HR> <ul compact><li><strong>Follow-Ups</strong>: <ul> <li><strong><A NAME="00370" HREF="msg00370.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong> <ul compact><li><em>From:</em> "T. Alexander Popiel" <popiel#snugharbor,com></li></ul> </UL></LI></UL> <!--X-Follow-Ups-End--> <!--X-References--> <!--X-References-End--> <!--X-BotPNI--> <UL> <LI>Prev by Date: <STRONG><A HREF="msg00367.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers i</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00369.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00372.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00370.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00368"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00368"><STRONG>Thread</STRONG></A></LI> </UL> </LI> </UL> <!--X-BotPNI-End--> <!--X-User-Footer--> <!--X-User-Footer-End--> <ul><li>Thread context: <BLOCKQUOTE><UL> <LI><STRONG>[MUD-Dev] Re: optimizing code</STRONG>, <EM>(continued)</EM> <ul compact> <ul compact> <LI><strong><A NAME="00374" HREF="msg00374.html">[MUD-Dev] Re: optimizing code</A></strong>, Hans-Henrik Staerfeldt <a href="mailto:hhs#cbs,dtu.dk">hhs#cbs,dtu.dk</a>, Tue 09 Feb 1999, 14:58 GMT </LI> </ul> </ul> </LI> <LI><strong><A NAME="00366" HREF="msg00366.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 09 Feb 1999, 03:31 GMT <UL> <LI><strong><A NAME="00369" HREF="msg00369.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, Adam J. Thornton <a href="mailto:adam#phoenix,Princeton.EDU">adam#phoenix,Princeton.EDU</a>, Tue 09 Feb 1999, 04:34 GMT <UL> <LI><strong><A NAME="00372" HREF="msg00372.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Tue 09 Feb 1999, 06:01 GMT </LI> </UL> </LI> </UL> <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00368" HREF="msg00368.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 09 Feb 1999, 03:54 GMT <UL> <LI><strong><A NAME="00370" HREF="msg00370.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers in general.</A></strong>, T. Alexander Popiel <a href="mailto:popiel#snugharbor,com">popiel#snugharbor,com</a>, Tue 09 Feb 1999, 04:41 GMT </LI> </UL> </LI> </UL> </LI> <LI><strong><A NAME="00355" HREF="msg00355.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers i</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Mon 08 Feb 1999, 06:11 GMT <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00367" HREF="msg00367.html">[MUD-Dev] Re: Question on c++ switch optimization, and parsers i</A></strong>, Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 09 Feb 1999, 03:45 GMT </LI> </UL> </LI> <LI><strong><A NAME="00353" HREF="msg00353.html">[MUD-Dev] Question on c++ switch optimization, and parsers in general.</A></strong>, Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Mon 08 Feb 1999, 05:32 GMT </LI> </UL></BLOCKQUOTE> </ul> <hr> <center> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>