converted comments to doxygen
[libfirm] / ir / adt / pmap.c
1 /* -------------------------------------------------------------------
2  * $Id$
3  * -------------------------------------------------------------------
4  * Datentyp: Vereinfachte Map (hash-map) zum Speichern von
5  * Zeigern/Adressen -> Zeigern/Adressen.
6  *
7  * Erstellt: Hubert Schmid, 09.06.2002
8  * ---------------------------------------------------------------- */
9
10
11 #include "pmap.h"
12
13 #include <assert.h>
14 #include "set.h"
15
16
17 struct pmap {
18   int dummy; /* dummy entry */
19 };
20
21
22 static const int INITIAL_SLOTS = 64;
23
24
25 static int pmap_entry_cmp(const pmap_entry * entry1, const pmap_entry * entry2, size_t size) {
26   return entry1->key == entry2->key ? 0 : 1;
27 }
28
29
30 pmap * pmap_create(void) {
31   return (pmap *) new_set((set_cmp_fun) pmap_entry_cmp, INITIAL_SLOTS);
32 }
33
34
35 void pmap_destroy(pmap * map) {
36   del_set((set *) map);
37 }
38
39
40 void pmap_insert(pmap * map, void * key, void * value) {
41   if (pmap_contains(map, key)) {
42     pmap_entry * entry = pmap_find(map, key);
43     entry->value = value;
44   } else {
45     pmap_entry entry;
46     entry.key = key;
47     entry.value = value;
48     set_insert((set *) map, &entry, sizeof(pmap_entry), (unsigned) key);
49   }
50 }
51
52
53 bool pmap_contains(pmap * map, void * key) {
54   return set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key) != NULL;
55 }
56
57
58 pmap_entry * pmap_find(pmap * map, void * key) {
59   return (pmap_entry *) set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key);
60 }
61
62
63 void * pmap_get(pmap * map, void * key) {
64   pmap_entry * entry = pmap_find(map, key);
65   return entry == NULL ? NULL : entry->value;
66 }
67
68
69 pmap_entry * pmap_first(pmap * map) {
70   return (pmap_entry *) set_first((set *) map);
71 }
72
73
74 pmap_entry * pmap_next(pmap * map) {
75   return (pmap_entry *) set_next((set *) map);
76 }