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.
21 int dummy; /* dummy entry */
25 static const int INITIAL_SLOTS = 64;
28 static int pmap_entry_cmp(const pmap_entry * entry1, const pmap_entry * entry2, size_t size) {
29 return entry1->key == entry2->key ? 0 : 1;
33 pmap * pmap_create(void) {
34 return (pmap *) new_set((set_cmp_fun) pmap_entry_cmp, INITIAL_SLOTS);
38 void pmap_destroy(pmap * map) {
43 void pmap_insert(pmap * map, void * key, void * value) {
44 if (pmap_contains(map, key)) {
45 pmap_entry * entry = pmap_find(map, key);
51 set_insert((set *) map, &entry, sizeof(pmap_entry), (unsigned) key);
56 bool pmap_contains(pmap * map, void * key) {
57 return set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key) != NULL;
61 pmap_entry * pmap_find(pmap * map, void * key) {
62 return (pmap_entry *) set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key);
66 void * pmap_get(pmap * map, void * key) {
67 pmap_entry * entry = pmap_find(map, key);
68 return entry == NULL ? NULL : entry->value;
72 pmap_entry * pmap_first(pmap * map) {
73 return (pmap_entry *) set_first((set *) map);
77 pmap_entry * pmap_next(pmap * map) {
78 return (pmap_entry *) set_next((set *) map);