1 /* -------------------------------------------------------------------
3 * -------------------------------------------------------------------
4 * Datentyp: Vereinfachte Map (hash-map) zum Speichern von
5 * Zeigern/Adressen -> Zeigern/Adressen.
7 * Erstellt: Hubert Schmid, 09.06.2002
8 * ---------------------------------------------------------------- */
18 int dummy; /* dummy entry */
22 static const int INITIAL_SLOTS = 64;
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;
30 pmap * pmap_create(void) {
31 return (pmap *) new_set((set_cmp_fun) pmap_entry_cmp, INITIAL_SLOTS);
35 void pmap_destroy(pmap * map) {
40 void pmap_insert(pmap * map, void * key, void * value) {
41 if (pmap_contains(map, key)) {
42 pmap_entry * entry = pmap_find(map, key);
48 set_insert((set *) map, &entry, sizeof(pmap_entry), (unsigned) key);
53 bool pmap_contains(pmap * map, void * key) {
54 return set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key) != NULL;
58 pmap_entry * pmap_find(pmap * map, void * key) {
59 return (pmap_entry *) set_find((set *) map, &key, sizeof(pmap_entry), (unsigned) key);
63 void * pmap_get(pmap * map, void * key) {
64 pmap_entry * entry = pmap_find(map, key);
65 return entry == NULL ? NULL : entry->value;
69 pmap_entry * pmap_first(pmap * map) {
70 return (pmap_entry *) set_first((set *) map);
74 pmap_entry * pmap_next(pmap * map) {
75 return (pmap_entry *) set_next((set *) map);