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  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  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: src/sys/sys/fnv_hash.h,v 1.2.2.1 2001/03/21 10:50:59 peter Exp $
    9  * $DragonFly: src/sys/sys/fnv_hash.h,v 1.3 2006/05/20 02:42:13 dillon Exp $
   10  */
   11 
   12 #ifndef _SYS_FNV_HASH_H_
   13 #define _SYS_FNV_HASH_H_
   14 
   15 #ifndef _SYS_TYPES_H_
   16 #include <sys/types.h>
   17 #endif
   18 
   19 typedef u_int32_t Fnv32_t;
   20 typedef u_int64_t Fnv64_t;
   21 
   22 #define FNV1_32_INIT ((Fnv32_t) 33554467UL)
   23 #define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL)
   24 
   25 #define FNV_32_PRIME ((Fnv32_t) 0x01000193UL)
   26 #define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL)
   27 
   28 static __inline Fnv32_t
   29 fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
   30 {
   31         const u_int8_t *s = (const u_int8_t *)buf;
   32 
   33         while (len-- != 0) {
   34                 hval *= FNV_32_PRIME;
   35                 hval ^= *s++;
   36         }
   37         return hval;
   38 }
   39 
   40 static __inline Fnv32_t
   41 fnv_32_str(const char *str, Fnv32_t hval)
   42 {
   43         const u_int8_t *s = (const u_int8_t *)str;
   44         Fnv32_t c;
   45 
   46         while ((c = *s++) != 0) {
   47                 hval *= FNV_32_PRIME;
   48                 hval ^= c;
   49         }
   50         return hval;
   51 }
   52 
   53 static __inline Fnv64_t
   54 fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
   55 {
   56         const u_int8_t *s = (const u_int8_t *)buf;
   57 
   58         while (len-- != 0) {
   59                 hval *= FNV_64_PRIME;
   60                 hval ^= *s++;
   61         }
   62         return hval;
   63 }
   64 
   65 static __inline Fnv64_t
   66 fnv_64_str(const char *str, Fnv64_t hval)
   67 {
   68         const u_int8_t *s = (const u_int8_t *)str;
   69         u_register_t c;          /* 32 bit on i386, 64 bit on alpha,ia64 */
   70 
   71         while ((c = *s++) != 0) {
   72                 hval *= FNV_64_PRIME;
   73                 hval ^= c;
   74         }
   75         return hval;
   76 }
   77 
   78 #endif

Cache object: dedd91360e971ec087dca24ac81c767e


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