If all you wanted was a hash value it is probably better to use 128!:3 (CRC), possibly p&|@(128!:3) where p is a prime. That way you would not be dependent on the internal workings of s: which may change from release to release. In any case, a hash value need not be unique. That is, if you have a hash function h then (h x)=h y in no way guarantees that x=y . One use of hashing is to allow you to quickly determine that x~:y, by testing that (h x)~:h y . Typically the domain of h is much larger than the range of h, so that the mapping is many-to-one. This explains the properties stated in the previous two sentences: non-uniqueness and quick test of non-equality.
You can read more about hashing in http://en.wikipedia.org/wiki/Hash_function More details in Knuth volume 3, Searching and Sorting. ----- Original Message ----- From: Matthew Brand <[EMAIL PROTECTED]> Date: Thursday, April 24, 2008 5:29 Subject: [Jprogramming] s: for hash codes and auto-caching calulation results To: [email protected] > I am writing an adverb which sets of a chain of time-comsuming > calculationsand want to cache the results automatically to disk. > > To achieve this I will: > > Generate a hash code of its input parameters (a gerund (u) > with the code > converted to a string and a string (y) concatenated with the > adverb name to > make a string), > Look for a file with the same name as the hash code, > EITHER load the file if it exists OR do the calculation as > asked and then > save results to a binary file with the hash code as a name. > > > The idea is to "auto-cache" the results of lengthy calculations > that calls > to that adverb creates. > > To generate the "unique" hash code I intend to use: > > ( 2: { [: ; (0: s: 2:) {~ [: 6&s: [: s: ' '&~: # ]) (3!:1) > 'stringofinputparameters' > > I do not know much about hash codes though. Is the hash code > unique? What > does the column "color" mean in the symbol table, do I need to > include it in > the hash code to make it unique? Is there any reference material > that I > could read to learn more about the subject, so far I can only > find the > dictionary entry. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
