X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=include%2Flibfirm%2Fadt%2Fhashptr.h;h=e868d60cda82db299532f886bbde11450bfc8055;hb=dd312230a8b2bd294780d451b26976599cec83dd;hp=043ba5b63c1ed916288988df16099d20a0d50509;hpb=435253f3a8766fec2ac2adf559bb10cfcb5d36f4;p=libfirm diff --git a/include/libfirm/adt/hashptr.h b/include/libfirm/adt/hashptr.h index 043ba5b63..e868d60cd 100644 --- a/include/libfirm/adt/hashptr.h +++ b/include/libfirm/adt/hashptr.h @@ -27,13 +27,13 @@ #define FIRM_ADT_HASHPTR_H #include "firm_config.h" +#include "compiler.h" #define _FIRM_FNV_OFFSET_BASIS 2166136261U #define _FIRM_FNV_FNV_PRIME 16777619U /* Computing x * _FIRM_FNV_FNV_PRIME */ -#define _FIRM_FNV_TIMES_PRIME(x) \ - (((x) << 24) + ((x) << 8) + ((x) << 7) + ((x) << 4) + ((x) << 1) + 1) +#define _FIRM_FNV_TIMES_PRIME(x) ((x) * _FIRM_FNV_FNV_PRIME) static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes) { @@ -48,11 +48,24 @@ static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes) return hash; } +static INLINE unsigned firm_fnv_hash_str(const char *data) +{ + unsigned i; + unsigned hash = _FIRM_FNV_OFFSET_BASIS; + + for(i = 0; data[i] != '\0'; ++i) { + hash = _FIRM_FNV_TIMES_PRIME(hash); + hash ^= data[i]; + } + + return hash; +} + /** * hash a pointer value: Pointer addresses are mostly aligned to 4 * or 8 bytes. So we remove the lowest 3 bits */ -#define HASH_PTR(ptr) (((char *) (ptr) - (char *)0) >> 3) +#define HASH_PTR(ptr) ((unsigned)(((char *) (ptr) - (char *)0) >> 3)) /** * Hash a string.