X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=map%2Fmap.c;h=fcd9f830c438240568543865a96f3ac0f9fc2f77;hp=c4749b3cfc21f80eecfc43147f0000ee26ca52fd;hb=329b5ab58cde015f4faec1879d3106f635294dd6;hpb=f1098084dd54496a61f9a254541190df77edd166 diff --git a/map/map.c b/map/map.c index c4749b3..fcd9f83 100644 --- a/map/map.c +++ b/map/map.c @@ -6,20 +6,23 @@ */ #include "common.h" -#include "mlocal.h" -#include "mem.h" #include "map.h" +#include "mem.h" struct map { const map_impl_t *impl; void *data; }; -map_t *map_alloc (map_type_t map_type, cmp_fun_t cmp_fun, hash_fun_t hash_fun, clone_fun_t clone_fun) { - const map_impl_t *map_impl = map_type; +struct map_iter { + const map_impl_t *impl; + void *state; +}; + +map_t *map_alloc (const map_impl_t *map_impl, const datatype_t *key_type) { map_t *map = nbd_malloc(sizeof(map_t)); map->impl = map_impl; - map->data = map->impl->alloc(cmp_fun, hash_fun, clone_fun); + map->data = map->impl->alloc(key_type); return map; } @@ -58,3 +61,19 @@ uint64_t map_replace(map_t *map, void *key, uint64_t new_val) { uint64_t map_remove (map_t *map, void *key) { return map->impl->remove(map->data, key); } + +map_iter_t * map_iter_begin (map_t *map, void *key) { + map_iter_t *iter = nbd_malloc(sizeof(map_iter_t)); + iter->impl = map->impl; + iter->state = map->impl->iter_begin(map->data, key); + return iter; +} + +uint64_t map_iter_next (map_iter_t *iter, void **key_ptr) { + return iter->impl->iter_next(iter->state, key_ptr); +} + +void map_iter_free (map_iter_t *iter) { + iter->impl->iter_free(iter->state); + nbd_free(iter); +}