2 * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Simplified hashnap for pointer->pointer relations
23 * @author Hubert Schmid
27 #ifndef FIRM_ADT_PMAP_H
28 #define FIRM_ADT_PMAP_H
34 /** A map which maps addresses to addresses. */
35 typedef struct pmap pmap;
40 typedef struct pmap_entry {
41 const void *key; /**< The key. */
42 void *value; /**< The value. */
46 /** Creates a new empty map. */
47 FIRM_API pmap *pmap_create(void);
49 /** Creates a new empty map with an initial number of slots. */
50 FIRM_API pmap *pmap_create_ex(size_t slots);
53 FIRM_API void pmap_destroy(pmap *);
56 * Inserts a pair (key,value) into the map. If an entry with key
57 * "key" already exists, its "value" is overwritten.
59 FIRM_API void pmap_insert(pmap *map, const void * key, void * value);
61 /** Checks if an entry with key "key" exists. */
62 FIRM_API int pmap_contains(pmap *map, const void * key);
64 /** Returns the key, value pair of "key". */
65 FIRM_API pmap_entry * pmap_find(pmap *map, const void * key);
67 /** Returns the value of "key". */
68 FIRM_API void * pmap_get(pmap *map, const void * key);
70 FIRM_API size_t pmap_count(pmap *map);
73 * Returns the first entry of a map if the map is not empty.
75 FIRM_API pmap_entry *pmap_first(pmap *map);
78 * Returns the next entry of a map or NULL if all entries were visited.
80 FIRM_API pmap_entry *pmap_next(pmap *);
82 #define foreach_pmap(pmap, curr) \
83 for (curr = pmap_first(pmap); curr; curr = pmap_next(pmap))
85 /** Breaks an iteration.
86 * Must be called, if a iteration ends before p_map_next() returns NULL.
88 FIRM_API void pmap_break(pmap *map);