The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/fnv_hash.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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: releng/10.3/sys/sys/fnv_hash.h 244209 2012-12-14 12:37:35Z ae $
    9  */
   10 #ifndef _SYS_FNV_HASH_H_
   11 #define _SYS_FNV_HASH_H_
   12 
   13 typedef u_int32_t Fnv32_t;
   14 typedef u_int64_t Fnv64_t;
   15 
   16 #define FNV1_32_INIT ((Fnv32_t) 33554467UL)
   17 #define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL)
   18 
   19 #define FNV_32_PRIME ((Fnv32_t) 0x01000193UL)
   20 #define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL)
   21 
   22 static __inline Fnv32_t
   23 fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
   24 {
   25         const u_int8_t *s = (const u_int8_t *)buf;
   26 
   27         while (len-- != 0) {
   28                 hval *= FNV_32_PRIME;
   29                 hval ^= *s++;
   30         }
   31         return hval;
   32 }
   33 
   34 static __inline Fnv32_t
   35 fnv_32_str(const char *str, Fnv32_t hval)
   36 {
   37         const u_int8_t *s = (const u_int8_t *)str;
   38         Fnv32_t c;
   39 
   40         while ((c = *s++) != 0) {
   41                 hval *= FNV_32_PRIME;
   42                 hval ^= c;
   43         }
   44         return hval;
   45 }
   46 
   47 static __inline Fnv64_t
   48 fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
   49 {
   50         const u_int8_t *s = (const u_int8_t *)buf;
   51 
   52         while (len-- != 0) {
   53                 hval *= FNV_64_PRIME;
   54                 hval ^= *s++;
   55         }
   56         return hval;
   57 }
   58 
   59 static __inline Fnv64_t
   60 fnv_64_str(const char *str, Fnv64_t hval)
   61 {
   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 */
   64 
   65         while ((c = *s++) != 0) {
   66                 hval *= FNV_64_PRIME;
   67                 hval ^= c;
   68         }
   69         return hval;
   70 }
   71 #endif /* _SYS_FNV_HASH_H_ */

Cache object: eb944f438500ceb2a996ae2740337d8d


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.