Hacker News new | ask | show | jobs
by albertzeyer 5348 days ago
I'm curios, what is (under normal circumstances) supposed to go into a string hash function?

The biggest problem I see with this hash function is that it will produce very many collisions (because most common strings will probably produce only small numbers).

I have seen other very simple string hash functions which just take the 4 first bytes (or 4 last or some sort of other pattern) of the string and use them (interpreted as 32bit integer) as the hash.

1 comments

I'm no expert in hash function design, but one thing that seems bad is that it will generate colliding hashes for all permutations of the same characters. Also, it will not "spread" the bits very well, due to just using addition. Most "real" hash functions tend to multiply the hash by each new character, thus causing it to "churn" more.