3 * File name: ir/adt/eset.c
4 * Purpose: Datentyp: Vereinfachte Map (hash-map) zum Speichern von
5 * Zeigern/Adressen -> Zeigern/Adressen.
6 * Author: Hubert Schmid
10 * Copyright: (c) 2002 Universit�t Karlsruhe
11 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 /** A map which maps addresses to addresses. */
18 typedef struct pmap pmap;
23 typedef struct pmap_entry {
24 const void *key; /**< The key. */
25 void *value; /**< The value. */
29 /** Creates a new empty map. */
30 pmap *pmap_create(void);
32 /** Creates a new empty map with an initial number of slots. */
33 pmap *pmap_create_ex(int slots);
36 void pmap_destroy(pmap *);
39 * Inserts a pair (key,value) into the map. If an entry with key
40 * "key" already exists, its "value" is overwritten.
42 void pmap_insert(pmap *map, const void * key, void * value);
44 /** Checks if an entry with key "key" exists. */
45 int pmap_contains(pmap *map, const void * key);
47 /** Returns the key, value pair of "key". */
48 pmap_entry * pmap_find(pmap *map, const void * key);
50 /** Returns the value of "key". */
51 void * pmap_get(pmap *map, const void * key);
53 int pmap_count(pmap *map);
56 * Returns the first entry of a map if the map is not empty.
58 pmap_entry *pmap_first(pmap *map);
61 * Returns the next entry of a map or NULL if all entries were visited.
63 pmap_entry *pmap_next(pmap *);
65 #define pmap_foreach(pmap, curr) \
66 for (curr = pmap_first(pmap); curr; curr = pmap_next(pmap))
68 /** Breaks an iteration.
69 * Must be called, if a iteration ends before p_map_next() returns NULL.
71 void pmap_break(pmap *map);