1 /* 2 * Fowler / Noll / Vo Hash (FNV Hash) 3 * http://www.isthe.com/chongo/tech/comp/fnv/ 4 * 5 * This is an implementation of the algorithms posted above. 6 * This file is placed in the public domain by Peter Wemm. 7 * 8 * $FreeBSD: src/sys/sys/fnv_hash.h,v 1.2.2.1 2001/03/21 10:50:59 peter Exp $ 9 */ 10 11 #ifndef _SYS_FNV_HASH_H_ 12 #define _SYS_FNV_HASH_H_ 13 14 #ifndef _SYS_TYPES_H_ 15 #include <sys/types.h> 16 #endif 17 18 typedef u_int32_t Fnv32_t; 19 20 #define FNV1_32_INIT ((Fnv32_t) 33554467UL) 21 #define FNV_32_PRIME ((Fnv32_t) 0x01000193UL) 22 23 static __inline Fnv32_t 24 fnv_32_buf(const void *buf, size_t len, Fnv32_t hval) 25 { 26 const u_int8_t *s = (const u_int8_t *)buf; 27 28 while (len-- != 0) { 29 hval *= FNV_32_PRIME; 30 hval ^= *s++; 31 } 32 return hval; 33 } 34 35 /* currently unused */ 36 #if 0 37 static __inline Fnv32_t 38 fnv_32_str(const char *str, Fnv32_t hval) 39 { 40 const u_int8_t *s = (const u_int8_t *)str; 41 Fnv32_t c; 42 43 while ((c = *s++) != 0) { 44 hval *= FNV_32_PRIME; 45 hval ^= c; 46 } 47 return hval; 48 } 49 #endif 50 51 #endif /* !_SYS_FNV_HASH_H_ */ 52