The family of hash functions that DJB belongs to is probably the most common form of hash function, with variants rumored to have been 'created' by DJB and Chris Torek. They take the form 'hash = hash * x op key[i]'. x is generally 2^n +/- 1 so hash * x can be computed with a shift and addition or subtraction.
This variant of DJB uses 'xor key[i]' which yields, relatively, much better mixing than the two other versions (x17 and x31) which use 'add key[i]'. While all versions are far from perfect, they are easy to remember, decently fast, and do perform well for ASCII text.
finline u32 fastcall DJB( const u8 *key, u32 len, u32 seed ) {
u32 hash = 5381 + seed + len;
for ( ; len & ~1; len -= 2, key += 2 )
hash = ( ( ( hash * 33 ) ^ key[0] ) * 33 ) ^ key[1];
if ( len & 1 )
hash = ( hash * 33 ) ^ key[0];
return hash ^ ( hash >> 16 );
}