becopyheur2: Remove unnecessary indirection.
[libfirm] / include / libfirm / adt / pmap.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Simplified hashmap for pointer->pointer relations
9  * @author      Hubert Schmid
10  * @date        09.06.2002
11  */
12 #ifndef FIRM_ADT_PMAP_H
13 #define FIRM_ADT_PMAP_H
14
15 #include <stddef.h>
16
17 #include "../begin.h"
18
19 /**
20  * @ingroup adt
21  * @defgroup pmap Pointer Map
22  * Pointer->Pointer hashmap
23  * @{
24  */
25
26 /**  A map which maps addresses to addresses. */
27 typedef struct pmap pmap;
28
29 /**
30  * A key, value pair.
31  */
32 typedef struct pmap_entry {
33         const void *key;    /**< The key. */
34         void *value;  /**< The value. */
35 } pmap_entry;
36
37
38 /** Creates a new empty map. */
39 FIRM_API pmap *pmap_create(void);
40
41 /** Creates a new empty map with an initial number of slots. */
42 FIRM_API pmap *pmap_create_ex(size_t slots);
43
44 /** Deletes a map. */
45 FIRM_API void pmap_destroy(pmap *);
46
47 /**
48  *  Inserts a pair (key,value) into the map. If an entry with key
49  * "key" already exists, its "value" is overwritten.
50  */
51 FIRM_API void pmap_insert(pmap *map, const void * key, void * value);
52
53 /** Checks if an entry with key "key" exists. */
54 FIRM_API int pmap_contains(pmap *map, const void * key);
55
56 /** Returns the key, value pair of "key". */
57 FIRM_API pmap_entry *pmap_find(pmap *map, const void * key);
58
59 /** Returns the value of "key". */
60 FIRM_API void * pmap_get(pmap *map, const void * key);
61
62 /**
63  * Returns the value of "key".
64  * This is a wrapper for pmap_get(map, key); It allows to express the
65  * intended type of the set elements (instead of weakly typed void*).
66  */
67 #define pmap_get(type, map, key) ((type*)pmap_get(map, key))
68
69 /** Return number of elements in the map */
70 FIRM_API size_t pmap_count(pmap *map);
71
72 /**
73  * Returns the first entry of a map if the map is not empty.
74  */
75 FIRM_API pmap_entry *pmap_first(pmap *map);
76
77 /**
78  * Returns the next entry of a map or NULL if all entries were visited.
79  */
80 FIRM_API pmap_entry *pmap_next(pmap *);
81
82 /**
83  * Iterate over all elements in the map setting curr to the current element.
84  */
85 #define foreach_pmap(pmap, curr) \
86         for (curr = pmap_first(pmap); curr; curr = pmap_next(pmap))
87
88 /** Breaks an iteration.
89  *  Must be called, if a iteration ends before p_map_next() returns NULL.
90  */
91 FIRM_API void pmap_break(pmap *map);
92
93 /**
94  * @}
95  */
96
97 #include "../end.h"
98
99 #endif