From 89ad3fb09bc48bb77aa1dd16af52720aff51ca68 Mon Sep 17 00:00:00 2001 From: hunt Date: Wed, 14 Sep 2005 21:13:55 +0000 Subject: 2005-09-14 Martin Hunt * map.c (_stp_map_clear): New function. CLears a map but does not free it. --- runtime/map.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'runtime/map.c') diff --git a/runtime/map.c b/runtime/map.c index 179f5098..9d83595d 100644 --- a/runtime/map.c +++ b/runtime/map.c @@ -262,6 +262,35 @@ struct map_node *_stp_map_iter(MAP map, struct map_node *m) return (struct map_node *)m->lnode.next; } +/** Clears all the elements in a map. + * @param map + */ + +void _stp_map_clear(MAP map) +{ + struct map_node *m; + + if (map == NULL) + return; + + map->create = 0; + map->key = NULL; + map->num = 0; + + while (!list_empty(&map->head)) { + m = (struct map_node *)map->head.next; + + /* remove node from old hash list */ + hlist_del_init(&m->hnode); + + /* remove from entry list */ + list_del(&m->lnode); + + /* add to free pool */ + list_add(&m->lnode, &map->pool); + } +} + /** Deletes a map. * Deletes a map, freeing all memory in all elements. Normally done only when the module exits. * @param map -- cgit