libFirm
pmap.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5 
12 #ifndef FIRM_ADT_PMAP_H
13 #define FIRM_ADT_PMAP_H
14 
15 #include <stddef.h>
16 
17 #include "../begin.h"
18 
27 typedef struct pmap pmap;
28 
32 typedef struct {
33  void const *key;
34  void *value;
35 } pmap_entry;
36 
37 
39 FIRM_API pmap *pmap_create(void);
40 
42 FIRM_API pmap *pmap_create_ex(size_t slots);
43 
45 FIRM_API void pmap_destroy(pmap *map);
46 
51 FIRM_API void pmap_insert(pmap *map, void const *key, void *value);
52 
54 FIRM_API int pmap_contains(pmap const *map, void const *key);
55 
57 FIRM_API pmap_entry *pmap_find(pmap const *map, void const *key);
58 
60 FIRM_API void *pmap_get(pmap const *map, void const *key);
61 
67 #define pmap_get(type, map, key) ((type*)pmap_get(map, key))
68 
70 FIRM_API size_t pmap_count(pmap const *map);
71 
75 FIRM_API pmap_entry *pmap_first(pmap *map);
76 
80 FIRM_API pmap_entry *pmap_next(pmap *map);
81 
85 #define foreach_pmap(pmap, curr) \
86  for (pmap_entry *curr = pmap_first(pmap); curr; curr = pmap_next(pmap))
87 
90 FIRM_API void pmap_break(pmap *map);
91 
96 #include "../end.h"
97 
98 #endif
pmap_entry * pmap_first(pmap *map)
Returns the first entry of a map if the map is not empty.
void pmap_insert(pmap *map, void const *key, void *value)
Inserts a pair (key,value) into the map.
A key, value pair.
Definition: pmap.h:32
void pmap_break(pmap *map)
Breaks an iteration.
pmap_entry * pmap_find(pmap const *map, void const *key)
Returns the key, value pair of "key".
void * value
The value.
Definition: pmap.h:34
pmap_entry * pmap_next(pmap *map)
Returns the next entry of a map or NULL if all entries were visited.
struct pmap pmap
A map which maps addresses to addresses.
Definition: pmap.h:27
pmap * pmap_create_ex(size_t slots)
Creates a new empty map with an initial number of slots.
void pmap_destroy(pmap *map)
Deletes a map.
pmap * pmap_create(void)
Creates a new empty map.
int pmap_contains(pmap const *map, void const *key)
Checks if an entry with key "key" exists.
void const * key
The key.
Definition: pmap.h:33
size_t pmap_count(pmap const *map)
Return number of elements in the map.
#define pmap_get(type, map, key)
Returns the value of "key".
Definition: pmap.h:67