Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!orion.oac.uci.edu!ucivax!milne From: milne@ics.uci.edu (Alastair Milne) Newsgroups: comp.lang.pascal Subject: Re: case (string) of Message-ID: <285076CC.12795@ics.uci.edu> Date: 8 Jun 91 06:18:52 GMT References: <1991Jun3.222059.16125@javelin.sim.es.com> <1048.284bd1ff@vger.nsu.edu> Distribution: na Organization: UC Irvine Department of ICS Lines: 38 In <1048.284bd1ff@vger.nsu.edu> g_harrison@vger.nsu.edu (George C. Harrison, Norfolk State University) writes: >In article <1991Jun3.222059.16125@javelin.sim.es.com>, tpehrson@javelin.sim.es.com (Tim Clinkenpeel) writes: >> so i can't use case for strings, eh? what are my alternatives? a list of >> if-thens? (tp5.0) >A list of if-then's in not so bad if you structure them correctly. After all >isn't that what case is all about? Often not. Turbo may implement them this way -- it's stepping during debugging seems to say so -- but jump tables are a preferred way if their size for the indexes of the give table is not prohibitive. A clever compiler will use an optimal mix of conditional jumps and jump tables. >As an alternative you may want to convert >the string or part thereof to an enumerated type and use a variable of that >type in the case statement; however, in general, this does not allow for >string's that don't conform to the type. As in ... ** a hash function ** The good part is it can be pretty quick conversion, depending on what function you use, and it frees you from playing games with the lengths of the strings you will be using. The bad part is you have to deal with hash collisions, either by using a function specialised to the set of strings you know you will have, or by more iterative hash resolution techniques. A full hash table is probably a good idea. If you record, with each string you're prepared to recognise, an enumeration that identifies it, it becomes very easy just to return the enumerated value (including one for "none", of course) and index the case on that. Alastair Milne