spooky_hash128 - generate a "spooky" hash of an arbitrary blob of data
#include <spooky-c.h>
void spooky_hash128(const void *message, size_t len, uint64_t *hash1, uint64_t *hash2);
uint64_t spooky_hash64(const void *message, size_t len, uint64_t seed);
uint32_t spooky_hash32(const void *message, size_t len, uint32_t seed);
Quoting from Bob Jenkins' web page (inventor of the spooky hash function):
"SpookyHash is a public domain noncryptographic hash function producing well-distributed 128-bit hash values for byte arrays of any length."
It can also produce 64-bit and 32-bit hash values too, by simply discarding the upper bits of the returned hash value. spooky_hash32 and spooky_hash64 are wrappers around spooky_hash128 that do this discarding.
The message is a pointer to the stream of bytes to be hashed. len is the length of message. seed allows the function to generate different hashes for the same key.
spooky_hash128 also accepts seed values in hash1 and hash2. Those values will be overwritten with the actual hash results on return.
spooky_hash64 and spooky_hash32 return the hash value directly. spooky_hash128 is a void return function. It overwrites the two 64-bit integers that hash1 and hash2 on return. These functions never return errors, only hash values.
The original code was written in C++. The spooky-c library is a reimplementation of the hash function in C. It's quite fast on 64-bit hardware.
There are some caveats with the SpookyHash function:
It was written for little-endian machines. It will run and work on big-endian machines as well, but it will produce different results. Do not use these functions if you plan to distribute these hashes in a mixed endianness environment.
It is optimized for 64-bit machines that can do unaligned reads. It will work on 32-bit hardware and on machines that require aligned reads, but it won't perform as well on that hardware. You may want to consider a different hash function in that situation.
Bob Jenkins' webpage on SpookyHash: <http://www.burtleburtle.net/bob/hash/spooky.html>
Bob Jenkins <[email protected]> invented the SpookyHash algorithm and wrote the original C++ implementation. The C implementation (spooky-c) was written by Andi Kleen <[email protected]>. This manpage was authored by Jeff Layton <[email protected]>.