cyrusimap / cyrus-imapd

Cyrus IMAP is an email, contacts and calendar server
http://cyrusimap.org
Other
530 stars 145 forks source link

djb2 implementation differs from the common one #4541

Open Roo4L opened 1 year ago

Roo4L commented 1 year ago

Hi! I've noticed that strhash_seeded_djb2 uses ^ c instead of + c as most of djb2 implementation do. Could you explain this choice, please? https://github.com/cyrusimap/cyrus-imapd/blob/c615862e7e862a3ff684edc38d8131c345e1cd36/lib/strhash.c#L53

elliefm commented 1 year ago

If you look at the comment a few lines above the line you linked, there's a link to a page that explains the choice:

another version of this algorithm (now favored by bernstein) uses xor: hash(i) = hash(i - 1) * 33 ^ str[i];

I don't know what difference it makes, I'm not a hash algorithm researcher. I suppose you could ask DJB, since it's his algorithm...