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-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
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$
    9  */
   10 
   11 typedef u_int32_t Fnv32_t;
   12 typedef u_int64_t Fnv64_t;
   13 
   14 #define FNV1_32_INIT ((Fnv32_t) 33554467UL)
   15 #define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL)
   16 
   17 #define FNV_32_PRIME ((Fnv32_t) 0x01000193UL)
   18 #define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL)
   19 
   20 static __inline Fnv32_t
   21 fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
   22 {
   23         const u_int8_t *s = (const u_int8_t *)buf;
   24 
   25         while (len-- != 0) {
   26                 hval *= FNV_32_PRIME;
   27                 hval ^= *s++;
   28         }
   29         return hval;
   30 }
   31 
   32 static __inline Fnv32_t
   33 fnv_32_str(const char *str, Fnv32_t hval)
   34 {
   35         const u_int8_t *s = (const u_int8_t *)str;
   36         Fnv32_t c;
   37 
   38         while ((c = *s++) != 0) {
   39                 hval *= FNV_32_PRIME;
   40                 hval ^= c;
   41         }
   42         return hval;
   43 }
   44 
   45 static __inline Fnv64_t
   46 fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
   47 {
   48         const u_int8_t *s = (const u_int8_t *)buf;
   49 
   50         while (len-- != 0) {
   51                 hval *= FNV_64_PRIME;
   52                 hval ^= *s++;
   53         }
   54         return hval;
   55 }
   56 
   57 static __inline Fnv64_t
   58 fnv_64_str(const char *str, Fnv64_t hval)
   59 {
   60         const u_int8_t *s = (const u_int8_t *)str;
   61         u_register_t c;          /* 32 bit on i386, 64 bit on alpha,ia64 */
   62 
   63         while ((c = *s++) != 0) {
   64                 hval *= FNV_64_PRIME;
   65                 hval ^= c;
   66         }
   67         return hval;
   68 }

Cache object: 8a902cffadd0edaa9b3f19f8d4677ad1


[ 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.