2 * This file was taken from http://ccodearchive.net/info/hash.html
3 * Changes to the original file include cleanups and removal of unwanted code
4 * and also code that depended on build_asert
12 /* Stolen mostly from: lookup3.c, by Bob Jenkins, May 2006, Public Domain.
14 * http://burtleburtle.net/bob/c/lookup3.c
17 #ifdef __LITTLE_ENDIAN
18 # define HAVE_LITTLE_ENDIAN 1
20 # define HAVE_BIG_ENDIAN 1
22 #error Unknown endianness. Failure in endian.h
26 * hash - fast hash of an array for internal use
27 * @p: the array or pointer to first element
28 * @num: the number of elements to hash
29 * @base: the base number to roll into the hash (usually 0)
31 * The memory region pointed to by p is combined with the base to form
34 * This hash will have different results on different machines, so is
35 * only useful for internal hashes (ie. not hashes sent across the
36 * network or saved to disk).
38 * It may also change with future versions: it could even detect at runtime
39 * what the fastest hash to use is.
41 * See also: hash64, hash_stable.
44 * #include <ccan/hash/hash.h>
49 * // Simple demonstration: idential strings will have the same hash, but
50 * // two different strings will probably not.
51 * int main(int argc, char *argv[])
53 * uint32_t hash1, hash2;
56 * err(1, "Usage: %s <string1> <string2>", argv[0]);
58 * hash1 = __nl_hash(argv[1], strlen(argv[1]), 0);
59 * hash2 = __nl_hash(argv[2], strlen(argv[2]), 0);
60 * printf("Hash is %s\n", hash1 == hash2 ? "same" : "different");
64 #define __nl_hash(p, num, base) nl_hash_any((p), (num)*sizeof(*(p)), (base))
66 /* Our underlying operations. */
67 uint32_t nl_hash_any(const void *key, size_t length, uint32_t base);