spooky_hash128 (3) - Linux Man Pages
spooky_hash128: generate a "spooky" hash of an arbitrary blob of data
spooky_hash128 - generate a "spooky" hash of an arbitrary blob of data
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);
DESCRIPTIONQuoting 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.
RETURN VALUEspooky_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.
NOTESThe 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.
AUTHORSBob Jenkins <bob_jenkins [at] burtleburtle.net> invented the SpookyHash algorithm and wrote the original C++ implementation. The C implementation (spooky-c) was written by Andi Kleen <andi [at] firstfloor.org>. This manpage was authored by Jeff Layton <jlayton [at] poochiereds.net>.