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