3 * File name: ir/adt/hashptr.h
4 * Purpose: Hash function for pointers
5 * Author: Michael Beck, Sebastian Hack
9 * Copyright: (C) 2004 University of Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 #include "firm_config.h"
17 #define _FIRM_FNV_OFFSET_BASIS 2166136261U
18 #define _FIRM_FNV_FNV_PRIME 16777619U
20 static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes)
23 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
25 for(i = 0; i < bytes; ++i) {
26 hash *= _FIRM_FNV_FNV_PRIME;
34 * hash a pointer value: Pointer addresses are mostly aligned to 4
35 * or 8 bytes. So we remove the lowest 3 bits
37 #define HASH_PTR(ptr) (((char *) (ptr) - (char *)0) >> 3)
41 * @param str The string (can be const).
42 * @param len The length of the string.
43 * @return A hash value for the string.
45 #define HASH_STR(str,len) firm_fnv_hash((const unsigned char *) (str), (len))
47 #endif /* __HASHPTR_H__ */