Any ideas? I need a fast hash routine that will go over a maximum of 20 bytes and output a single byte result. I'm thinking of something simple like adding the byte values together, but doing a rotate left before each addition. Is there any decent hashes out there first though that will generate a single byte result?

I'd prefer to do this without any loops whatsoever for speed reasons (don't care about code size).
Posted on 2003-02-02 18:19:35 by squidge
What will these 20 bytes be? Letters, numbers, etc.
Posted on 2003-02-02 18:59:34 by bitRAKE
sorry, they'll be in the range 32 - 127 (standard ascii).
Posted on 2003-02-03 02:20:15 by squidge
XORing them together seems like the faster solution. It's not that safe since it generates the same result if two bits on the same position in two bytes are swapped.
Posted on 2003-02-03 04:09:44 by gliptic
done some tests and it does indeed seem that XOR is the best way of doing it. It's only so I can search through a list of strings without having to do a string compare on each - creating a hash of each one means I only have to compare those strings where the hash matches. So the hash function itself doesn't have to be brilliant, but the less dupes it throws out means less string compares.
Posted on 2003-02-03 04:17:50 by squidge
And if you care to use the whole hash concept, you create a table with 256 linked lists and store the strings with hash value 0 in linked list 0, strings with hash value 1 in linked list 1 and so on.
Then if you need to test if a string exists, you calculate it's hash value and walk the linked list associated with that hash value until you find (or don't find) the string.
Posted on 2003-02-03 04:31:04 by gliptic
The problem I'm having is that I'm very short on ram. This is the reason I am using a single byte value to store the hash. Don't really have the room for a linked list. Only got about 4Kb of RAM left and this needs to store all the names etc as well as the internal variables. I don't have access to any of the extended memory.
Posted on 2003-02-03 05:01:53 by squidge
consider using length-prepended strings, and compare string lengths and first-char before doing compares. somebody did this with the original QuakeC compiler (before experimenting with hashing), and the results were rather nice.
Posted on 2003-02-03 11:04:12 by f0dder