summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
11bef4b)
defined in hashptr.h
[r4469]
... or at the IPD, either. */
#ifdef NDEBUG
# define _ARR_DBGINF_DECL
... or at the IPD, either. */
#ifdef NDEBUG
# define _ARR_DBGINF_DECL
-# define _ARR_SET_DBGINF(descr, co, es) ((co), (es))
+# define _ARR_SET_DBGINF(descr, co, es)
#else
# define _ARR_DBGINF_DECL int cookie; size_t eltsize;
# define _ARR_SET_DBGINF(descr, co, es) \
#else
# define _ARR_DBGINF_DECL int cookie; size_t eltsize;
# define _ARR_SET_DBGINF(descr, co, es) \
- ((descr)->cookie = (co), (descr)->eltsize = (es))
+ ( (descr)->cookie = (co), (descr)->eltsize = (es) )
#include "eset.h"
#include "set.h"
#include "eset.h"
#include "set.h"
struct eset {
int dummy; /* dummy entry */
};
struct eset {
int dummy; /* dummy entry */
};
-static const int INITIAL_SLOTS = 64;
+#define INITIAL_SLOTS 64
+static int pcmp(const void *p1, const void *p2, size_t size) {
+ const void **q1 = (const void **)p1;
+ const void **q2 = (const void **)p2;
-static int pcmp(const void ** p1, const void ** p2, size_t size) {
- return *p1 != *p2;
}
eset * eset_create(void) {
}
eset * eset_create(void) {
- return (eset *) new_set((set_cmp_fun) pcmp, INITIAL_SLOTS);
+ return (eset *) new_set(pcmp, INITIAL_SLOTS);
-eset * eset_copy(eset * source) {
+eset * eset_copy(eset *source) {
eset * ret = eset_create();
void * p;
for (p = eset_first(source); p; p = eset_next(source)) {
eset * ret = eset_create();
void * p;
for (p = eset_first(source); p; p = eset_next(source)) {
-void eset_destroy(eset * s) {
- del_set((set *) s);
+void eset_destroy(eset *s) {
+ del_set((set *)s);
-void eset_insert(eset * s, void * p) {
+void eset_insert(eset *s, void *p) {
if (!eset_contains(s, p)) {
if (!eset_contains(s, p)) {
- set_insert((set *) s, &p, sizeof(void *), (unsigned) p);
+ set_insert((set *)s, &p, sizeof(p), HASH_PTR(p));
-bool eset_contains(eset * s, void * p) {
- return set_find((set *) s, &p, sizeof(void *), (unsigned) p) != NULL;
+bool eset_contains(eset *s, void *p) {
+ return set_find((set *)s, &p, sizeof(p), HASH_PTR(p)) != NULL;
-void * eset_first(eset * s) {
+void * eset_first(eset *s) {
void * p = set_first((set *) s);
void * p = set_first((set *) s);
- return p == NULL ? NULL : *((void * *) p);
+ return p == NULL ? NULL : *((void **)p);
}
void * eset_next(eset *s) {
}
void * eset_next(eset *s) {
- void * p = set_next((set *) s);
- return p == NULL ? NULL : *((void * *) p);
+ void *p = set_next((set *) s);
+ return p == NULL ? NULL : *((void **)p);
-void eset_insert_all(eset * target, eset * source) {
- void * p;
+void eset_insert_all(eset *target, eset *source) {
+ void *p;
for (p = eset_first(source); p; p = eset_next(source)) {
eset_insert(target, p);
}
for (p = eset_first(source); p; p = eset_next(source)) {
eset_insert(target, p);
}
--- /dev/null
+/*
+ * Project: libFIRM
+ * File name: ir/adt/hashptr.h
+ * Purpose: Hash function for pointers
+ * Author: Michael Beck, Sebastian Hack
+ * Modified by:
+ * Created: 2004
+ * CVS-ID: $Id$
+ * Copyright: (C) 2004 University of Karlsruhe
+ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ */
+#ifndef __HASHPTR_H__
+#define __HASHPTR_H__
+
+/**
+ * hash a pointer value: Pointer addresses are mostly aligned to 4
+ * or 8 bytes. So we remove the lowest 3 bits
+ */
+#define HASHPTR(ptr) (((char *)ptr - (char *)0) >> 3)
+
+#endif /* __HASHPTR_H__ */
#include <assert.h>
#include "set.h"
#include <assert.h>
#include "set.h"
-static const int INITIAL_SLOTS = 64;
+#define INITIAL_SLOTS 64
-static int pmap_entry_cmp(const pmap_entry * entry1, const pmap_entry * entry2, size_t size) {
- return entry1->key == entry2->key ? 0 : 1;
+static int pmap_entry_cmp(const void *p1, const void *p2, size_t size) {
+ const pmap_entry *entry1 = p1;
+ const pmap_entry *entry2 = p2;
+
+ return entry1->key != entry2->key;
-pmap * pmap_create(void) {
- return (pmap *) new_set((set_cmp_fun) pmap_entry_cmp, INITIAL_SLOTS);
+pmap *pmap_create(void) {
+ return (pmap *)new_set(pmap_entry_cmp, INITIAL_SLOTS);
-void pmap_destroy(pmap * map) {
- del_set((set *) map);
+void pmap_destroy(pmap *map) {
+ del_set((set *)map);
-void pmap_insert(pmap * map, void * key, void * value) {
+void pmap_insert(pmap *map, void *key, void *value) {
if (pmap_contains(map, key)) {
pmap_entry * entry = pmap_find(map, key);
entry->value = value;
if (pmap_contains(map, key)) {
pmap_entry * entry = pmap_find(map, key);
entry->value = value;
pmap_entry entry;
entry.key = key;
entry.value = value;
pmap_entry entry;
entry.key = key;
entry.value = value;
- set_insert((set *) map, &entry, sizeof(pmap_entry), (unsigned) key);
+ set_insert((set *)map, &entry, sizeof(pmap_entry), HASH_PTR(key));
-bool pmap_contains(pmap * map, void * key) {
- return set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key) != NULL;
+bool pmap_contains(pmap *map, void *key) {
+ return set_find((set *)map, &key, sizeof(pmap_entry), HASH_PTR(key)) != NULL;
-pmap_entry * pmap_find(pmap * map, void * key) {
- return (pmap_entry *) set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key);
+pmap_entry * pmap_find(pmap *map, void *key) {
+ return (pmap_entry *)set_find((set *)map, &key, sizeof(pmap_entry), HASH_PTR(key));
-void * pmap_get(pmap * map, void * key) {
+void * pmap_get(pmap *map, void *key) {
pmap_entry * entry = pmap_find(map, key);
return entry == NULL ? NULL : entry->value;
}
pmap_entry * entry = pmap_find(map, key);
return entry == NULL ? NULL : entry->value;
}
-pmap_entry * pmap_first(pmap * map) {
- return (pmap_entry *) set_first((set *) map);
+pmap_entry *pmap_first(pmap *map) {
+ return (pmap_entry *) set_first((set *)map);
-pmap_entry * pmap_next(pmap * map) {
- return (pmap_entry *) set_next((set *) map);
+pmap_entry *pmap_next(pmap *map) {
+ return (pmap_entry *) set_next((set *)map);