Integer Hash Function (1997)
gist.github.com
gist.github.com
Siphash is simple, pretty fast, versatile and can be used in a way not vulnerable to hash collisions denial of service attacks (aka: hash flooding): http://www.ocert.org/advisories/ocert-2011-003.html
https://code.google.com/p/cityhash/ http://www.stanford.edu/class/ee380/Abstracts/121017-slides....
"Using multiplication requires a mechanism to transport changes from high bit positions to low bit positions. Bit reversal is best, but is slow to implement. A viable alternative is left shifts."
Left shifts transport bits from low to high, no?
Less trivially, the discussion of reversibility appears to be incorrect and irrelevant. The property that every key has a unique hash is too strong for a general purpose hash function. For a general purpose hash function, the space of hashes is assumed to be much smaller than the space of keys, so a 1:1 mapping is unattainable. The goal instead is to decorrelate collisions from the input key distribution, even when the key distribution isn't known in advance. The hashes should resemble random numbers, even when the set of inputs is highly skewed (which is almost always the case). Collisions should occur about as often as if the hashes had actually been random numbers. The random-appearing distribution of outputs, regardless of input distribution, is the property that defines a good general purpose hash.
http://en.wikipedia.org/wiki/Universal_hashing
Thorup: Even strongly universal hashing is pretty fast ([PDF] http://www.diku.dk/hjemmesider/ansatte/henglein/papers/thoru...)
And another: [PDF] http://www.daimi.au.dk/~bromille/Notes/un.pdf
Cryptographic hashes may perform to good quality, but they are a zillion times slower. And obviously they are not guaranteed to be reversible.
Elsewhere in this discussion are some good links to fast, non-cryptographic hashing functions (very cool, I hadn't heard about SipHash before).
I don't understand how this article does not give any consideration to the distribution of the input integer. After all, if the input key is uniformly distributed, or is already unique, then you could just use the identity function as your hash function.
Having a hash function that gives a 1:1 mapping for short keys could be considered a positive feature, all else being equal, but in reality, all else would not be equal, because this property doesn't naturally go along with the things that make a good hash function generally. It would certainly come at a cost, and it serves little purpose. It makes no sense to me, and I think the author must have been making it up as he went.
If you're using it for a hash function, I'd advise several repititions for good mixing. Hmm, maybe I'll write a blog post about that...
This document was lasted updated in 2007.