Click to See Complete Forum and Search --> : Hashing keys into a 1-byte result with no collisions


Vogon5
September 6th, 2009, 10:58 AM
Hi all,

I'm having trouble implementing a hash function that produces 1-byte hash values (ranging from 0-255) for variable length keys. I've tried the Generalized CRC and Pearson algorithms described here (http://burtleburtle.net/bob/hash/doobs.html).

While the CRC one works great, seemingly with no collisions based on my tests, it produces 4-byte hashes which are not very convenient for my purposes. Pearson gives me 1-byte hashes but I get around 60+ collisions in a 256-element key set (the keys are all unique) which is not very convenient either.

Is there a way to either reduce a 4-byte hash value into a 1-byte hash while preserving the non-colliding-ness or make the Pearson algorithm to produce fewer collisions with 1-byte hashes?