1 /* 2 * fnv - Fowler/Noll/Vo- hash code 3 * 4 * @(#) $Revision: 1028 $ 5 * @(#) $Id: fnv.h 1028 2007-04-02 06:21:19Z oetiker $ 6 * @(#) $Source$ 7 * 8 *** 9 * 10 * Fowler/Noll/Vo- hash 11 * 12 * The basis of this hash algorithm was taken from an idea sent 13 * as reviewer comments to the IEEE POSIX P1003.2 committee by: 14 * 15 * Phong Vo (http://www.research.att.com/info/kpv/) 16 * Glenn Fowler (http://www.research.att.com/~gsf/) 17 * 18 * In a subsequent ballot round: 19 * 20 * Landon Curt Noll (http://reality.sgi.com/chongo/) 21 * 22 * improved on their algorithm. Some people tried this hash 23 * and found that it worked rather well. In an EMail message 24 * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash. 25 * 26 * FNV hashes are architected to be fast while maintaining a low 27 * collision rate. The FNV speed allows one to quickly hash lots 28 * of data while maintaining a reasonable collision rate. See: 29 * 30 * http://reality.sgi.com/chongo/tech/comp/fnv/ 31 * 32 * for more details as well as other forms of the FNV hash. 33 * 34 *** 35 * 36 * NOTE: The FNV-0 historic hash is not recommended. One should use 37 * the FNV-1 hash instead. 38 * 39 * To use the 32 bit FNV-0 historic hash, pass FNV0_32_INIT as the 40 * Fnv32_t hashval argument to fnv_32_buf() or fnv_32_str(). 41 * 42 * To use the 64 bit FNV-0 historic hash, pass FNV0_64_INIT as the 43 * Fnv64_t hashval argument to fnv_64_buf() or fnv_64_str(). 44 * 45 * To use the recommended 32 bit FNV-1 hash, pass FNV1_32_INIT as the 46 * Fnv32_t hashval argument to fnv_32_buf() or fnv_32_str(). 47 * 48 * To use the recommended 64 bit FNV-1 hash, pass FNV1_64_INIT as the 49 * Fnv64_t hashval argument to fnv_64_buf() or fnv_64_str(). 50 * 51 *** 52 * 53 * Please do not copyright this code. This code is in the public domain. 54 * 55 * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 56 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO 57 * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR 58 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 59 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 60 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 61 * PERFORMANCE OF THIS SOFTWARE. 62 * 63 * By: 64 * chongo <Landon Curt Noll> /\oo/\ 65 * http://reality.sgi.com/chongo/ 66 * EMail: chongo_fnv at prime dot engr dot sgi dot com 67 * 68 * Share and Enjoy! :-) 69 */ 70 71 #if !defined(__FNV_H__) 72 #define __FNV_H__ 73 74 75 /* 76 * 32 bit FNV-0 hash type 77 */ 78 typedef unsigned long Fnv32_t; 79 80 81 /* 82 * 32 bit FNV-0 zero initial basis 83 * 84 * This historic hash is not recommended. One should use 85 * the FNV-1 hash and inital basis instead. 86 */ 87 #define FNV0_32_INIT ((Fnv32_t)0) 88 89 90 /* 91 * 32 bit FNV-1 non-zero initial basis 92 * 93 * The FNV-1 initial basis is the FNV-0 hash of the following 32 octets: 94 * 95 * chongo <Landon Curt Noll> /\../\ 96 * 97 * Note that the \'s above are not back-slashing escape characters. 98 * They are literal ASCII backslash 0x5c characters. 99 */ 100 #define FNV1_32_INIT ((Fnv32_t)0x811c9dc5) 101 102 Fnv32_t fnv_32_buf(const void *, size_t, Fnv32_t); 103 104 Fnv32_t fnv_32_str(const char *, Fnv32_t ); 105 106 unsigned long FnvHash(const char *); 107 108 #endif /* __FNV_H__ */ 109