Remove the questionable and unused functions find_value() and r_find_value().
[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 hashmap 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 /**
34  * @ingroup adt
35  * @defgroup pmap Pointer Map
36  * Pointer->Pointer hashmap
37  * @{
38  */
39
40 /**  A map which maps addresses to addresses. */
41 typedef struct pmap pmap;
42
43 /**
44  * A key, value pair.
45  */
46 typedef struct pmap_entry {
47         const void *key;    /**< The key. */
48         void *value;  /**< The value. */
49 } pmap_entry;
50
51
52 /** Creates a new empty map. */
53 FIRM_API pmap *pmap_create(void);
54
55 /** Creates a new empty map with an initial number of slots. */
56 FIRM_API pmap *pmap_create_ex(size_t slots);
57
58 /** Deletes a map. */
59 FIRM_API void pmap_destroy(pmap *);
60
61 /**
62  *  Inserts a pair (key,value) into the map. If an entry with key
63  * "key" already exists, its "value" is overwritten.
64  */
65 FIRM_API void pmap_insert(pmap *map, const void * key, void * value);
66
67 /** Checks if an entry with key "key" exists. */
68 FIRM_API int pmap_contains(pmap *map, const void * key);
69
70 /** Returns the key, value pair of "key". */
71 FIRM_API pmap_entry *pmap_find(pmap *map, const void * key);
72
73 /** Returns the value of "key". */
74 FIRM_API void * pmap_get(pmap *map, const void * key);
75
76 /** Return number of elements in the map */
77 FIRM_API size_t pmap_count(pmap *map);
78
79 /**
80  * Returns the first entry of a map if the map is not empty.
81  */
82 FIRM_API pmap_entry *pmap_first(pmap *map);
83
84 /**
85  * Returns the next entry of a map or NULL if all entries were visited.
86  */
87 FIRM_API pmap_entry *pmap_next(pmap *);
88
89 /**
90  * Iterate over all elements in the map setting curr to the current element.
91  */
92 #define foreach_pmap(pmap, curr) \
93         for (curr = pmap_first(pmap); curr; curr = pmap_next(pmap))
94
95 /** Breaks an iteration.
96  *  Must be called, if a iteration ends before p_map_next() returns NULL.
97  */
98 FIRM_API void pmap_break(pmap *map);
99
100 /**
101  * @}
102  */
103
104 #include "../end.h"
105
106 #endif