xref: /titanic_50/usr/src/lib/libast/common/include/fnv.h (revision bcd6185e1c81586e6929dc444ef32123263dd51c)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * Landon Kurt Knoll
26  * Phong Vo
27  *
28  * FNV-1 linear congruent checksum/hash/PRNG
29  * see http://www.isthe.com/chongo/tech/comp/fnv/
30  */
31 
32 #ifndef _FNV_H
33 #define _FNV_H
34 
35 #include <ast_common.h>
36 
37 #define FNV_INIT	0x811c9dc5L
38 #define FNV_MULT	0x01000193L
39 
40 #define FNVINIT(h)	(h = FNV_INIT)
41 #define FNVPART(h,c)	(h = (h) * FNV_MULT ^ (c))
42 #define FNVSUM(h,s,n)	do { \
43 			register size_t _i_ = 0; \
44 			while (_i_ < n) \
45 				FNVPART(h, ((unsigned char*)s)[_i_++]); \
46 			} while (0)
47 
48 #if _typ_int64_t
49 
50 #ifdef _ast_LL
51 
52 #define FNV_INIT64	0xcbf29ce484222325LL
53 #define FNV_MULT64	0x00000100000001b3LL
54 
55 #else
56 
57 #define FNV_INIT64	((int64_t)0xcbf29ce484222325)
58 #define FNV_MULT64	((int64_t)0x00000100000001b3)
59 
60 #endif
61 
62 #define FNVINIT64(h)	(h = FNV_INIT64)
63 #define FNVPART64(h,c)	(h = (h) * FNV_MULT64 ^ (c))
64 #define FNVSUM64(h,s,n)	do { \
65 			register int _i_ = 0; \
66 			while (_i_ < n) \
67 				FNVPART64(h, ((unsigned char*)s)[_i_++]); \
68 			} while (0)
69 
70 #endif
71 
72 #endif
73