2 * Fowler / Noll / Vo Hash (FNV Hash)
3 * http://www.isthe.com/chongo/tech/comp/fnv/
5 * This is an implementation of the algorithms posted above.
6 * This file is placed in the public domain by Peter Wemm.
10 #ifndef _SYS_FNV_HASH_H_
11 #define _SYS_FNV_HASH_H_
13 typedef u_int32_t Fnv32_t;
14 typedef u_int64_t Fnv64_t;
16 #define FNV1_32_INIT ((Fnv32_t) 33554467UL)
17 #define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL)
19 #define FNV_32_PRIME ((Fnv32_t) 0x01000193UL)
20 #define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL)
22 static __inline Fnv32_t
23 fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
25 const u_int8_t *s = (const u_int8_t *)buf;
34 static __inline Fnv32_t
35 fnv_32_str(const char *str, Fnv32_t hval)
37 const u_int8_t *s = (const u_int8_t *)str;
40 while ((c = *s++) != 0) {
47 static __inline Fnv64_t
48 fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
50 const u_int8_t *s = (const u_int8_t *)buf;
59 static __inline Fnv64_t
60 fnv_64_str(const char *str, Fnv64_t hval)
62 const u_int8_t *s = (const u_int8_t *)str;
63 u_register_t c; /* 32 bit on i386, 64 bit on alpha,ia64 */
65 while ((c = *s++) != 0) {
71 #endif /* _SYS_FNV_HASH_H_ */