Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!stjhmc!f14.n15.z1.fidonet.org!Dave.Harris From: Dave.Harris@f14.n15.z1.fidonet.org (Dave Harris) Newsgroups: comp.lang.c Subject: Re: hash function for mac needed Message-ID: <14491.28619071@stjhmc.fidonet.org> Date: 21 Jun 91 05:11:40 GMT Sender: ufgate@stjhmc.fidonet.org (newsout1.26) Organization: FidoNet node 1:15/14 - Nibbles 'n Bits, Orem UT Lines: 27 In a message of , Chris Torek (1:114/15) writes: >Indeed: as it turns out, while many people have spent much time looking >for `good' hashing functions, fewer seem to have noted that many >hashing systems spend more time computing hashes than searching. I >find that this is usually the case, and that a fast hash function is >better than a slower-but-better-distribution function. One good hash >function, useful in many applications, is this: > hash = 0; > for (each character) > hash = (hash * 33) + (the character); > hash_index = hash & ((some power of two) - 1); Is the *33 use to keep short sequences has key more random or does it really help in the distribution of large string too? -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!15!14!Dave.Harris Internet: Dave.Harris@f14.n15.z1.fidonet.org