55-freebsd-126-freebsd-12freebsd-9.3
Last change
on this file since a438f52 was
a438f52,
checked in by Sebastian Huber <sebastian.huber@…>, on 04/18/16 at 12:46:23
|
fnv_hash.h: Disable unused 64-bit functions
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[a9153ec] | 1 | /*- |
---|
| 2 | * Fowler / Noll / Vo Hash (FNV Hash) |
---|
| 3 | * http://www.isthe.com/chongo/tech/comp/fnv/ |
---|
| 4 | * |
---|
| 5 | * This is an implementation of the algorithms posted above. |
---|
| 6 | * This file is placed in the public domain by Peter Wemm. |
---|
| 7 | * |
---|
| 8 | * $FreeBSD$ |
---|
| 9 | */ |
---|
[66659ff] | 10 | #ifndef _SYS_FNV_HASH_H_ |
---|
| 11 | #define _SYS_FNV_HASH_H_ |
---|
[a9153ec] | 12 | |
---|
| 13 | typedef u_int32_t Fnv32_t; |
---|
| 14 | typedef u_int64_t Fnv64_t; |
---|
| 15 | |
---|
| 16 | #define FNV1_32_INIT ((Fnv32_t) 33554467UL) |
---|
| 17 | #define FNV1_64_INIT ((Fnv64_t) 0xcbf29ce484222325ULL) |
---|
| 18 | |
---|
| 19 | #define FNV_32_PRIME ((Fnv32_t) 0x01000193UL) |
---|
| 20 | #define FNV_64_PRIME ((Fnv64_t) 0x100000001b3ULL) |
---|
| 21 | |
---|
| 22 | static __inline Fnv32_t |
---|
| 23 | fnv_32_buf(const void *buf, size_t len, Fnv32_t hval) |
---|
| 24 | { |
---|
| 25 | const u_int8_t *s = (const u_int8_t *)buf; |
---|
| 26 | |
---|
| 27 | while (len-- != 0) { |
---|
| 28 | hval *= FNV_32_PRIME; |
---|
| 29 | hval ^= *s++; |
---|
| 30 | } |
---|
| 31 | return hval; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | static __inline Fnv32_t |
---|
| 35 | fnv_32_str(const char *str, Fnv32_t hval) |
---|
| 36 | { |
---|
| 37 | const u_int8_t *s = (const u_int8_t *)str; |
---|
| 38 | Fnv32_t c; |
---|
| 39 | |
---|
| 40 | while ((c = *s++) != 0) { |
---|
| 41 | hval *= FNV_32_PRIME; |
---|
| 42 | hval ^= c; |
---|
| 43 | } |
---|
| 44 | return hval; |
---|
| 45 | } |
---|
| 46 | |
---|
[a438f52] | 47 | #ifndef __rtems__ |
---|
[a9153ec] | 48 | static __inline Fnv64_t |
---|
| 49 | fnv_64_buf(const void *buf, size_t len, Fnv64_t hval) |
---|
| 50 | { |
---|
| 51 | const u_int8_t *s = (const u_int8_t *)buf; |
---|
| 52 | |
---|
| 53 | while (len-- != 0) { |
---|
| 54 | hval *= FNV_64_PRIME; |
---|
| 55 | hval ^= *s++; |
---|
| 56 | } |
---|
| 57 | return hval; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | static __inline Fnv64_t |
---|
| 61 | fnv_64_str(const char *str, Fnv64_t hval) |
---|
| 62 | { |
---|
| 63 | const u_int8_t *s = (const u_int8_t *)str; |
---|
| 64 | u_register_t c; /* 32 bit on i386, 64 bit on alpha,ia64 */ |
---|
| 65 | |
---|
| 66 | while ((c = *s++) != 0) { |
---|
| 67 | hval *= FNV_64_PRIME; |
---|
| 68 | hval ^= c; |
---|
| 69 | } |
---|
| 70 | return hval; |
---|
| 71 | } |
---|
[a438f52] | 72 | #endif /* __rtems__ */ |
---|
[66659ff] | 73 | #endif /* _SYS_FNV_HASH_H_ */ |
---|
Note: See
TracBrowser
for help on using the repository browser.