home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!timbuk.cray.com!raistlin!uc.msc.edu!noc.msc.net!news.gac.edu!nntp-server!max
- From: max@Kolmogorov.gac.edu (Max Hailperin)
- Newsgroups: comp.lang.scheme
- Subject: Re: How to lookup symbols fast?
- Date: 22 Jan 93 09:34:14
- Organization: Gustavus Adolphus College, St. Peter, MN
- Lines: 34
- Message-ID: <MAX.93Jan22093414@Kolmogorov.gac.edu>
- References: <1je4kvINN5cj@shelley.u.washington.edu>
- <1993Jan19.212543.29200@gallant.apple.com>
- Reply-To: Max Hailperin <max@nic.gac.edu>
- NNTP-Posting-Host: kolmogorov.gac.edu
- In-reply-to: kend@newton.apple.com's message of 19 Jan 93 21:25:43 GMT
-
- In article <1993Jan19.212543.29200@gallant.apple.com>
- kend@newton.apple.com (Kenneth Dickey) writes:
-
- In article <1je4kvINN5cj@shelley.u.washington.edu> Charles Bass,
- chuckb@stein.u.washington.edu writes:
- >We are writing a simple pattern matching program in scheme and
- >would like to speed up some of the internal "stuff". We have a
- >table of 20 or 30 functions that our evaluate uses to determine
- >which function/rule-set to apply.
- ...
- >Is there anything better than a simple linear search of the
- >symbols?
-
- The rule of thumb is "for less than 100 elements, linear search beats
- hashing". For 30 entries use an alist & assq.
-
- Yes, but if read has already read in something as a symbol and the
- "symbol" data type in your particular variant of Scheme has a spare
- slot in it's representation (say, the property-list slot), then the
- hashing has *already been done* by read. Assuming you only put a few
- properties on each symbol's property list (i.e. much less than 30),
- and that property lists are linearly searched much like assq
- (typically true, though often the details are a bit different, i.e.
- alternating key and data elements rather than a list of pairs), this
- has got to be faster than searching an alist of length 30. Moreover,
- it will typically grow more gracefully, since you are more likely to
- multiply by a large factor the number of symbols in the table than the
- number of tables (i.e. properties).
-
- Yes, I know that property lists are archaic and not a standard feature
- of the Scheme language, but many implementations do have them and if
- Bass was using such an implementation, and if he really was of
- necessity starting from *symbols* as he stated (i.e. pre-hashed by
- read), then there seems like little point in redoing read's work.
-