diff options
author | Marvin Borner | 2023-05-31 13:21:24 +0200 |
---|---|---|
committer | Marvin Borner | 2023-05-31 13:21:24 +0200 |
commit | 931df5e774eebb098c5d7be93937d2b2f12b86ac (patch) | |
tree | ec60efb28549b4f83a42bbb41a2c702c0565e3b5 /src/map.c | |
parent | d347a2fa6483059e6397d2b70e82aa657f1144d2 (diff) |
Added parent hashmaps
Diffstat (limited to 'src/map.c')
-rw-r--r-- | src/map.c | 35 |
1 files changed, 20 insertions, 15 deletions
@@ -15,17 +15,22 @@ static void hashmap_free_term(void *item) free(term); } -struct term *map_get(hash_t hash) +struct hashmap *map_all_terms(void) { - struct term **handle = hashmap_get(all_terms, hash); + return all_terms; +} + +struct term *map_get(struct hashmap *map, hash_t hash) +{ + struct term **handle = hashmap_get(map, hash); if (!handle) return 0; return *handle; } -void map_set(struct term *term, hash_t hash) +void map_set(struct hashmap *map, struct term *term, hash_t hash) { - hashmap_set(all_terms, &term, hash); + hashmap_set(map, &term, hash); } void map_initialize(void) @@ -33,22 +38,22 @@ void map_initialize(void) all_terms = hashmap_new(sizeof(struct term *), 0, hashmap_free_term); } -void map_delete(struct term *term) +void map_delete(struct hashmap *map, struct term *term) { - hashmap_delete(all_terms, term->hash); + hashmap_delete(map, term->hash); } -void map_destroy(void) +void map_destroy(struct hashmap *map) { - hashmap_free(all_terms); + hashmap_free(map); } -void map_dump(void) +void map_dump(struct hashmap *map) { fprintf(stderr, "\n---\nMap dump:\n"); size_t iter = 0; void *iter_val; - while (hashmap_iter(all_terms, &iter, &iter_val)) { + while (hashmap_iter(map, &iter, &iter_val)) { struct term *term = *(struct term **)iter_val; fprintf(stderr, "%d ", term->type); term_print(term); @@ -57,17 +62,17 @@ void map_dump(void) fprintf(stderr, "---\n\n"); } -struct pqueue *map_to_pqueue(pqueue_cmp_pri_f cmppri, pqueue_get_pri_f getpri, - pqueue_set_pos_f setpos) +struct pqueue *map_to_pqueue(struct hashmap *map, pqueue_cmp_pri_f cmppri, + pqueue_get_pri_f getpri, pqueue_set_pos_f setpos) { - size_t size = hashmap_count(all_terms) + 42; + size_t size = hashmap_count(map) + 42; struct pqueue *queue = pqueue_init(size, cmppri, getpri, setpos); size_t iter = 0; void *iter_val; - while (hashmap_iter(all_terms, &iter, &iter_val)) { + while (hashmap_iter(map, &iter, &iter_val)) { struct term *term = *(struct term **)iter_val; - if (term->type == APP) { + if (term->type == APP && term->u.app.lhs->type == ABS) { pqueue_insert(queue, term); } } |