11 #ifndef FIRM_ADT_HASHPTR_H 12 #define FIRM_ADT_HASHPTR_H 26 #define _FIRM_FNV_OFFSET_BASIS 2166136261U 27 #define _FIRM_FNV_FNV_PRIME 16777619U 34 static inline unsigned hash_data(
unsigned char const *data,
size_t bytes)
36 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
37 for (
size_t i = 0; i < bytes; ++i) {
38 hash *= _FIRM_FNV_FNV_PRIME;
50 static inline unsigned hash_str(
char const *
const str)
52 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
53 for(
char const *c = str; *c !=
'\0'; ++c) {
54 hash *= _FIRM_FNV_FNV_PRIME;
66 static inline unsigned hash_ptr(
void const *
const ptr)
68 return (
unsigned)(((
char const *)ptr - (
char const *)0) >> 3);
77 static inline unsigned hash_combine(
unsigned const x,
unsigned const y)
79 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
80 hash *= _FIRM_FNV_FNV_PRIME;
82 hash *= _FIRM_FNV_FNV_PRIME;
static unsigned hash_combine(unsigned const x, unsigned const y)
Combines 2 hash values.
static unsigned hash_ptr(void const *const ptr)
Returns a hash value for a pointer.
static unsigned hash_str(char const *const str)
Returns a hash value for a string.
static unsigned hash_data(unsigned char const *data, size_t bytes)
Returns a hash value for a block of data.