add documentation make target, fix docu bugs
[libfirm] / include / libfirm / adt / pmap.h
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       Simplified hashnap for pointer->pointer relations
23  * @author      Hubert Schmid
24  * @date        09.06.2002
25  */
26 #ifndef FIRM_ADT_PMAP_H
27 #define FIRM_ADT_PMAP_H
28
29 #include <stddef.h>
30
31 #include "../begin.h"
32
33 /**  A map which maps addresses to addresses. */
34 typedef struct pmap pmap;
35
36 /**
37  * A key, value pair.
38  */
39 typedef struct pmap_entry {
40         const void *key;    /**< The key. */
41         void *value;  /**< The value. */
42 } pmap_entry;
43
44
45 /** Creates a new empty map. */
46 FIRM_API pmap *pmap_create(void);
47
48 /** Creates a new empty map with an initial number of slots. */
49 FIRM_API pmap *pmap_create_ex(size_t slots);
50
51 /** Deletes a map. */
52 FIRM_API void pmap_destroy(pmap *);
53
54 /**
55  *  Inserts a pair (key,value) into the map. If an entry with key
56  * "key" already exists, its "value" is overwritten.
57  */
58 FIRM_API void pmap_insert(pmap *map, const void * key, void * value);
59
60 /** Checks if an entry with key "key" exists. */
61 FIRM_API int pmap_contains(pmap *map, const void * key);
62
63 /** Returns the key, value pair of "key". */
64 FIRM_API pmap_entry * pmap_find(pmap *map, const void * key);
65
66 /** Returns the value of "key". */
67 FIRM_API void * pmap_get(pmap *map, const void * key);
68
69 FIRM_API size_t pmap_count(pmap *map);
70
71 /**
72  * Returns the first entry of a map if the map is not empty.
73  */
74 FIRM_API pmap_entry *pmap_first(pmap *map);
75
76 /**
77  * Returns the next entry of a map or NULL if all entries were visited.
78  */
79 FIRM_API pmap_entry *pmap_next(pmap *);
80
81 #define foreach_pmap(pmap, curr) \
82         for (curr = pmap_first(pmap); curr; curr = pmap_next(pmap))
83
84 /** Breaks an iteration.
85  *  Must be called, if a iteration ends before p_map_next() returns NULL.
86  */
87 FIRM_API void pmap_break(pmap *map);
88
89 #include "../end.h"
90
91 #endif