Import vtfontcvt & console bitmap fonts
[unleashed.git] / bin / vtfontcvt / fnv_hash.h
blob9efae029502e76b1086277ec183f7253602f7934
1 /*
2 * Fowler / Noll / Vo Hash (FNV Hash)
3 * http://www.isthe.com/chongo/tech/comp/fnv/
5 * This is an implementation of the algorithms posted above.
6 * This file is placed in the public domain by Peter Wemm.
7 */
8 #ifndef _SYS_FNV_HASH_H_
9 #define _SYS_FNV_HASH_H_
11 typedef uint32_t Fnv32_t;
12 typedef uint64_t Fnv64_t;
14 #define FNV1_32_INIT ((Fnv32_t)33554467UL)
15 #define FNV1_64_INIT ((Fnv64_t)0xcbf29ce484222325ULL)
17 #define FNV_32_PRIME ((Fnv32_t)0x01000193UL)
18 #define FNV_64_PRIME ((Fnv64_t)0x100000001b3ULL)
20 static __inline Fnv32_t
21 fnv_32_buf(const void *buf, size_t len, Fnv32_t hval)
23 const uint8_t *s = (const uint8_t *)buf;
25 while (len-- != 0) {
26 hval *= FNV_32_PRIME;
27 hval ^= *s++;
29 return (hval);
32 static __inline Fnv32_t
33 fnv_32_str(const char *str, Fnv32_t hval)
35 const uint8_t *s = (const uint8_t *)str;
36 Fnv32_t c;
38 while ((c = *s++) != 0) {
39 hval *= FNV_32_PRIME;
40 hval ^= c;
42 return (hval);
45 static __inline Fnv64_t
46 fnv_64_buf(const void *buf, size_t len, Fnv64_t hval)
48 const uint8_t *s = (const uint8_t *)buf;
50 while (len-- != 0) {
51 hval *= FNV_64_PRIME;
52 hval ^= *s++;
54 return (hval);
57 static __inline Fnv64_t
58 fnv_64_str(const char *str, Fnv64_t hval)
60 const uint8_t *s = (const uint8_t *)str;
61 uint32_t c;
63 while ((c = *s++) != 0) {
64 hval *= FNV_64_PRIME;
65 hval ^= c;
67 return (hval);
69 #endif /* _SYS_FNV_HASH_H_ */