lookup3.h (3) - Linux Manuals

NAME

src/lookup3.h -

32bit hash function implementation.

SYNOPSIS


#include <pbs_config.h>

Functions


uint32_t hashword (const uint32_t *k, size_t length, uint32_t initval)
This works on all machines.
uint32_t hashlittle (const void *key, size_t length, uint32_t initval)
hashlittle() -- hash a variable-length key into a 32-bit value
uint32_t hashbig (const void *key, size_t length, uint32_t initval)
hashbig(): This is the same as hashword() on big-endian machines.

Detailed Description

32bit hash function implementation.

Taken from: http://burtleburtle.net/bob/hash/

Function Documentation

uint32_t hashword (const uint32 *k, size_tlength, uint32initval)

This works on all machines. To be useful, it requires -- that the key be an array of uint32's, and -- that all your machines have the same endianness, and -- that the length be the number of uint32's in the key

The function hashword() is identical to hashlittle() on little-endian machines, and identical to hashbig() on big-endian machines, except that the length has to be measured in uint32s rather than in bytes. hashlittle() is more complicated than hashword() only because hashlittle() has to dance around fitting the key bytes into registers.

Parameters:

k the key, an array of uint32 values
length the length of the key, in uint32s
initval the previous hash, or an arbitrary value

uint32_t hashlittle (const void *key, size_tlength, uint32initval)

hashlittle() -- hash a variable-length key into a 32-bit value

Parameters:

key the key (the unaligned variable-length array of bytes)
length the length of the key, counting by bytes
initval can be any 4-byte value

Returns a 32-bit value. Every bit of the key affects every bit of the return value. Two keys differing by one or two bits will have totally different hash values.

The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do h = (h & hashmask(10)); In which case, the hash table should have hashsize(10) elements.

If you are hashing n strings (uint8 **)k, do it like this: for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);

By Bob Jenkins, 2006. bob_jenkins [at] burtleburtle.net. You may use this code any way you wish, private, educational, or commercial. It's free.

Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes.

uint32_t hashbig (const void *key, size_tlength, uint32initval)

hashbig(): This is the same as hashword() on big-endian machines. It is different from hashlittle() on all machines. hashbig() takes advantage of big-endian byte ordering.

Author

Generated automatically by Doxygen for torque from the source code.