Lumiera  0.pre.03
»edit your freedom«
hash-fnv.h
Go to the documentation of this file.
1 /*
2  HASH-FNV.h - FNV hash functions
3 
4  adapted by Lumiera.org
5  2010, 2011 Christian Thaeter <ct@pipapo.org>
6 
7  original by chongo <Landon Curt Noll> /\oo/\
8  http://www.isthe.com/chongo/
9 
10  Please do not copyright this code. This code is in the public domain.
11 
12  LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
13  INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
14  EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
15  CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
16  USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18  PERFORMANCE OF THIS SOFTWARE.
19 
20  Share and Enjoy! :-)
21 
22 */
23 
24 
31 #ifndef HASH_FNV_H
32 #define HASH_FNV_H
33 
34 #include <stdlib.h> /* for size_t */
35 #include <inttypes.h>
36 
37 #define HASH_FNV64_BASE ((uint64_t)14695981039346656037ULL)
38 #define HASH_FNV32_BASE ((uint32_t)2166136261UL)
39 
40 #define HASH_FNV64_PRIME ((uint64_t)1099511628211ULL)
41 #define HASH_FNV32_PRIME ((uint32_t)16777619UL)
42 
43 
51 uint64_t
52 hash_fnv64a_buf (const void *buf, size_t len, uint64_t hval);
53 
61 uint64_t
62 hash_fnv64a_strn (const char* str, size_t len, uint64_t hval);
63 
64 
72 uint32_t
73 hash_fnv32a_buf (const void *buf, size_t len, uint32_t hval);
74 
75 
83 uint32_t
84 hash_fnv32a_strn (const char* str, size_t len, uint32_t hval);
85 
86 
87 
95 uint64_t
96 hash_fnv64_xorfold (uint64_t hash, int bits);
97 
98 
106 uint32_t
107 hash_fnv32_xorfold (uint32_t hash, int bits);
108 
109 
117 uint64_t
118 hash_fnv64_retry (uint64_t hash, uint64_t limit);
119 
120 
128 uint32_t
129 hash_fnv32_retry (uint64_t hash, uint32_t limit);
130 
131 
132 
133 /*
134 PLANNED? 128 bit and 256bit hashes
135 128 bit FNV_prime = 288 + 28 + 0x3b = 309485009821345068724781371
136 
137 256 bit FNV_prime = 2168 + 28 + 0x63 = 374144419156711147060143317175368453031918731002211
138 
139 128 bit offset_basis = 144066263297769815596495629667062367629
140 
141 256 bit offset_basis =
142 100029257958052580907070968620625704837092796014241193945225284501741471925557
143 
144 */
145 
146 
147 
148 #endif
149 
150 /*
151 // Local Variables:
152 // mode: C
153 // c-file-style: "gnu"
154 // indent-tabs-mode: nil
155 // End:
156 */
uint64_t hash_fnv64a_buf(const void *buf, size_t len, uint64_t hval)
FNV-1a 64 bit hash over a buffer.
Definition: hash-fnv.c:38
uint32_t hash_fnv32a_buf(const void *buf, size_t len, uint32_t hval)
FNV-1a 32 bit hash over a buffer.
Definition: hash-fnv.c:54
uint64_t hash_fnv64_xorfold(uint64_t hash, int bits)
reduce a hash value to n bits.
Definition: hash-fnv.c:101
uint64_t hash_fnv64a_strn(const char *str, size_t len, uint64_t hval)
FNV-1a 64 bit hash over a zero terminated string.
Definition: hash-fnv.c:69
uint64_t hash_fnv64_retry(uint64_t hash, uint64_t limit)
reduce hash to be within 0 to limit-1.
Definition: hash-fnv.c:139
uint32_t hash_fnv32a_strn(const char *str, size_t len, uint32_t hval)
FNV-1a 32 bit hash over a zero terminated string.
Definition: hash-fnv.c:85
uint32_t hash_fnv32_retry(uint64_t hash, uint32_t limit)
reduce hash to be within 0 to limit-1.
Definition: hash-fnv.c:151
uint32_t hash_fnv32_xorfold(uint32_t hash, int bits)
reduce a hash value to n bits.
Definition: hash-fnv.c:120